{-# LANGUAGE MultiWayIf #-}
module Graphics.RedViz.Input.FRP.Yampa.AppInput
    ( AppInput
    , parseWinInput
    , mousePos
    , mouseRelPos
    , runSFEveryOtherTick
    , mouseMoving
    , mouseStopped
    , lbp
    , lbpPos
    , lbDown
    , rbp
    , rbpPos
    , rbDown
    , keyInput
    , quitEvent
    , centerEvent
    , module SDL.Input.Keyboard.Codes
    ) where

import           Data.Maybe

import           FRP.Yampa

import           Linear (V2(..))
import           Linear.Affine (Point(..))

import           SDL.Input.Keyboard.Codes
import qualified SDL

-- import Debug.Trace as DT

-- <| Signal Functions |> --
-- | Current mouse position
mousePos :: SF AppInput (Double,Double)
mousePos :: SF AppInput (Double, Double)
mousePos = (AppInput -> (Double, Double)) -> SF AppInput (Double, Double)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr AppInput -> (Double, Double)
inpMousePos

mouseRelPos :: SF AppInput (Double,Double)
--mouseRelPos = iPre initAppInput >>> arr inpMouseRelPos
mouseRelPos :: SF AppInput (Double, Double)
mouseRelPos = (AppInput -> (Double, Double)) -> SF AppInput (Double, Double)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr AppInput -> (Double, Double)
inpMouseRelPos

runSFEveryOtherTick :: SF a (Event b) -> SF a (Event b)
runSFEveryOtherTick :: SF a (Event b) -> SF a (Event b)
runSFEveryOtherTick SF a (Event b)
sf =
  SF Identity a (Event b, Event ())
-> (() -> SF a (Event b)) -> SF a (Event b)
forall (m :: * -> *) a b c.
Monad m =>
SF m a (b, Event c) -> (c -> SF m a b) -> SF m a b
dSwitch
    (Event b -> SF a (Event b)
forall (m :: * -> *) b a. Monad m => b -> SF m a b
constant Event b
forall a. Event a
noEvent SF a (Event b)
-> MSF (ClockInfo Identity) a (Event ())
-> SF Identity a (Event b, Event ())
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Event () -> MSF (ClockInfo Identity) a (Event ())
forall (m :: * -> *) b a. Monad m => b -> SF m a b
constant (() -> Event ()
forall a. a -> Event a
Event ()))
    (SF a (Event b) -> () -> SF a (Event b)
forall a b. a -> b -> a
const (SF a (Event b) -> () -> SF a (Event b))
-> SF a (Event b) -> () -> SF a (Event b)
forall a b. (a -> b) -> a -> b
$ SF Identity a (Event b, Event ())
-> (() -> SF a (Event b)) -> SF a (Event b)
forall (m :: * -> *) a b c.
Monad m =>
SF m a (b, Event c) -> (c -> SF m a b) -> SF m a b
dSwitch
         (SF a (Event b)
sf SF a (Event b)
-> MSF (ClockInfo Identity) a (Event ())
-> SF Identity a (Event b, Event ())
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Event () -> MSF (ClockInfo Identity) a (Event ())
forall (m :: * -> *) b a. Monad m => b -> SF m a b
constant (() -> Event ()
forall a. a -> Event a
Event ()))
         (SF a (Event b) -> () -> SF a (Event b)
forall a b. a -> b -> a
const (SF a (Event b) -> () -> SF a (Event b))
-> SF a (Event b) -> () -> SF a (Event b)
forall a b. (a -> b) -> a -> b
$ SF a (Event b) -> SF a (Event b)
forall a b. SF a (Event b) -> SF a (Event b)
runSFEveryOtherTick SF a (Event b)
sf))

-- | Events that indicate left button click
lbp :: SF AppInput (Event ())
lbp :: SF AppInput (Event ())
lbp = SF AppInput (Event (Double, Double))
lbpPos SF AppInput (Event (Double, Double))
-> (Event (Double, Double) -> Event ()) -> SF AppInput (Event ())
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ () -> Event (Double, Double) -> Event ()
forall b a. b -> Event a -> Event b
tagWith ()

-- | Events that indicate left button click and are tagged with mouse position
lbpPos :: SF AppInput (Event (Double,Double))
lbpPos :: SF AppInput (Event (Double, Double))
lbpPos = AppInput -> Maybe (Double, Double)
inpMouseLeft (AppInput -> Maybe (Double, Double))
-> MSF
     (ClockInfo Identity)
     (Maybe (Double, Double))
     (Event (Double, Double))
-> SF AppInput (Event (Double, Double))
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> MSF
  (ClockInfo Identity)
  (Maybe (Double, Double))
  (Event (Double, Double))
forall (m :: * -> *) a. Monad m => SF m (Maybe a) (Event a)
edgeJust

-- | Is left button down
lbDown :: SF AppInput Bool
lbDown :: SF AppInput Bool
lbDown = (AppInput -> Bool) -> SF AppInput Bool
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (Maybe (Double, Double) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (Double, Double) -> Bool)
-> (AppInput -> Maybe (Double, Double)) -> AppInput -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppInput -> Maybe (Double, Double)
inpMouseLeft)

