{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
module SDL.Init
( initialize
, initializeAll
, InitFlag(..)
, quit
, version
) where
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Bitmask (foldFlags)
import Data.Data (Data)
import Data.Typeable
import Data.Word
import Foreign.Marshal.Alloc
import Foreign.Storable
import GHC.Generics
import SDL.Internal.Exception
import SDL.Internal.Numbered
import qualified SDL.Raw as Raw
#if !MIN_VERSION_base(4,8,0)
import Data.Foldable
#endif
data InitFlag
= InitTimer
| InitAudio
| InitVideo
| InitJoystick
| InitHaptic
| InitGameController
| InitEvents
deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show, Typeable)
instance ToNumber InitFlag Word32 where
toNumber InitTimer = Raw.SDL_INIT_TIMER
toNumber InitAudio = Raw.SDL_INIT_AUDIO
toNumber InitVideo = Raw.SDL_INIT_VIDEO
toNumber InitJoystick = Raw.SDL_INIT_JOYSTICK
toNumber InitHaptic = Raw.SDL_INIT_HAPTIC
toNumber InitGameController = Raw.SDL_INIT_GAMECONTROLLER
toNumber InitEvents = Raw.SDL_INIT_EVENTS
initialize :: (Foldable f, Functor m, MonadIO m) => f InitFlag -> m ()
initialize flags =
throwIfNeg_ "SDL.Init.init" "SDL_Init" $
Raw.init (foldFlags toNumber flags)
initializeAll :: (Functor m, MonadIO m) => m ()
initializeAll = initialize [minBound .. maxBound]
quit :: MonadIO m => m ()
quit = Raw.quit
version :: (Integral a, MonadIO m) => m (a, a, a)
version = liftIO $ do
Raw.Version major minor patch <- alloca $ \v -> Raw.getVersion v >> peek v
return (fromIntegral major, fromIntegral minor, fromIntegral patch)