Skip to content

Commit

Permalink
menu_animation: add delayed animations
Browse files Browse the repository at this point in the history
  • Loading branch information
natinusala committed Jan 23, 2019
1 parent bd84bb1 commit 5102361
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions menu/menu_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,29 @@ void menu_animation_free(void)
da_free(anim.pending);
}

static void menu_delayed_animation_cb(void *userdata)
{
menu_delayed_animation_t *delayed_animation = (menu_delayed_animation_t*) userdata;

menu_animation_push(&delayed_animation->entry);

free(delayed_animation);
}

void menu_animation_push_delayed(unsigned delay, menu_animation_ctx_entry_t *entry)
{
menu_timer_ctx_entry_t timer_entry;
menu_delayed_animation_t *delayed_animation = (menu_delayed_animation_t*) malloc(sizeof(menu_delayed_animation_t));

memcpy(&delayed_animation->entry, entry, sizeof(menu_animation_ctx_entry_t));

timer_entry.cb = menu_delayed_animation_cb;
timer_entry.duration = delay;
timer_entry.userdata = delayed_animation;

menu_timer_start(&delayed_animation->timer, &timer_entry);
}

bool menu_animation_push(menu_animation_ctx_entry_t *entry)
{
struct tween t;
Expand Down
8 changes: 8 additions & 0 deletions menu/menu_animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ typedef struct menu_timer_ctx_entry
void *userdata;
} menu_timer_ctx_entry_t;

typedef struct menu_delayed_animation
{
menu_timer_t timer;
menu_animation_ctx_entry_t entry;
} menu_delayed_animation_t;

void menu_timer_start(menu_timer_t *timer, menu_timer_ctx_entry_t *timer_entry);

void menu_timer_kill(menu_timer_t *timer);
Expand All @@ -151,6 +157,8 @@ void menu_animation_kill_by_subject(menu_animation_ctx_subject_t *subject);

bool menu_animation_push(menu_animation_ctx_entry_t *entry);

void menu_animation_push_delayed(unsigned delay, menu_animation_ctx_entry_t *entry);

float menu_animation_get_delta_time(void);

bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data);
Expand Down

0 comments on commit 5102361

Please sign in to comment.