Skip to content

Commit 4819f8a

Browse files
committed
Improve gamepad shortcut configuration
1 parent 4dedd02 commit 4819f8a

5 files changed

Lines changed: 50 additions & 38 deletions

File tree

platforms/shared/desktop/events.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,12 @@ void events_shortcuts(const SDL_Event* event)
6464
return;
6565
}
6666

67-
if (events_check_hotkey(event, config_hotkeys[config_HotkeyIndex_Fullscreen], false))
68-
{
69-
config_emulator.fullscreen = !config_emulator.fullscreen;
70-
application_trigger_fullscreen(config_emulator.fullscreen);
71-
return;
72-
}
73-
74-
if (events_check_hotkey(event, config_hotkeys[config_HotkeyIndex_CaptureMouse], false))
75-
{
76-
config_emulator.capture_mouse = !config_emulator.capture_mouse;
77-
return;
78-
}
79-
80-
// Check slot selection hotkeys
81-
for (int i = 0; i < 5; i++)
82-
{
83-
if (events_check_hotkey(event, config_hotkeys[config_HotkeyIndex_SelectSlot1 + i], false))
84-
{
85-
config_emulator.save_slot = i;
86-
return;
87-
}
88-
}
89-
9067
// Check all hotkeys mapped to gui shortcuts
9168
for (int i = 0; i < GUI_HOTKEY_MAP_COUNT; i++)
9269
{
93-
if (gui_hotkey_map[i].shortcut >= 0 && events_check_hotkey(event, config_hotkeys[gui_hotkey_map[i].config_index], gui_hotkey_map[i].allow_repeat))
70+
if (events_check_hotkey(event, config_hotkeys[gui_hotkey_map[i].config_index], gui_hotkey_map[i].allow_repeat))
9471
{
95-
gui_shortcut((gui_ShortCutEvent)gui_hotkey_map[i].shortcut);
72+
gui_shortcut(gui_hotkey_map[i].shortcut);
9673
return;
9774
}
9875
}

platforms/shared/desktop/gamepad.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,12 @@ void gamepad_check_shortcuts(int controller)
377377

378378
if (button_pressed && !gamepad_shortcut_prev[controller][i])
379379
{
380-
if (i >= config_HotkeyIndex_SelectSlot1 && i <= config_HotkeyIndex_SelectSlot5)
380+
for (int j = 0; j < GUI_HOTKEY_MAP_COUNT; j++)
381381
{
382-
config_emulator.save_slot = i - config_HotkeyIndex_SelectSlot1;
383-
}
384-
else
385-
{
386-
for (int j = 0; j < GUI_HOTKEY_MAP_COUNT; j++)
382+
if (gui_hotkey_map[j].config_index == i)
387383
{
388-
if (gui_hotkey_map[j].config_index == i)
389-
{
390-
gui_shortcut((gui_ShortCutEvent)gui_hotkey_map[j].shortcut);
391-
break;
392-
}
384+
gui_shortcut(gui_hotkey_map[j].shortcut);
385+
break;
393386
}
394387
}
395388
}

platforms/shared/desktop/gui.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,31 @@ void gui_shortcut(gui_ShortCutEvent event)
222222
emu_load_state_slot(config_emulator.save_slot + 1);
223223
break;
224224
}
225+
case gui_ShortcutSelectSlot1:
226+
config_emulator.save_slot = 0;
227+
break;
228+
case gui_ShortcutSelectSlot2:
229+
config_emulator.save_slot = 1;
230+
break;
231+
case gui_ShortcutSelectSlot3:
232+
config_emulator.save_slot = 2;
233+
break;
234+
case gui_ShortcutSelectSlot4:
235+
config_emulator.save_slot = 3;
236+
break;
237+
case gui_ShortcutSelectSlot5:
238+
config_emulator.save_slot = 4;
239+
break;
225240
case gui_ShortcutScreenshot:
226241
gui_action_save_screenshot(NULL);
227242
break;
243+
case gui_ShortcutFullscreen:
244+
config_emulator.fullscreen = !config_emulator.fullscreen;
245+
application_trigger_fullscreen(config_emulator.fullscreen);
246+
break;
247+
case gui_ShortcutCaptureMouse:
248+
config_emulator.capture_mouse = !config_emulator.capture_mouse;
249+
break;
228250
case gui_ShortcutDebugStepOver:
229251
if (config_debug.debug)
230252
emu_debug_step_over();

platforms/shared/desktop/gui.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ enum gui_ShortCutEvent
4343
gui_ShortcutMute,
4444
gui_ShortcutSaveState,
4545
gui_ShortcutLoadState,
46+
gui_ShortcutSelectSlot1,
47+
gui_ShortcutSelectSlot2,
48+
gui_ShortcutSelectSlot3,
49+
gui_ShortcutSelectSlot4,
50+
gui_ShortcutSelectSlot5,
4651
gui_ShortcutScreenshot,
52+
gui_ShortcutFullscreen,
53+
gui_ShortcutCaptureMouse,
4754
gui_ShortcutDebugStepOver,
4855
gui_ShortcutDebugStepInto,
4956
gui_ShortcutDebugStepOut,
@@ -61,12 +68,12 @@ enum gui_ShortCutEvent
6168