-- | Events that indicate right button click
rbp :: SF AppInput (Event ())
rbp :: SF AppInput (Event ())
rbp = SF AppInput (Event (Double, Double))
rbpPos SF AppInput (Event (Double, Double))
-> (Event (Double, Double) -> Event ()) -> SF AppInput (Event ())
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ () -> Event (Double, Double) -> Event ()
forall b a. b -> Event a -> Event b
tagWith ()

-- | Events that indicate right button click and are tagged with mouse position
rbpPos :: SF AppInput (Event (Double,Double))
rbpPos :: SF AppInput (Event (Double, Double))
rbpPos = AppInput -> Maybe (Double, Double)
inpMouseRight (AppInput -> Maybe (Double, Double))
-> MSF
     (ClockInfo Identity)
     (Maybe (Double, Double))
     (Event (Double, Double))
-> SF AppInput (Event (Double, Double))
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> MSF
  (ClockInfo Identity)
  (Maybe (Double, Double))
  (Event (Double, Double))
forall (m :: * -> *) a. Monad m => SF m (Maybe a) (Event a)
edgeJust

-- | Is right button down
rbDown :: SF AppInput Bool
rbDown :: SF AppInput Bool
rbDown = (AppInput -> Bool) -> SF AppInput Bool
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (Maybe (Double, Double) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (Double, Double) -> Bool)
-> (AppInput -> Maybe (Double, Double)) -> AppInput -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppInput -> Maybe (Double, Double)
inpMouseRight)

mouseMoving :: SF AppInput (Event (Double, Double))
--mouseMoving = arr inpMouseMoving >>> edge
mouseMoving :: SF AppInput (Event (Double, Double))
mouseMoving = AppInput -> Maybe (Double, Double)
inpMouseMoving (AppInput -> Maybe (Double, Double))
-> MSF
     (ClockInfo Identity)
     (Maybe (Double, Double))
     (Event (Double, Double))
-> SF AppInput (Event (Double, Double))
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> MSF
  (ClockInfo Identity)
  (Maybe (Double, Double))
  (Event (Double, Double))
forall (m :: * -> *) a. Monad m => SF m (Maybe a) (Event a)
edgeJust

mouseStopped :: SF AppInput (Event ())
mouseStopped :: SF AppInput (Event ())
mouseStopped = (AppInput -> Bool) -> SF AppInput Bool
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr AppInput -> Bool
inpMouseStopped SF AppInput Bool
-> MSF (ClockInfo Identity) Bool (Event ())
-> SF AppInput (Event ())
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> MSF (ClockInfo Identity) Bool (Event ())
forall (m :: * -> *). Monad m => SF m Bool (Event ())
edge

quitEvent :: SF AppInput (Event ())
quitEvent :: SF AppInput (Event ())
quitEvent = (AppInput -> Bool) -> SF AppInput Bool
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr AppInput -> Bool
inpQuit SF AppInput Bool
-> MSF (ClockInfo Identity) Bool (Event ())
-> SF AppInput (Event ())
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> MSF (ClockInfo Identity) Bool (Event ())
forall (m :: * -> *). Monad m => SF m Bool (Event ())
edge

centerEvent :: SF AppInput (Event ())
centerEvent :: SF AppInput (Event ())
centerEvent = (AppInput -> Bool) -> SF AppInput Bool
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr AppInput -> Bool
inpCenter SF AppInput Bool
-> MSF (ClockInfo Identity) Bool (Event ())
-> SF AppInput (Event ())
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> MSF (ClockInfo Identity) Bool (Event ())
forall (m :: * -> *). Monad m => SF m Bool (Event ())
edge

