module Affection.MessageBus.Message.WindowMessage
  ( WindowMessage(..)
  -- | SDL reexports
  , SDL.Window
  ) where

import Affection.MessageBus.Message.Class

import Data.Int (Int32)

import qualified SDL

import Linear (V2(..))

-- | Datatype for handling Window events handed down rom SDL2
data WindowMessage
  -- | Window show event
  = MsgWindowShow
    { msgWSWhen :: Double       -- ^ Message time
    , msgWSWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window hide event
  | MsgWindowHide
    { msgWHWhen :: Double       -- ^ Message time
    , msgWHWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window expose event
  | MsgWindowExpose
    { msgWEWhen :: Double       -- ^ Message time
    , msgWEWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window move event
  | MsgWindowMove
    { msgWMWhen :: Double       -- ^ Message time
    , msgWMWindow :: SDL.Window -- ^ Window identifier
    , msgWMNewPos :: V2 Int32   -- ^ New absolute window position
    }
  -- | Window resize event
  | MsgWindowResize
    { msgWRWhen :: Double       -- ^ Message time
    , msgWRWindow :: SDL.Window -- ^ Window identifier
    , msgWRNewSize :: V2 Int32  -- ^ New absolute window size
    }
  -- | Window size change event
  | MsgWindowSizeChange
    { msgWSCWhen    :: Double     -- ^ Message time
    , msgWSCWindow  :: SDL.Window -- ^ Window identifier
    , msgWSCNewSize :: V2 Int32   -- ^ New absolute window size
    }
  -- | Window minimize event
  | MsgWindowMinimize
    { msgWMinWhen   :: Double     -- ^ Message time
    , msgWMinWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window maximize event
  | MsgWindowMaximize
    { msgWMaxWhen   :: Double     -- ^ Message time
    , msgWMaxWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window restore event
  | MsgWindowRestore
    { msgWRestWhen   :: Double     -- ^ Message time
    , msgWRestWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window gain mouse focus event
  | MsgWindowGainMouseFocus
    { msgWGMFWhen   :: Double     -- ^ Message Time
    , msgWGMFWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window lose mouse focus event
  | MsgWindowLoseMouseFocus
    { msgWLMFWhen   :: Double     -- ^ Message Time
    , msgWLMFWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window gain keyboard focus event
  | MsgWindowGainKeyboardFocus
    { msgWGKFWhen   :: Double     -- ^ Message time
    , msgWGKFWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window lose keyboard focus event
  | MsgWindowLoseKeyboardFocus
    { msgWLKFWhen   :: Double     -- ^ Message time
    , msgWLKFWindow :: SDL.Window -- ^ Window identifier
    }
  -- | Window close event
  | MsgWindowClose
    { msgWCWhen   :: Double     -- ^ Message time
    , msgWCWindow :: SDL.Window -- ^ Window identifier
    }
  deriving (Show)

instance Message WindowMessage where
  msgTime (MsgWindowShow t _) = t
  msgTime (MsgWindowHide t _) = t
  msgTime (MsgWindowExpose t _) = t
  msgTime (MsgWindowMove t _ _) = t
  msgTime (MsgWindowResize t _ _) = t
  msgTime (MsgWindowSizeChange t _ _) = t
  msgTime (MsgWindowMinimize t _) = t
  msgTime (MsgWindowMaximize t _) = t
  msgTime (MsgWindowRestore t _) = t
  msgTime (MsgWindowGainMouseFocus t _) = t
  msgTime (MsgWindowLoseMouseFocus t _) = t
  msgTime (MsgWindowGainKeyboardFocus t _) = t
  msgTime (MsgWindowLoseKeyboardFocus t _) = t
  msgTime (MsgWindowClose t _) = t