Refactor menu

This commit is contained in:
twinaphex 2015-02-11 21:15:39 +01:00
parent 7ade44cbc3
commit c3fdd42fb0
5 changed files with 48 additions and 54 deletions

View File

@ -31,10 +31,10 @@
#include "shared.h"
#define RGUI_TERM_START_X (driver.menu->width / 21)
#define RGUI_TERM_START_Y (driver.menu->height / 9)
#define RGUI_TERM_WIDTH (((driver.menu->width - RGUI_TERM_START_X - RGUI_TERM_START_X) / (FONT_WIDTH_STRIDE)))
#define RGUI_TERM_HEIGHT (((driver.menu->height - RGUI_TERM_START_Y - RGUI_TERM_START_X) / (FONT_HEIGHT_STRIDE)) - 1)
#define RGUI_TERM_START_X (menu->width / 21)
#define RGUI_TERM_START_Y (menu->height / 9)
#define RGUI_TERM_WIDTH (((menu->width - RGUI_TERM_START_X - RGUI_TERM_START_X) / (FONT_WIDTH_STRIDE)))
#define RGUI_TERM_HEIGHT (((menu->height - RGUI_TERM_START_Y - RGUI_TERM_START_X) / (FONT_HEIGHT_STRIDE)) - 1)
static int rgui_entry_iterate(menu_handle_t *menu, unsigned action)
{
@ -296,8 +296,8 @@ static void rgui_blit_cursor(menu_handle_t *menu)
int16_t x = menu->mouse.x;
int16_t y = menu->mouse.y;
color_rect(driver.menu, x, y - 5, 1, 11, 0xFFFF);
color_rect(driver.menu, x - 5, y, 11, 1, 0xFFFF);
color_rect(menu, x, y - 5, 1, 11, 0xFFFF);
color_rect(menu, x - 5, y, 11, 1, 0xFFFF);
}
static void rgui_render(menu_handle_t *menu)
@ -504,7 +504,7 @@ static void rgui_free(void *data)
if (menu->userdata)
free(menu->userdata);
driver.menu->userdata = NULL;
menu->userdata = NULL;
if (menu->alloc_font)
free((uint8_t*)menu->font);

View File

