(menu_animation) Add tween tagging support

This commit is contained in:
Higor Eurípedes 2015-06-23 11:04:57 -03:00
parent 5d8519c814
commit f167a416f1
4 changed files with 63 additions and 35 deletions

View File

@ -681,7 +681,7 @@ static void glui_navigation_set(bool scroll)
} }
menu_animation_push(disp->animation, 10, scroll_pos, 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) static void glui_navigation_clear(bool pending_push)

View File

@ -583,7 +583,7 @@ static void xmb_update_boxart(xmb_handle_t *xmb, unsigned i)
static void xmb_selection_pointer_changed(void) static void xmb_selection_pointer_changed(void)
{ {
unsigned i, current, end; unsigned i, current, end, tag;
xmb_handle_t *xmb = NULL; xmb_handle_t *xmb = NULL;
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
menu_display_t *disp = menu_display_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; current = nav->selection_ptr;
end = menu_entries_get_end(); end = menu_entries_get_end();
tag = (uintptr_t)menu_list;
menu_animation_kill_by_tag(disp->animation, tag);
for (i = 0; i < end; i++) for (i = 0; i < end; i++)
{ {
float iy; float iy;
@ -625,13 +629,13 @@ static void xmb_selection_pointer_changed(void)
} }
menu_animation_push(disp->animation, 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, 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, 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, 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; ia = 0;
menu_animation_push(disp->animation, 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, 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, menu_animation_push(disp->animation,
XMB_DELAY, xmb->icon.size * dir * -2, &node->x, 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; ia = xmb->item.active.alpha;
menu_animation_push(disp->animation, 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, 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, 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; xmb->old_depth = xmb->depth;
@ -752,11 +756,11 @@ static void xmb_push_animations(xmb_node_t *node, float ia, float ix)
return; return;
menu_animation_push(disp->animation, 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, 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, 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, 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, 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, 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, menu_animation_push(disp->animation, XMB_DELAY,
xmb->icon.spacing.horizontal * -(float)xmb->categories.selection_ptr, 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; dir = -1;
if (xmb->categories.selection_ptr > xmb->categories.selection_ptr_old) 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; ia = xmb->categories.passive.alpha;
menu_animation_push(menu->display.animation, XMB_DELAY, ia, 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: case 1:
menu_animation_push(disp->animation, menu_animation_push(disp->animation,
XMB_DELAY, xmb->icon.size * -(xmb->depth*2-2), 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, menu_animation_push(disp->animation,
XMB_DELAY, 0, &xmb->textures.arrow.alpha, XMB_DELAY, 0, &xmb->textures.arrow.alpha,
EASING_IN_OUT_QUAD, NULL); EASING_IN_OUT_QUAD, -1, NULL);
break; break;
case 2: case 2:
menu_animation_push(disp->animation, menu_animation_push(disp->animation,
XMB_DELAY, xmb->icon.size * -(xmb->depth*2-2), 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, menu_animation_push(disp->animation,
XMB_DELAY, 1, &xmb->textures.arrow.alpha, XMB_DELAY, 1, &xmb->textures.arrow.alpha,
EASING_IN_OUT_QUAD, NULL); EASING_IN_OUT_QUAD, -1, NULL);
break; break;
} }
@ -2334,7 +2338,7 @@ static void xmb_toggle(bool menu_on)
} }
menu_animation_push(disp->animation, XMB_DELAY, 1.0f, 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(); xmb->prevent_populate = !menu_entries_needs_refresh();

View File

@ -293,7 +293,7 @@ void menu_animation_kill_by_subject(menu_animation_t *animation,
{ {
if (animation->list[i].subject == sub[j]) if (animation->list[i].subject == sub[j])
{ {
animation->list[i].alive = 0; animation->list[i].alive = false;
animation->list[i].subject = NULL; animation->list[i].subject = NULL;
if (i < animation->first_dead) 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) static void menu_animation_push_internal(menu_animation_t *anim, const struct tween *t)
{ {
struct tween *target = NULL; struct tween *target = NULL;
@ -327,25 +347,24 @@ static void menu_animation_push_internal(menu_animation_t *anim, const struct tw
*target = *t; *target = *t;
} }
bool menu_animation_push( bool menu_animation_push(menu_animation_t *anim,
menu_animation_t *anim,
float duration, float duration,
float target_value, float target_value, float* subject,
float* subject,
enum menu_animation_easing_type easing_enum, enum menu_animation_easing_type easing_enum,
tween_cb cb) unsigned tag, tween_cb cb)
{ {
struct tween t; struct tween t;
if (!subject) if (!subject)
return false; return false;
t.alive = 1; t.alive = true;
t.duration = duration; t.duration = duration;
t.running_since = 0; t.running_since = 0;
t.initial_value = *subject; t.initial_value = *subject;
t.target_value = target_value; t.target_value = target_value;
t.subject = subject; t.subject = subject;
t.tag = tag;
t.cb = cb; t.cb = cb;
switch (easing_enum) switch (easing_enum)
@ -491,7 +510,7 @@ static int menu_animation_iterate(
if (tween->running_since >= tween->duration) if (tween->running_since >= tween->duration)
{ {
*tween->subject = tween->target_value; *tween->subject = tween->target_value;
tween->alive = 0; tween->alive = false;
if (idx < anim->first_dead) if (idx < anim->first_dead)
anim->first_dead = idx; anim->first_dead = idx;

View File

@ -35,12 +35,13 @@ typedef void (*tween_cb) (void);
struct tween struct tween
{ {
int alive; bool alive;
float duration; float duration;
float running_since; float running_since;
float initial_value; float initial_value;
float target_value; float target_value;
float* subject; float* subject;
unsigned tag;
easingFunc easing; easingFunc easing;
tween_cb cb; tween_cb cb;
}; };
@ -119,11 +120,15 @@ void menu_animation_kill_by_subject(
size_t count, size_t count,
const void *subjects); const void *subjects);
void menu_animation_kill_by_tag(menu_animation_t *anim, unsigned tag);
/* Use -1 for untagged */
bool menu_animation_push( bool menu_animation_push(
menu_animation_t *animation, menu_animation_t *animation,
float duration, float duration,
float target_value, float* subject, 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( bool menu_animation_update(
menu_animation_t *animation, menu_animation_t *animation,