flipperzero-firmware/applications/services/desktop/animations/views/one_shot_animation_view.c

131 lines
3.5 KiB
C
Raw Normal View History

[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965) * Desktop: cleanup headers * Get loader pubsub via record * [FL-2183] Dolphin refactoring 2022.01 * Restruct animations assets structure * Rename assets * Cleanup headers * Update Recording animation * Add BadBattery animation * Provide loader's pubsub via record * Fix load/unload animations * Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin. * Sync internal meta.txt and manifest.txt * Reorder, rename dolphin assets * Split essential generated assets * Add ReadMe for dolphin assets * Separate essential blocking animations * Scripts: full dolphin validation before packaging * Assets, Scripts: dolphin external resources packer * Github: update codeowners * Scripts: proper slots handling in dolphin animation meta * Scripts: correct frames enumeration and fix compiled assets. * [FL-2209] Add Dolphin Deeds points and many more * Remove excess frame_rate * Change dolphin assets directory * Scripts: add internal resource support to dolphin compiler * Scripts: add internal assets generation, renaming * Scripts: correct assert, renaming * Code cleanup, documentation, fixes * Update Levelup animations * Rename essential -> blocking * Fix Unlocked hint * Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates. * Documentation: add key combos description and use information * Scripts: cleanup templit, more debug info and add dev comment Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
#include "one_shot_animation_view.h"
#include <furi.h>
#include <portmacro.h>
#include <gui/canvas.h>
#include <gui/view.h>
#include <gui/icon_i.h>
#include <stdint.h>
typedef void (*OneShotInteractCallback)(void*);
struct OneShotView {
View* view;
TimerHandle_t update_timer;
OneShotInteractCallback interact_callback;
void* interact_callback_context;
};
typedef struct {
const Icon* icon;
uint32_t index;
bool block_input;
} OneShotViewModel;
static void one_shot_view_update_timer_callback(TimerHandle_t xTimer) {
OneShotView* view = (void*)pvTimerGetTimerID(xTimer);
OneShotViewModel* model = view_get_model(view->view);
if((model->index + 1) < model->icon->frame_count) {
++model->index;
} else {
model->block_input = false;
model->index = model->icon->frame_count - 2;
}
view_commit_model(view->view, true);
}
static void one_shot_view_draw(Canvas* canvas, void* model_) {
furi_assert(canvas);
furi_assert(model_);
OneShotViewModel* model = model_;
furi_check(model->index < model->icon->frame_count);
uint8_t y_offset = canvas_height(canvas) - model->icon->height;
canvas_draw_bitmap(
canvas,
0,
y_offset,
model->icon->width,
model->icon->height,
model->icon->frames[model->index]);
}
static bool one_shot_view_input(InputEvent* event, void* context) {
furi_assert(context);
furi_assert(event);
OneShotView* view = context;
bool consumed = false;
OneShotViewModel* model = view_get_model(view->view);
consumed = model->block_input;
view_commit_model(view->view, false);
if(!consumed) {
if(event->key == InputKeyRight) {
/* Right button reserved for animation activation, so consume */
consumed = true;
if(event->type == InputTypeShort) {
if(view->interact_callback) {
view->interact_callback(view->interact_callback_context);
}
}
}
}
return consumed;
}
OneShotView* one_shot_view_alloc(void) {
[FL-2274] Inventing streams and moving FFF to them (#981) * Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-02-18 19:53:46 +00:00
OneShotView* view = malloc(sizeof(OneShotView));
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965) * Desktop: cleanup headers * Get loader pubsub via record * [FL-2183] Dolphin refactoring 2022.01 * Restruct animations assets structure * Rename assets * Cleanup headers * Update Recording animation * Add BadBattery animation * Provide loader's pubsub via record * Fix load/unload animations * Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin. * Sync internal meta.txt and manifest.txt * Reorder, rename dolphin assets * Split essential generated assets * Add ReadMe for dolphin assets * Separate essential blocking animations * Scripts: full dolphin validation before packaging * Assets, Scripts: dolphin external resources packer * Github: update codeowners * Scripts: proper slots handling in dolphin animation meta * Scripts: correct frames enumeration and fix compiled assets. * [FL-2209] Add Dolphin Deeds points and many more * Remove excess frame_rate * Change dolphin assets directory * Scripts: add internal resource support to dolphin compiler * Scripts: add internal assets generation, renaming * Scripts: correct assert, renaming * Code cleanup, documentation, fixes * Update Levelup animations * Rename essential -> blocking * Fix Unlocked hint * Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates. * Documentation: add key combos description and use information * Scripts: cleanup templit, more debug info and add dev comment Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
view->view = view_alloc();
view->update_timer =
xTimerCreate(NULL, 1000, pdTRUE, view, one_shot_view_update_timer_callback);
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965) * Desktop: cleanup headers * Get loader pubsub via record * [FL-2183] Dolphin refactoring 2022.01 * Restruct animations assets structure * Rename assets * Cleanup headers * Update Recording animation * Add BadBattery animation * Provide loader's pubsub via record * Fix load/unload animations * Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin. * Sync internal meta.txt and manifest.txt * Reorder, rename dolphin assets * Split essential generated assets * Add ReadMe for dolphin assets * Separate essential blocking animations * Scripts: full dolphin validation before packaging * Assets, Scripts: dolphin external resources packer * Github: update codeowners * Scripts: proper slots handling in dolphin animation meta * Scripts: correct frames enumeration and fix compiled assets. * [FL-2209] Add Dolphin Deeds points and many more * Remove excess frame_rate * Change dolphin assets directory * Scripts: add internal resource support to dolphin compiler * Scripts: add internal assets generation, renaming * Scripts: correct assert, renaming * Code cleanup, documentation, fixes * Update Levelup animations * Rename essential -> blocking * Fix Unlocked hint * Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates. * Documentation: add key combos description and use information * Scripts: cleanup templit, more debug info and add dev comment Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
view_allocate_model(view->view, ViewModelTypeLocking, sizeof(OneShotViewModel));
view_set_context(view->view, view);
view_set_draw_callback(view->view, one_shot_view_draw);
view_set_input_callback(view->view, one_shot_view_input);
return view;
}
void one_shot_view_free(OneShotView* view) {
furi_assert(view);
xTimerDelete(view->update_timer, portMAX_DELAY);
view_free(view->view);
view->view = NULL;
free(view);
}
void one_shot_view_set_interact_callback(
OneShotView* view,
OneShotInteractCallback callback,
void* context) {
furi_assert(view);
view->interact_callback_context = context;
view->interact_callback = callback;
}
void one_shot_view_start_animation(OneShotView* view, const Icon* icon) {
furi_assert(view);
furi_assert(icon);
furi_check(icon->frame_count >= 2);
OneShotViewModel* model = view_get_model(view->view);
model->index = 0;
model->icon = icon;
model->block_input = true;
view_commit_model(view->view, true);
xTimerChangePeriod(view->update_timer, 1000 / model->icon->frame_rate, portMAX_DELAY);
}
View* one_shot_view_get_view(OneShotView* view) {
furi_assert(view);
return view->view;
}