Skip to content

Commit

Permalink
rg_gui: Insert extra items in about menu items via a handler rather…
Browse files Browse the repository at this point in the history
… than an argument
  • Loading branch information
ducalex committed Dec 17, 2024
1 parent 50121fc commit 92da1ec
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 46 deletions.
21 changes: 9 additions & 12 deletions components/retro-go/rg_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)
{
Expand All @@ -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)) {
Expand All @@ -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];
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions components/retro-go/rg_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
23 changes: 9 additions & 14 deletions components/retro-go/rg_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 19 additions & 18 deletions launcher/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions retro-core/main/main_lynx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 92da1ec

Please sign in to comment.