keyInput :: SDL.Scancode -> String -> SF AppInput (Event ())
keyInput :: Scancode -> String -> SF AppInput (Event ())
keyInput Scancode
code String
mode =
  (AppInput -> Maybe Scancode
inpKeyMode (AppInput -> Maybe Scancode)
-> MSF (ClockInfo Identity) (Maybe Scancode) (Event Scancode)
-> MSF (ClockInfo Identity) AppInput (Event Scancode)
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> MSF (ClockInfo Identity) (Maybe Scancode) (Event Scancode)
forall (m :: * -> *) a. Monad m => SF m (Maybe a) (Event a)
edgeJust) MSF (ClockInfo Identity) AppInput (Event Scancode)
-> (Event Scancode -> Event ()) -> SF AppInput (Event ())
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (Scancode -> Bool) -> Event Scancode -> Event Scancode
forall a. (a -> Bool) -> Event a -> Event a
filterE (Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
==) (Event Scancode -> Event Scancode)
-> (Event Scancode -> Event ()) -> Event Scancode -> Event ()
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ () -> Event Scancode -> Event ()
forall b a. b -> Event a -> Event b
tagWith ()
  where
    inpKeyMode :: AppInput -> Maybe Scancode
inpKeyMode
      -- code == code = inpMousePos -- TODO: attempting to add mouse input sensing
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeSpace
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeySpacePressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeySpaceReleased           
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeW
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyWPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyWReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeS
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeySPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeySReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeA
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyAPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyAReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeD
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyDPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyDReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeQ
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyQPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyQReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeE
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyEPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyEReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeZ
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyZPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyZReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeX
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyXPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyXReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeC
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyCPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyCReleased           
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeUp
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyUpPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyUpReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeDown
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyDownPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyDownReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLeft
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyLeftPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyLeftReleased           
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeRight
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyRightPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyRightReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodePageUp
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyPageUpPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyPageUpReleased           
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodePageDown
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyPageDownPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyPageDownReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLShift
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyLShiftPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyLShiftReleased           
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLCtrl
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyLCtrlPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyLCtrlReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLAlt
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyLAltPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyLAltReleased
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeRShift
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyRShiftPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyRShiftReleased           
      | Scancode
code Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeRCtrl
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpKeyRCtrlPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpKeyRCtrlReleased
      | Bool
otherwise
      = if | String
mode String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Pressed" -> AppInput -> Maybe Scancode
inpAnyKeyPressed
           | Bool
otherwise         -> AppInput -> Maybe Scancode
inpAnyKeyReleased

data AppInput =
     AppInput
     { AppInput -> (Double, Double)
inpMousePos          :: (Double, Double)        -- ^ Current mouse position
     , AppInput -> (Double, Double)
inpMouseRelPos       :: (Double, Double)        -- ^ Relative mouse motion
     , AppInput -> Maybe (Double, Double)
inpMouseLeft         :: Maybe (Double, Double)  -- ^ Left   button currently down
     , AppInput -> Maybe (Double, Double)
inpMouseRight        :: Maybe (Double, Double)  -- ^ Right  button currently down
     , AppInput -> Maybe (Double, Double)
inpMouseMiddle       :: Maybe (Double, Double)  -- ^ Middle button currently down
     , AppInput -> Bool
inpQuit              :: Bool                    -- ^ SDL's QuitEvent
     , AppInput -> Bool
inpCenter            :: Bool
     , AppInput -> Maybe (Double, Double)
inpMouseMoving       :: Maybe (Double, Double)
     , AppInput -> Bool
inpMouseStopped      :: Bool
     , AppInput -> Maybe Scancode
inpKeySpacePressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeySpaceReleased  :: Maybe SDL.Scancode
     -- W
     , AppInput -> Maybe Scancode
inpKeyWPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyWReleased      :: Maybe SDL.Scancode
     -- S                   
     , AppInput -> Maybe Scancode
inpKeySPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeySReleased      :: Maybe SDL.Scancode
     -- A                   
     , AppInput -> Maybe Scancode
inpKeyAPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyAReleased      :: Maybe SDL.Scancode
     -- D                   
     , AppInput -> Maybe Scancode
inpKeyDPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyDReleased      :: Maybe SDL.Scancode
     -- Q                   
     , AppInput -> Maybe Scancode
inpKeyQPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyQReleased      :: Maybe SDL.Scancode
     -- E                   
     , AppInput -> Maybe Scancode
inpKeyEPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyEReleased      :: Maybe SDL.Scancode
     -- Z                   
     , AppInput -> Maybe Scancode
inpKeyZPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyZReleased      :: Maybe SDL.Scancode
     -- X                   
     , AppInput -> Maybe Scancode
inpKeyXPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyXReleased      :: Maybe SDL.Scancode
     -- C                   
     , AppInput -> Maybe Scancode
inpKeyCPressed       :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyCReleased      :: Maybe SDL.Scancode
     -- Up
     , AppInput -> Maybe Scancode
inpKeyUpPressed      :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyUpReleased     :: Maybe SDL.Scancode
     -- Down
     , AppInput -> Maybe Scancode
inpKeyDownPressed    :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyDownReleased   :: Maybe SDL.Scancode
     -- Left
     , AppInput -> Maybe Scancode
inpKeyLeftPressed    :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyLeftReleased   :: Maybe SDL.Scancode
     -- Right
     , AppInput -> Maybe Scancode
inpKeyRightPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyRightReleased  :: Maybe SDL.Scancode
     -- PageUp
     , AppInput -> Maybe Scancode
inpKeyPageUpPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyPageUpReleased  :: Maybe SDL.Scancode
     -- PageDown
     , AppInput -> Maybe Scancode
inpKeyPageDownPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyPageDownReleased  :: Maybe SDL.Scancode
     -- -- LShift
     , AppInput -> Maybe Scancode
inpKeyLShiftPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyLShiftReleased  :: Maybe SDL.Scancode
     -- LCtrl
     , AppInput -> Maybe Scancode
inpKeyLCtrlPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyLCtrlReleased  :: Maybe SDL.Scancode
     -- LAlt
     , AppInput -> Maybe Scancode
inpKeyLAltPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyLAltReleased  :: Maybe SDL.Scancode
     -- RShift
     , AppInput -> Maybe Scancode
inpKeyRShiftPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyRShiftReleased  :: Maybe SDL.Scancode     
     -- RCtrl
     , AppInput -> Maybe Scancode
inpKeyRCtrlPressed   :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpKeyRCtrlReleased  :: Maybe SDL.Scancode
     -- Catch All
     , AppInput -> Maybe Scancode
inpAnyKeyPressed     :: Maybe SDL.Scancode
     , AppInput -> Maybe Scancode
inpAnyKeyReleased    :: Maybe SDL.Scancode
     }

