[FL-1908] New animation update scheme (#737)
* Assets: update desktop animation frame rate and cleanup. * Power: update ViewPort only if changed. * Gui: tie IconAnimation with View, new update event generation scheme. Desktop: update IconAnimation usage. Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
@@ -7,26 +7,26 @@ IconAnimation* icon_animation_alloc(const Icon* icon) {
|
||||
furi_assert(icon);
|
||||
IconAnimation* instance = furi_alloc(sizeof(IconAnimation));
|
||||
instance->icon = icon;
|
||||
instance->timer = osTimerNew(icon_animation_timer_callback, osTimerPeriodic, instance, NULL);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void icon_animation_free(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
furi_check(osTimerDelete(instance->timer) == osOK);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
const uint8_t* icon_animation_get_data(IconAnimation* instance) {
|
||||
void icon_animation_set_update_callback(
|
||||
IconAnimation* instance,
|
||||
IconAnimationCallback callback,
|
||||
void* context) {
|
||||
furi_assert(instance);
|
||||
if(instance->tick) {
|
||||
uint32_t now = osKernelGetTickCount();
|
||||
if(now < instance->tick) {
|
||||
instance->tick = now;
|
||||
icon_animation_next_frame(instance);
|
||||
} else if(now - instance->tick > osKernelGetTickFreq() / instance->icon->frame_rate) {
|
||||
instance->tick = now;
|
||||
icon_animation_next_frame(instance);
|
||||
}
|
||||
}
|
||||
instance->callback = callback;
|
||||
instance->callback_context = context;
|
||||
}
|
||||
|
||||
const uint8_t* icon_animation_get_data(IconAnimation* instance) {
|
||||
return instance->icon->frames[instance->frame];
|
||||
}
|
||||
|
||||
@@ -35,6 +35,19 @@ void icon_animation_next_frame(IconAnimation* instance) {
|
||||
instance->frame = (instance->frame + 1) % instance->icon->frame_count;
|
||||
}
|
||||
|
||||
void icon_animation_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
IconAnimation* instance = context;
|
||||
|
||||
if(!instance->animating) return;
|
||||
|
||||
icon_animation_next_frame(instance);
|
||||
if(instance->callback) {
|
||||
instance->callback(instance, instance->callback_context);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t icon_animation_get_width(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->icon->width;
|
||||
@@ -45,33 +58,26 @@ uint8_t icon_animation_get_height(IconAnimation* instance) {
|
||||
return instance->icon->height;
|
||||
}
|
||||
|
||||
bool icon_animation_is_animated(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->icon->frame_count > 1;
|
||||
}
|
||||
|
||||
bool icon_animation_is_animating(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->tick > 0;
|
||||
}
|
||||
|
||||
void icon_animation_start(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
instance->tick = osKernelGetTickCount();
|
||||
if(!instance->animating) {
|
||||
instance->animating = true;
|
||||
furi_check(
|
||||
osTimerStart(instance->timer, (osKernelGetTickFreq() / instance->icon->frame_rate)) ==
|
||||
osOK);
|
||||
}
|
||||
}
|
||||
|
||||
void icon_animation_stop(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
instance->tick = 0;
|
||||
instance->frame = 0;
|
||||
}
|
||||
|
||||
uint8_t icon_animation_get_current_frame(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->frame;
|
||||
if(instance->animating) {
|
||||
instance->animating = false;
|
||||
furi_check(osTimerStop(instance->timer) == osOK);
|
||||
instance->frame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool icon_animation_is_last_frame(IconAnimation* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->icon->frame_count - instance->frame <= 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user