module Graphics.UI.Fungen.Input (
InputBinding, InputHandler,
KeyEvent(..), Key(..), SpecialKey(..), MouseButton(..), Modifiers(..), Position(..),
funBinding
) where
import Graphics.UI.Fungen.Game
import Graphics.UI.GLUT
import Graphics.UI.GLUT.Input (KeyEvent(..), KeyBinder, StillDownHandler, initGLUTInput)
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)
funBinding :: [InputBinding t s u v] -> Game t s u v -> IO (KeyBinder, StillDownHandler)
funBinding inputs g = do
(bindKey, stillDown) <- initGLUTInput
mapM (userBinding g bindKey) inputs
return (bindKey, stillDown)
userBinding :: Game t s u v -> KeyBinder -> InputBinding t s u v -> IO ()
userBinding g bindKey (key, keyEvent, inputHandler) = bindKey key keyEvent (Just (\mods pos -> runIOGameM (inputHandler mods pos) g))