2020-10-26 17:00:17 +00:00
|
|
|
#include "icon.h"
|
|
|
|
#include "icon_i.h"
|
|
|
|
|
|
|
|
#include <cmsis_os2.h>
|
|
|
|
#include <flipper.h>
|
2020-10-29 06:27:17 +00:00
|
|
|
#include <flipper_v2.h>
|
2020-10-26 17:00:17 +00:00
|
|
|
|
|
|
|
Icon* icon_alloc(const IconData* data) {
|
|
|
|
Icon* icon = furi_alloc(sizeof(Icon));
|
|
|
|
icon->data = data;
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
void icon_free(Icon* icon) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
free(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t* icon_get_data(Icon* icon) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
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) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
icon->frame = (icon->frame + 1) % icon->data->frame_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t icon_get_width(Icon* icon) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
return icon->data->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t icon_get_height(Icon* icon) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
return icon->data->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool icon_is_animated(Icon* icon) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
return icon->data->frame_count > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void icon_start_animation(Icon* icon) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
icon->tick = osKernelGetTickCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void icon_stop_animation(Icon* icon) {
|
2020-10-29 06:27:17 +00:00
|
|
|
furi_assert(icon);
|
2020-10-26 17:00:17 +00:00
|
|
|
icon->tick = 0;
|
|
|
|
icon->frame = 0;
|
|
|
|
}
|