From e4e5ebda3bb45ad668e21f99017fce4594fd06ed Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Tue, 20 Jul 2021 20:48:45 -0700 Subject: [PATCH] rename event handlers --- src/crab/common/emu.cr | 2 +- src/crab/common/frontend/controller.cr | 4 ++-- .../frontend/controllers/stubbed_controller.cr | 2 +- .../common/frontend/sdl_opengl_imgui_frontend.cr | 16 +++++++--------- src/crab/gb/gb.cr | 2 +- src/crab/gba/gba.cr | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/crab/common/emu.cr b/src/crab/common/emu.cr index f992e45..97b3448 100644 --- a/src/crab/common/emu.cr +++ b/src/crab/common/emu.cr @@ -4,6 +4,6 @@ abstract class Emu abstract def scheduler : Scheduler abstract def run_until_frame : Nil - abstract def handle_event(event : SDL::Event) : Nil + abstract def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil abstract def toggle_sync : Nil end diff --git a/src/crab/common/frontend/controller.cr b/src/crab/common/frontend/controller.cr index 7c2606b..f445370 100644 --- a/src/crab/common/frontend/controller.cr +++ b/src/crab/common/frontend/controller.cr @@ -32,8 +32,8 @@ abstract class Controller emu.run_until_frame end - def handle_event(event : SDL::Event) : Nil - emu.handle_event(event) + def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil + emu.handle_controller_event(event) end def handle_input(input : Input, pressed : Bool) : Nil diff --git a/src/crab/common/frontend/controllers/stubbed_controller.cr b/src/crab/common/frontend/controllers/stubbed_controller.cr index 3f33202..15a897c 100644 --- a/src/crab/common/frontend/controllers/stubbed_controller.cr +++ b/src/crab/common/frontend/controllers/stubbed_controller.cr @@ -19,7 +19,7 @@ class StubbedController < Controller def run_until_frame : Nil end - def handle_event(event : SDL::Event) : Nil + def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil end def handle_input(input : Input, pressed : Bool) : Nil diff --git a/src/crab/common/frontend/sdl_opengl_imgui_frontend.cr b/src/crab/common/frontend/sdl_opengl_imgui_frontend.cr index 230ddce..f104a52 100644 --- a/src/crab/common/frontend/sdl_opengl_imgui_frontend.cr +++ b/src/crab/common/frontend/sdl_opengl_imgui_frontend.cr @@ -121,18 +121,16 @@ class SDLOpenGLImGuiFrontend < Frontend case event when SDL::Event::Quit then exit when SDL::Event::JoyHat, - SDL::Event::JoyButton then @controller.handle_event(event) + SDL::Event::JoyButton then @controller.handle_controller_event(event) when SDL::Event::Keyboard if @keybindings.wants_input? @keybindings.key_released(event.sym) unless event.pressed? # pass on key release - else - if event.sym == LibSDL::Keycode::TAB - @controller.toggle_sync if event.pressed? - elsif event.sym == LibSDL::Keycode::Q && event.mod.includes?(LibSDL::Keymod::LCTRL) - exit - elsif input = @keybindings[event.sym]? - @controller.handle_input(input, event.pressed?) - end + elsif input = @keybindings[event.sym]? + @controller.handle_input(input, event.pressed?) + elsif event.sym == LibSDL::Keycode::TAB + @controller.toggle_sync if event.pressed? + elsif event.sym == LibSDL::Keycode::Q && event.mod.includes?(LibSDL::Keymod::LCTRL) + exit end else nil end diff --git a/src/crab/gb/gb.cr b/src/crab/gb/gb.cr index a97e9e0..c071450 100644 --- a/src/crab/gb/gb.cr +++ b/src/crab/gb/gb.cr @@ -58,7 +58,7 @@ module GB ppu.frame = false end - def handle_event(event : SDL::Event) : Nil + def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil joypad.handle_joypad_event event end diff --git a/src/crab/gba/gba.cr b/src/crab/gba/gba.cr index eb4967c..7203f46 100644 --- a/src/crab/gba/gba.cr +++ b/src/crab/gba/gba.cr @@ -57,7 +57,7 @@ module GBA ppu.frame = false end - def handle_event(event : SDL::Event) : Nil + def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil keypad.handle_keypad_event event end