pioneers/src/UI/Callbacks.hs

52 lines
2.0 KiB
Haskell
Raw Normal View History

2014-03-09 13:46:49 +01:00
{-# LANGUAGE ExistentialQuantification #-}
2014-02-05 21:06:19 +01:00
module UI.Callbacks where
import Control.Monad.Trans (liftIO)
import Types
2014-03-09 13:46:49 +01:00
import UI.UITypes
2014-02-05 21:06:19 +01:00
data Pixel = Pixel Int Int
2014-03-09 13:46:49 +01:00
getGUI :: [GUIAny]
getGUI = [ toGUIAny $ GUIContainer 0 0 120 80 [] 1
, toGUIAny $ GUIPanel $ GUIContainer 0 0 0 0
[toGUIAny $ GUIContainer 0 80 100 200 [] 4
,GUIAnyB (GUIButton 50 400 200 175 2 (testMessage) defaultUIState)
] 3
]
testMessage :: (Show w) => w -> ScreenUnit -> ScreenUnit -> IO w
testMessage w x y = do
putStrLn ("\tclick on " ++ show x ++ "," ++ show y)
return w
2014-03-09 13:46:49 +01:00
2014-02-05 21:06:19 +01:00
-- | Handler for UI-Inputs.
-- Indicates a primary click on something (e.g. left-click, touch on Touchpad, fire on Gamepad, ...
clickHandler :: Pixel -> Pioneers ()
clickHandler (Pixel x y) = case concatMap (isInside x y) getGUI of
2014-03-09 13:46:49 +01:00
[] -> liftIO $ putStrLn $ unwords ["button press on (",show x,",",show y,")"]
hit -> liftIO $ do
_ <- sequence $ map (\w ->
case w of
(GUIAnyB b) -> do
putStrLn $ "hitting " ++ getShorthand w ++ ": " ++ show (getBoundary w) ++ " " ++ show (getPriority w)
++ " at ["++show x++","++show y++"]"
(b', _) <- onMousePressed x y b b
_ <- onMouseReleased x y b' b'
return ()
_ -> putStrLn $ "hitting " ++ getShorthand w ++ ": " ++ show (getBoundary w) ++ " " ++ show (getPriority w)
++ " at ["++show x++","++show y++"]"
) hit
return ()
2014-02-05 21:06:19 +01:00
-- | Handler for UI-Inputs.
-- Indicates an alternate click on something (e.g. right-click, touch&hold on Touchpad, ...
alternateClickHandler :: Pixel -> Pioneers ()
alternateClickHandler (Pixel x y) = liftIO $ putStrLn $ unwords ["alternate press on (",show x,",",show y,")"]
--TODO: Add scroll-Handler, return (Pioneers Bool) to indicate event-bubbling etc.
--TODO: Maybe queues are better?