mirror of
https://github.com/libretro/RetroArch
synced 2025-03-23 10:20:57 +00:00
(Menu) Create menu_animation_get_ptr
This commit is contained in:
parent
3fb751ebd2
commit
bff61a9485
@ -340,6 +340,7 @@ static void glui_frame(void)
|
||||
const struct font_renderer *font_driver = NULL;
|
||||
driver_t *driver = driver_get_ptr();
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_input_t *menu_input = menu_input_get_ptr();
|
||||
@ -389,7 +390,7 @@ static void glui_frame(void)
|
||||
nav->selection_ptr,
|
||||
width, glui->line_height, 1, 1, 1, 0.1);
|
||||
|
||||
menu->animation_is_active = true;
|
||||
anim->is_active = true;
|
||||
menu->label.is_updated = false;
|
||||
|
||||
glui_render_quad(gl, 0, 0, width,
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <retro_inline.h>
|
||||
|
||||
#include "../menu.h"
|
||||
#include "../menu_animation.h"
|
||||
#include "../menu_entry.h"
|
||||
#include "../menu_display.h"
|
||||
|
||||
@ -351,6 +352,7 @@ static void rgui_render(void)
|
||||
driver_t *driver = driver_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_input_t *menu_input = menu_input_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
uint64_t frame_count = video_driver_get_frame_count();
|
||||
|
||||
(void)driver;
|
||||
@ -369,7 +371,7 @@ static void rgui_render(void)
|
||||
|
||||
/* ensures the framebuffer will be rendered on the screen */
|
||||
menu_display_fb_set_dirty();
|
||||
menu->animation_is_active = false;
|
||||
anim->is_active = false;
|
||||
menu->label.is_updated = false;
|
||||
|
||||
if (settings->menu.pointer.enable)
|
||||
|
@ -1213,6 +1213,7 @@ static void xmb_render(void)
|
||||
xmb_handle_t *xmb = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
menu_input_t *menu_input = menu_input_get_ptr();
|
||||
menu_navigation_t *nav = menu_navigation_get_ptr();
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
@ -1253,7 +1254,7 @@ static void xmb_render(void)
|
||||
}
|
||||
}
|
||||
|
||||
menu->animation_is_active = false;
|
||||
anim->is_active = false;
|
||||
menu->label.is_updated = false;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,14 @@
|
||||
#include "menu_animation.h"
|
||||
#include "../runloop.h"
|
||||
|
||||
menu_animation_t *menu_animation_get_ptr(void)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (!menu)
|
||||
return NULL;
|
||||
return menu->animation;
|
||||
}
|
||||
|
||||
/* from https://github.com/kikito/tween.lua/blob/master/tween.lua */
|
||||
|
||||
static float easing_linear(float t, float b, float c, float d)
|
||||
@ -250,162 +258,168 @@ static float easing_out_in_bounce(float t, float b, float c, float d)
|
||||
return easing_in_bounce((t * 2) - d, b + c / 2, c / 2, d);
|
||||
}
|
||||
|
||||
void menu_animation_free(animation_t *animation)
|
||||
void menu_animation_free(menu_animation_t *anim)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!animation)
|
||||
if (!anim)
|
||||
return;
|
||||
|
||||
for (i = 0; i < animation->size; i++)
|
||||
for (i = 0; i < anim->size; i++)
|
||||
{
|
||||
if (animation->list[i].subject)
|
||||
animation->list[i].subject = NULL;
|
||||
if (anim->list[i].subject)
|
||||
anim->list[i].subject = NULL;
|
||||
}
|
||||
|
||||
free(animation->list);
|
||||
free(animation);
|
||||
free(anim->list);
|
||||
free(anim);
|
||||
}
|
||||
|
||||
bool menu_animation_push(animation_t *animation,
|
||||
float duration, float target_value, float* subject,
|
||||
enum animation_easing_type easing_enum, tween_cb cb)
|
||||
bool menu_animation_push(
|
||||
menu_animation_t *anim,
|
||||
float duration,
|
||||
float target_value,
|
||||
float* subject,
|
||||
enum menu_animation_easing_type easing_enum,
|
||||
tween_cb cb)
|
||||
{
|
||||
if (animation->size >= animation->capacity)
|
||||
if (anim->size >= anim->capacity)
|
||||
{
|
||||
animation->capacity++;
|
||||
animation->list = (struct tween*)realloc(animation->list,
|
||||
animation->capacity * sizeof(struct tween));
|
||||
anim->capacity++;
|
||||
anim->list = (struct tween*)realloc(anim->list,
|
||||
anim->capacity * sizeof(struct tween));
|
||||
}
|
||||
|
||||
animation->list[animation->size].alive = 1;
|
||||
animation->list[animation->size].duration = duration;
|
||||
animation->list[animation->size].running_since = 0;
|
||||
animation->list[animation->size].initial_value = *subject;
|
||||
animation->list[animation->size].target_value = target_value;
|
||||
animation->list[animation->size].subject = subject;
|
||||
animation->list[animation->size].cb = cb;
|
||||
anim->list[anim->size].alive = 1;
|
||||
anim->list[anim->size].duration = duration;
|
||||
anim->list[anim->size].running_since = 0;
|
||||
anim->list[anim->size].initial_value = *subject;
|
||||
anim->list[anim->size].target_value = target_value;
|
||||
anim->list[anim->size].subject = subject;
|
||||
anim->list[anim->size].cb = cb;
|
||||
|
||||
switch (easing_enum)
|
||||
{
|
||||
case EASING_LINEAR:
|
||||
animation->list[animation->size].easing = &easing_linear;
|
||||
anim->list[anim->size].easing = &easing_linear;
|
||||
break;
|
||||
/* Quad */
|
||||
case EASING_IN_QUAD:
|
||||
animation->list[animation->size].easing = &easing_in_quad;
|
||||
anim->list[anim->size].easing = &easing_in_quad;
|
||||
break;
|
||||
case EASING_OUT_QUAD:
|
||||
animation->list[animation->size].easing = &easing_out_quad;
|
||||
anim->list[anim->size].easing = &easing_out_quad;
|
||||
break;
|
||||
case EASING_IN_OUT_QUAD:
|
||||
animation->list[animation->size].easing = &easing_in_out_quad;
|
||||
anim->list[anim->size].easing = &easing_in_out_quad;
|
||||
break;
|
||||
case EASING_OUT_IN_QUAD:
|
||||
animation->list[animation->size].easing = &easing_out_in_quad;
|
||||
anim->list[anim->size].easing = &easing_out_in_quad;
|
||||
break;
|
||||
/* Cubic */
|
||||
case EASING_IN_CUBIC:
|
||||
animation->list[animation->size].easing = &easing_in_cubic;
|
||||
anim->list[anim->size].easing = &easing_in_cubic;
|
||||
break;
|
||||
case EASING_OUT_CUBIC:
|
||||
animation->list[animation->size].easing = &easing_out_cubic;
|
||||
anim->list[anim->size].easing = &easing_out_cubic;
|
||||
break;
|
||||
case EASING_IN_OUT_CUBIC:
|
||||
animation->list[animation->size].easing = &easing_in_out_cubic;
|
||||
anim->list[anim->size].easing = &easing_in_out_cubic;
|
||||
break;
|
||||
case EASING_OUT_IN_CUBIC:
|
||||
animation->list[animation->size].easing = &easing_out_in_cubic;
|
||||
anim->list[anim->size].easing = &easing_out_in_cubic;
|
||||
break;
|
||||
/* Quart */
|
||||
case EASING_IN_QUART:
|
||||
animation->list[animation->size].easing = &easing_in_quart;
|
||||
anim->list[anim->size].easing = &easing_in_quart;
|
||||
break;
|
||||
case EASING_OUT_QUART:
|
||||
animation->list[animation->size].easing = &easing_out_quart;
|
||||
anim->list[anim->size].easing = &easing_out_quart;
|
||||
break;
|
||||
case EASING_IN_OUT_QUART:
|
||||
animation->list[animation->size].easing = &easing_in_out_quart;
|
||||
anim->list[anim->size].easing = &easing_in_out_quart;
|
||||
break;
|
||||
case EASING_OUT_IN_QUART:
|
||||
animation->list[animation->size].easing = &easing_out_in_quart;
|
||||
anim->list[anim->size].easing = &easing_out_in_quart;
|
||||
break;
|
||||
/* Quint */
|
||||
case EASING_IN_QUINT:
|
||||
animation->list[animation->size].easing = &easing_in_quint;
|
||||
anim->list[anim->size].easing = &easing_in_quint;
|
||||
break;
|
||||
case EASING_OUT_QUINT:
|
||||
animation->list[animation->size].easing = &easing_out_quint;
|
||||
anim->list[anim->size].easing = &easing_out_quint;
|
||||
break;
|
||||
case EASING_IN_OUT_QUINT:
|
||||
animation->list[animation->size].easing = &easing_in_out_quint;
|
||||
anim->list[anim->size].easing = &easing_in_out_quint;
|
||||
break;
|
||||
case EASING_OUT_IN_QUINT:
|
||||
animation->list[animation->size].easing = &easing_out_in_quint;
|
||||
anim->list[anim->size].easing = &easing_out_in_quint;
|
||||
break;
|
||||
/* Sine */
|
||||
case EASING_IN_SINE:
|
||||
animation->list[animation->size].easing = &easing_in_sine;
|
||||
anim->list[anim->size].easing = &easing_in_sine;
|
||||
break;
|
||||
case EASING_OUT_SINE:
|
||||
animation->list[animation->size].easing = &easing_out_sine;
|
||||
anim->list[anim->size].easing = &easing_out_sine;
|
||||
break;
|
||||
case EASING_IN_OUT_SINE:
|
||||
animation->list[animation->size].easing = &easing_in_out_sine;
|
||||
anim->list[anim->size].easing = &easing_in_out_sine;
|
||||
break;
|
||||
case EASING_OUT_IN_SINE:
|
||||
animation->list[animation->size].easing = &easing_out_in_sine;
|
||||
anim->list[anim->size].easing = &easing_out_in_sine;
|
||||
break;
|
||||
/* Expo */
|
||||
case EASING_IN_EXPO:
|
||||
animation->list[animation->size].easing = &easing_in_expo;
|
||||
anim->list[anim->size].easing = &easing_in_expo;
|
||||
break;
|
||||
case EASING_OUT_EXPO:
|
||||
animation->list[animation->size].easing = &easing_out_expo;
|
||||
anim->list[anim->size].easing = &easing_out_expo;
|
||||
break;
|
||||
case EASING_IN_OUT_EXPO:
|
||||
animation->list[animation->size].easing = &easing_in_out_expo;
|
||||
anim->list[anim->size].easing = &easing_in_out_expo;
|
||||
break;
|
||||
case EASING_OUT_IN_EXPO:
|
||||
animation->list[animation->size].easing = &easing_out_in_expo;
|
||||
anim->list[anim->size].easing = &easing_out_in_expo;
|
||||
break;
|
||||
/* Circ */
|
||||
case EASING_IN_CIRC:
|
||||
animation->list[animation->size].easing = &easing_in_circ;
|
||||
anim->list[anim->size].easing = &easing_in_circ;
|
||||
break;
|
||||
case EASING_OUT_CIRC:
|
||||
animation->list[animation->size].easing = &easing_out_circ;
|
||||
anim->list[anim->size].easing = &easing_out_circ;
|
||||
break;
|
||||
case EASING_IN_OUT_CIRC:
|
||||
animation->list[animation->size].easing = &easing_in_out_circ;
|
||||
anim->list[anim->size].easing = &easing_in_out_circ;
|
||||
break;
|
||||
case EASING_OUT_IN_CIRC:
|
||||
animation->list[animation->size].easing = &easing_out_in_circ;
|
||||
anim->list[anim->size].easing = &easing_out_in_circ;
|
||||
break;
|
||||
/* Bounce */
|
||||
case EASING_IN_BOUNCE:
|
||||
animation->list[animation->size].easing = &easing_in_bounce;
|
||||
anim->list[anim->size].easing = &easing_in_bounce;
|
||||
break;
|
||||
case EASING_OUT_BOUNCE:
|
||||
animation->list[animation->size].easing = &easing_out_bounce;
|
||||
anim->list[anim->size].easing = &easing_out_bounce;
|
||||
break;
|
||||
case EASING_IN_OUT_BOUNCE:
|
||||
animation->list[animation->size].easing = &easing_in_out_bounce;
|
||||
anim->list[anim->size].easing = &easing_in_out_bounce;
|
||||
break;
|
||||
case EASING_OUT_IN_BOUNCE:
|
||||
animation->list[animation->size].easing = &easing_out_in_bounce;
|
||||
anim->list[anim->size].easing = &easing_out_in_bounce;
|
||||
break;
|
||||
default:
|
||||
animation->list[animation->size].easing = NULL;
|
||||
anim->list[anim->size].easing = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
animation->size++;
|
||||
anim->size++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int menu_animation_iterate(struct tween *tween, float dt,
|
||||
static int menu_animation_iterate(
|
||||
struct tween *tween,
|
||||
float dt,
|
||||
unsigned *active_tweens)
|
||||
{
|
||||
if (!tween)
|
||||
@ -437,22 +451,24 @@ static int menu_animation_iterate(struct tween *tween, float dt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool menu_animation_update(animation_t *animation, float dt)
|
||||
bool menu_animation_update(
|
||||
menu_animation_t *anim,
|
||||
float dt)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned active_tweens = 0;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
|
||||
for(i = 0; i < animation->size; i++)
|
||||
menu_animation_iterate(&animation->list[i], dt, &active_tweens);
|
||||
for(i = 0; i < anim->size; i++)
|
||||
menu_animation_iterate(&anim->list[i], dt, &active_tweens);
|
||||
|
||||
if (!active_tweens)
|
||||
{
|
||||
animation->size = 0;
|
||||
anim->size = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
menu->animation_is_active = true;
|
||||
anim->is_active = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -474,8 +490,9 @@ void menu_animation_ticker_line(char *buf, size_t len, uint64_t idx,
|
||||
unsigned ticker_period, phase, phase_left_stop;
|
||||
unsigned phase_left_moving, phase_right_stop;
|
||||
unsigned left_offset, right_offset;
|
||||
size_t str_len = strlen(str);
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
size_t str_len = strlen(str);
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
|
||||
if (str_len <= len)
|
||||
{
|
||||
@ -516,5 +533,5 @@ void menu_animation_ticker_line(char *buf, size_t len, uint64_t idx,
|
||||
else
|
||||
strlcpy(buf, str + right_offset, len + 1);
|
||||
|
||||
menu->animation_is_active = true;
|
||||
anim->is_active = true;
|
||||
}
|
||||
|
@ -40,15 +40,16 @@ struct tween
|
||||
tween_cb cb;
|
||||
};
|
||||
|
||||
typedef struct animation
|
||||
typedef struct menu_animation
|
||||
{
|
||||
struct tween *list;
|
||||
|
||||
size_t capacity;
|
||||
size_t size;
|
||||
} animation_t;
|
||||
bool is_active;
|
||||
} menu_animation_t;
|
||||
|
||||
enum animation_easing_type
|
||||
enum menu_animation_easing_type
|
||||
{
|
||||
/* Linear */
|
||||
EASING_LINEAR = 0,
|
||||
@ -94,15 +95,23 @@ enum animation_easing_type
|
||||
EASING_OUT_IN_BOUNCE,
|
||||
};
|
||||
|
||||
void menu_animation_free(animation_t *animation);
|
||||
void menu_animation_free(
|
||||
menu_animation_t *animation);
|
||||
|
||||
void menu_animation_kill_by_subject(animation_t *animation, size_t count, const void *subjects);
|
||||
void menu_animation_kill_by_subject(
|
||||
menu_animation_t *animation,
|
||||
size_t count,
|
||||
const void *subjects);
|
||||
|
||||
bool menu_animation_push(animation_t *animation, float duration,
|
||||
bool menu_animation_push(
|
||||
menu_animation_t *animation,
|
||||
float duration,
|
||||
float target_value, float* subject,
|
||||
enum animation_easing_type easing_enum, tween_cb cb);
|
||||
enum menu_animation_easing_type easing_enum, tween_cb cb);
|
||||
|
||||
bool menu_animation_update(animation_t *animation, float dt);
|
||||
bool menu_animation_update(
|
||||
menu_animation_t *animation,
|
||||
float dt);
|
||||
|
||||
/**
|
||||
* menu_animation_ticker_line:
|
||||
@ -118,6 +127,8 @@ bool menu_animation_update(animation_t *animation, float dt);
|
||||
void menu_animation_ticker_line(char *buf, size_t len, uint64_t tick,
|
||||
const char *str, bool selected);
|
||||
|
||||
menu_animation_t *menu_animation_get_ptr(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -87,11 +87,12 @@ void menu_display_fb(void)
|
||||
bool menu_display_update_pending(void)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
|
||||
|
||||
if (menu)
|
||||
{
|
||||
if (menu->animation_is_active || menu->label.is_updated)
|
||||
if (anim->is_active || menu->label.is_updated)
|
||||
return true;
|
||||
if (frame_buf && frame_buf->dirty)
|
||||
return true;
|
||||
@ -127,7 +128,8 @@ bool menu_display_init(void *data)
|
||||
if (!menu)
|
||||
return false;
|
||||
|
||||
menu->animation = (animation_t*)calloc(1, sizeof(animation_t));
|
||||
menu->animation = (menu_animation_t*)calloc
|
||||
(1, sizeof(menu_animation_t));
|
||||
|
||||
if (!menu->animation)
|
||||
return false;
|
||||
|
@ -119,8 +119,7 @@ typedef struct
|
||||
|
||||
|
||||
rarch_setting_t *list_settings;
|
||||
animation_t *animation;
|
||||
bool animation_is_active;
|
||||
menu_animation_t *animation;
|
||||
|
||||
content_playlist_t *playlist;
|
||||
char db_playlist_file[PATH_MAX_LENGTH];
|
||||
|
@ -597,6 +597,7 @@ static int menu_input_mouse(unsigned *action)
|
||||
const struct retro_keybind *binds[MAX_USERS];
|
||||
driver_t *driver = driver_get_ptr();
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
menu_input_t *menu_input = menu_input_get_ptr();
|
||||
menu_framebuf_t *frame_buf= menu_display_fb_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
@ -677,7 +678,7 @@ static int menu_input_mouse(unsigned *action)
|
||||
menu_input->mouse.scrollup ||
|
||||
menu_input->mouse.scrolldown
|
||||
)
|
||||
menu->animation_is_active = true;
|
||||
anim->is_active = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -688,6 +689,7 @@ static int menu_input_pointer(unsigned *action)
|
||||
const struct retro_keybind *binds[MAX_USERS] = {NULL};
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_input_t *menu_input = menu_input_get_ptr();
|
||||
menu_animation_t *anim = menu_animation_get_ptr();
|
||||
menu_framebuf_t *frame_buf= menu_display_fb_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
driver_t *driver = driver_get_ptr();
|
||||
@ -725,7 +727,7 @@ static int menu_input_pointer(unsigned *action)
|
||||
(menu_input->pointer.dy != 0) ||
|
||||
(menu_input->pointer.dx != 0)
|
||||
)
|
||||
menu->animation_is_active = true;
|
||||
anim->is_active = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user