module YampaSDL2.Internal.AppOutput
( RenderObject(..)
, translate
, Scene(..)
, AppOutput(..)
, Camera(..)
, ShapeColour(..)
, Sound(..)
, isFilled
, getColour
, colourToV4
, Center
, Bounds
, Cache
) where
import Control.Concurrent.MVar
import Data.Colour
import Data.Colour.SRGB
import Data.Dynamic
import Data.Word
import Linear.V2
import Linear.V4
import qualified SDL
data AppOutput = AppOutput
{ scene :: Scene
, sound :: [Sound]
, shouldExit :: Bool
}
data Scene = Scene
{ cam :: Camera
, objects :: [RenderObject]
}
data Camera = Camera
{ cPos :: V2 Double
, cSize :: V2 Double
}
type Center = V2 Double
type Bounds = V4 Double
type Cache = MVar [(String, Dynamic)]
data RenderObject = RO
{ center :: Center
, bounds :: Bounds
, zIndex :: Int
, draw :: Cache -> Center -> SDL.Renderer -> IO ()
}
translate :: (Center -> Center) -> RenderObject -> RenderObject
translate f r = r {center = f $ center r}
data ShapeColour
= Filled (AlphaColour Double)
| Unfilled (AlphaColour Double)
deriving (Show, Eq)
isFilled :: ShapeColour -> Bool
isFilled (Filled _) = True
isFilled _ = False
getColour :: ShapeColour -> AlphaColour Double
getColour (Filled c) = c
getColour (Unfilled c) = c
colourToV4 :: ShapeColour -> V4 Word8
colourToV4 sc =
let c = getColour sc
(RGB r g b) = toSRGB24 (colourChannel c)
alpha = truncate $ alphaChannel c * 255
in V4 r g b alpha
data Sound =
NotImplementedYet