type WinInput = Event SDL.EventPayload    

initAppInput :: AppInput
initAppInput :: AppInput
initAppInput =
     AppInput :: (Double, Double)
-> (Double, Double)
-> Maybe (Double, Double)
-> Maybe (Double, Double)
-> Maybe (Double, Double)
-> Bool
-> Bool
-> Maybe (Double, Double)
-> Bool
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> Maybe Scancode
-> AppInput
AppInput 
     { inpMousePos :: (Double, Double)
inpMousePos          = (Double
0.0, Double
0.0)
     , inpMouseRelPos :: (Double, Double)
inpMouseRelPos       = (Double
0.0, Double
0.0)
     , inpMouseLeft :: Maybe (Double, Double)
inpMouseLeft         = Maybe (Double, Double)
forall a. Maybe a
Nothing
     , inpMouseMiddle :: Maybe (Double, Double)
inpMouseMiddle       = Maybe (Double, Double)
forall a. Maybe a
Nothing
     , inpMouseRight :: Maybe (Double, Double)
inpMouseRight        = Maybe (Double, Double)
forall a. Maybe a
Nothing
     , inpMouseMoving :: Maybe (Double, Double)
inpMouseMoving       = Maybe (Double, Double)
forall a. Maybe a
Nothing
     , inpMouseStopped :: Bool
inpMouseStopped      = Bool
True
     --, inpMouseMiddle       = Nothing
     , inpQuit :: Bool
inpQuit              = Bool
False
     , inpCenter :: Bool
inpCenter            = Bool
True
     , inpKeySpacePressed :: Maybe Scancode
inpKeySpacePressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeySpaceReleased :: Maybe Scancode
inpKeySpaceReleased  = Maybe Scancode
forall a. Maybe a
Nothing
     -- W
     , inpKeyWPressed :: Maybe Scancode
inpKeyWPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyWReleased :: Maybe Scancode
inpKeyWReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- S                   
     , inpKeySPressed :: Maybe Scancode
inpKeySPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeySReleased :: Maybe Scancode
inpKeySReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- A                   
     , inpKeyAPressed :: Maybe Scancode
inpKeyAPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyAReleased :: Maybe Scancode
inpKeyAReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- D                   
     , inpKeyDPressed :: Maybe Scancode
inpKeyDPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyDReleased :: Maybe Scancode
inpKeyDReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- Q                   
     , inpKeyQPressed :: Maybe Scancode
inpKeyQPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyQReleased :: Maybe Scancode
inpKeyQReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- E                   
     , inpKeyEPressed :: Maybe Scancode
inpKeyEPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyEReleased :: Maybe Scancode
inpKeyEReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- Z                   
     , inpKeyZPressed :: Maybe Scancode
inpKeyZPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyZReleased :: Maybe Scancode
inpKeyZReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- X                   
     , inpKeyXPressed :: Maybe Scancode
inpKeyXPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyXReleased :: Maybe Scancode
inpKeyXReleased      = Maybe Scancode
forall a. Maybe a
Nothing
     -- C                   
     , inpKeyCPressed :: Maybe Scancode
inpKeyCPressed       = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyCReleased :: Maybe Scancode
inpKeyCReleased      = Maybe Scancode
forall a. Maybe a
Nothing     
     -- Up
     , inpKeyUpPressed :: Maybe Scancode
inpKeyUpPressed      = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyUpReleased :: Maybe Scancode
inpKeyUpReleased     = Maybe Scancode
forall a. Maybe a
Nothing
     -- Down
     , inpKeyDownPressed :: Maybe Scancode
inpKeyDownPressed    = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyDownReleased :: Maybe Scancode
inpKeyDownReleased   = Maybe Scancode
forall a. Maybe a
Nothing
     -- Left
     , inpKeyLeftPressed :: Maybe Scancode
inpKeyLeftPressed    = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyLeftReleased :: Maybe Scancode
inpKeyLeftReleased   = Maybe Scancode
forall a. Maybe a
Nothing
     -- Right
     , inpKeyRightPressed :: Maybe Scancode
inpKeyRightPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyRightReleased :: Maybe Scancode
inpKeyRightReleased  = Maybe Scancode
forall a. Maybe a
Nothing
     -- PageUp
     , inpKeyPageUpPressed :: Maybe Scancode
inpKeyPageUpPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyPageUpReleased :: Maybe Scancode
inpKeyPageUpReleased  = Maybe Scancode
forall a. Maybe a
Nothing
     -- PageDown
     , inpKeyPageDownPressed :: Maybe Scancode
inpKeyPageDownPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyPageDownReleased :: Maybe Scancode
inpKeyPageDownReleased  = Maybe Scancode
forall a. Maybe a
Nothing
     -- LShift
     , inpKeyLShiftPressed :: Maybe Scancode
inpKeyLShiftPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyLShiftReleased :: Maybe Scancode
inpKeyLShiftReleased  = Maybe Scancode
forall a. Maybe a
Nothing     
     -- LCtrl
     , inpKeyLCtrlPressed :: Maybe Scancode
inpKeyLCtrlPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyLCtrlReleased :: Maybe Scancode
inpKeyLCtrlReleased  = Maybe Scancode
forall a. Maybe a
Nothing
     -- LAlt
     , inpKeyLAltPressed :: Maybe Scancode
inpKeyLAltPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyLAltReleased :: Maybe Scancode
inpKeyLAltReleased  = Maybe Scancode
forall a. Maybe a
Nothing
     -- RShift
     , inpKeyRShiftPressed :: Maybe Scancode
inpKeyRShiftPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyRShiftReleased :: Maybe Scancode
inpKeyRShiftReleased  = Maybe Scancode
forall a. Maybe a
Nothing     
     -- RCtrl
     , inpKeyRCtrlPressed :: Maybe Scancode
inpKeyRCtrlPressed   = Maybe Scancode
forall a. Maybe a
Nothing
     , inpKeyRCtrlReleased :: Maybe Scancode
inpKeyRCtrlReleased  = Maybe Scancode
forall a. Maybe a
Nothing
     -- Any Other Key
     , inpAnyKeyPressed :: Maybe Scancode
inpAnyKeyPressed     = Maybe Scancode
forall a. Maybe a
Nothing
     , inpAnyKeyReleased :: Maybe Scancode
inpAnyKeyReleased     = Maybe Scancode
forall a. Maybe a
Nothing
     }

