Start to generalise text input to "terminal signal" input
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
-- | Deals with events that only affect Input.
|
||||
-- | Capture input events, store them in structures for later use.
|
||||
-- Should not update the world other than this.
|
||||
module Dodge.Event.Input (
|
||||
handleKeyboardEvent,
|
||||
handleTextInput,
|
||||
@@ -15,19 +16,27 @@ import SDL
|
||||
-- annoyingly, the text input event doesn't register backspace, so deletion has to be
|
||||
-- dealt with separately
|
||||
handleTextInput :: String -> Input -> Input
|
||||
handleTextInput text = textInput %~ (++ text)
|
||||
handleTextInput text = textInput %~ (++ map Right text)
|
||||
|
||||
-- | Handles keyboard press and release.
|
||||
handleKeyboardEvent :: KeyboardEventData -> Input -> Input
|
||||
handleKeyboardEvent kev = case keyboardEventKeyMotion kev of
|
||||
Released -> pressedKeys . at scode .~ Nothing
|
||||
Pressed -> pressedKeys . at scode ?~ val
|
||||
Pressed -> (pressedKeys . at scode ?~ val)
|
||||
. addTermSignal scode
|
||||
where
|
||||
val
|
||||
| keyboardEventRepeat kev = LongPress
|
||||
| otherwise = InitialPress
|
||||
scode = (keysymScancode . keyboardEventKeysym) kev
|
||||
|
||||
addTermSignal :: Scancode -> Input -> Input
|
||||
addTermSignal sc = case sc of
|
||||
ScancodeBackspace -> textInput .:~ Left TSbackspace
|
||||
ScancodeEscape -> textInput .:~ Left TSescape
|
||||
ScancodeReturn -> textInput .:~ Left TSreturn
|
||||
_ -> id
|
||||
|
||||
handleMouseMotionEvent :: MouseMotionEventData -> Configuration -> Input -> Input
|
||||
handleMouseMotionEvent mmev cfig =
|
||||
set mousePos themousepos
|
||||
|
||||
Reference in New Issue
Block a user