Merge pull request #12914 from libretro/move-code-over-to-menu-driver

Move lots of menu code over to menu/menu_driver.c
This commit is contained in:
Autechre 2021-08-31 14:20:42 +02:00 committed by GitHub
commit 256713e888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 2554 additions and 2362 deletions

View File

@ -1048,6 +1048,7 @@ endif
ifeq ($(HAVE_MENU_COMMON), 1)
OBJ += menu/menu_setting.o \
menu/menu_driver.o \
menu/cbs/menu_cbs_ok.o \
menu/cbs/menu_cbs_cancel.o \
menu/cbs/menu_cbs_select.o \

View File

@ -159,6 +159,7 @@ static float gfx_display_get_widget_dpi_scale(
return adjusted_scale;
}
#if defined(HAVE_MENU) && defined(HAVE_XMB)
static float gfx_display_get_widget_pixel_scale(
gfx_display_t *p_disp,
settings_t *settings,
@ -237,7 +238,7 @@ static float gfx_display_get_widget_pixel_scale(
return adjusted_scale;
}
#endif
static void msg_widget_msg_transition_animation_done(void *userdata)
{

View File

@ -1369,6 +1369,7 @@ MENU
#endif
#ifdef HAVE_MENU
#include "../menu/menu_driver.c"
#include "../menu/menu_setting.c"
#if defined(HAVE_MATERIALUI) || defined(HAVE_XMB) || defined(HAVE_OZONE)
#include "../menu/menu_screensaver.c"

2220
menu/menu_driver.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -29,17 +29,22 @@
#include <formats/image.h>
#include <queues/task_queue.h>
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include "menu_defines.h"
#include "menu_dialog.h"
#include "menu_input.h"
#include "../input/input_osk.h"
#include "menu_input_bind_dialog.h"
#include "menu_entries.h"
#include "menu_shader.h"
#include "../gfx/gfx_display.h"
#include "../gfx/font_driver.h"
#include "../performance_counters.h"
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
RETRO_BEGIN_DECLS
@ -51,6 +56,25 @@ RETRO_BEGIN_DECLS
#define MAX_CHEAT_COUNTERS 6000
#endif
#define SCROLL_INDEX_SIZE (2 * (26 + 2) + 1)
#define POWERSTATE_CHECK_INTERVAL (30 * 1000000)
#define DATETIME_CHECK_INTERVAL 1000000
#define MENU_MAX_BUTTONS 219
#define MENU_MAX_AXES 32
#define MENU_MAX_HATS 4
#define MENU_MAX_MBUTTONS 32 /* Enough to cover largest libretro constant*/
#define MENU_LIST_GET(list, idx) ((list) ? ((list)->menu_stack[(idx)]) : NULL)
#define MENU_LIST_GET_SELECTION(list, idx) ((list) ? ((list)->selection_buf[(idx)]) : NULL)
#define MENU_LIST_GET_STACK_SIZE(list, idx) ((list)->menu_stack[(idx)]->size)
#define MENU_ENTRIES_GET_SELECTION_BUF_PTR_INTERNAL(menu_st, idx) ((menu_st->entries.list) ? MENU_LIST_GET_SELECTION(menu_st->entries.list, (unsigned)idx) : NULL)
#define MENU_ENTRIES_NEEDS_REFRESH(menu_st) (!(menu_st->entries_nonblocking_refresh || !menu_st->entries_need_refresh))
#define MENU_SETTINGS_CORE_INFO_NONE 0xffff
#define MENU_SETTINGS_CORE_OPTION_NONE 0xffff
#define MENU_SETTINGS_CHEEVOS_NONE 0xffff
@ -249,6 +273,112 @@ enum menu_settings_type
MENU_SETTINGS_LAST
};
struct menu_list
{
file_list_t **menu_stack;
size_t menu_stack_size;
file_list_t **selection_buf;
size_t selection_buf_size;
};
typedef struct menu_list menu_list_t;
struct menu_state
{
/* Timers */
retro_time_t current_time_us;
retro_time_t powerstate_last_time_us;
retro_time_t datetime_last_time_us;
retro_time_t input_last_time_us;
struct
{
rarch_setting_t *list_settings;
menu_list_t *list;
size_t begin;
} entries;
size_t selection_ptr;
/* Quick jumping indices with L/R.
* Rebuilt when parsing directory. */
struct
{
size_t index_list[SCROLL_INDEX_SIZE];
unsigned index_size;
unsigned acceleration;
} scroll;
/* Storage container for current menu datetime
* representation string */
char datetime_cache[255];
/* When generating a menu list in menu_displaylist_build_list(),
* the entry with a label matching 'pending_selection' will
* be selected automatically */
char pending_selection[PATH_MAX_LENGTH];
/* when enabled, on next iteration the 'Quick Menu' list will
* be pushed onto the stack */
bool pending_quick_menu;
bool prevent_populate;
/* The menu driver owns the userdata */
bool data_own;
/* Flagged when menu entries need to be refreshed */
bool entries_need_refresh;
bool entries_nonblocking_refresh;
/* 'Close Content'-hotkey menu resetting */
bool pending_close_content;
/* Screensaver status
* - Does menu driver support screensaver functionality?
* - Is screensaver currently active? */
bool screensaver_supported;
bool screensaver_active;
};
typedef struct menu_ctx_load_image
{
void *data;
enum menu_image_type type;
} menu_ctx_load_image_t;
struct menu_bind_state_port
{
int16_t axes[MENU_MAX_AXES];
uint16_t hats[MENU_MAX_HATS];
bool mouse_buttons[MENU_MAX_MBUTTONS];
bool buttons[MENU_MAX_BUTTONS];
};
struct menu_bind_axis_state
{
/* Default axis state. */
int16_t rested_axes[MENU_MAX_AXES];
/* Locked axis state. If we configured an axis,
* avoid having the same axis state trigger something again right away. */
int16_t locked_axes[MENU_MAX_AXES];
};
struct menu_bind_state
{
rarch_timer_t timer_timeout;
rarch_timer_t timer_hold;
struct retro_keybind *output;
struct retro_keybind buffer;
struct menu_bind_state_port state[MAX_USERS];
struct menu_bind_axis_state axis_state[MAX_USERS];
unsigned begin;
unsigned last;
unsigned user;
unsigned port;
bool skip;
};
typedef struct menu_ctx_driver
{
/* Set a framebuffer texture. This is used for instance by RGUI. */
@ -537,8 +667,158 @@ enum action_iterate_type
ITERATE_TYPE_BIND
};
int menu_dialog_iterate(
menu_dialog_t *p_dialog,
settings_t *settings,
char *s, size_t len,
retro_time_t current_time);
void menu_entries_settings_deinit(struct menu_state *menu_st);
int menu_input_key_bind_set_mode_common(
struct menu_state *menu_st,
struct menu_bind_state *binds,
enum menu_input_binds_ctl_state state,
rarch_setting_t *setting,
settings_t *settings);
void menu_input_key_bind_poll_bind_get_rested_axes(
const input_device_driver_t *joypad,
const input_device_driver_t *sec_joypad,
struct menu_bind_state *state);
#ifdef ANDROID
bool menu_input_key_bind_poll_find_hold_pad(
struct menu_bind_state *new_state,
struct retro_keybind * output,
unsigned p);
#endif
bool menu_input_key_bind_poll_find_trigger_pad(
struct menu_bind_state *state,
struct menu_bind_state *new_state,
struct retro_keybind * output,
unsigned p);
bool menu_input_key_bind_poll_find_trigger(
unsigned max_users,
struct menu_bind_state *state,
struct menu_bind_state *new_state,
struct retro_keybind * output);
void input_event_osk_iterate(
void *osk_grid,
enum osk_type osk_idx);
void menu_input_get_mouse_hw_state(
gfx_display_t *p_disp,
menu_handle_t *menu,
input_driver_state_t *input_driver_st,
input_driver_t *current_input,
const input_device_driver_t *joypad,
const input_device_driver_t *sec_joypad,
bool keyboard_mapping_blocked,
bool menu_mouse_enable,
bool input_overlay_enable,
bool overlay_active,
menu_input_pointer_hw_state_t *hw_state);
void menu_input_get_touchscreen_hw_state(
gfx_display_t *p_disp,
menu_handle_t *menu,
input_driver_state_t *input_driver_st,
input_driver_t *current_input,
const input_device_driver_t *joypad,
const input_device_driver_t *sec_joypad,
bool keyboard_mapping_blocked,
bool overlay_active,
bool pointer_enabled,
unsigned input_touch_scale,
menu_input_pointer_hw_state_t *hw_state);
bool menu_entries_init(
struct menu_state *menu_st,
const menu_ctx_driver_t *menu_driver_ctx);
void menu_entries_list_deinit(
const menu_ctx_driver_t *menu_driver_ctx,
struct menu_state *menu_st);
void menu_list_flush_stack(
const menu_ctx_driver_t *menu_driver_ctx,
void *menu_userdata,
struct menu_state *menu_st,
menu_list_t *list,
size_t idx, const char *needle, unsigned final_type);
bool menu_list_pop_stack(
const menu_ctx_driver_t *menu_driver_ctx,
void *menu_userdata,
menu_list_t *list,
size_t idx,
size_t *directory_ptr);
bool input_event_osk_show_symbol_pages(
menu_handle_t *menu);
float menu_input_get_dpi(
menu_handle_t *menu,
gfx_display_t *p_disp,
unsigned video_width,
unsigned video_height);
void menu_input_pointer_close_messagebox(struct menu_state *menu_st);
void menu_input_key_bind_poll_bind_state(
input_driver_state_t *input_driver_st,
const struct retro_keybind **binds,
float input_axis_threshold,
unsigned joy_idx,
struct menu_bind_state *state,
bool timed_out,
bool keyboard_mapping_blocked);
enum action_iterate_type action_iterate_type(const char *label);
void menu_cbs_init(
struct menu_state *menu_st,
const menu_ctx_driver_t *menu_driver_ctx,
file_list_t *list,
menu_file_list_cbs_t *cbs,
const char *path, const char *label,
unsigned type, size_t idx);
bool menu_driver_displaylist_push(
struct menu_state *menu_st,
settings_t *settings,
file_list_t *entry_list,
file_list_t *entry_stack);
void bundle_decompressed(retro_task_t *task,
void *task_data,
void *user_data, const char *err);
int generic_menu_entry_action(void *userdata, menu_entry_t *entry, size_t i, enum menu_action action);
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
void menu_driver_get_last_shader_path_int(
settings_t *settings, enum rarch_shader_type type,
const char *shader_dir, const char *shader_file_name,
const char **dir_out, const char **file_name_out);
#endif
bool generic_menu_init_list(struct menu_state *menu_st,
settings_t *settings);
bool menu_init(
struct menu_state *menu_st,
menu_dialog_t *p_dialog,
const menu_ctx_driver_t *menu_driver_ctx,
menu_input_t *menu_input,
menu_input_pointer_hw_state_t *pointer_hw_state,
settings_t *settings
);
extern menu_ctx_driver_t menu_ctx_ozone;
extern menu_ctx_driver_t menu_ctx_xui;
extern menu_ctx_driver_t menu_ctx_rgui;

File diff suppressed because it is too large Load Diff

View File

@ -268,18 +268,6 @@
#define MAPPER_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
#define MAPPER_UNSET_KEY(state, key) (state)->keys[(key) / 32] &= ~(1 << ((key) % 32))
#ifdef HAVE_MENU
#define MENU_LIST_GET(list, idx) ((list) ? ((list)->menu_stack[(idx)]) : NULL)
#define MENU_LIST_GET_SELECTION(list, idx) ((list) ? ((list)->selection_buf[(idx)]) : NULL)
#define MENU_LIST_GET_STACK_SIZE(list, idx) ((list)->menu_stack[(idx)]->size)
#define MENU_ENTRIES_GET_SELECTION_BUF_PTR_INTERNAL(menu_st, idx) ((menu_st->entries.list) ? MENU_LIST_GET_SELECTION(menu_st->entries.list, (unsigned)idx) : NULL)
#define MENU_ENTRIES_NEEDS_REFRESH(menu_st) (!(menu_st->entries_nonblocking_refresh || !menu_st->entries_need_refresh))
#endif
#define CDN_URL "https://cdn.discordapp.com/avatars"
#ifdef HAVE_DYNAMIC
@ -388,18 +376,6 @@
#define PERF_LOG_FMT "[PERF]: Avg (%s): %llu ticks, %llu runs.\n"
#endif
#ifdef HAVE_MENU
#define SCROLL_INDEX_SIZE (2 * (26 + 2) + 1)
#define POWERSTATE_CHECK_INTERVAL (30 * 1000000)
#define DATETIME_CHECK_INTERVAL 1000000
#define MENU_MAX_BUTTONS 219
#define MENU_MAX_AXES 32
#define MENU_MAX_HATS 4
#define MENU_MAX_MBUTTONS 32 /* Enough to cover largest libretro constant*/
#endif
/* DRIVERS */
audio_driver_t audio_null = {
@ -1244,112 +1220,6 @@ typedef struct input_game_focus_state
typedef bool(*runahead_load_state_function)(const void*, size_t);
#endif
#ifdef HAVE_MENU
typedef struct menu_ctx_load_image
{
void *data;
enum menu_image_type type;
} menu_ctx_load_image_t;
struct menu_list
{
file_list_t **menu_stack;
size_t menu_stack_size;
file_list_t **selection_buf;
size_t selection_buf_size;
};
typedef struct menu_list menu_list_t;
struct menu_state
{
/* Timers */
retro_time_t current_time_us;
retro_time_t powerstate_last_time_us;
retro_time_t datetime_last_time_us;
retro_time_t input_last_time_us;
struct
{
rarch_setting_t *list_settings;
menu_list_t *list;
size_t begin;
} entries;
size_t selection_ptr;
/* Quick jumping indices with L/R.
* Rebuilt when parsing directory. */
struct
{
size_t index_list[SCROLL_INDEX_SIZE];
unsigned index_size;
unsigned acceleration;
} scroll;
/* Storage container for current menu datetime
* representation string */
char datetime_cache[255];
/* When generating a menu list in menu_displaylist_build_list(),
* the entry with a label matching 'pending_selection' will
* be selected automatically */
char pending_selection[PATH_MAX_LENGTH];
/* when enabled, on next iteration the 'Quick Menu' list will
* be pushed onto the stack */
bool pending_quick_menu;
bool prevent_populate;
/* The menu driver owns the userdata */
bool data_own;
/* Flagged when menu entries need to be refreshed */
bool entries_need_refresh;
bool entries_nonblocking_refresh;
/* 'Close Content'-hotkey menu resetting */
bool pending_close_content;
/* Screensaver status
* - Does menu driver support screensaver functionality?
* - Is screensaver currently active? */
bool screensaver_supported;
bool screensaver_active;
};
struct menu_bind_state_port
{
int16_t axes[MENU_MAX_AXES];
uint16_t hats[MENU_MAX_HATS];
bool mouse_buttons[MENU_MAX_MBUTTONS];
bool buttons[MENU_MAX_BUTTONS];
};
struct menu_bind_axis_state
{
/* Default axis state. */
int16_t rested_axes[MENU_MAX_AXES];
/* Locked axis state. If we configured an axis,
* avoid having the same axis state trigger something again right away. */
int16_t locked_axes[MENU_MAX_AXES];
};
struct menu_bind_state
{
rarch_timer_t timer_timeout;
rarch_timer_t timer_hold;
struct retro_keybind *output;
struct retro_keybind buffer;
struct menu_bind_state_port state[MAX_USERS];
struct menu_bind_axis_state axis_state[MAX_USERS];
unsigned begin;
unsigned last;
unsigned user;
unsigned port;
bool skip;
};
#endif
typedef struct input_mapper
{
/* Left X, Left Y, Right X, Right Y */

View File

@ -44,13 +44,13 @@ static bool midi_driver_set_all_sounds_off(struct rarch_state *p_rarch);
static const void *midi_driver_find_handle(int index);
static bool midi_driver_flush(void);
static void retroarch_deinit_core_options(struct rarch_state *p_rarch,
static void retroarch_deinit_core_options(
const char *p);
static void retroarch_init_core_variables(
struct rarch_state *p_rarch,
settings_t *settings,
const struct retro_variable *vars);
static void rarch_init_core_options(
struct rarch_state *p_rarch,
settings_t *settings,
const struct retro_core_options_v2 *options_v2);
#ifdef HAVE_RUNAHEAD
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
@ -190,10 +190,6 @@ static const char **input_keyboard_start_line(
void *userdata,
struct input_keyboard_line *keyboard_line,
input_keyboard_line_complete_t cb);
static void menu_driver_list_free(
const menu_ctx_driver_t *menu_driver_ctx,
menu_ctx_list_t *list);
static int menu_input_post_iterate(
struct rarch_state *p_rarch,
gfx_display_t *p_disp,