-- | Filter and transform SDL events into events which are relevant to our
--   application
parseWinInput :: SF WinInput AppInput
parseWinInput :: SF WinInput AppInput
parseWinInput = (AppInput -> EventPayload -> AppInput)
-> AppInput -> SF WinInput AppInput
forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> SF m (Event a) b
accumHoldBy AppInput -> EventPayload -> AppInput
nextAppInput AppInput
initAppInput

scancode :: SDL.KeyboardEventData -> Scancode
scancode :: KeyboardEventData -> Scancode
scancode KeyboardEventData
ev =
  Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev

keyModifier :: SDL.KeyboardEventData -> SDL.KeyModifier
keyModifier :: KeyboardEventData -> KeyModifier
keyModifier KeyboardEventData
ev =
  Keysym -> KeyModifier
SDL.keysymModifier (Keysym -> KeyModifier) -> Keysym -> KeyModifier
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev

nextAppInput :: AppInput -> SDL.EventPayload -> AppInput
-- | quit event
nextAppInput :: AppInput -> EventPayload -> AppInput
nextAppInput AppInput
inp EventPayload
SDL.QuitEvent
  = AppInput
inp { inpQuit :: Bool
inpQuit = Bool
True }
-- | mouse movement/position
nextAppInput AppInput
inp (SDL.MouseMotionEvent MouseMotionEventData
ev) =
  AppInput
