flipperzero-firmware/applications/gui/icon.c
あく 665f6d7d9c
Assets, Icons, UI toolkit. Part 1. (#202)
* Assets: import from gdrive
* Assets: fully working build pipeline and registry
* NFC: menu icon
* Gui: layers. Irukagotchi: base app to handle input on idle screen. Makefile: reboot after flash in dfu mode.
* ValueMutex: with lambda
* Assets: proper animation frames sorting
* ValueMutex: proper furi_open usage
* Assets,GUI: split icon into icon data and icon state.
* Format source code
* Docker: add python3 and imagemagic
* Irukagotchi: cleanup
* GUI: event lock moved to gui.
* Rfid: proper gui layer
* GUI: elements. Menu: frame and scroll
* GUI, Menu: format code.
* Menu: dual font main menu
* Menu: format sources
* GUI: 0 total scrollbar
* CI: enable lfs
* Menu: pixel perfect main menu

Co-authored-by: Aleksandr Kutuzov <aku@plooks.com>
Co-authored-by: aanper <mail@s3f.ru>
2020-10-26 20:00:17 +03:00

64 lines
1.3 KiB
C

#include "icon.h"
#include "icon_i.h"
#include <cmsis_os2.h>
#include <flipper.h>
#include <assert.h>
Icon* icon_alloc(const IconData* data) {
Icon* icon = furi_alloc(sizeof(Icon));
icon->data = data;
return icon;
}
void icon_free(Icon* icon) {
assert(icon);
free(icon);
}
const uint8_t* icon_get_data(Icon* icon) {
assert(icon);
if(icon->tick) {
uint32_t now = osKernelGetTickCount();
if(now < icon->tick) {
icon->tick = now;
icon_next_frame(icon);
} else if(now - icon->tick > osKernelGetTickFreq() / icon->data->frame_rate) {
icon->tick = now;
icon_next_frame(icon);
}
}
return icon->data->frames[icon->frame];
}
void icon_next_frame(Icon* icon) {
assert(icon);
icon->frame = (icon->frame + 1) % icon->data->frame_count;
}
uint8_t icon_get_width(Icon* icon) {
assert(icon);
return icon->data->width;
}
uint8_t icon_get_height(Icon* icon) {
assert(icon);
return icon->data->height;
}
bool icon_is_animated(Icon* icon) {
assert(icon);
return icon->data->frame_count > 1;
}
void icon_start_animation(Icon* icon) {
assert(icon);
icon->tick = osKernelGetTickCount();
}
void icon_stop_animation(Icon* icon) {
assert(icon);
icon->tick = 0;
icon->frame = 0;
}