2017-11-27 22:30:11 +00:00
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
|
|
{-# LANGUAGE AllowAmbiguousTypes #-}
|
|
|
|
module Affection.Subsystems.AffectionWindow where
|
2017-11-27 04:27:34 +00:00
|
|
|
|
|
|
|
import Affection.MessageBus
|
|
|
|
import Affection.Subsystems.Class
|
2017-11-27 22:30:11 +00:00
|
|
|
import Affection.Types
|
|
|
|
|
|
|
|
import Control.Monad.State.Class (get)
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
2017-11-27 04:27:34 +00:00
|
|
|
|
|
|
|
import qualified SDL
|
|
|
|
|
2017-11-27 22:30:11 +00:00
|
|
|
data AffectionWindow msg = AffectionWindow
|
2017-11-27 04:27:34 +00:00
|
|
|
{ windowChannel :: Channel msg
|
|
|
|
}
|
|
|
|
|
2017-11-27 22:30:11 +00:00
|
|
|
instance Participant (AffectionWindow (SystemMessage m)) (SystemMessage m) where
|
2017-11-27 04:27:34 +00:00
|
|
|
partChannel = windowChannel
|
|
|
|
|
2017-11-27 22:30:11 +00:00
|
|
|
partInit = do
|
|
|
|
ad <- get
|
|
|
|
nchan <- liftIO $ dupChannel $ messageChannel ad
|
|
|
|
return $ AffectionWindow
|
|
|
|
{ windowChannel = nchan
|
|
|
|
}
|
|
|
|
|
2017-11-27 04:27:34 +00:00
|
|
|
partListen p = do
|
|
|
|
let chan = partChannel p
|
|
|
|
mmsg <- tryPeekChannel chan
|
|
|
|
return mmsg
|
|
|
|
|
|
|
|
partEmit p m = do
|
|
|
|
let chan = partChannel p
|
|
|
|
writeChannel chan m
|
|
|
|
|
2017-11-27 22:30:11 +00:00
|
|
|
instance Subsystem (AffectionWindow (SystemMessage m)) (SystemMessage m) where
|
2017-11-27 04:27:34 +00:00
|
|
|
consumeEvents aw evs = doConsume evs
|
|
|
|
where
|
|
|
|
doConsume (e:es) = case SDL.eventPayload e of
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowShownEvent (SDL.WindowShownEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowShown (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowHiddenEvent (SDL.WindowHiddenEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowHidden (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowExposedEvent (SDL.WindowExposedEventData window) -> do
|
2017-11-27 04:27:34 +00:00
|
|
|
partEmit aw (MsgWindowExposed (SDL.eventTimestamp e) window)
|
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowMovedEvent (SDL.WindowMovedEventData window (SDL.P newPos)) -> do
|
|
|
|
partEmit aw (MsgWindowMoved (SDL.eventTimestamp e) window newPos)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowResizedEvent (SDL.WindowResizedEventData window newSize) -> do
|
|
|
|
partEmit aw (MsgWindowResized (SDL.eventTimestamp e) window newSize)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowSizeChangedEvent (SDL.WindowSizeChangedEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowSizeChanged (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowMinimizedEvent (SDL.WindowMinimizedEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowMinimized (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowMaximizedEvent (SDL.WindowMaximizedEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowMaximized (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowRestoredEvent (SDL.WindowRestoredEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowRestored (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowGainedMouseFocusEvent (SDL.WindowGainedMouseFocusEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowGainedMouseFocus (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowLostMouseFocusEvent (SDL.WindowLostMouseFocusEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowLostMouseFocus (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowGainedKeyboardFocusEvent (SDL.WindowGainedKeyboardFocusEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowGainedKeyboardFocus (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowLostKeyboardFocusEvent (SDL.WindowLostKeyboardFocusEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowLostKeyboardFocus (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
SDL.WindowClosedEvent (SDL.WindowClosedEventData window) -> do
|
|
|
|
partEmit aw (MsgWindowClosed (SDL.eventTimestamp e) window)
|
2017-11-27 04:27:34 +00:00
|
|
|
doConsume es
|
2017-11-27 22:30:11 +00:00
|
|
|
_ -> fmap (e :) (doConsume es)
|