WIP keyboard Event classes.
This commit is contained in:
parent
73d1206edb
commit
04c5e35f52
28
src/main.cr
28
src/main.cr
@ -80,6 +80,23 @@ class Naka::Event
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: Split in KeyUp and KeyDown.
|
||||
class KeyUp
|
||||
getter key : LibSDL::Keycode
|
||||
getter scan_code : LibSDL::Scancode
|
||||
|
||||
def initialize(@key, @scan_code)
|
||||
end
|
||||
end
|
||||
class KeyDown
|
||||
getter key : LibSDL::Keycode
|
||||
getter scan_code : LibSDL::Scancode
|
||||
getter repeat : Bool
|
||||
|
||||
def initialize(@key, @scan_code, @repeat)
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: THIS MAIN LOOP IS **NOT** READY FOR PRODUCTION
|
||||
# Update events are still missing, and both Draw and Update should
|
||||
# be time-based.
|
||||
@ -101,6 +118,13 @@ class Naka::Event
|
||||
r_value = yield case event
|
||||
when SDL::Event::Quit
|
||||
Naka::Event::Quit.new
|
||||
when SDL::Event::Keyboard
|
||||
keysym = event.keysym
|
||||
if event.type == LibSDL::EventType::KEYUP
|
||||
Naka::Event::KeyUp.new keysym.sym, keysym.scancode
|
||||
elsif event.type == LibSDL::EventType::KEYDOWN
|
||||
Naka::Event::KeyDown.new keysym.sym, keysym.scancode, event.repeat != 0
|
||||
end
|
||||
else # FIXME: Most event types may need proper Naka:: classes.
|
||||
event
|
||||
end
|
||||
@ -144,10 +168,10 @@ Naka::Event.loop window do |event|
|
||||
when Naka::Event::Quit
|
||||
next Naka::Event::Quit
|
||||
when Naka::Event::Update
|
||||
p "Update(#{event.dt})"
|
||||
when Naka::Event::Draw
|
||||
p "Draw"
|
||||
event.window.draw naka, 20, 20
|
||||
when Naka::Event::KeyUp, Naka::Event::KeyDown
|
||||
pp! event
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user