inp { inpMouseMoving :: Maybe (Double, Double)
inpMouseMoving  = (Double, Double) -> Maybe (Double, Double)
forall a. a -> Maybe a
Just (Int32 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x', Int32 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
y')
      , inpMouseStopped :: Bool
inpMouseStopped = Bool
False
      , inpMousePos :: (Double, Double)
inpMousePos     = (Int32 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x, Int32 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
y)
      , inpMouseRelPos :: (Double, Double)
inpMouseRelPos  = (Int32 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x', Int32 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
y')
      }
  --where (P (V2 x  y ))  = SDL.mouseMotionEventPos ev
  where (P (V2 Int32
x  Int32
y ))  = MouseMotionEventData -> Point V2 Int32
SDL.mouseMotionEventPos MouseMotionEventData
ev
        (  (V2 Int32
x' Int32
y'))  = MouseMotionEventData -> V2 Int32
SDL.mouseMotionEventRelMotion MouseMotionEventData
ev
-- | keyInput events
nextAppInput AppInput
inp (SDL.KeyboardEvent KeyboardEventData
ev)
    | KeyboardEventData -> Scancode
scancode KeyboardEventData
ev Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeEscape
      = AppInput
inp { inpQuit :: Bool
inpQuit = Bool
True }
      
    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeSpace
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeySpacePressed :: Maybe Scancode
inpKeySpacePressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeySpaceReleased :: Maybe Scancode
inpKeySpaceReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise
             -> AppInput
inp { inpKeySpacePressed :: Maybe Scancode
inpKeySpacePressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeySpaceReleased :: Maybe Scancode
inpKeySpaceReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeW
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed Bool -> Bool -> Bool
||
             KeyboardEventData -> Bool
SDL.keyboardEventRepeat    KeyboardEventData
ev Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True
             -> AppInput
inp { inpKeyWPressed :: Maybe Scancode
inpKeyWPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyWReleased :: Maybe Scancode
inpKeyWReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise       
             -> AppInput
inp { inpKeyWPressed :: Maybe Scancode
inpKeyWPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyWReleased :: Maybe Scancode
inpKeyWReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeS
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed Bool -> Bool -> Bool
||
             KeyboardEventData -> Bool
SDL.keyboardEventRepeat    KeyboardEventData
ev Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True
             -> AppInput
inp { inpKeySPressed :: Maybe Scancode
inpKeySPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeySReleased :: Maybe Scancode
inpKeySReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise
             -> AppInput
inp { inpKeySPressed :: Maybe Scancode
inpKeySPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeySReleased :: Maybe Scancode
inpKeySReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }
                
    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeA
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed Bool -> Bool -> Bool
||
             KeyboardEventData -> Bool
SDL.keyboardEventRepeat    KeyboardEventData
ev Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True
             -> AppInput
inp { inpKeyAPressed :: Maybe Scancode
inpKeyAPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyAReleased :: Maybe Scancode
inpKeyAReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise
             -> AppInput
inp { inpKeyAPressed :: Maybe Scancode
inpKeyAPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyAReleased :: Maybe Scancode
inpKeyAReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeD
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed Bool -> Bool -> Bool
||
             KeyboardEventData -> Bool
SDL.keyboardEventRepeat    KeyboardEventData
ev Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True
             -> AppInput
inp { inpKeyDPressed :: Maybe Scancode
inpKeyDPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyDReleased :: Maybe Scancode
inpKeyDReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise
             -> AppInput
inp { inpKeyDPressed :: Maybe Scancode
inpKeyDPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyDReleased :: Maybe Scancode
inpKeyDReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeQ
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed Bool -> Bool -> Bool
||
             KeyboardEventData -> Bool
SDL.keyboardEventRepeat    KeyboardEventData
ev Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True
             -> AppInput
inp { inpKeyQPressed :: Maybe Scancode
inpKeyQPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyQReleased :: Maybe Scancode
inpKeyQReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise
             -> AppInput
inp { inpKeyQPressed :: Maybe Scancode
inpKeyQPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyQReleased :: Maybe Scancode
inpKeyQReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeE
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed Bool -> Bool -> Bool
||
             KeyboardEventData -> Bool
SDL.keyboardEventRepeat    KeyboardEventData
ev Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True
             -> AppInput
inp { inpKeyEPressed :: Maybe Scancode
inpKeyEPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyEReleased :: Maybe Scancode
inpKeyEReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyEPressed :: Maybe Scancode
inpKeyEPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyEReleased :: Maybe Scancode
inpKeyEReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeZ
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyZPressed :: Maybe Scancode
inpKeyZPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyZReleased :: Maybe Scancode
inpKeyZReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyZPressed :: Maybe Scancode
inpKeyZPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyZReleased :: Maybe Scancode
inpKeyZReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }
                
    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeX
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyXPressed :: Maybe Scancode
inpKeyXPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyXReleased :: Maybe Scancode
inpKeyXReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyXPressed :: Maybe Scancode
inpKeyXPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyXReleased :: Maybe Scancode
inpKeyXReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeC
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyCPressed :: Maybe Scancode
inpKeyCPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyCReleased :: Maybe Scancode
inpKeyCReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyCPressed :: Maybe Scancode
inpKeyCPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyCReleased :: Maybe Scancode
inpKeyCReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLShift
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyLShiftPressed :: Maybe Scancode
inpKeyLShiftPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyLShiftReleased :: Maybe Scancode
inpKeyLShiftReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyLShiftPressed :: Maybe Scancode
inpKeyLShiftPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyLShiftReleased :: Maybe Scancode
inpKeyLShiftReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }
    
    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLCtrl
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyLCtrlPressed :: Maybe Scancode
inpKeyLCtrlPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyLCtrlReleased :: Maybe Scancode
inpKeyLCtrlReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyLCtrlPressed :: Maybe Scancode
inpKeyLCtrlPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyLCtrlReleased :: Maybe Scancode
inpKeyLCtrlReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLAlt
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyLAltPressed :: Maybe Scancode
inpKeyLAltPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyLAltReleased :: Maybe Scancode
inpKeyLAltReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyLAltPressed :: Maybe Scancode
inpKeyLAltPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyLAltReleased :: Maybe Scancode
inpKeyLAltReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeRShift
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyRShiftPressed :: Maybe Scancode
inpKeyRShiftPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyRShiftReleased :: Maybe Scancode
inpKeyRShiftReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyRShiftPressed :: Maybe Scancode
inpKeyRShiftPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyRShiftReleased :: Maybe Scancode
inpKeyRShiftReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }
                
    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeRCtrl
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyRCtrlPressed :: Maybe Scancode
inpKeyRCtrlPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyRCtrlReleased :: Maybe Scancode
inpKeyRCtrlReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyRCtrlPressed :: Maybe Scancode
inpKeyRCtrlPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyRCtrlReleased :: Maybe Scancode
inpKeyRCtrlReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodePageUp
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyPageUpPressed :: Maybe Scancode
inpKeyPageUpPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyPageUpReleased :: Maybe Scancode
inpKeyPageUpReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyPageUpPressed :: Maybe Scancode
inpKeyPageUpPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyPageUpReleased :: Maybe Scancode
inpKeyPageUpReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodePageDown
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyPageDownPressed :: Maybe Scancode
inpKeyPageDownPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyPageDownReleased :: Maybe Scancode
inpKeyPageDownReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyPageDownPressed :: Maybe Scancode
inpKeyPageDownPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyPageDownReleased :: Maybe Scancode
inpKeyPageDownReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeUp
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyUpPressed :: Maybe Scancode
inpKeyUpPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyUpReleased :: Maybe Scancode
inpKeyUpReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyUpPressed :: Maybe Scancode
inpKeyUpPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyUpReleased :: Maybe Scancode
inpKeyUpReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeDown
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyDownPressed :: Maybe Scancode
inpKeyDownPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyDownReleased :: Maybe Scancode
inpKeyDownReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyDownPressed :: Maybe Scancode
inpKeyDownPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyDownReleased :: Maybe Scancode
inpKeyDownReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeLeft
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyLeftPressed :: Maybe Scancode
inpKeyLeftPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyLeftReleased :: Maybe Scancode
inpKeyLeftReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyLeftPressed :: Maybe Scancode
inpKeyLeftPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyLeftReleased :: Maybe Scancode
inpKeyLeftReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }

    | (KeyboardEventData -> Scancode
scancode KeyboardEventData
ev) Scancode -> Scancode -> Bool
forall a. Eq a => a -> a -> Bool
== Scancode
SDL.ScancodeRight
      = if | KeyboardEventData -> InputMotion
SDL.keyboardEventKeyMotion KeyboardEventData
ev InputMotion -> InputMotion -> Bool
forall a. Eq a => a -> a -> Bool
== InputMotion
SDL.Pressed
             -> AppInput
inp { inpKeyRightPressed :: Maybe Scancode
inpKeyRightPressed  = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev
                    , inpKeyRightReleased :: Maybe Scancode
inpKeyRightReleased = Maybe Scancode
forall a. Maybe a
Nothing }
           | Bool
otherwise      
             -> AppInput
inp { inpKeyRightPressed :: Maybe Scancode
inpKeyRightPressed  = Maybe Scancode
forall a. Maybe a
Nothing
                    , inpKeyRightReleased :: Maybe Scancode
inpKeyRightReleased = Scancode -> Maybe Scancode
forall a. a -> Maybe a
Just (Scancode -> Maybe Scancode) -> Scancode -> Maybe Scancode
forall a b. (a -> b) -> a -> b
$ Keysym -> Scancode
SDL.keysymScancode (Keysym -> Scancode) -> Keysym -> Scancode
forall a b. (a -> b) -> a -> b
$ KeyboardEventData -> Keysym
SDL.keyboardEventKeysym KeyboardEventData
ev }
                
-- | mouse button events              
nextAppInput AppInput
inp (SDL.MouseButtonEvent MouseButtonEventData
ev)
  = AppInput
inp { inpMouseLeft :: Maybe (Double, Double)
inpMouseLeft  = Maybe (Double, Double)
lmb
        , inpMouseRight :: Maybe (Double, Double)
inpMouseRight = Maybe (Double, Double)
rmb }
    where motion :: InputMotion
motion = MouseButtonEventData -> InputMotion
SDL.mouseButtonEventMotion MouseButtonEventData
ev
          button :: MouseButton
button = MouseButtonEventData -> MouseButton
SDL.mouseButtonEventButton MouseButtonEventData
ev
          pos :: (Double, Double)
pos    = AppInput -> (Double, Double)
inpMousePos AppInput
inp
          (Maybe (Double, Double)
lmb,Maybe (Double, Double)
rmb) = (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
inpMod ((Maybe (Double, Double), Maybe (Double, Double))
 -> (Maybe (Double, Double), Maybe (Double, Double)))
-> (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
forall a b. (a -> b) -> a -> b
$ (AppInput -> Maybe (Double, Double)
inpMouseLeft (AppInput -> Maybe (Double, Double))
-> (AppInput -> Maybe (Double, Double))
-> AppInput
-> (Maybe (Double, Double), Maybe (Double, Double))
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& AppInput -> Maybe (Double, Double)
inpMouseRight) AppInput
inp
            where
              inpMod :: (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
inpMod = case (InputMotion
motion,MouseButton
button) of
                (InputMotion
SDL.Released, MouseButton
SDL.ButtonLeft)   -> (Maybe (Double, Double) -> Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first  (Maybe (Double, Double)
-> Maybe (Double, Double) -> Maybe (Double, Double)
forall a b. a -> b -> a
const Maybe (Double, Double)
forall a. Maybe a
Nothing)
                (InputMotion
SDL.Pressed,  MouseButton
SDL.ButtonLeft)   -> (Maybe (Double, Double) -> Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first  (Maybe (Double, Double)
-> Maybe (Double, Double) -> Maybe (Double, Double)
forall a b. a -> b -> a
const ((Double, Double) -> Maybe (Double, Double)
forall a. a -> Maybe a
Just (Double, Double)
pos))
                (InputMotion
SDL.Released, MouseButton
SDL.ButtonRight)  -> (Maybe (Double, Double) -> Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second (Maybe (Double, Double)
-> Maybe (Double, Double) -> Maybe (Double, Double)
forall a b. a -> b -> a
const Maybe (Double, Double)
forall a. Maybe a
Nothing)
                (InputMotion
SDL.Pressed,  MouseButton
SDL.ButtonRight)  -> (Maybe (Double, Double) -> Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second (Maybe (Double, Double)
-> Maybe (Double, Double) -> Maybe (Double, Double)
forall a b. a -> b -> a
const ((Double, Double) -> Maybe (Double, Double)
forall a. a -> Maybe a
Just (Double, Double)
pos))
                -- (SDL.Released, SDL.ButtonMiddle) -> second (const Nothing)
                -- (SDL.Pressed,  SDL.ButtonMiddle) -> second (const (Just pos))
                (InputMotion, MouseButton)
_ -> (Maybe (Double, Double), Maybe (Double, Double))
-> (Maybe (Double, Double), Maybe (Double, Double))
forall a. a -> a
id
                
nextAppInput AppInput
inp EventPayload
_ =
  AppInput
inp { inpMouseMoving :: Maybe (Double, Double)
inpMouseMoving  = Maybe (Double, Double)
forall a. Maybe a
Nothing
      , inpMouseStopped :: Bool
inpMouseStopped = Bool
True
      , inpMouseRelPos :: (Double, Double)
inpMouseRelPos  = (Double
0,Double
0)
      }

--nextAppInput inp _ = inp