{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Imj.Graphics.Render.Delta.Types
(
Buffers(..)
, Policies(..)
, ResizePolicy(..)
, ClearPolicy(..)
, Dim(..)
, BufferSize
, BufferIndex
, getRowCol
, getHeight
, Word16
, Height
, Width
, Row
, Col
, IORef
, Color8
) where
import Imj.Prelude
import Control.Exception(assert)
import Data.IORef(IORef)
import Data.Word(Word16)
import Imj.Geo.Discrete.Types(Width, Height, Row, Col)
import Imj.Graphics.Color.Types
import Imj.Graphics.Render.Delta.Internal.Types
data ResizePolicy = MatchTerminalSize
| FixedSize !(Dim Width) !(Dim Height)
deriving(Show, Eq)
data ClearPolicy = ClearAtEveryFrame
| ClearOnAllocationOnly
deriving(Show, Eq)
newtype Dim a = Dim Word16 deriving(Num, Eq, Ord, Show, Real, Enum, Integral)
data BufferSize
data BufferIndex
{-# INLINE getHeight #-}
getHeight :: Dim Width -> Dim BufferSize -> Dim Height
getHeight (Dim w) (Dim sz) =
let h = quot sz w
in Dim $ assert (h * w == sz) h
{-# INLINE getRowCol #-}
getRowCol :: Dim BufferIndex -> Dim Width -> (Dim Col, Dim Row)
getRowCol (Dim idx) (Dim w) =
(Dim x, Dim y)
where
y = idx `div` w
x = idx - y * w
data Buffers = Buffers {
_renderStateBackBuffer :: !(Buffer Back)
, _renderStateFrontBuffer :: !(Buffer Front)
, _buffersDrawWidth :: !(Dim Width)
, _buffersDelta :: !Delta
, _buffersPolicies :: !Policies
}
data Policies = Policies {
_policiesResizePolicy :: !ResizePolicy
, _policiesClearPolicy :: !ClearPolicy
, _policiesClearColor :: !(Color8 Background)
} deriving(Show)