@ -158,17 +158,17 @@ static void rmenu_render(menu_handle_t *menu)
&& !menu->msg_force)
return;
if (!driver.menu->menu_list->selection_buf)
if (!menu->menu_list->selection_buf)
return;
begin = (menu->selection_ptr >= (ENTRIES_HEIGHT / 2)) ?
(menu->selection_ptr - (ENTRIES_HEIGHT / 2)) : 0;
end = ((menu->selection_ptr + ENTRIES_HEIGHT) <=
menu_list_get_size(driver.menu->menu_list)) ?
menu_list_get_size(menu->menu_list)) ?
menu->selection_ptr + ENTRIES_HEIGHT :
menu_list_get_size(driver.menu->menu_list);
menu_list_get_size(menu->menu_list);
if (menu_list_get_size(driver.menu->menu_list) <= ENTRIES_HEIGHT)
if (menu_list_get_size(menu->menu_list) <= ENTRIES_HEIGHT)
begin = 0;
if (end - begin > ENTRIES_HEIGHT)
@ -176,7 +176,7 @@ static void rmenu_render(menu_handle_t *menu)
rmenu_render_background();
menu_list_get_last_stack(driver.menu->menu_list, &dir, &label, &menu_type);
menu_list_get_last_stack(menu->menu_list, &dir, &label, &menu_type);
get_title(label, dir, menu_type, title, sizeof(title));
@ -235,17 +235,17 @@ static void rmenu_render(menu_handle_t *menu)
&path, &entry_label, &type);
cbs = (menu_file_list_cbs_t*)
menu_list_get_actiondata_at_offset(driver.menu->menu_list->selection_buf,
menu_list_get_actiondata_at_offset(menu->menu_list->selection_buf,
i);
if (cbs && cbs->action_get_representation)
cbs->action_get_representation(driver.menu->menu_list->selection_buf,
cbs->action_get_representation(menu->menu_list->selection_buf,
&w, type, i, label,
type_str, sizeof(type_str),
entry_label, path,
path_buf, sizeof(path_buf));
selected = (i == driver.menu->selection_ptr);
selected = (i == menu->selection_ptr);
menu_ticker_line(entry_title_buf, RMENU_TERM_WIDTH - (w + 1 + 2),
g_extern.frame_count / 15, path, selected);

View File

@ -577,7 +577,7 @@ static xmb_node_t* xmb_node_for_core(xmb_handle_t *xmb, int i)
return node;
}
static void xmb_list_switch_old(xmb_handle_t *xmb, file_list_t *list, int dir, size_t current)
static void xmb_list_switch_old(menu_handle_t *menu, xmb_handle_t *xmb, file_list_t *list, int dir, size_t current)
{
int i;
@ -589,13 +589,13 @@ static void xmb_list_switch_old(xmb_handle_t *xmb, file_list_t *list, int dir, s
if (!node)
continue;
menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->label_alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(driver.menu->animation, XMB_DELAY, -xmb->hspacing*dir, &node->x, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, 0, &node->alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, 0, &node->label_alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, -xmb->hspacing*dir, &node->x, EASING_IN_OUT_QUAD, NULL);
}
}
static void xmb_list_switch_new(xmb_handle_t *xmb, file_list_t *list, int dir, size_t current)
static void xmb_list_switch_new(menu_handle_t *menu, xmb_handle_t *xmb, file_list_t *list, int dir, size_t current)
{
int i;
@ -615,21 +615,21 @@ static void xmb_list_switch_new(xmb_handle_t *xmb, file_list_t *list, int dir, s
if (i == current)
ia = 1.0;
menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(driver.menu->animation, XMB_DELAY, 0, &node->x, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, ia, &node->label_alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, 0, &node->x, EASING_IN_OUT_QUAD, NULL);
}
}
static void xmb_set_title(xmb_handle_t *xmb)
static void xmb_set_title(menu_handle_t *menu, xmb_handle_t *xmb)
{
if (driver.menu->cat_selection_ptr == 0)
if (menu->cat_selection_ptr == 0)
{
const char *dir = NULL;
const char *label = NULL;
unsigned menu_type = 0;
menu_list_get_last_stack(driver.menu->menu_list, &dir, &label, &menu_type);
menu_list_get_last_stack(menu->menu_list, &dir, &label, &menu_type);
get_title(label, dir, menu_type, xmb->title, sizeof(xmb->title));
}
else
@ -640,24 +640,24 @@ static void xmb_set_title(xmb_handle_t *xmb)
if (!info_list)
return;
info = (core_info_t*)&info_list->list[driver.menu->cat_selection_ptr - 1];
info = (core_info_t*)&info_list->list[menu->cat_selection_ptr - 1];
if (info)
strlcpy(xmb->title, info->display_name, sizeof(xmb->title));
}
}
static void xmb_list_open(xmb_handle_t *xmb)
static void xmb_list_open(menu_handle_t *menu, xmb_handle_t *xmb)
{
unsigned j;
int dir = -1;
if (driver.menu->cat_selection_ptr > xmb->cat_selection_ptr_old)
if (menu->cat_selection_ptr > xmb->cat_selection_ptr_old)
dir = 1;
xmb->active_category += dir;
for (j = 0; j < driver.menu->num_categories; j++)
for (j = 0; j < menu->num_categories; j++)
{
float ia = xmb->c_passive_alpha;
float iz = xmb->c_passive_zoom;
@ -672,21 +672,21 @@ static void xmb_list_open(xmb_handle_t *xmb)
iz = xmb->c_active_zoom;
}
menu_animation_push(driver.menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(driver.menu->animation, XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, ia, &node->alpha, EASING_IN_OUT_QUAD, NULL);
menu_animation_push(menu->animation, XMB_DELAY, iz, &node->zoom, EASING_IN_OUT_QUAD, NULL);
}
menu_animation_push(driver.menu->animation, XMB_DELAY,
xmb->hspacing * -(float)driver.menu->cat_selection_ptr,
menu_animation_push(menu->animation, XMB_DELAY,
xmb->hspacing * -(float)menu->cat_selection_ptr,
&xmb->categories_x, EASING_IN_OUT_QUAD, NULL);
dir = -1;
if (driver.menu->cat_selection_ptr > xmb->cat_selection_ptr_old)
if (menu->cat_selection_ptr > xmb->cat_selection_ptr_old)
dir = 1;
xmb_list_switch_old(xmb, xmb->selection_buf_old, dir, xmb->selection_ptr_old);
xmb_list_switch_new(xmb, driver.menu->menu_list->selection_buf, dir, driver.menu->selection_ptr);
xmb->active_category_old = driver.menu->cat_selection_ptr;
xmb_list_switch_old(menu, xmb, xmb->selection_buf_old, dir, xmb->selection_ptr_old);
xmb_list_switch_new(menu, xmb, menu->menu_list->selection_buf, dir, menu->selection_ptr);
xmb->active_category_old = menu->cat_selection_ptr;
}
static void xmb_list_switch(menu_handle_t *menu, xmb_handle_t *xmb)
@ -759,10 +759,10 @@ static void xmb_populate_entries(menu_handle_t *menu, const char *path,
return;
}
xmb_set_title(xmb);
xmb_set_title(menu, xmb);
if (menu->cat_selection_ptr != xmb->active_category_old)
xmb_list_open(xmb);
xmb_list_open(menu, xmb);
else
xmb_list_switch(menu, xmb);
}
@ -1513,21 +1513,15 @@ static void xmb_context_destroy(menu_handle_t *menu)
}
}
static void xmb_toggle(bool menu_on)
static void xmb_toggle(menu_handle_t *menu, bool menu_on)
{
int i;
xmb_handle_t *xmb = NULL;
menu_handle_t *menu = (menu_handle_t*)driver.menu;
if (!menu)
return;
xmb = (xmb_handle_t*)menu->userdata;
xmb_handle_t *xmb = (xmb_handle_t*)menu->userdata;
if (!xmb)
return;
xmb->depth = file_list_get_size(driver.menu->menu_list->menu_stack);
xmb->depth = file_list_get_size(menu->menu_list->menu_stack);
if (!menu_on)
{
@ -1535,12 +1529,12 @@ static void xmb_toggle(bool menu_on)
return;
}
menu_animation_push(driver.menu->animation, XMB_DELAY, 1.0f,
menu_animation_push(menu->animation, XMB_DELAY, 1.0f,
&xmb->alpha, EASING_IN_OUT_QUAD, NULL);
xmb->prevent_populate = !menu->need_refresh;
for (i = 0; i < driver.menu->num_categories; i++)
for (i = 0; i < menu->num_categories; i++)
{
xmb_node_t *node = i ? xmb_node_for_core(xmb, i - 1) : &xmb->settings_node;

View File

@ -191,7 +191,7 @@ typedef struct menu_ctx_driver
void (*context_destroy)(menu_handle_t *menu);
void (*populate_entries)(menu_handle_t *menu, const char *path, const char *label,
unsigned k);
void (*toggle)(bool);
void (*toggle)(menu_handle_t *menu, bool);
void (*navigation_clear)(menu_handle_t *menu, bool);
void (*navigation_decrement)(menu_handle_t *menu);
void (*navigation_increment)(menu_handle_t *menu);

View File

@ -1959,7 +1959,7 @@ void rarch_main_set_state(unsigned cmd)
return;
if (driver.menu && driver.menu_ctx && driver.menu_ctx->toggle)
driver.menu_ctx->toggle(true);
driver.menu_ctx->toggle(driver.menu, true);
/* Menu should always run with vsync on. */
rarch_main_command(RARCH_CMD_VIDEO_SET_BLOCKING_STATE);
@ -1994,7 +1994,7 @@ void rarch_main_set_state(unsigned cmd)
menu_apply_deferred_settings();
if (driver.menu && driver.menu_ctx && driver.menu_ctx->toggle)
driver.menu_ctx->toggle(false);
driver.menu_ctx->toggle(driver.menu, false);
g_extern.is_menu = false;