module FRP.Helm.Window (
dimensions,
width,
height,
position
) where
import Control.Applicative (pure)
import Foreign.Marshal.Alloc
import Foreign.Storable
import FRP.Elerea.Param hiding (Signal)
import FRP.Helm.Engine
import FRP.Helm.Sample
import FRP.Helm.Signal
import qualified Graphics.UI.SDL as SDL
dimensions :: Signal (Int, Int)
dimensions =
Signal $ input >>= getDimensions >>= transfer (pure (0,0)) update
where
getDimensions = effectful1 action
action engine = alloca $ \wptr -> alloca $ \hptr -> do
SDL.getWindowSize (window engine) wptr hptr
w <- peek wptr
h <- peek hptr
return (fromIntegral w, fromIntegral h)
position :: Signal (Int, Int)
position =
Signal $ input >>= getPosition >>= transfer (pure (0,0)) update
where
getPosition = effectful1 action
action engine = alloca $ \xptr -> alloca $ \yptr -> do
SDL.getWindowPosition (window engine) xptr yptr
x <- peek xptr
y <- peek yptr
return (fromIntegral x, fromIntegral y)
width :: Signal Int
width = fst <~ dimensions
height :: Signal Int
height = snd <~ dimensions