Move code from menu_list.c to menu_entry.c

This commit is contained in:
twinaphex 2015-05-10 11:23:00 +02:00
parent 2996f389a2
commit 7914946d19
10 changed files with 99 additions and 92 deletions

View File

@ -22,6 +22,7 @@
#include <limits.h>
#include "../menu.h"
#include "../menu_entry.h"
#include "../menu_display.h"
#include "../../runloop_data.h"
@ -310,8 +311,8 @@ static void glui_render_menu_list(runloop_t *runloop,
entry_title_buf[PATH_MAX_LENGTH], type_str_buf[PATH_MAX_LENGTH];
bool selected = false;
menu_list_get_entry(&entry, i, NULL, true);
selected = menu_list_entry_is_currently_selected(&entry);
menu_entry_get(&entry, i, NULL, true);
selected = menu_entry_is_currently_selected(&entry);
menu_animation_ticker_line(entry_title_buf, glui->ticker_limit,
frame_count / 100, entry.path, selected);

View File

@ -22,6 +22,7 @@
#include <limits.h>
#include "../menu.h"
#include "../menu_entry.h"
#include "../menu_display.h"
#include <compat/posix_string.h>
#include <file/file_path.h>
@ -494,8 +495,8 @@ static void rgui_render(void)
entry_title_buf[PATH_MAX_LENGTH], type_str_buf[PATH_MAX_LENGTH];
bool selected = false;
menu_list_get_entry(&entry, i, NULL, true);
selected = menu_list_entry_is_currently_selected(&entry);
menu_entry_get(&entry, i, NULL, true);
selected = menu_entry_is_currently_selected(&entry);
if (i > (menu->navigation.selection_ptr + 100))
continue;

View File

@ -22,6 +22,7 @@
#include <limits.h>
#include "../menu_driver.h"
#include "../menu_entry.h"
#include "../menu_input.h"
#include "../menu.h"
#include "../../general.h"
@ -235,8 +236,8 @@ static void rmenu_render(void)
entry_title_buf[PATH_MAX_LENGTH], type_str_buf[PATH_MAX_LENGTH];
bool selected = false;
menu_list_get_entry(&entry, i, NULL, true);
selected = menu_list_entry_is_currently_selected(&entry);
menu_entry_get(&entry, i, NULL, true);
selected = menu_entry_is_currently_selected(&entry);
menu_animation_ticker_line(entry_title_buf, RMENU_TERM_WIDTH - (entry.spacing + 1 + 2),
frame_count / 15, entry.path, selected);

View File

@ -28,6 +28,7 @@
#include "../menu_driver.h"
#include "../menu.h"
#include "../menu_entry.h"
#include "../menu_list.h"
#include "../menu_input.h"
@ -606,7 +607,7 @@ static void rmenu_xui_render(void)
menu_entry_t entry;
wchar_t msg_left[PATH_MAX_LENGTH], msg_right[PATH_MAX_LENGTH];
menu_list_get_entry(&entry, i, NULL, true);
menu_entry_get(&entry, i, NULL, true);
mbstowcs(msg_left, entry.path, sizeof(msg_left) / sizeof(wchar_t));
mbstowcs(msg_right, entry.value, sizeof(msg_right) / sizeof(wchar_t));

View File

@ -21,6 +21,7 @@
#include <limits.h>
#include "../menu.h"
#include "../menu_entry.h"
#include "../menu_animation.h"
#include "../menu_display.h"
@ -1020,7 +1021,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl,
icon_y > global->video_data.height + xmb->icon.size)
continue;
menu_list_get_entry(&entry, i, list, true);
menu_entry_get(&entry, i, list, true);
if (entry.type == MENU_FILE_CONTENTLIST_ENTRY)
strlcpy(entry.path, path_basename(entry.path), sizeof(entry.path));

View File

@ -16,6 +16,7 @@
#include <file/file_path.h>
#include <retro_inline.h>
#include "menu.h"
#include "menu_entry.h"
#include "menu_entries_cbs.h"
#include "menu_setting.h"
#include "menu_input.h"
@ -489,7 +490,7 @@ static int action_iterate_switch(const char *label, unsigned action)
if (!menu)
return 0;
menu_list_get_entry(&entry, selected, NULL, false);
menu_entry_get(&entry, selected, NULL, false);
cbs = (menu_file_list_cbs_t*)menu_list_get_actiondata_at_offset(menu_list->selection_buf, selected);
@ -566,7 +567,7 @@ static void action_iterate_post(int *ret, const char *label, unsigned action)
menu_list_t *menu_list = menu_list_get_ptr();
size_t selected = menu_navigation_get_current_selection();
menu_list_get_entry(&entry, selected, NULL, false);
menu_entry_get(&entry, selected, NULL, false);
cbs = (menu_file_list_cbs_t*)menu_list_get_actiondata_at_offset(menu_list->selection_buf, selected);

View File

