Skip to content

Commit 74297ee

Browse files
committed
Add reset functionality
1 parent d080cf6 commit 74297ee

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/crab/common/frontend/sdl_opengl_imgui_frontend.cr

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,20 @@ class SDLOpenGLImGuiFrontend < Frontend
9595
LibGL.clear_color(red / 255, green / 255, blue / 255, alpha / 255)
9696
end
9797

98+
private def reset : Nil
99+
return if @controller.is_a? StubbedController
100+
recent_rom = @config.recents.shift?
101+
load_new_rom(recent_rom) if recent_rom
102+
end
103+
98104
def pause(b : Bool) : Nil
99105
if @pause != b
100106
@pause = b
101107
LibSDL.gl_set_swap_interval(@pause.to_unsafe)
102108
end
103109
end
104110

105-
private def load_new_rom(rom : String?) : Nil
111+
private def load_new_rom(rom : String) : Nil
106112
LibSDL.close_audio(1)
107113
@controller = init_controller(nil, rom, @config.run_bios)
108114

@@ -129,6 +135,7 @@ class SDLOpenGLImGuiFrontend < Frontend
129135
@config_editor.keybindings.key_released(event.sym) unless event.pressed? # pass on key release
130136
elsif event.mod.includes?(LibSDL::Keymod::LCTRL)
131137
case event.sym
138+
when LibSDL::Keycode::R then reset
132139
when LibSDL::Keycode::P then pause(!@pause) unless event.pressed?
133140
when LibSDL::Keycode::F then @window.fullscreen = (@fullscreen = !@fullscreen) unless event.pressed?
134141
when LibSDL::Keycode::Q then exit
@@ -190,7 +197,7 @@ class SDLOpenGLImGuiFrontend < Frontend
190197

191198
private def render_imgui : Nil
192199
ImGui::OpenGL3.new_frame
193-
ImGui::SDL2.new_frame()
200+
ImGui::SDL2.new_frame
194201
ImGui.new_frame
195202

196203
overlay_height = 10.0
@@ -217,11 +224,14 @@ class SDLOpenGLImGuiFrontend < Frontend
217224
end
218225

219226
ImGui.menu "Emulation" do
227+
should_reset = false
220228
pause = @pause
221229

230+
ImGui.menu_item "Reset", "Ctrl+R", pointerof(should_reset)
222231
ImGui.menu_item "Pause", "Ctrl+P", pointerof(pause)
223232
@controller.toggle_sync if ImGui.menu_item "Audio Sync", "Tab", @controller.sync?, !stubbed?
224233

234+
reset if should_reset
225235
pause(pause)
226236
end
227237

0 commit comments

Comments
 (0)