rg_gui: Insert extra items in about menu items via a handler rather than an argument

This commit is contained in:
Alex Duchesne 2024-12-16 19:04:46 -05:00
parent 50121fc28b
commit 92da1ec155
5 changed files with 41 additions and 46 deletions

View File

@ -1587,6 +1587,9 @@ void rg_gui_options_menu(void)
*opt++ = (rg_gui_option_t)RG_DIALOG_END;
if (app->handlers.options)
app->handlers.options(options + get_dialog_items_count(options));
rg_audio_set_mute(true);
rg_gui_dialog(_("Options"), options, 0);
@ -1595,7 +1598,7 @@ void rg_gui_options_menu(void)
rg_audio_set_mute(false);
}
void rg_gui_about_menu(const rg_gui_option_t *extra_options)
void rg_gui_about_menu(void)
{
const rg_app_t *app = rg_system_get_app();
bool have_option_btn = rg_input_get_key_mapping(RG_KEY_OPTION);
@ -1614,14 +1617,8 @@ void rg_gui_about_menu(const rg_gui_option_t *extra_options)
RG_DIALOG_END,
};
size_t extra_options_count = get_dialog_items_count(extra_options);
if (extra_options_count > 0)
{
rg_gui_option_t *opt = options + get_dialog_items_count(options);
for (size_t i = 0; i < extra_options_count; i++)
*opt++ = extra_options[i];
*opt++ = (rg_gui_option_t)RG_DIALOG_END;
}
if (app->handlers.about)
app->handlers.about(options + get_dialog_items_count(options));
while (true)
{
@ -1632,7 +1629,7 @@ void rg_gui_about_menu(const rg_gui_option_t *extra_options)
rg_gui_alert("Credits", RG_PROJECT_CREDITS);
break;
case 2:
rg_gui_debug_menu(NULL);
rg_gui_debug_menu();
break;
case 3:
if (rg_gui_confirm(_("Reset all settings?"), NULL, false)) {
@ -1651,7 +1648,7 @@ void rg_gui_about_menu(const rg_gui_option_t *extra_options)
}
}
void rg_gui_debug_menu(const rg_gui_option_t *extra_options)
void rg_gui_debug_menu(void)
{
char screen_res[20], source_res[20], scaled_res[20];
char stack_hwm[20], heap_free[20], block_free[20];
@ -1857,7 +1854,7 @@ void rg_gui_game_menu(void)
case 5000: rg_netplay_quick_start(); break;
#endif
case 5500: rg_gui_options_menu(); break;
case 6000: rg_gui_about_menu(NULL); break;
case 6000: rg_gui_about_menu(); break;
case 7000: rg_system_exit(); break;
}

View File

@ -124,8 +124,8 @@ char *rg_gui_prompt(const char *title, const char *message, const char *default_
int rg_gui_savestate_menu(const char *title, const char *rom_path);
void rg_gui_options_menu(void);
void rg_gui_game_menu(void);
void rg_gui_about_menu(const rg_gui_option_t *extra_options);
void rg_gui_debug_menu(const rg_gui_option_t *extra_options);
void rg_gui_about_menu(void);
void rg_gui_debug_menu(void);
// Creates a 565LE color from C_RGB(255, 255, 255)
#define C_RGB(r, g, b) ((((r) >> 3) << 11) | (((g) >> 2) << 5) | (((b) & 0x1F)))

View File

@ -126,22 +126,17 @@ typedef enum
RG_EVENT_SLEEP = RG_EVENT_TYPE_POWER | 2,
} rg_event_t;
typedef bool (*rg_state_handler_t)(const char *filename);
typedef bool (*rg_reset_handler_t)(bool hard);
typedef void (*rg_event_handler_t)(int event, void *data);
typedef bool (*rg_screenshot_handler_t)(const char *filename, int width, int height);
typedef int (*rg_mem_read_handler_t)(int addr);
typedef int (*rg_mem_write_handler_t)(int addr, int value);
typedef struct
{
rg_state_handler_t loadState; // rg_emu_load_state() handler
rg_state_handler_t saveState; // rg_emu_save_state() handler
rg_reset_handler_t reset; // rg_emu_reset() handler
rg_screenshot_handler_t screenshot; // rg_emu_screenshot() handler
rg_event_handler_t event; // listen to retro-go system events
rg_mem_read_handler_t memRead; // Used by for cheats and debugging
rg_mem_write_handler_t memWrite; // Used by for cheats and debugging
bool (*loadState)(const char *filename); // rg_emu_load_state() handler
bool (*saveState)(const char *filename); // rg_emu_save_state() handler
bool (*reset)(bool hard); // rg_emu_reset() handler
bool (*screenshot)(const char *filename, int width, int height); // rg_emu_screenshot() handler
void (*event)(int event, void *data); // listen to retro-go system events
int (*memRead)(int addr); // Used by for cheats and debugging
int (*memWrite)(int addr, int value); // Used by for cheats and debugging
void (*options)(rg_gui_option_t *dest); // Add extra options to rg_gui_options_menu()
void (*about)(rg_gui_option_t *dest); // Add extra options to rg_gui_about_menu()
} rg_handlers_t;
typedef struct

View File

@ -210,18 +210,6 @@ static rg_gui_event_t prebuild_cache_cb(rg_gui_option_t *option, rg_gui_event_t
return RG_DIALOG_VOID;
}
static void show_about_menu(void)
{
const rg_gui_option_t options[] = {
{0, _("Build CRC cache"), NULL, RG_DIALOG_FLAG_NORMAL, &prebuild_cache_cb},
#ifdef RG_ENABLE_NETWORKING
{0, _("Check for updates"), NULL, RG_DIALOG_FLAG_NORMAL, &updater_cb},
#endif
RG_DIALOG_END,
};
rg_gui_about_menu(options);
}
static void retro_loop(void)
{
tab_t *tab = NULL;
@ -281,7 +269,7 @@ static void retro_loop(void)
if (joystick & (RG_KEY_MENU|RG_KEY_OPTION))
{
if (joystick == RG_KEY_MENU)
show_about_menu();
rg_gui_about_menu();
else
rg_gui_options_menu();
@ -440,17 +428,30 @@ void event_handler(int event, void *arg)
gui_redraw();
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Launcher options"), NULL, RG_DIALOG_FLAG_NORMAL, &launcher_options_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
static void about_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Build CRC cache"), NULL, RG_DIALOG_FLAG_NORMAL, &prebuild_cache_cb};
#ifdef RG_ENABLE_NETWORKING
*dest++ = (rg_gui_option_t){0, _("Check for updates"), NULL, RG_DIALOG_FLAG_NORMAL, &updater_cb};
#endif
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void app_main(void)
{
const rg_handlers_t handlers = {
.event = &event_handler,
};
const rg_gui_option_t options[] = {
{0, _("Launcher options"), NULL, RG_DIALOG_FLAG_NORMAL, &launcher_options_cb},
RG_DIALOG_END,
.options = &options_handler,
.about = &about_handler,
};
app = rg_system_init(32000, &handlers, options);
app = rg_system_init(32000, &handlers, NULL);
app->configNs = "launcher";
app->isLauncher = true;

View File

@ -189,6 +189,8 @@ extern "C" void lynx_main(void)
.event = &event_handler,
.memRead = NULL,
.memWrite = NULL,
.options = NULL,
.about = NULL,
};
const rg_gui_option_t options[] = {
{0, _("Rotation"), (char *)"-", RG_DIALOG_FLAG_NORMAL, &rotation_cb},