From f167a416f11ac8a967cc25cdc1a12096343ea4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Tue, 23 Jun 2015 11:04:57 -0300 Subject: [PATCH] (menu_animation) Add tween tagging support --- menu/drivers/glui.c | 2 +- menu/drivers/xmb.c | 52 +++++++++++++++++++++++-------------------- menu/menu_animation.c | 35 ++++++++++++++++++++++------- menu/menu_animation.h | 9 ++++++-- 4 files changed, 63 insertions(+), 35 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index d8f192e673..a16fdf97ed 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -681,7 +681,7 @@ static void glui_navigation_set(bool scroll) } menu_animation_push(disp->animation, 10, scroll_pos, - &menu->scroll_y, EASING_IN_OUT_QUAD, NULL); + &menu->scroll_y, EASING_IN_OUT_QUAD, -1, NULL); } static void glui_navigation_clear(bool pending_push) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index bd02ea9446..ea5cfbd2af 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -583,7 +583,7 @@ static void xmb_update_boxart(xmb_handle_t *xmb, unsigned i) static void xmb_selection_pointer_changed(void) { - unsigned i, current, end; + unsigned i, current, end, tag; xmb_handle_t *xmb = NULL; menu_handle_t *menu = menu_driver_get_ptr(); menu_display_t *disp = menu_display_get_ptr(); @@ -602,6 +602,10 @@ static void xmb_selection_pointer_changed(void) current = nav->selection_ptr; end = menu_entries_get_end(); + tag = (uintptr_t)menu_list; + + menu_animation_kill_by_tag(disp->animation, tag); + for (i = 0; i < end; i++) { float iy; @@ -613,7 +617,7 @@ static void xmb_selection_pointer_changed(void) if (!node) continue; - iy = xmb_item_y(xmb, i, current); + iy = xmb_item_y(xmb, i, current); if (i == current) { @@ -625,13 +629,13 @@ static void xmb_selection_pointer_changed(void) } menu_animation_push(disp->animation, - XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, tag, NULL); menu_animation_push(disp->animation, - XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, tag, NULL); menu_animation_push(disp->animation, - XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, tag, NULL); menu_animation_push(disp->animation, - XMB_DELAY, iy, &node->y, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, iy, &node->y, EASING_IN_OUT_QUAD, tag, NULL); } } @@ -661,12 +665,12 @@ static void xmb_list_open_old(xmb_handle_t *xmb, ia = 0; menu_animation_push(disp->animation, - XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, - XMB_DELAY, 0, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, 0, &node->label_alpha, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, XMB_DELAY, xmb->icon.size * dir * -2, &node->x, - EASING_IN_OUT_QUAD, NULL); + EASING_IN_OUT_QUAD, -1, NULL); } } @@ -704,11 +708,11 @@ static void xmb_list_open_new(xmb_handle_t *xmb, ia = xmb->item.active.alpha; menu_animation_push(disp->animation, - XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, - XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, - XMB_DELAY, 0, &node->x, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, 0, &node->x, EASING_IN_OUT_QUAD, -1, NULL); } xmb->old_depth = xmb->depth; @@ -752,11 +756,11 @@ static void xmb_push_animations(xmb_node_t *node, float ia, float ix) return; menu_animation_push(disp->animation, - XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, - XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, - XMB_DELAY, ix, &node->x, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ix, &node->x, EASING_IN_OUT_QUAD, -1, NULL); } static void xmb_list_switch_old(xmb_handle_t *xmb, @@ -869,9 +873,9 @@ static void xmb_list_switch_horizontal_list(xmb_handle_t *xmb, menu_handle_t *me } menu_animation_push(menu->display.animation, - XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(menu->display.animation, - XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, NULL); + XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, -1, NULL); } } @@ -896,7 +900,7 @@ static void xmb_list_switch(xmb_handle_t *xmb) menu_animation_push(disp->animation, XMB_DELAY, xmb->icon.spacing.horizontal * -(float)xmb->categories.selection_ptr, - &xmb->categories.x_pos, EASING_IN_OUT_QUAD, NULL); + &xmb->categories.x_pos, EASING_IN_OUT_QUAD, -1, NULL); dir = -1; if (xmb->categories.selection_ptr > xmb->categories.selection_ptr_old) @@ -934,7 +938,7 @@ static void xmb_list_open_horizontal_list(xmb_handle_t *xmb, menu_handle_t *menu ia = xmb->categories.passive.alpha; menu_animation_push(menu->display.animation, XMB_DELAY, ia, - &node->alpha, EASING_IN_OUT_QUAD, NULL); + &node->alpha, EASING_IN_OUT_QUAD, -1, NULL); } } @@ -968,18 +972,18 @@ static void xmb_list_open(xmb_handle_t *xmb) case 1: menu_animation_push(disp->animation, XMB_DELAY, xmb->icon.size * -(xmb->depth*2-2), - &xmb->x, EASING_IN_OUT_QUAD, NULL); + &xmb->x, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, XMB_DELAY, 0, &xmb->textures.arrow.alpha, - EASING_IN_OUT_QUAD, NULL); + EASING_IN_OUT_QUAD, -1, NULL); break; case 2: menu_animation_push(disp->animation, XMB_DELAY, xmb->icon.size * -(xmb->depth*2-2), - &xmb->x, EASING_IN_OUT_QUAD, NULL); + &xmb->x, EASING_IN_OUT_QUAD, -1, NULL); menu_animation_push(disp->animation, XMB_DELAY, 1, &xmb->textures.arrow.alpha, - EASING_IN_OUT_QUAD, NULL); + EASING_IN_OUT_QUAD, -1, NULL); break; } @@ -2334,7 +2338,7 @@ static void xmb_toggle(bool menu_on) } menu_animation_push(disp->animation, XMB_DELAY, 1.0f, - &xmb->alpha, EASING_IN_OUT_QUAD, NULL); + &xmb->alpha, EASING_IN_OUT_QUAD, -1, NULL); xmb->prevent_populate = !menu_entries_needs_refresh(); diff --git a/menu/menu_animation.c b/menu/menu_animation.c index f5941bd992..c30ee8c2f3 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -293,7 +293,7 @@ void menu_animation_kill_by_subject(menu_animation_t *animation, { if (animation->list[i].subject == sub[j]) { - animation->list[i].alive = 0; + animation->list[i].alive = false; animation->list[i].subject = NULL; if (i < animation->first_dead) @@ -306,6 +306,26 @@ void menu_animation_kill_by_subject(menu_animation_t *animation, } } +void menu_animation_kill_by_tag(menu_animation_t *anim, unsigned tag) +{ + unsigned i; + + if (tag == -1) + return; + + for (i = 0; i < anim->size; ++i) + { + if (anim->list[i].tag == tag) + { + anim->list[i].alive = false; + anim->list[i].subject = NULL; + + if (i < anim->first_dead) + anim->first_dead = i; + } + } +} + static void menu_animation_push_internal(menu_animation_t *anim, const struct tween *t) { struct tween *target = NULL; @@ -327,25 +347,24 @@ static void menu_animation_push_internal(menu_animation_t *anim, const struct tw *target = *t; } -bool menu_animation_push( - menu_animation_t *anim, +bool menu_animation_push(menu_animation_t *anim, float duration, - float target_value, - float* subject, + float target_value, float* subject, enum menu_animation_easing_type easing_enum, - tween_cb cb) + unsigned tag, tween_cb cb) { struct tween t; if (!subject) return false; - t.alive = 1; + t.alive = true; t.duration = duration; t.running_since = 0; t.initial_value = *subject; t.target_value = target_value; t.subject = subject; + t.tag = tag; t.cb = cb; switch (easing_enum) @@ -491,7 +510,7 @@ static int menu_animation_iterate( if (tween->running_since >= tween->duration) { *tween->subject = tween->target_value; - tween->alive = 0; + tween->alive = false; if (idx < anim->first_dead) anim->first_dead = idx; diff --git a/menu/menu_animation.h b/menu/menu_animation.h index c6039c8d85..c340eeb835 100644 --- a/menu/menu_animation.h +++ b/menu/menu_animation.h @@ -35,12 +35,13 @@ typedef void (*tween_cb) (void); struct tween { - int alive; + bool alive; float duration; float running_since; float initial_value; float target_value; float* subject; + unsigned tag; easingFunc easing; tween_cb cb; }; @@ -119,11 +120,15 @@ void menu_animation_kill_by_subject( size_t count, const void *subjects); +void menu_animation_kill_by_tag(menu_animation_t *anim, unsigned tag); + +/* Use -1 for untagged */ bool menu_animation_push( menu_animation_t *animation, float duration, float target_value, float* subject, - enum menu_animation_easing_type easing_enum, tween_cb cb); + enum menu_animation_easing_type easing_enum, + unsigned tag, tween_cb cb); bool menu_animation_update( menu_animation_t *animation,