affection/src/Affection/Subsystems/AffectionMouse.hs

58 lines
1.6 KiB
Haskell
Raw Normal View History

2017-12-13 04:05:18 +00:00
{-# LANGUAGE MultiParamTypeClasses #-}
2017-12-15 16:48:12 +00:00
{-# LANGUAGE FlexibleContexts #-}
2017-12-13 03:37:16 +00:00
module Affection.Subsystems.AffectionMouse where
import Affection.MessageBus
2017-12-13 04:05:18 +00:00
import Affection.Subsystems.Class
2017-12-13 03:37:16 +00:00
import Affection.Types
2017-12-13 14:19:53 +00:00
import Affection.Util
2017-12-13 03:37:16 +00:00
import Control.Monad.IO.Class (liftIO)
import Control.Concurrent.STM
2017-12-13 04:05:18 +00:00
import Linear.Affine (unP)
2017-12-13 03:37:16 +00:00
import qualified SDL
2017-12-15 16:48:12 +00:00
consumeSDLMouseEvents
:: (Participant am MouseMessage us)
=> am
-> [SDL.EventPayload]
-> Affection us [SDL.EventPayload]
2017-12-15 16:58:55 +00:00
consumeSDLMouseEvents am = doConsume
2017-12-15 16:48:12 +00:00
where
doConsume [] = return []
doConsume (e:es) = do
ts <- getElapsedTime
case e of
SDL.MouseMotionEvent dat -> do
partEmit am (MsgMouseMotion
ts
(SDL.mouseMotionEventWindow dat)
(SDL.mouseMotionEventWhich dat)
(SDL.mouseMotionEventState dat)
(unP $ SDL.mouseMotionEventPos dat)
(SDL.mouseMotionEventRelMotion dat)
)
doConsume es
SDL.MouseButtonEvent dat -> do
partEmit am (MsgMouseButton
ts
(SDL.mouseButtonEventWindow dat)
(SDL.mouseButtonEventWhich dat)
(SDL.mouseButtonEventButton dat)
(SDL.mouseButtonEventClicks dat)
(unP $ SDL.mouseButtonEventPos dat)
)
doConsume es
SDL.MouseWheelEvent dat -> do
partEmit am (MsgMouseWheel
ts
(SDL.mouseWheelEventWindow dat)
(SDL.mouseWheelEventWhich dat)
(SDL.mouseWheelEventPos dat)
(SDL.mouseWheelEventDirection dat)
)
doConsume es
_ -> fmap (e :) (doConsume es)