module SFML.Window.ContextSettings
(
ContextSettings(..)
, ContextAttribute(..)
)
where
import Control.Applicative ((<$>), (<*>))
import Data.Word (Word32)
import Foreign.C.Types
import Foreign.Storable
data ContextSettings = ContextSettings
{ depthBits :: Int
, stencilBits :: Int
, antialiasingLevel :: Int
, majorVersion :: Int
, minorVersion :: Int
, attributeFlags :: [ContextAttribute]
}
deriving (Show)
instance Storable ContextSettings where
sizeOf _ = (24)
alignment _ = 4
peek ptr = ContextSettings
<$> fmap fromIntegral ((\hsc_ptr -> peekByteOff hsc_ptr 0) ptr :: IO CInt)
<*> fmap fromIntegral ((\hsc_ptr -> peekByteOff hsc_ptr 4) ptr :: IO CInt)
<*> fmap fromIntegral ((\hsc_ptr -> peekByteOff hsc_ptr 8) ptr :: IO CInt)
<*> fmap fromIntegral ((\hsc_ptr -> peekByteOff hsc_ptr 12) ptr :: IO CInt)
<*> fmap fromIntegral ((\hsc_ptr -> peekByteOff hsc_ptr 16) ptr :: IO CInt)
<*> fmap (toFlags . fromIntegral) ((\hsc_ptr -> peekByteOff hsc_ptr 20) ptr :: IO Word32)
poke ptr (ContextSettings db sb al ma mi af) = do
(\hsc_ptr -> pokeByteOff hsc_ptr 0) ptr (fromIntegral db :: CInt)
(\hsc_ptr -> pokeByteOff hsc_ptr 4) ptr (fromIntegral sb :: CInt)
(\hsc_ptr -> pokeByteOff hsc_ptr 8) ptr (fromIntegral al :: CInt)
(\hsc_ptr -> pokeByteOff hsc_ptr 12) ptr (fromIntegral ma :: CInt)
(\hsc_ptr -> pokeByteOff hsc_ptr 16) ptr (fromIntegral mi :: CInt)
(\hsc_ptr -> pokeByteOff hsc_ptr 20) ptr ((fromIntegral . fromFlags) af :: Word32)
data ContextAttribute
= ContextDefault
| ContextCore
| ContextDebug
deriving (Eq, Show)
instance Enum ContextAttribute where
fromEnum ContextDefault = 0
fromEnum ContextCore = 1
fromEnum ContextDebug = 2
toEnum 0 = ContextDefault
toEnum 1 = ContextCore
toEnum 2 = ContextDebug
fromFlags :: [ContextAttribute] -> Int
fromFlags = sum . map fromEnum
toFlags :: Int -> [ContextAttribute]
toFlags = return . toEnum