6269
struct gui_HotkeyMapping
6370
{
64-
int shortcut;
71+
gui_ShortCutEvent shortcut;
6572
int config_index;
6673
bool allow_repeat;
6774
};
6875

69-
#define GUI_HOTKEY_MAP_COUNT 19
76+
#define GUI_HOTKEY_MAP_COUNT 26
7077

7178
const gui_HotkeyMapping gui_hotkey_map[GUI_HOTKEY_MAP_COUNT] = {
7279
{gui_ShortcutOpenROM, config_HotkeyIndex_OpenROM, false},
@@ -77,7 +84,14 @@ const gui_HotkeyMapping gui_hotkey_map[GUI_HOTKEY_MAP_COUNT] = {
7784
{gui_ShortcutMute, config_HotkeyIndex_Mute, false},
7885
{gui_ShortcutSaveState, config_HotkeyIndex_SaveState, false},
7986
{gui_ShortcutLoadState, config_HotkeyIndex_LoadState, false},
87+
{gui_ShortcutSelectSlot1, config_HotkeyIndex_SelectSlot1, false},
88+
{gui_ShortcutSelectSlot2, config_HotkeyIndex_SelectSlot2, false},
89+
{gui_ShortcutSelectSlot3, config_HotkeyIndex_SelectSlot3, false},
90+
{gui_ShortcutSelectSlot4, config_HotkeyIndex_SelectSlot4, false},
91+
{gui_ShortcutSelectSlot5, config_HotkeyIndex_SelectSlot5, false},
8092
{gui_ShortcutScreenshot, config_HotkeyIndex_Screenshot, false},
93+
{gui_ShortcutFullscreen, config_HotkeyIndex_Fullscreen, false},
94+
{gui_ShortcutCaptureMouse, config_HotkeyIndex_CaptureMouse, false},
8195
{gui_ShortcutShowMainMenu, config_HotkeyIndex_ShowMainMenu, false},
8296
{gui_ShortcutDebugStepInto, config_HotkeyIndex_DebugStepInto, true},
8397
{gui_ShortcutDebugStepOver, config_HotkeyIndex_DebugStepOver, true},

platforms/shared/desktop/gui_menus.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ static void menu_input(void)
934934
gamepad_configuration_item("Rewind:", &config_input_gamepad_shortcuts[0].gamepad_shortcuts[config_HotkeyIndex_Rewind], 0);
935935
gamepad_configuration_item("Screenshot:", &config_input_gamepad_shortcuts[0].gamepad_shortcuts[config_HotkeyIndex_Screenshot], 0);
936936
gamepad_configuration_item("Mute Audio:", &config_input_gamepad_shortcuts[0].gamepad_shortcuts[config_HotkeyIndex_Mute], 0);
937+
gamepad_configuration_item("Fullscreen:", &config_input_gamepad_shortcuts[0].gamepad_shortcuts[config_HotkeyIndex_Fullscreen], 0);
938+
gamepad_configuration_item("Capture Mouse:", &config_input_gamepad_shortcuts[0].gamepad_shortcuts[config_HotkeyIndex_CaptureMouse], 0);
939+
gamepad_configuration_item("Show Main Menu:", &config_input_gamepad_shortcuts[0].gamepad_shortcuts[config_HotkeyIndex_ShowMainMenu], 0);
937940

938941
gui_popup_modal_gamepad(0);
939942

@@ -996,6 +999,9 @@ static void menu_input(void)
996999
gamepad_configuration_item("Rewind:", &config_input_gamepad_shortcuts[1].gamepad_shortcuts[config_HotkeyIndex_Rewind], 1);
9971000
gamepad_configuration_item("Screenshot:", &config_input_gamepad_shortcuts[1].gamepad_shortcuts[config_HotkeyIndex_Screenshot], 1);
9981001
gamepad_configuration_item("Mute Audio:", &config_input_gamepad_shortcuts[1].gamepad_shortcuts[config_HotkeyIndex_Mute], 1);
1002+
gamepad_configuration_item("Fullscreen:", &config_input_gamepad_shortcuts[1].gamepad_shortcuts[config_HotkeyIndex_Fullscreen], 1);
1003+
gamepad_configuration_item("Capture Mouse:", &config_input_gamepad_shortcuts[1].gamepad_shortcuts[config_HotkeyIndex_CaptureMouse], 1);
1004+
gamepad_configuration_item("Show Main Menu:", &config_input_gamepad_shortcuts[1].gamepad_shortcuts[config_HotkeyIndex_ShowMainMenu], 1);
9991005

10001006
gui_popup_modal_gamepad(1);
10011007

0 commit comments

Comments
 (0)