pioneers/src/UI/Callbacks.hs

29 lines
1.1 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 = (GUIAny $ GUIContainer 0 0 120 80 [] 1):(GUIAny $ GUIContainer 50 60 300 700 [(GUIAny $ GUIContainer 55 65 200 400 [] 5)] 1):[]
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 ()
2014-03-09 13:46:49 +01:00
clickHandler (Pixel x y) = case concat $ map (isInside x y) getGUI of
[] -> liftIO $ putStrLn $ unwords ["button press on (",show x,",",show y,")"]
hit -> liftIO $ putStrLn $ unwords $ foldl (++) ["hitting"] ([map (\w -> (show.getBoundary) w ++ ' ':(show.getPriority) w) hit])
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?