module FRP.Helm.Mouse (
Mouse(..),
isDown,
position, x, y
) where
import Control.Applicative
import FRP.Elerea.Simple
import qualified Graphics.UI.SDL as SDL
import qualified Graphics.UI.SDL.Utilities as Util
data Mouse = LeftMouse | MiddleMouse | RightMouse deriving (Show, Eq, Ord, Read)
instance Enum Mouse where
fromEnum LeftMouse = 1
fromEnum MiddleMouse = 2
fromEnum RightMouse = 3
toEnum 1 = LeftMouse
toEnum 2 = MiddleMouse
toEnum 3 = RightMouse
toEnum _ = error "FRP.Helm.Mouse.Mouse.toEnum: bad argument"
position :: SignalGen (Signal (Int, Int))
position = effectful $ (\(x_, y_, _) -> (x_, y_)) <$> SDL.getMouseState
x :: SignalGen (Signal Int)
x = effectful $ (\(x_, _, _) -> x_) <$> SDL.getMouseState
y :: SignalGen (Signal Int)
y = effectful $ (\(_, y_, _) -> y_) <$> SDL.getMouseState
isDown :: Mouse -> SignalGen (Signal Bool)
isDown m = effectful $ (\(_, _, b_) -> elem (Util.toEnum $ fromIntegral $ fromEnum m) b_) <$> SDL.getMouseState