Start to generalise text input to "terminal signal" input

This commit is contained in:
2023-03-26 13:57:26 +01:00
parent cfb0a49059
commit 082ce9c9a1
39 changed files with 171 additions and 165 deletions
+12 -3
View File
@@ -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