rename event handlers

This commit is contained in:
Matthew Berry 2021-07-20 20:48:45 -07:00
parent e02b31bcc7
commit e4e5ebda3b
6 changed files with 13 additions and 15 deletions

View file

@ -4,6 +4,6 @@ abstract class Emu
abstract def scheduler : Scheduler abstract def scheduler : Scheduler
abstract def run_until_frame : Nil 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 abstract def toggle_sync : Nil
end end

View file

@ -32,8 +32,8 @@ abstract class Controller
emu.run_until_frame emu.run_until_frame
end end
def handle_event(event : SDL::Event) : Nil def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil
emu.handle_event(event) emu.handle_controller_event(event)
end end
def handle_input(input : Input, pressed : Bool) : Nil def handle_input(input : Input, pressed : Bool) : Nil

View file

@ -19,7 +19,7 @@ class StubbedController < Controller
def run_until_frame : Nil def run_until_frame : Nil
end end
def handle_event(event : SDL::Event) : Nil def handle_controller_event(event : SDL::Event::JoyHat | SDL::Event::JoyButton) : Nil
end end
def handle_input(input : Input, pressed : Bool) : Nil def handle_input(input : Input, pressed : Bool) : Nil

View file

@ -121,18 +121,16 @@ class SDLOpenGLImGuiFrontend < Frontend
case event case event
when SDL::Event::Quit then exit when SDL::Event::Quit then exit
when SDL::Event::JoyHat, 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 when SDL::Event::Keyboard
if @keybindings.wants_input? if @keybindings.wants_input?
@keybindings.key_released(event.sym) unless event.pressed? # pass on key release @keybindings.key_released(event.sym) unless event.pressed? # pass on key release
else elsif input = @keybindings[event.sym]?
if event.sym == LibSDL::Keycode::TAB @controller.handle_input(input, event.pressed?)
@controller.toggle_sync if event.pressed? elsif event.sym == LibSDL::Keycode::TAB
elsif event.sym == LibSDL::Keycode::Q && event.mod.includes?(LibSDL::Keymod::LCTRL) @controller.toggle_sync if event.pressed?
exit elsif event.sym == LibSDL::Keycode::Q && event.mod.includes?(LibSDL::Keymod::LCTRL)
elsif input = @keybindings[event.sym]? exit
@controller.handle_input(input, event.pressed?)
end
end end
else nil else nil
end end

View file

@ -58,7 +58,7 @@ module GB
ppu.frame = false ppu.frame = false
end 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 joypad.handle_joypad_event event
end end

View file

@ -57,7 +57,7 @@ module GBA
ppu.frame = false ppu.frame = false
end 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 keypad.handle_keypad_event event
end end