{-# OPTIONS_HADDOCK hide #-}
module Graphics.UI.Fungen.Input (
InputBinding, InputHandler,
KeyEvent(..), Key(..), SpecialKey(..), MouseButton(..), Modifiers(..), Position(..),
funInitInput
) where
import Graphics.UI.Fungen.Game
import Graphics.UI.GLUT
import Graphics.UI.GLUT.Input (KeyEvent(..), KeyBinder, StillDownHandler, glutInitInput)
type InputHandler t s u v = Modifiers -> Position -> IOGame t s u v ()
type InputBinding t s u v = (Key, KeyEvent, InputHandler t s u v)
funInitInput :: [InputBinding t s u v] -> Game t s u v -> IO (KeyBinder, StillDownHandler)
funInitInput :: forall t s u v.
[InputBinding t s u v]
-> Game t s u v -> IO (KeyBinder, StillDownHandler)
funInitInput [InputBinding t s u v]
bindings Game t s u v
game = do
(KeyBinder
glutBindKey, StillDownHandler
glutStillDown) <- IO (KeyBinder, StillDownHandler)
glutInitInput
let funBindKey :: (Key, KeyEvent, Modifiers -> Position -> IOGame t s u v a)
-> StillDownHandler
funBindKey (Key
key, KeyEvent
keyEvent, Modifiers -> Position -> IOGame t s u v a
inputHandler) =
KeyBinder
glutBindKey Key
key KeyEvent
keyEvent (forall a. a -> Maybe a
Just (\Modifiers
mods Position
pos -> forall t s u v a.
IOGame t s u v a -> Game t s u v -> StillDownHandler
runIOGameM (Modifiers -> Position -> IOGame t s u v a
inputHandler Modifiers
mods Position
pos) Game t s u v
game))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall {a}.
(Key, KeyEvent, Modifiers -> Position -> IOGame t s u v a)
-> StillDownHandler
funBindKey [InputBinding t s u v]
bindings
forall (m :: * -> *) a. Monad m => a -> m a
return (KeyBinder
glutBindKey, StillDownHandler
glutStillDown)