@ -237,6 +237,71 @@ float menu_entry_num_max(uint32_t i)
return setting->max;
}
void menu_entry_get(menu_entry_t *entry, size_t i,
void *userdata, bool use_representation)
{
const char *label = NULL;
const char *path = NULL;
const char *entry_label = NULL;
menu_file_list_cbs_t *cbs = NULL;
file_list_t *list = NULL;
menu_list_t *menu_list = menu_list_get_ptr();
if (!menu_list)
return;
menu_list_get_last_stack(menu_list, NULL, &label, NULL);
list = userdata ? (file_list_t*)userdata : menu_list->selection_buf;
if (!list)
return;
menu_list_get_at_offset(list, i, &path, &entry_label, &entry->type);
cbs = (menu_file_list_cbs_t*)menu_list_get_actiondata_at_offset(list, i);
if (cbs && cbs->action_get_representation && use_representation)
cbs->action_get_representation(list,
&entry->spacing, entry->type, i, label,
entry->value, sizeof(entry->value),
entry_label, path,
entry->path, sizeof(entry->path));
entry->id = i;
if (path)
strlcpy(entry->path, path, sizeof(entry->path));
if (entry_label)
strlcpy(entry->label, entry_label, sizeof(entry->label));
}
bool menu_entry_is_currently_selected(menu_entry_t *entry)
{
menu_navigation_t *nav = menu_navigation_get_ptr();
if (!entry || !nav)
return false;
return (entry->id == nav->selection_ptr);
}
int menu_entry_get_current_id(bool use_representation)
{
size_t i;
menu_list_t *menu_list = menu_list_get_ptr();
size_t end = menu_list_get_size(menu_list);
for (i = 0; i < end; i++)
{
menu_entry_t entry;
menu_entry_get(&entry, i, NULL, use_representation);
if (menu_entry_is_currently_selected(&entry))
return i;
}
return -1;
}
/* Returns true if the menu should reload */
uint32_t menu_entry_select(uint32_t i)
{
@ -247,7 +312,7 @@ uint32_t menu_entry_select(uint32_t i)
rarch_setting_t *setting = menu_setting_find(
menu_list->selection_buf->list[i].label);
menu_list_get_entry(&entry, i, NULL, false);
menu_entry_get(&entry, i, NULL, false);
cbs = (menu_file_list_cbs_t*)
menu_list_get_actiondata_at_offset(menu_list->selection_buf, i);

View File

@ -37,6 +37,16 @@ enum menu_entry_type
MENU_ENTRY_ENUM,
};
typedef struct menu_entry
{
char path[PATH_MAX_LENGTH];
char label[PATH_MAX_LENGTH];
char value[PATH_MAX_LENGTH];
unsigned id;
unsigned type;
unsigned spacing;
} menu_entry_t;
void get_core_title(char *title_msg, size_t title_msg_len);
rarch_setting_t *menu_entry_get_setting(uint32_t i);
@ -85,6 +95,13 @@ float menu_entry_num_min(uint32_t i);
float menu_entry_num_max(uint32_t i);
int menu_entry_get_current_id(bool use_representation);
bool menu_entry_is_currently_selected(menu_entry_t *entry);
void menu_entry_get(menu_entry_t *entry, size_t i,
void *userdata, bool use_representation);
uint32_t menu_entry_select(uint32_t i);
#ifdef __cplusplus

View File

@ -420,68 +420,3 @@ int menu_list_populate_generic(file_list_t *list, const char *path,
return 0;
}
void menu_list_get_entry(menu_entry_t *entry, size_t i, void *userdata,
bool use_representation)
{
const char *label = NULL;
const char *path = NULL;
const char *entry_label = NULL;
menu_file_list_cbs_t *cbs = NULL;
file_list_t *list = NULL;
menu_list_t *menu_list = menu_list_get_ptr();
if (!menu_list)
return;
menu_list_get_last_stack(menu_list, NULL, &label, NULL);
list = userdata ? (file_list_t*)userdata : menu_list->selection_buf;
if (!list)
return;
menu_list_get_at_offset(list, i, &path, &entry_label, &entry->type);
cbs = (menu_file_list_cbs_t*)menu_list_get_actiondata_at_offset(list, i);
if (cbs && cbs->action_get_representation && use_representation)
cbs->action_get_representation(list,
&entry->spacing, entry->type, i, label,
entry->value, sizeof(entry->value),
entry_label, path,
entry->path, sizeof(entry->path));
entry->id = i;
if (path)
strlcpy(entry->path, path, sizeof(entry->path));
if (entry_label)
strlcpy(entry->label, entry_label, sizeof(entry->label));
}
bool menu_list_entry_is_currently_selected(menu_entry_t *entry)
{
menu_navigation_t *nav = menu_navigation_get_ptr();
if (!entry || !nav)
return false;
return (entry->id == nav->selection_ptr);
}
int menu_list_get_current_entry_id(bool use_representation)
{
size_t i;
menu_list_t *menu_list = menu_list_get_ptr();
size_t end = menu_list_get_size(menu_list);
for (i = 0; i < end; i++)
{
menu_entry_t entry;
menu_list_get_entry(&entry, i, NULL, use_representation);
if (menu_list_entry_is_currently_selected(&entry))
return i;
}
return -1;
}

View File

@ -30,16 +30,6 @@ typedef struct menu_list
file_list_t *selection_buf;
} menu_list_t;
typedef struct menu_entry
{
char path[PATH_MAX_LENGTH];
char label[PATH_MAX_LENGTH];
char value[PATH_MAX_LENGTH];
unsigned id;
unsigned type;
unsigned spacing;
} menu_entry_t;
menu_list_t *menu_list_get_ptr(void);
void menu_list_free(menu_list_t *menu_list);
@ -99,12 +89,6 @@ void menu_list_set_alt_at_offset(file_list_t *list, size_t idx,
int menu_list_populate_generic(file_list_t *list,
const char *path, const char *label, unsigned type);
void menu_list_get_entry(menu_entry_t *entry, size_t i, void *userdata, bool use_representation);
int menu_list_get_current_entry_id(bool use_representation);
bool menu_list_entry_is_currently_selected(menu_entry_t *entry);
#ifdef __cplusplus
}
#endif