{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}

-- | "SDL.Video.Renderer" provides a high-level interface to SDL's accelerated 2D rendering library.

module SDL.Video.Renderer
  ( Renderer

    -- * 'Renderer' Configuration
    -- | These configuration options can be used with 'SDL.Video.createRenderer' to create 'Renderer's.
  , RendererConfig(..)
  , defaultRenderer
  , RendererType(..)

  -- * Drawing Primitives
  , clear
  , copy
  , copyEx
  , drawLine
  , drawLines
  , drawPoint
  , drawPoints
  , drawRect
  , drawRects
  , fillRect
  , fillRects
#ifdef RECENT_ISH
  , copyF
  , copyExF
  , drawLineF
  , drawLinesF
  , drawPointF
  , drawPointsF
  , drawRectF
  , drawRectsF
  , fillRectF
  , fillRectsF
  , renderGeometry
  , Raw.Vertex(..)
  , renderGeometryRaw
#endif
  , present

  -- * 'Renderer' State
  -- | SDL exposes a stateful interface to 'Renderer's - the above primitives drawing routines will change their
  -- output depending on the value of these state variables.
  , rendererDrawBlendMode
  , rendererDrawColor
  , rendererRenderTarget
  , rendererClipRect
  , rendererLogicalSize
  , rendererScale
  , rendererViewport
  , renderTargetSupported

  -- * 'Surface's
  , Surface(..)
  , updateWindowSurface
  , surfaceBlit
  , surfaceBlitScaled
  , surfaceFillRect
  , surfaceFillRects

  -- ** Creating and Destroying 'Surface's
  , convertSurface
  , createRGBSurface
  , createRGBSurfaceFrom
  , freeSurface
  , getWindowSurface
  , loadBMP

  -- ** 'Surface' state
  , surfaceColorKey
  , surfaceBlendMode
  , surfaceDimensions
  , surfaceFormat
  , surfacePixels

  -- ** Accessing 'Surface' Data
  , lockSurface
  , unlockSurface

  -- * 'Palette's and pixel formats
  , Palette
  , paletteNColors
  , paletteColors
  , paletteColor
  , PixelFormat(..)
  , SurfacePixelFormat(..)
  , formatPalette
  , setPaletteColors
  , pixelFormatToMasks
  , masksToPixelFormat

  -- * Textures
  , Texture

  -- ** Creating, Using and Destroying 'Texture's
  , createTexture
  , TextureAccess(..)
  , createTextureFromSurface
  , updateTexture
  , destroyTexture
  , glBindTexture
  , glUnbindTexture

  -- ** 'Texture' State
  , textureAlphaMod
  , textureBlendMode
  , BlendMode(..)
  , textureColorMod

  -- ** Accessing 'Texture' Data
  , lockTexture
  , unlockTexture
  , queryTexture
  , TextureInfo(..)

  , Rectangle(..)

  -- * Available 'Renderer's
  -- | These functions allow you to query the current system for available 'Renderer's that can be created
  -- with 'SDL.Video.createRenderer'.
  , getRendererInfo
  , RendererInfo(..)
  , getRenderDriverInfo
  ) where

import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Bits
import Data.Data (Data)
import Data.Foldable
import Data.StateVar
import Data.Text (Text)
import Data.Typeable
import Data.Word
import Foreign.C.String
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Marshal.Alloc
import Foreign.Marshal.Utils
import Foreign.Ptr
import Foreign.Storable
import GHC.Generics (Generic)
import Prelude hiding (foldr)
import SDL.Vect
import SDL.Internal.Exception
import SDL.Internal.Numbered
import SDL.Internal.Types
import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BSI
import qualified Data.Text.Encoding as Text
import qualified Data.Vector.Storable as SV
import qualified Data.Vector.Storable.Mutable as MSV
import qualified SDL.Raw as Raw

#if !MIN_VERSION_base(4,8,0)
import Control.Applicative
import Data.Traversable
#endif

-- | Perform a fast surface copy to a destination surface.
--
-- See @<https://wiki.libsdl.org/SDL_BlitSurface SDL_BlitSurface>@ for C documentation.
surfaceBlit :: MonadIO m
            => Surface -- ^ The 'Surface' to be copied from
            -> Maybe (Rectangle CInt) -- ^ The rectangle to be copied, or 'Nothing' to copy the entire surface
            -> Surface -- ^ The 'Surface' that is the blit target
            -> Maybe (Point V2 CInt) -- ^ The position to blit to
            -> m (Maybe (Rectangle CInt))
surfaceBlit :: forall (m :: Type -> Type).
MonadIO m =>
Surface
-> Maybe (Rectangle CInt)
-> Surface
-> Maybe (Point V2 CInt)
-> m (Maybe (Rectangle CInt))
surfaceBlit (Surface Ptr Surface
src Maybe (IOVector Word8)
_) Maybe (Rectangle CInt)
srcRect (Surface Ptr Surface
dst Maybe (IOVector Word8)
_) Maybe (Point V2 CInt)
dstLoc = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
srcPtr ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with (forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Point V2 a -> V2 a -> Rectangle a
Rectangle V2 CInt
0) Maybe (Point V2 CInt)
dstLoc) forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dstPtr -> do
      CInt
_ <- forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m a
throwIfNeg Text
"SDL.Video.blitSurface" Text
"SDL_BlitSurface" forall a b. (a -> b) -> a -> b
$
           forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr Rect -> Ptr Surface -> Ptr Rect -> m CInt
Raw.blitSurface Ptr Surface
src (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
srcPtr) Ptr Surface
dst (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
dstPtr)
      forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing) (\Point V2 CInt
_ -> forall a. a -> Maybe a
Just forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr (Rectangle CInt)
dstPtr) Maybe (Point V2 CInt)
dstLoc

-- | Create a texture for a rendering context.
--
-- See @<https://wiki.libsdl.org/SDL_CreateTexture SDL_CreateTexture>@ for C documentation.
createTexture :: (Functor m,MonadIO m)
              => Renderer -- ^ The rendering context.
              -> PixelFormat
              -> TextureAccess
              -> V2 CInt -- ^ The size of the texture.
              -> m Texture
createTexture :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Renderer -> PixelFormat -> TextureAccess -> V2 CInt -> m Texture
createTexture (Renderer Renderer
r) PixelFormat
fmt TextureAccess
access (V2 CInt
w CInt
h) =
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Renderer -> Texture
Texture forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.Renderer.createTexture" Text
"SDL_CreateTexture" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type).
MonadIO m =>
Renderer -> BlendMode -> CInt -> CInt -> CInt -> m Renderer
Raw.createTexture Renderer
r (forall a b. ToNumber a b => a -> b
toNumber PixelFormat
fmt) (forall a b. ToNumber a b => a -> b
toNumber TextureAccess
access) CInt
w CInt
h

-- | Create a texture from an existing surface.
--
-- See @<https://wiki.libsdl.org/SDL_CreateTextureFromSurface SDL_CreateTextureFromSurface>@ for C documentation.
createTextureFromSurface :: (Functor m,MonadIO m)
                         => Renderer -- ^ The rendering context
                         -> Surface -- ^ The surface containing pixel data used to fill the texture
                         -> m Texture
createTextureFromSurface :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Renderer -> Surface -> m Texture
createTextureFromSurface (Renderer Renderer
r) (Surface Ptr Surface
s Maybe (IOVector Word8)
_) =
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Renderer -> Texture
Texture forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.createTextureFromSurface" Text
"SDL_CreateTextureFromSurface" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Surface -> m Renderer
Raw.createTextureFromSurface Renderer
r Ptr Surface
s

-- | Bind an OpenGL\/ES\/ES2 texture to the current context for use with when rendering OpenGL primitives directly.
--
-- See @<https://wiki.libsdl.org/SDL_GL_BindTexture SDL_GL_BindTexture>@ for C documentation.
glBindTexture :: (Functor m,MonadIO m)
              => Texture -- ^ The texture to bind to the current OpenGL\/ES\/ES2 context
              -> m ()
glBindTexture :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Texture -> m ()
glBindTexture (Texture Renderer
t) =
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.glBindTexture" Text
"SDL_GL_BindTexture" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr CFloat -> Ptr CFloat -> m CInt
Raw.glBindTexture Renderer
t forall a. Ptr a
nullPtr forall a. Ptr a
nullPtr

-- | Unbind an OpenGL\/ES\/ES2 texture from the current context.
--
-- See @<https://wiki.libsdl.org/SDL_GL_UnbindTexture SDL_GL_UnbindTexture>@ for C documentation.
glUnbindTexture :: (Functor m,MonadIO m)
                => Texture -- ^ The texture to unbind from the current OpenGL\/ES\/ES2 context
                -> m ()
glUnbindTexture :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Texture -> m ()
glUnbindTexture (Texture Renderer
t) =
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.glUnindTexture" Text
"SDL_GL_UnbindTexture" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type). MonadIO m => Renderer -> m CInt
Raw.glUnbindTexture Renderer
t

-- | Updates texture rectangle with new pixel data.
--
-- See @<https://wiki.libsdl.org/SDL_UpdateTexture SDL_UpdateTexture>@ for C documentation.
updateTexture :: (Functor m, MonadIO m)
              => Texture -- ^ The 'Texture' to be updated
              -> Maybe (Rectangle CInt) -- ^ The area to update, Nothing for entire texture
              -> BS.ByteString -- ^ The raw pixel data
              -> CInt -- ^ The number of bytes in a row of pixel data, including padding between lines
              -> m ()
updateTexture :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Texture -> Maybe (Rectangle CInt) -> ByteString -> CInt -> m ()
updateTexture (Texture Renderer
t) Maybe (Rectangle CInt)
rect ByteString
pixels CInt
pitch = do
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.updateTexture" Text
"SDL_UpdateTexture" forall a b. (a -> b) -> a -> b
$
    forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rectPtr ->
      let (ForeignPtr Word8
pixelForeign, Int
_, Int
_) = ByteString -> (ForeignPtr Word8, Int, Int)
BSI.toForeignPtr ByteString
pixels
      in forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
pixelForeign forall a b. (a -> b) -> a -> b
$ \Ptr Word8
pixelsPtr ->
        forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> Renderer -> CInt -> m CInt
Raw.updateTexture Renderer
t (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rectPtr) (forall a b. Ptr a -> Ptr b
castPtr Ptr Word8
pixelsPtr) CInt
pitch

-- | Destroy the specified texture.
--
-- See @<https://wiki.libsdl.org/SDL_DestroyTexture SDL_DestroyTexture>@ for the C documentation.
destroyTexture :: MonadIO m => Texture -> m ()
destroyTexture :: forall (m :: Type -> Type). MonadIO m => Texture -> m ()
destroyTexture (Texture Renderer
t) = forall (m :: Type -> Type). MonadIO m => Renderer -> m ()
Raw.destroyTexture Renderer
t

-- | Lock a portion of the texture for *write-only* pixel access.
--
-- See @<https://wiki.libsdl.org/SDL_LockTexture SDL_LockTexture>@ for C documentation.
lockTexture :: MonadIO m
            => Texture -- ^ The 'Texture' to lock for access, which must have been created with 'TextureAccessStreaming'
            -> Maybe (Rectangle CInt) -- ^ The area to lock for access; 'Nothing' to lock the entire texture
            -> m (Ptr (),CInt) -- ^ A pointer to the locked pixels, appropriately offset by the locked area, and the pitch of the locked pixels (the pitch is the length of one row in bytes).
lockTexture :: forall (m :: Type -> Type).
MonadIO m =>
Texture -> Maybe (Rectangle CInt) -> m (Renderer, CInt)
lockTexture (Texture Renderer
t) Maybe (Rectangle CInt)
rect = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Renderer
pixelsPtr ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
pitchPtr ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rectPtr -> do
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"lockTexture" Text
"SDL_LockTexture" forall a b. (a -> b) -> a -> b
$
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> Ptr Renderer -> Ptr CInt -> m CInt
Raw.lockTexture Renderer
t (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rectPtr) Ptr Renderer
pixelsPtr Ptr CInt
pitchPtr
    Renderer
pixels <- forall a. Storable a => Ptr a -> IO a
peek Ptr Renderer
pixelsPtr
    CInt
pitch <- forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
pitchPtr
    forall (m :: Type -> Type) a. Monad m => a -> m a
return (Renderer
pixels, CInt
pitch)

-- | Unlock a texture, uploading the changes to video memory, if needed.
--
-- /Warning/: See <https://bugzilla.libsdl.org/show_bug.cgi?id=1586 Bug No. 1586> before using this function!
--
-- See @<https://wiki.libsdl.org/SDL_UnlockTexture SDL_UnlockTexture>@ for C documentation.
unlockTexture :: MonadIO m => Texture -> m ()
unlockTexture :: forall (m :: Type -> Type). MonadIO m => Texture -> m ()
unlockTexture (Texture Renderer
t) = forall (m :: Type -> Type). MonadIO m => Renderer -> m ()
Raw.unlockTexture Renderer
t

-- | Set up a surface for directly accessing the pixels.
--
-- See @<https://wiki.libsdl.org/SDL_LockSurface SDL_LockSurface>@ for C documentation.
lockSurface :: MonadIO m => Surface -> m ()
lockSurface :: forall (m :: Type -> Type). MonadIO m => Surface -> m ()
lockSurface (Surface Ptr Surface
s Maybe (IOVector Word8)
_) =
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"lockSurface" Text
"SDL_LockSurface" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type). MonadIO m => Ptr Surface -> m CInt
Raw.lockSurface Ptr Surface
s

-- | Release a surface after directly accessing the pixels.
--
-- See @<https://wiki.libsdl.org/SDL_UnlockSurface SDL_UnlockSurface>@ for C documentation.
unlockSurface :: MonadIO m => Surface -> m ()
unlockSurface :: forall (m :: Type -> Type). MonadIO m => Surface -> m ()
unlockSurface (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = forall (m :: Type -> Type). MonadIO m => Ptr Surface -> m ()
Raw.unlockSurface Ptr Surface
s

-- | Information to the GPU about how you will use a texture.
data TextureAccess
  = TextureAccessStatic
    -- ^ Changes rarely, cannot be locked
  | TextureAccessStreaming
    -- ^ changes frequently, can be locked
  | TextureAccessTarget
    -- ^ Can be used as a render target
  deriving (TextureAccess
forall a. a -> a -> Bounded a
maxBound :: TextureAccess
$cmaxBound :: TextureAccess
minBound :: TextureAccess
$cminBound :: TextureAccess
Bounded, Typeable TextureAccess
TextureAccess -> DataType
TextureAccess -> Constr
(forall b. Data b => b -> b) -> TextureAccess -> TextureAccess
forall a.
Typeable a
-> (forall (c :: Type -> Type).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TextureAccess -> u
forall u. (forall d. Data d => d -> u) -> TextureAccess -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> c TextureAccess
forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TextureAccess)
forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c TextureAccess)
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
gmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
$cgmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
gmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
$cgmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TextureAccess -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TextureAccess -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> TextureAccess -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TextureAccess -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
gmapT :: (forall b. Data b => b -> b) -> TextureAccess -> TextureAccess
$cgmapT :: (forall b. Data b => b -> b) -> TextureAccess -> TextureAccess
dataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c TextureAccess)
$cdataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c TextureAccess)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TextureAccess)
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TextureAccess)
dataTypeOf :: TextureAccess -> DataType
$cdataTypeOf :: TextureAccess -> DataType
toConstr :: TextureAccess -> Constr
$ctoConstr :: TextureAccess -> Constr
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
gfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> c TextureAccess
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> c TextureAccess
Data, Int -> TextureAccess
TextureAccess -> Int
TextureAccess -> [TextureAccess]
TextureAccess -> TextureAccess
TextureAccess -> TextureAccess -> [TextureAccess]
TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromThenTo :: TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
enumFromTo :: TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromTo :: TextureAccess -> TextureAccess -> [TextureAccess]
enumFromThen :: TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromThen :: TextureAccess -> TextureAccess -> [TextureAccess]
enumFrom :: TextureAccess -> [TextureAccess]
$cenumFrom :: TextureAccess -> [TextureAccess]
fromEnum :: TextureAccess -> Int
$cfromEnum :: TextureAccess -> Int
toEnum :: Int -> TextureAccess
$ctoEnum :: Int -> TextureAccess
pred :: TextureAccess -> TextureAccess
$cpred :: TextureAccess -> TextureAccess
succ :: TextureAccess -> TextureAccess
$csucc :: TextureAccess -> TextureAccess
Enum, TextureAccess -> TextureAccess -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextureAccess -> TextureAccess -> Bool
$c/= :: TextureAccess -> TextureAccess -> Bool
== :: TextureAccess -> TextureAccess -> Bool
$c== :: TextureAccess -> TextureAccess -> Bool
Eq, forall x. Rep TextureAccess x -> TextureAccess
forall x. TextureAccess -> Rep TextureAccess x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TextureAccess x -> TextureAccess
$cfrom :: forall x. TextureAccess -> Rep TextureAccess x
Generic, Eq TextureAccess
TextureAccess -> TextureAccess -> Bool
TextureAccess -> TextureAccess -> Ordering
TextureAccess -> TextureAccess -> TextureAccess
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TextureAccess -> TextureAccess -> TextureAccess
$cmin :: TextureAccess -> TextureAccess -> TextureAccess
max :: TextureAccess -> TextureAccess -> TextureAccess
$cmax :: TextureAccess -> TextureAccess -> TextureAccess
>= :: TextureAccess -> TextureAccess -> Bool
$c>= :: TextureAccess -> TextureAccess -> Bool
> :: TextureAccess -> TextureAccess -> Bool
$c> :: TextureAccess -> TextureAccess -> Bool
<= :: TextureAccess -> TextureAccess -> Bool
$c<= :: TextureAccess -> TextureAccess -> Bool
< :: TextureAccess -> TextureAccess -> Bool
$c< :: TextureAccess -> TextureAccess -> Bool
compare :: TextureAccess -> TextureAccess -> Ordering
$ccompare :: TextureAccess -> TextureAccess -> Ordering
Ord, ReadPrec [TextureAccess]
ReadPrec TextureAccess
Int -> ReadS TextureAccess
ReadS [TextureAccess]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TextureAccess]
$creadListPrec :: ReadPrec [TextureAccess]
readPrec :: ReadPrec TextureAccess
$creadPrec :: ReadPrec TextureAccess
readList :: ReadS [TextureAccess]
$creadList :: ReadS [TextureAccess]
readsPrec :: Int -> ReadS TextureAccess
$creadsPrec :: Int -> ReadS TextureAccess
Read, Int -> TextureAccess -> ShowS
[TextureAccess] -> ShowS
TextureAccess -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [TextureAccess] -> ShowS
$cshowList :: [TextureAccess] -> ShowS
show :: TextureAccess -> [Char]
$cshow :: TextureAccess -> [Char]
showsPrec :: Int -> TextureAccess -> ShowS
$cshowsPrec :: Int -> TextureAccess -> ShowS
Show, Typeable)

instance FromNumber TextureAccess CInt where
  fromNumber :: CInt -> TextureAccess
fromNumber CInt
n' = case CInt
n' of
    CInt
Raw.SDL_TEXTUREACCESS_STATIC -> TextureAccess
TextureAccessStatic
    CInt
Raw.SDL_TEXTUREACCESS_STREAMING -> TextureAccess
TextureAccessStreaming
    CInt
Raw.SDL_TEXTUREACCESS_TARGET -> TextureAccess
TextureAccessTarget
    CInt
_ -> forall a. HasCallStack => [Char] -> a
error [Char]
"Unknown value"

instance ToNumber TextureAccess CInt where
  toNumber :: TextureAccess -> CInt
toNumber TextureAccess
t = case TextureAccess
t of
    TextureAccess
TextureAccessStatic -> forall {a}. (Eq a, Num a) => a
Raw.SDL_TEXTUREACCESS_STATIC
    TextureAccess
TextureAccessStreaming -> forall {a}. (Eq a, Num a) => a
Raw.SDL_TEXTUREACCESS_STREAMING
    TextureAccess
TextureAccessTarget -> forall {a}. (Eq a, Num a) => a
Raw.SDL_TEXTUREACCESS_TARGET

data TextureInfo = TextureInfo
  { TextureInfo -> PixelFormat
texturePixelFormat :: PixelFormat
    -- ^ Raw format of the texture; the actual format may differ, but pixel transfers will use this format
  , TextureInfo -> TextureAccess
textureAccess      :: TextureAccess
    -- ^ The access available to the texture
  , TextureInfo -> CInt
textureWidth       :: CInt
    -- ^ The width of the texture
  , TextureInfo -> CInt
textureHeight      :: CInt
    -- ^ The height of the texture
  } deriving (TextureInfo -> TextureInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextureInfo -> TextureInfo -> Bool
$c/= :: TextureInfo -> TextureInfo -> Bool
== :: TextureInfo -> TextureInfo -> Bool
$c== :: TextureInfo -> TextureInfo -> Bool
Eq, forall x. Rep TextureInfo x -> TextureInfo
forall x. TextureInfo -> Rep TextureInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TextureInfo x -> TextureInfo
$cfrom :: forall x. TextureInfo -> Rep TextureInfo x
Generic, Eq TextureInfo
TextureInfo -> TextureInfo -> Bool
TextureInfo -> TextureInfo -> Ordering
TextureInfo -> TextureInfo -> TextureInfo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TextureInfo -> TextureInfo -> TextureInfo
$cmin :: TextureInfo -> TextureInfo -> TextureInfo
max :: TextureInfo -> TextureInfo -> TextureInfo
$cmax :: TextureInfo -> TextureInfo -> TextureInfo
>= :: TextureInfo -> TextureInfo -> Bool
$c>= :: TextureInfo -> TextureInfo -> Bool
> :: TextureInfo -> TextureInfo -> Bool
$c> :: TextureInfo -> TextureInfo -> Bool
<= :: TextureInfo -> TextureInfo -> Bool
$c<= :: TextureInfo -> TextureInfo -> Bool
< :: TextureInfo -> TextureInfo -> Bool
$c< :: TextureInfo -> TextureInfo -> Bool
compare :: TextureInfo -> TextureInfo -> Ordering
$ccompare :: TextureInfo -> TextureInfo -> Ordering
Ord, ReadPrec [TextureInfo]
ReadPrec TextureInfo
Int -> ReadS TextureInfo
ReadS [TextureInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TextureInfo]
$creadListPrec :: ReadPrec [TextureInfo]
readPrec :: ReadPrec TextureInfo
$creadPrec :: ReadPrec TextureInfo
readList :: ReadS [TextureInfo]
$creadList :: ReadS [TextureInfo]
readsPrec :: Int -> ReadS TextureInfo
$creadsPrec :: Int -> ReadS TextureInfo
Read, Int -> TextureInfo -> ShowS
[TextureInfo] -> ShowS
TextureInfo -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [TextureInfo] -> ShowS
$cshowList :: [TextureInfo] -> ShowS
show :: TextureInfo -> [Char]
$cshow :: TextureInfo -> [Char]
showsPrec :: Int -> TextureInfo -> ShowS
$cshowsPrec :: Int -> TextureInfo -> ShowS
Show, Typeable)

-- | Query the attributes of a texture.
--
-- See @<https://wiki.libsdl.org/SDL_QueryTexture SDL_QueryTexture>@ for C documentation.
queryTexture :: MonadIO m => Texture -> m TextureInfo
queryTexture :: forall (m :: Type -> Type). MonadIO m => Texture -> m TextureInfo
queryTexture (Texture Renderer
tex) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
pfPtr ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
acPtr ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
wPtr ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
hPtr -> do
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.queryTexture" Text
"SDL_QueryTexture" forall a b. (a -> b) -> a -> b
$
      forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Ptr BlendMode -> Ptr CInt -> Ptr CInt -> Ptr CInt -> m CInt
Raw.queryTexture Renderer
tex Ptr BlendMode
pfPtr Ptr CInt
acPtr Ptr CInt
wPtr Ptr CInt
hPtr
    PixelFormat -> TextureAccess -> CInt -> CInt -> TextureInfo
TextureInfo forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$>
      forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. FromNumber a b => b -> a
fromNumber (forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
pfPtr) forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*>
      forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. FromNumber a b => b -> a
fromNumber (forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
acPtr) forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*>
      forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
wPtr forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*>
      forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
hPtr

-- | Allocate a new RGB surface.
--
-- See @<https://wiki.libsdl.org/SDL_CreateRGBSurface SDL_CreateRGBSurface>@ for C documentation.
createRGBSurface :: (Functor m, MonadIO m)
                 => V2 CInt -- ^ The size of the surface
                 -> PixelFormat -- ^ The bit depth, red, green, blue and alpha mask for the pixels
                 -> m Surface
createRGBSurface :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
V2 CInt -> PixelFormat -> m Surface
createRGBSurface (V2 CInt
w CInt
h) PixelFormat
pf =
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.createRGBSurface" Text
"SDL_CreateRGBSurface" forall a b. (a -> b) -> a -> b
$ do
      (CInt
bpp, V4 BlendMode
r BlendMode
g BlendMode
b BlendMode
a) <- forall (m :: Type -> Type).
MonadIO m =>
PixelFormat -> m (CInt, V4 BlendMode)
pixelFormatToMasks PixelFormat
pf
      forall (m :: Type -> Type).
MonadIO m =>
BlendMode
-> CInt
-> CInt
-> CInt
-> BlendMode
-> BlendMode
-> BlendMode
-> BlendMode
-> m (Ptr Surface)
Raw.createRGBSurface BlendMode
0 CInt
w CInt
h CInt
bpp BlendMode
r BlendMode
g BlendMode
b BlendMode
a

-- | Allocate a new RGB surface with existing pixel data.
--
-- See @<https://wiki.libsdl.org/SDL_CreateRGBSurfaceFrom SDL_CreateRGBSurfaceFrom>@ for C documentation.
createRGBSurfaceFrom :: (Functor m, MonadIO m)
                     => MSV.IOVector Word8 -- ^ The existing pixel data
                     -> V2 CInt -- ^ The size of the surface
                     -> CInt -- ^ The pitch - the length of a row of pixels in bytes
                     -> PixelFormat -- ^ The bit depth, red, green, blue and alpha mask for the pixels
                     -> m Surface
createRGBSurfaceFrom :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
IOVector Word8 -> V2 CInt -> CInt -> PixelFormat -> m Surface
createRGBSurfaceFrom IOVector Word8
pixels (V2 CInt
w CInt
h) CInt
p PixelFormat
pf = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (IOVector Word8 -> Ptr Surface -> Surface
managedSurface IOVector Word8
pixels) forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.createRGBSurfaceFrom" Text
"SDL_CreateRGBSurfaceFrom" forall a b. (a -> b) -> a -> b
$ do
      (CInt
bpp, V4 BlendMode
r BlendMode
g BlendMode
b BlendMode
a) <- forall (m :: Type -> Type).
MonadIO m =>
PixelFormat -> m (CInt, V4 BlendMode)
pixelFormatToMasks PixelFormat
pf
      forall a b. Storable a => IOVector a -> (Ptr a -> IO b) -> IO b
MSV.unsafeWith IOVector Word8
pixels forall a b. (a -> b) -> a -> b
$ \Ptr Word8
pixelPtr ->
        forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> CInt
-> CInt
-> CInt
-> CInt
-> BlendMode
-> BlendMode
-> BlendMode
-> BlendMode
-> m (Ptr Surface)
Raw.createRGBSurfaceFrom (forall a b. Ptr a -> Ptr b
castPtr Ptr Word8
pixelPtr) CInt
w CInt
h CInt
bpp CInt
p BlendMode
r BlendMode
g BlendMode
b BlendMode
a

-- | Perform a fast fill of a rectangle with a specific color.
--
-- If there is a clip rectangle set on the destination (set via 'clipRect'), then this function will fill based on the intersection of the clip rectangle and the given 'Rectangle'.
--
-- See @<https://wiki.libsdl.org/SDL_FillRect SDL_FillRect>@ for C documentation.
surfaceFillRect :: MonadIO m
                => Surface -- ^ The 'Surface' that is the drawing target.
                -> Maybe (Rectangle CInt) -- ^ The rectangle to fill, or 'Nothing' to fill the entire surface.
                -> V4 Word8 -- ^ The color to fill with. If the color value contains an alpha component then the destination is simply filled with that alpha information, no blending takes place. This colour will be implictly mapped to the closest approximation that matches the surface's pixel format.
                -> m ()
surfaceFillRect :: forall (m :: Type -> Type).
MonadIO m =>
Surface -> Maybe (Rectangle CInt) -> V4 Word8 -> m ()
surfaceFillRect (Surface Ptr Surface
s Maybe (IOVector Word8)
_) Maybe (Rectangle CInt)
rect (V4 Word8
r Word8
g Word8
b Word8
a) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRect" Text
"SDL_FillRect" forall a b. (a -> b) -> a -> b
$
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rectPtr -> do
    Ptr PixelFormat
format <- Surface -> Ptr PixelFormat
Raw.surfaceFormat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s
    forall (m :: Type -> Type).
MonadIO m =>
Ptr PixelFormat -> Word8 -> Word8 -> Word8 -> Word8 -> m BlendMode
Raw.mapRGBA Ptr PixelFormat
format Word8
r Word8
g Word8
b Word8
a forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr Rect -> BlendMode -> m CInt
Raw.fillRect Ptr Surface
s (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rectPtr)

-- | Perform a fast fill of a set of rectangles with a specific color.
--
-- If there is a clip rectangle set on any of the destinations (set via 'clipRect'), then this function will fill based on the intersection of the clip rectangle and the given 'Rectangle's.
--
-- See @<https://wiki.libsdl.org/SDL_FillRect SDL_FillRects>@ for C documentation.
surfaceFillRects :: MonadIO m
                 => Surface -- ^ The 'Surface' that is the drawing target.
                 -> SV.Vector (Rectangle CInt) -- ^ A 'SV.Vector' of 'Rectangle's to be filled.
                 -> V4 Word8 -- ^ The color to fill with. If the color value contains an alpha component then the destination is simply filled with that alpha information, no blending takes place. This colour will be implictly mapped to the closest approximation that matches the surface's pixel format.
                 -> m ()
surfaceFillRects :: forall (m :: Type -> Type).
MonadIO m =>
Surface -> Vector (Rectangle CInt) -> V4 Word8 -> m ()
surfaceFillRects (Surface Ptr Surface
s Maybe (IOVector Word8)
_) Vector (Rectangle CInt)
rects (V4 Word8
r Word8
g Word8
b Word8
a) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRects" Text
"SDL_FillRects" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CInt)
rects forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rp -> do
      Ptr PixelFormat
format <- Surface -> Ptr PixelFormat
Raw.surfaceFormat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s
      forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr Rect -> CInt -> BlendMode -> m CInt
Raw.fillRects Ptr Surface
s
                    (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rp)
                    (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Rectangle CInt)
rects))
                    forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: Type -> Type).
MonadIO m =>
Ptr PixelFormat -> Word8 -> Word8 -> Word8 -> Word8 -> m BlendMode
Raw.mapRGBA Ptr PixelFormat
format Word8
r Word8
g Word8
b Word8
a

-- | Free an RGB surface.
--
-- If the surface was created using 'createRGBSurfaceFrom' then the pixel data is not freed.
--
-- See @<https://wiki.libsdl.org/SDL_FreeSurface SDL_FreeSurface>@ for the C documentation.
freeSurface :: MonadIO m => Surface -> m ()
freeSurface :: forall (m :: Type -> Type). MonadIO m => Surface -> m ()
freeSurface (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = forall (m :: Type -> Type). MonadIO m => Ptr Surface -> m ()
Raw.freeSurface Ptr Surface
s

-- | Load a surface from a BMP file.
--
-- See @<https://wiki.libsdl.org/SDL_LoadBMP SDL_LoadBMP>@ for C documentation.
loadBMP :: MonadIO m => FilePath -> m Surface
loadBMP :: forall (m :: Type -> Type). MonadIO m => [Char] -> m Surface
loadBMP [Char]
filePath = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.loadBMP" Text
"SDL_LoadBMP" forall a b. (a -> b) -> a -> b
$
  forall a. [Char] -> (CString -> IO a) -> IO a
withCString [Char]
filePath forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type). MonadIO m => CString -> m (Ptr Surface)
Raw.loadBMP

newtype SurfacePixelFormat = SurfacePixelFormat (Ptr Raw.PixelFormat)
  deriving (SurfacePixelFormat -> SurfacePixelFormat -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
$c/= :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
== :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
$c== :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
Eq, Typeable)

-- It's possible we could use unsafePerformIO here, but I'm not
-- sure. surface->{w,h} are immutable, but do we need to guarantee that pointers
-- aren't reused by *different* surfaces.
-- | Retrive the width and height of a 'Surface'.
surfaceDimensions :: MonadIO m => Surface -> m (V2 CInt)
surfaceDimensions :: forall (m :: Type -> Type). MonadIO m => Surface -> m (V2 CInt)
surfaceDimensions (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ (forall a. a -> a -> V2 a
V2 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Surface -> CInt
Raw.surfaceW forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Surface -> CInt
Raw.surfaceH) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s

-- | Obtain the pointer to the underlying pixels in a surface. You should bracket
-- this call with 'lockSurface' and 'unlockSurface', respectively.
surfacePixels :: MonadIO m => Surface -> m (Ptr ())
surfacePixels :: forall (m :: Type -> Type). MonadIO m => Surface -> m Renderer
surfacePixels (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Surface -> Renderer
Raw.surfacePixels forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s

-- It's possible we could use unsafePerformIO here, but I'm not
-- sure. surface->format is immutable, but do we need to guarantee that pointers
-- aren't reused by *different* surfaces?
-- | Inspect the pixel format under a surface.
surfaceFormat :: MonadIO m => Surface -> m SurfacePixelFormat
surfaceFormat :: forall (m :: Type -> Type).
MonadIO m =>
Surface -> m SurfacePixelFormat
surfaceFormat (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Ptr PixelFormat -> SurfacePixelFormat
SurfacePixelFormat forall b c a. (b -> c) -> (a -> b) -> a -> c
. Surface -> Ptr PixelFormat
Raw.surfaceFormat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s

newtype Palette = Palette (Ptr Raw.Palette)
  deriving (Palette -> Palette -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Palette -> Palette -> Bool
$c/= :: Palette -> Palette -> Bool
== :: Palette -> Palette -> Bool
$c== :: Palette -> Palette -> Bool
Eq, Typeable)

formatPalette :: MonadIO m => SurfacePixelFormat -> m (Maybe Palette)
formatPalette :: forall (m :: Type -> Type).
MonadIO m =>
SurfacePixelFormat -> m (Maybe Palette)
formatPalette (SurfacePixelFormat Ptr PixelFormat
f) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Ptr Palette -> Maybe Palette
wrap forall b c a. (b -> c) -> (a -> b) -> a -> c
. PixelFormat -> Ptr Palette
Raw.pixelFormatPalette forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr PixelFormat
f
  where wrap :: Ptr Palette -> Maybe Palette
wrap Ptr Palette
p
          | Ptr Palette
p forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr = forall a. Maybe a
Nothing
          | Bool
otherwise = forall a. a -> Maybe a
Just (Ptr Palette -> Palette
Palette Ptr Palette
p)

paletteNColors :: MonadIO m => Palette -> m CInt
paletteNColors :: forall (m :: Type -> Type). MonadIO m => Palette -> m CInt
paletteNColors (Palette Ptr Palette
p) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Palette -> CInt
Raw.paletteNColors forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Palette
p

paletteColors :: MonadIO m => Palette -> m (Maybe (SV.Vector (V4 Word8)))
paletteColors :: forall (m :: Type -> Type).
MonadIO m =>
Palette -> m (Maybe (Vector (V4 Word8)))
paletteColors q :: Palette
q@(Palette Ptr Palette
p) = do
  Int
n <- forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: Type -> Type). MonadIO m => Palette -> m CInt
paletteNColors Palette
q
  let wrap :: Ptr a -> Maybe (Ptr a)
wrap Ptr a
p' | Ptr a
p' forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr = forall a. Maybe a
Nothing
              | Bool
otherwise     = forall (m :: Type -> Type) a. Monad m => a -> m a
return Ptr a
p'
  Maybe (Ptr (V4 Word8))
mv <- forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall {a}. Ptr a -> Maybe (Ptr a)
wrap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Palette -> Ptr Color
Raw.paletteColors forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Palette
p
  Maybe (ForeignPtr (V4 Word8))
mColor <- forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall a. Ptr a -> IO (ForeignPtr a)
newForeignPtr_ Maybe (Ptr (V4 Word8))
mv
  forall (m :: Type -> Type) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. ForeignPtr a -> Int -> Vector a
SV.unsafeFromForeignPtr0 Int
n forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (ForeignPtr (V4 Word8))
mColor

paletteColor :: MonadIO m => Palette -> CInt -> m (Maybe (V4 Word8))
paletteColor :: forall (m :: Type -> Type).
MonadIO m =>
Palette -> CInt -> m (Maybe (V4 Word8))
paletteColor q :: Palette
q@(Palette Ptr Palette
p) CInt
i = do
    Palette
rp <- forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek Ptr Palette
p
    CInt
m <- forall (m :: Type -> Type). MonadIO m => Palette -> m CInt
paletteNColors Palette
q
    if CInt
m forall a. Ord a => a -> a -> Bool
> CInt
i Bool -> Bool -> Bool
&& CInt
i forall a. Ord a => a -> a -> Bool
>= CInt
0 then
      forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: Type -> Type) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff (forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
i) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Palette -> Ptr Color
Raw.paletteColors forall a b. (a -> b) -> a -> b
$ Palette
rp
    else
      forall (m :: Type -> Type) a. Monad m => a -> m a
return forall a. Maybe a
Nothing

-- | Set a range of colors in a palette.
--
-- See @<https://wiki.libsdl.org/SDL_SetPaletteColors SDL_SetPaletteColors>@ for C documentation.
setPaletteColors :: MonadIO m
                 => Palette -- ^ The 'Palette' to modify
                 -> (SV.Vector (V4 Word8)) -- ^ A 'SV.Vector' of colours to copy into the palette
                 -> CInt -- ^ The index of the first palette entry to modify
                 -> m ()
setPaletteColors :: forall (m :: Type -> Type).
MonadIO m =>
Palette -> Vector (V4 Word8) -> CInt -> m ()
setPaletteColors (Palette Ptr Palette
p) Vector (V4 Word8)
colors CInt
first = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.setPaletteColors" Text
"SDL_SetPaletteColors" forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (V4 Word8)
colors forall a b. (a -> b) -> a -> b
$ \Ptr (V4 Word8)
cp ->
    forall (m :: Type -> Type).
MonadIO m =>
Ptr Palette -> Ptr Color -> CInt -> CInt -> m CInt
Raw.setPaletteColors Ptr Palette
p (forall a b. Ptr a -> Ptr b
castPtr Ptr (V4 Word8)
cp) CInt
first CInt
n
  where
    n :: CInt
n = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Vector a -> Int
SV.length Vector (V4 Word8)
colors

-- | Get the SDL surface associated with the window.
--
-- See @<https://wiki.libsdl.org/SDL_GetWindowSurface SDL_GetWindowSurface>@ for C documentation.
getWindowSurface :: (Functor m, MonadIO m) => Window -> m Surface
getWindowSurface :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Window -> m Surface
getWindowSurface (Window Renderer
w) =
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.getWindowSurface" Text
"SDL_GetWindowSurface" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type).
MonadIO m =>
Renderer -> m (Ptr Surface)
Raw.getWindowSurface Renderer
w

-- | Get or set the blend mode used for drawing operations (fill and line).
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetRenderDrawBlendMode SDL_SetRenderDrawBlendMode>@ and @<https://wiki.libsdl.org/SDL_GetRenderDrawBlendMode SDL_GetRenderDrawBlendMode>@ for C documentation.
rendererDrawBlendMode :: Renderer -> StateVar BlendMode
rendererDrawBlendMode :: Renderer -> StateVar BlendMode
rendererDrawBlendMode (Renderer Renderer
r) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO BlendMode
getRenderDrawBlendMode forall {m :: Type -> Type} {a}.
(MonadIO m, ToNumber a BlendMode) =>
a -> m ()
setRenderDrawBlendMode
  where
  getRenderDrawBlendMode :: IO BlendMode
getRenderDrawBlendMode = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
bmPtr -> do
      forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.getRenderDrawBlendMode" Text
"SDL_GetRenderDrawBlendMode" forall a b. (a -> b) -> a -> b
$
        forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr BlendMode -> m Int
Raw.getRenderDrawBlendMode Renderer
r Ptr BlendMode
bmPtr
      forall a b. FromNumber a b => b -> a
fromNumber forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
bmPtr

  setRenderDrawBlendMode :: a -> m ()
setRenderDrawBlendMode a
bm =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.setRenderDrawBlendMode" Text
"SDL_SetRenderDrawBlendMode" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> BlendMode -> m CInt
Raw.setRenderDrawBlendMode Renderer
r (forall a b. ToNumber a b => a -> b
toNumber a
bm)

-- | Get or set the color used for drawing operations (rect, line and clear).
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetRenderDrawColor SDL_SetRenderDrawColor>@ and @<https://wiki.libsdl.org/SDL_GetRenderDrawColor SDL_GetRenderDrawColor>@ for C documentation.
rendererDrawColor :: Renderer -> StateVar (V4 Word8)
rendererDrawColor :: Renderer -> StateVar (V4 Word8)
rendererDrawColor (Renderer Renderer
re) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (V4 Word8)
getRenderDrawColor forall {m :: Type -> Type}. MonadIO m => V4 Word8 -> m ()
setRenderDrawColor
  where
  getRenderDrawColor :: IO (V4 Word8)
getRenderDrawColor = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
r ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
g ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
b ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
a -> do
      forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.getRenderDrawColor" Text
"SDL_GetRenderDrawColor" forall a b. (a -> b) -> a -> b
$
        forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> m CInt
Raw.getRenderDrawColor Renderer
re Ptr Word8
r Ptr Word8
g Ptr Word8
b Ptr Word8
a
      forall a. a -> a -> a -> a -> V4 a
V4 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
r forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
g forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
b forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
a

  setRenderDrawColor :: V4 Word8 -> m ()
setRenderDrawColor (V4 Word8
r Word8
g Word8
b Word8
a) =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.setRenderDrawColor" Text
"SDL_SetRenderDrawColor" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Word8 -> Word8 -> Word8 -> Word8 -> m CInt
Raw.setRenderDrawColor Renderer
re Word8
r Word8
g Word8
b Word8
a

-- | Copy the window surface to the screen.
--
-- This is the function you use to reflect any changes to the surface on the screen.
--
-- See @<https://wiki.libsdl.org/SDL_UpdateWindowSurface SDL_UpdateWindowSurface>@ for C documentation.
updateWindowSurface :: (Functor m, MonadIO m) => Window -> m ()
updateWindowSurface :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Window -> m ()
updateWindowSurface (Window Renderer
w) =
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.updateWindowSurface" Text
"SDL_UpdateWindowSurface" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type). MonadIO m => Renderer -> m CInt
Raw.updateWindowSurface Renderer
w

-- | Blend modes used in 'copy' and drawing operations.
data BlendMode
  = BlendNone
    -- ^ No blending
  | BlendAlphaBlend
    -- ^ Alpha blending.
    --
    -- @
    -- dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
    -- dstA = srcA + (dstA * (1-srcA))
    -- @
  | BlendAdditive
    -- ^ Additive blending
    --
    -- @
    -- dstRGB = (srcRGB * srcA) + dstRGB
    -- dstA = dstA
    -- @
  | BlendMod
    -- ^ Color modulate
    --
    -- @
    -- dstRGB = srcRGB * dstRGB
    -- dstA = dstA
    --
  deriving (BlendMode
forall a. a -> a -> Bounded a
maxBound :: BlendMode
$cmaxBound :: BlendMode
minBound :: BlendMode
$cminBound :: BlendMode
Bounded, Typeable BlendMode
BlendMode -> DataType
BlendMode -> Constr
(forall b. Data b => b -> b) -> BlendMode -> BlendMode
forall a.
Typeable a
-> (forall (c :: Type -> Type).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BlendMode -> u
forall u. (forall d. Data d => d -> u) -> BlendMode -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BlendMode
forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BlendMode -> c BlendMode
forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BlendMode)
forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BlendMode)
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
gmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
$cgmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
gmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
$cgmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BlendMode -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BlendMode -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> BlendMode -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BlendMode -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
gmapT :: (forall b. Data b => b -> b) -> BlendMode -> BlendMode
$cgmapT :: (forall b. Data b => b -> b) -> BlendMode -> BlendMode
dataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BlendMode)
$cdataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BlendMode)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BlendMode)
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BlendMode)
dataTypeOf :: BlendMode -> DataType
$cdataTypeOf :: BlendMode -> DataType
toConstr :: BlendMode -> Constr
$ctoConstr :: BlendMode -> Constr
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BlendMode
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BlendMode
gfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BlendMode -> c BlendMode
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BlendMode -> c BlendMode
Data, Int -> BlendMode
BlendMode -> Int
BlendMode -> [BlendMode]
BlendMode -> BlendMode
BlendMode -> BlendMode -> [BlendMode]
BlendMode -> BlendMode -> BlendMode -> [BlendMode]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: BlendMode -> BlendMode -> BlendMode -> [BlendMode]
$cenumFromThenTo :: BlendMode -> BlendMode -> BlendMode -> [BlendMode]
enumFromTo :: BlendMode -> BlendMode -> [BlendMode]
$cenumFromTo :: BlendMode -> BlendMode -> [BlendMode]
enumFromThen :: BlendMode -> BlendMode -> [BlendMode]
$cenumFromThen :: BlendMode -> BlendMode -> [BlendMode]
enumFrom :: BlendMode -> [BlendMode]
$cenumFrom :: BlendMode -> [BlendMode]
fromEnum :: BlendMode -> Int
$cfromEnum :: BlendMode -> Int
toEnum :: Int -> BlendMode
$ctoEnum :: Int -> BlendMode
pred :: BlendMode -> BlendMode
$cpred :: BlendMode -> BlendMode
succ :: BlendMode -> BlendMode
$csucc :: BlendMode -> BlendMode
Enum, BlendMode -> BlendMode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlendMode -> BlendMode -> Bool
$c/= :: BlendMode -> BlendMode -> Bool
== :: BlendMode -> BlendMode -> Bool
$c== :: BlendMode -> BlendMode -> Bool
Eq, forall x. Rep BlendMode x -> BlendMode
forall x. BlendMode -> Rep BlendMode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlendMode x -> BlendMode
$cfrom :: forall x. BlendMode -> Rep BlendMode x
Generic, Eq BlendMode
BlendMode -> BlendMode -> Bool
BlendMode -> BlendMode -> Ordering
BlendMode -> BlendMode -> BlendMode
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BlendMode -> BlendMode -> BlendMode
$cmin :: BlendMode -> BlendMode -> BlendMode
max :: BlendMode -> BlendMode -> BlendMode
$cmax :: BlendMode -> BlendMode -> BlendMode
>= :: BlendMode -> BlendMode -> Bool
$c>= :: BlendMode -> BlendMode -> Bool
> :: BlendMode -> BlendMode -> Bool
$c> :: BlendMode -> BlendMode -> Bool
<= :: BlendMode -> BlendMode -> Bool
$c<= :: BlendMode -> BlendMode -> Bool
< :: BlendMode -> BlendMode -> Bool
$c< :: BlendMode -> BlendMode -> Bool
compare :: BlendMode -> BlendMode -> Ordering
$ccompare :: BlendMode -> BlendMode -> Ordering
Ord, ReadPrec [BlendMode]
ReadPrec BlendMode
Int -> ReadS BlendMode
ReadS [BlendMode]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BlendMode]
$creadListPrec :: ReadPrec [BlendMode]
readPrec :: ReadPrec BlendMode
$creadPrec :: ReadPrec BlendMode
readList :: ReadS [BlendMode]
$creadList :: ReadS [BlendMode]
readsPrec :: Int -> ReadS BlendMode
$creadsPrec :: Int -> ReadS BlendMode
Read, Int -> BlendMode -> ShowS
[BlendMode] -> ShowS
BlendMode -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [BlendMode] -> ShowS
$cshowList :: [BlendMode] -> ShowS
show :: BlendMode -> [Char]
$cshow :: BlendMode -> [Char]
showsPrec :: Int -> BlendMode -> ShowS
$cshowsPrec :: Int -> BlendMode -> ShowS
Show, Typeable)

instance FromNumber BlendMode Word32 where
  fromNumber :: BlendMode -> BlendMode
fromNumber BlendMode
n = case BlendMode
n of
    BlendMode
Raw.SDL_BLENDMODE_ADD -> BlendMode
BlendAdditive
    BlendMode
Raw.SDL_BLENDMODE_BLEND -> BlendMode
BlendAlphaBlend
    BlendMode
Raw.SDL_BLENDMODE_NONE -> BlendMode
BlendNone
    BlendMode
Raw.SDL_BLENDMODE_MOD -> BlendMode
BlendMod
    BlendMode
_ -> forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"fromNumber<BlendMode>: unknown blend mode: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show BlendMode
n

instance ToNumber BlendMode Word32 where
  toNumber :: BlendMode -> BlendMode
toNumber BlendMode
BlendNone = BlendMode
Raw.SDL_BLENDMODE_NONE
  toNumber BlendMode
BlendAlphaBlend = BlendMode
Raw.SDL_BLENDMODE_BLEND
  toNumber BlendMode
BlendAdditive = BlendMode
Raw.SDL_BLENDMODE_ADD
  toNumber BlendMode
BlendMod = BlendMode
Raw.SDL_BLENDMODE_MOD

data Rectangle a = Rectangle (Point V2 a) (V2 a)
  deriving (Rectangle a -> Rectangle a -> Bool
forall a. Eq a => Rectangle a -> Rectangle a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rectangle a -> Rectangle a -> Bool
$c/= :: forall a. Eq a => Rectangle a -> Rectangle a -> Bool
== :: Rectangle a -> Rectangle a -> Bool
$c== :: forall a. Eq a => Rectangle a -> Rectangle a -> Bool
Eq, forall a b. a -> Rectangle b -> Rectangle a
forall a b. (a -> b) -> Rectangle a -> Rectangle b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Rectangle b -> Rectangle a
$c<$ :: forall a b. a -> Rectangle b -> Rectangle a
fmap :: forall a b. (a -> b) -> Rectangle a -> Rectangle b
$cfmap :: forall a b. (a -> b) -> Rectangle a -> Rectangle b
Functor, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Rectangle a) x -> Rectangle a
forall a x. Rectangle a -> Rep (Rectangle a) x
$cto :: forall a x. Rep (Rectangle a) x -> Rectangle a
$cfrom :: forall a x. Rectangle a -> Rep (Rectangle a) x
Generic, Rectangle a -> Rectangle a -> Bool
Rectangle a -> Rectangle a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Rectangle a)
forall a. Ord a => Rectangle a -> Rectangle a -> Bool
forall a. Ord a => Rectangle a -> Rectangle a -> Ordering
forall a. Ord a => Rectangle a -> Rectangle a -> Rectangle a
min :: Rectangle a -> Rectangle a -> Rectangle a
$cmin :: forall a. Ord a => Rectangle a -> Rectangle a -> Rectangle a
max :: Rectangle a -> Rectangle a -> Rectangle a
$cmax :: forall a. Ord a => Rectangle a -> Rectangle a -> Rectangle a
>= :: Rectangle a -> Rectangle a -> Bool
$c>= :: forall a. Ord a => Rectangle a -> Rectangle a -> Bool
> :: Rectangle a -> Rectangle a -> Bool
$c> :: forall a. Ord a => Rectangle a -> Rectangle a -> Bool
<= :: Rectangle a -> Rectangle a -> Bool
$c<= :: forall a. Ord a => Rectangle a -> Rectangle a -> Bool
< :: Rectangle a -> Rectangle a -> Bool
$c< :: forall a. Ord a => Rectangle a -> Rectangle a -> Bool
compare :: Rectangle a -> Rectangle a -> Ordering
$ccompare :: forall a. Ord a => Rectangle a -> Rectangle a -> Ordering
Ord, ReadPrec [Rectangle a]
ReadPrec (Rectangle a)
ReadS [Rectangle a]
forall a. Read a => ReadPrec [Rectangle a]
forall a. Read a => ReadPrec (Rectangle a)
forall a. Read a => Int -> ReadS (Rectangle a)
forall a. Read a => ReadS [Rectangle a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Rectangle a]
$creadListPrec :: forall a. Read a => ReadPrec [Rectangle a]
readPrec :: ReadPrec (Rectangle a)
$creadPrec :: forall a. Read a => ReadPrec (Rectangle a)
readList :: ReadS [Rectangle a]
$creadList :: forall a. Read a => ReadS [Rectangle a]
readsPrec :: Int -> ReadS (Rectangle a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Rectangle a)
Read, Int -> Rectangle a -> ShowS
forall a. Show a => Int -> Rectangle a -> ShowS
forall a. Show a => [Rectangle a] -> ShowS
forall a. Show a => Rectangle a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [Rectangle a] -> ShowS
$cshowList :: forall a. Show a => [Rectangle a] -> ShowS
show :: Rectangle a -> [Char]
$cshow :: forall a. Show a => Rectangle a -> [Char]
showsPrec :: Int -> Rectangle a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Rectangle a -> ShowS
Show, Typeable)

instance Storable a => Storable (Rectangle a) where
  sizeOf :: Rectangle a -> Int
sizeOf ~(Rectangle Point V2 a
o V2 a
s) = forall a. Storable a => a -> Int
sizeOf Point V2 a
o forall a. Num a => a -> a -> a
+ forall a. Storable a => a -> Int
sizeOf V2 a
s
  alignment :: Rectangle a -> Int
alignment Rectangle a
_ = forall a. Storable a => a -> Int
alignment (forall a. HasCallStack => a
undefined :: a)
  peek :: Ptr (Rectangle a) -> IO (Rectangle a)
peek Ptr (Rectangle a)
ptr = do
    Point V2 a
o <- forall a. Storable a => Ptr a -> IO a
peek (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle a)
ptr)
    V2 a
s <- forall a. Storable a => Ptr a -> IO a
peek (forall a b. Ptr a -> Ptr b
castPtr (Ptr (Rectangle a)
ptr forall a b. Ptr a -> Int -> Ptr b
`plusPtr` forall a. Storable a => a -> Int
sizeOf Point V2 a
o))
    forall (m :: Type -> Type) a. Monad m => a -> m a
return (forall a. Point V2 a -> V2 a -> Rectangle a
Rectangle Point V2 a
o V2 a
s)
  poke :: Ptr (Rectangle a) -> Rectangle a -> IO ()
poke Ptr (Rectangle a)
ptr (Rectangle Point V2 a
o V2 a
s) = do
    forall a. Storable a => Ptr a -> a -> IO ()
poke (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle a)
ptr) Point V2 a
o
    forall a. Storable a => Ptr a -> a -> IO ()
poke (forall a b. Ptr a -> Ptr b
castPtr (Ptr (Rectangle a)
ptr forall a b. Ptr a -> Int -> Ptr b
`plusPtr` forall a. Storable a => a -> Int
sizeOf Point V2 a
o)) V2 a
s

data Surface = Surface (Ptr Raw.Surface) (Maybe (MSV.IOVector Word8))
  deriving (Typeable)

unmanagedSurface :: Ptr Raw.Surface -> Surface
unmanagedSurface :: Ptr Surface -> Surface
unmanagedSurface Ptr Surface
s = Ptr Surface -> Maybe (IOVector Word8) -> Surface
Surface Ptr Surface
s forall a. Maybe a
Nothing

managedSurface :: MSV.IOVector Word8 -> Ptr Raw.Surface -> Surface
managedSurface :: IOVector Word8 -> Ptr Surface -> Surface
managedSurface IOVector Word8
p Ptr Surface
s = Ptr Surface -> Maybe (IOVector Word8) -> Surface
Surface Ptr Surface
s (forall a. a -> Maybe a
Just IOVector Word8
p)

newtype Texture = Texture Raw.Texture
  deriving (Texture -> Texture -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Texture -> Texture -> Bool
$c/= :: Texture -> Texture -> Bool
== :: Texture -> Texture -> Bool
$c== :: Texture -> Texture -> Bool
Eq, Typeable)

-- | Draw a rectangle outline on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL_RenderDrawRect SDL_RenderDrawRect>@ for C documentation.
drawRect :: MonadIO m
         => Renderer
         -> Maybe (Rectangle CInt) -- ^ The rectangle outline to draw. 'Nothing' for the entire rendering context.
         -> m ()
drawRect :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Maybe (Rectangle CInt) -> m ()
drawRect (Renderer Renderer
r) Maybe (Rectangle CInt)
rect = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRect" Text
"SDL_RenderDrawRect" forall a b. (a -> b) -> a -> b
$
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect (forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> m CInt
Raw.renderDrawRect Renderer
r forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr)

-- | Draw some number of rectangles on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL_RenderDrawRects SDL_RenderDrawRects>@ for C documentation.
drawRects :: MonadIO m => Renderer -> SV.Vector (Rectangle CInt) -> m ()
drawRects :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Rectangle CInt) -> m ()
drawRects (Renderer Renderer
r) Vector (Rectangle CInt)
rects = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRects" Text
"SDL_RenderDrawRects" forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CInt)
rects forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rp ->
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> CInt -> m CInt
Raw.renderDrawRects Renderer
r
                        (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rp)
                        (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Rectangle CInt)
rects))

-- | Fill a rectangle on the current rendering target with the drawing color.
--
-- See @<https://wiki.libsdl.org/SDL_RenderFillRect SDL_RenderFillRect>@ for C documentation.
fillRect ::
     MonadIO m
  => Renderer
  -> Maybe (Rectangle CInt) -- ^ The rectangle to fill.
  -> m ()
fillRect :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Maybe (Rectangle CInt) -> m ()
fillRect (Renderer Renderer
r) Maybe (Rectangle CInt)
rect =
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRect" Text
"SDL_RenderFillRect" forall a b. (a -> b) -> a -> b
$
  case Maybe (Rectangle CInt)
rect of
    Maybe (Rectangle CInt)
Nothing -> forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> m CInt
Raw.renderFillRect Renderer
r forall a. Ptr a
nullPtr
    Just (Rectangle (P (V2 CInt
x CInt
y)) (V2 CInt
w CInt
h)) -> forall (m :: Type -> Type).
MonadIO m =>
Renderer -> CInt -> CInt -> CInt -> CInt -> m CInt
Raw.renderFillRectEx Renderer
r CInt
x CInt
y CInt
w CInt
h
{-# INLINE fillRect #-}

-- | Fill some number of rectangles on the current rendering target with the drawing color.
--
-- See @<https://wiki.libsdl.org/SDL_RenderFillRects SDL_RenderFillRects>@ for C documentation.
fillRects :: MonadIO m => Renderer -> SV.Vector (Rectangle CInt) -> m ()
fillRects :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Rectangle CInt) -> m ()
fillRects (Renderer Renderer
r) Vector (Rectangle CInt)
rects = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRects" Text
"SDL_RenderFillRects" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CInt)
rects forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rp ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> CInt -> m CInt
Raw.renderFillRects Renderer
r
                          (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rp)
                          (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Rectangle CInt)
rects))

#ifdef RECENT_ISH

-- | Copy a portion of the texture to the current rendering target.
copyF :: MonadIO m => Renderer -> Texture -> Maybe (Rectangle CInt) -> Maybe (Rectangle CFloat) -> m ()
copyF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Texture
-> Maybe (Rectangle CInt)
-> Maybe (Rectangle CFloat)
-> m ()
copyF (Renderer Renderer
r) (Texture Renderer
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CFloat)
dstRect = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copyF" Text
"SDL_RenderCopyF" forall a b. (a -> b) -> a -> b
$
    forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
      forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CFloat)
dstRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
dst ->
        forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Renderer -> Ptr Rect -> Ptr FRect -> m CInt
Raw.renderCopyF Renderer
r Renderer
t (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
dst)

-- | Copy a portion of the texture to the current rendering target, optionally rotating it by angle around the given center and also flipping it top-bottom and/or left-right.
copyExF :: MonadIO m
       => Renderer -- ^ The rendering context
       -> Texture -- ^ The source texture
       -> Maybe (Rectangle CInt) -- ^ The source rectangle to copy, or 'Nothing' for the whole texture
       -> Maybe (Rectangle CFloat) -- ^ The destination rectangle to copy to, or 'Nothing' for the whole rendering target. The texture will be stretched to fill the given rectangle.
       -> CDouble -- ^ The angle of rotation in degrees. The rotation will be performed clockwise.
       -> Maybe (Point V2 CFloat) -- ^ The point indicating the center of the rotation, or 'Nothing' to rotate around the center of the destination rectangle
       -> V2 Bool -- ^ Whether to flip the texture on the X and/or Y axis
       -> m ()
copyExF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Texture
-> Maybe (Rectangle CInt)
-> Maybe (Rectangle CFloat)
-> CDouble
-> Maybe (Point V2 CFloat)
-> V2 Bool
-> m ()
copyExF (Renderer Renderer
r) (Texture Renderer
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CFloat)
dstRect CDouble
theta Maybe (Point V2 CFloat)
center V2 Bool
flips =
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copyExF" Text
"SDL_RenderCopyExF" forall a b. (a -> b) -> a -> b
$
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CFloat)
dstRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
dst ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Point V2 CFloat)
center forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CFloat)
c ->
  forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Renderer
-> Ptr Rect
-> Ptr FRect
-> CDouble
-> Ptr FPoint
-> BlendMode
-> m CInt
Raw.renderCopyExF Renderer
r Renderer
t (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
dst) CDouble
theta (forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CFloat)
c)
                   (case V2 Bool
flips of
                      V2 Bool
x Bool
y -> (if Bool
x then BlendMode
Raw.SDL_FLIP_HORIZONTAL else BlendMode
0) forall a. Bits a => a -> a -> a
.|.
                               (if Bool
y then BlendMode
Raw.SDL_FLIP_VERTICAL else BlendMode
0))

-- | Draw a line between two points on the current rendering target.
drawLineF :: MonadIO m => Renderer -> Point V2 CFloat -> Point V2 CFloat -> m ()
drawLineF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Point V2 CFloat -> Point V2 CFloat -> m ()
drawLineF (Renderer Renderer
r) (P (V2 CFloat
x CFloat
y)) (P (V2 CFloat
x' CFloat
y')) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLineF" Text
"SDL_RenderDrawLineF" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> CFloat -> CFloat -> CFloat -> CFloat -> m CInt
Raw.renderDrawLineF Renderer
r CFloat
x CFloat
y CFloat
x' CFloat
y'

-- | Draw a series of connected lines on the current rendering target.
drawLinesF :: MonadIO m => Renderer -> SV.Vector (Point V2 CFloat) -> m ()
drawLinesF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Point V2 CFloat) -> m ()
drawLinesF (Renderer Renderer
r) Vector (Point V2 CFloat)
points = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLinesF" Text
"SDL_RenderDrawLinesF" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CFloat)
points forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CFloat)
p ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr FPoint -> CInt -> m CInt
Raw.renderDrawLinesF Renderer
r (forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CFloat)
p) (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Point V2 CFloat)
points))

-- | Draw a point on the current rendering target.
drawPointF :: MonadIO m => Renderer -> Point V2 CFloat -> m ()
drawPointF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Point V2 CFloat -> m ()
drawPointF (Renderer Renderer
r) (P (V2 CFloat
x CFloat
y)) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPointF" Text
"SDL_RenderDrawPointF" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> CFloat -> CFloat -> m CInt
Raw.renderDrawPointF Renderer
r CFloat
x CFloat
y

-- | Draw a collection of points on the current rendering target.
drawPointsF :: MonadIO m => Renderer -> SV.Vector (Point V2 CFloat) -> m ()
drawPointsF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Point V2 CFloat) -> m ()
drawPointsF (Renderer Renderer
r) Vector (Point V2 CFloat)
points = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPointsF" Text
"SDL_RenderDrawPointsF" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CFloat)
points forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CFloat)
p ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr FPoint -> CInt -> m CInt
Raw.renderDrawPointsF Renderer
r (forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CFloat)
p) (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Point V2 CFloat)
points))

-- | Draw the outline of a rectangle on the current rendering target.
drawRectF :: MonadIO m => Renderer -> Rectangle CFloat -> m ()
drawRectF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Rectangle CFloat -> m ()
drawRectF (Renderer Renderer
r) Rectangle CFloat
rect = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRectF" Text
"SDL_RenderDrawRectF" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Rectangle CFloat
rect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rectPtr ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr FRect -> m CInt
Raw.renderDrawRectF Renderer
r (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
rectPtr)

-- | Draw a series of rectangle outlines on the current rendering target.
drawRectsF :: MonadIO m => Renderer -> SV.Vector (Rectangle CFloat) -> m ()
drawRectsF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Rectangle CFloat) -> m ()
drawRectsF (Renderer Renderer
r) Vector (Rectangle CFloat)
rects = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRectsF" Text
"SDL_RenderDrawRectsF" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CFloat)
rects forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rp ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr FRect -> CInt -> m CInt
Raw.renderDrawRectsF Renderer
r (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
rp) (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Rectangle CFloat)
rects))

-- | Draw a filled rectangle on the current rendering target.
fillRectF :: MonadIO m => Renderer -> Rectangle CFloat -> m ()
fillRectF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Rectangle CFloat -> m ()
fillRectF (Renderer Renderer
r) Rectangle CFloat
rect = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRectF" Text
"SDL_RenderFillRectF" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Rectangle CFloat
rect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rectPtr ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr FRect -> m CInt
Raw.renderFillRectF Renderer
r (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
rectPtr)

-- | Draw a series of filled rectangles on the current rendering target.
fillRectsF :: MonadIO m => Renderer -> SV.Vector (Rectangle CFloat) -> m ()
fillRectsF :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Rectangle CFloat) -> m ()
fillRectsF (Renderer Renderer
r) Vector (Rectangle CFloat)
rects = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRectsF" Text
"SDL_RenderFillRectsF" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CFloat)
rects forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rp ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr FRect -> CInt -> m CInt
Raw.renderFillRectsF Renderer
r (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
rp) (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Rectangle CFloat)
rects))

-- | Render a list of triangles, optionally using a texture and indices into the
-- vertex array Color and alpha modulation is done per vertex
-- (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
renderGeometry :: MonadIO m => Renderer -> Maybe Texture -> SV.Vector Raw.Vertex -> SV.Vector CInt -> m ()
renderGeometry :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Maybe Texture -> Vector Vertex -> Vector CInt -> m ()
renderGeometry (Renderer Renderer
r) Maybe Texture
mtexture Vector Vertex
vertices Vector CInt
indices = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderGeometry" Text
"SDL_RenderGeometry" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector Vertex
vertices forall a b. (a -> b) -> a -> b
$ \Ptr Vertex
vp ->
      forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector CInt
indices forall a b. (a -> b) -> a -> b
$ \Ptr CInt
ip ->
        forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Renderer -> Ptr Vertex -> CInt -> Ptr CInt -> CInt -> m CInt
Raw.renderGeometry Renderer
r Renderer
t Ptr Vertex
vp (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector Vertex
vertices)) (forall {a}. Ptr a -> Ptr a
ipOrNull Ptr CInt
ip) CInt
ipSize
  where
    t :: Renderer
t = case Maybe Texture
mtexture of
      Just (Texture Renderer
found) -> Renderer
found
      Maybe Texture
Nothing -> forall a. Ptr a
nullPtr

    ipOrNull :: Ptr a -> Ptr a
ipOrNull Ptr a
ip = if CInt
ipSize forall a. Eq a => a -> a -> Bool
== CInt
0 then forall a. Ptr a
nullPtr else Ptr a
ip

    ipSize :: CInt
ipSize = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector CInt
indices)

-- | Render a list of triangles, optionally using a texture and indices into the
-- vertex array Color and alpha modulation is done per vertex
-- (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
--
-- This version allows storeing vertex data in arbitrary types, but you have to provide
-- pointers and strides yourself.
renderGeometryRaw :: forall ix m . (Storable ix, MonadIO m) => Renderer -> Maybe Texture -> Ptr Raw.FPoint -> CInt -> Ptr Raw.Color -> CInt -> Ptr Raw.FPoint -> CInt -> CInt -> SV.Vector ix -> m ()
renderGeometryRaw :: forall ix (m :: Type -> Type).
(Storable ix, MonadIO m) =>
Renderer
-> Maybe Texture
-> Ptr FPoint
-> CInt
-> Ptr Color
-> CInt
-> Ptr FPoint
-> CInt
-> CInt
-> Vector ix
-> m ()
renderGeometryRaw (Renderer Renderer
r) Maybe Texture
mtexture Ptr FPoint
xy CInt
xyStride Ptr Color
color CInt
colorStride Ptr FPoint
uv CInt
uvStride CInt
numVertices Vector ix
indices = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderGeometryRaw" Text
"SDL_RenderGeometryRaw" forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector ix
indices forall a b. (a -> b) -> a -> b
$ \Ptr ix
ip ->
      forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Renderer
-> Ptr FPoint
-> CInt
-> Ptr Color
-> CInt
-> Ptr FPoint
-> CInt
-> CInt
-> Renderer
-> CInt
-> CInt
-> m CInt
Raw.renderGeometryRaw Renderer
r Renderer
t Ptr FPoint
xy CInt
xyStride Ptr Color
color CInt
colorStride Ptr FPoint
uv CInt
uvStride CInt
numVertices (forall a b. Ptr a -> Ptr b
castPtr forall a b. (a -> b) -> a -> b
$ forall {a}. Ptr a -> Ptr a
ipOrNull Ptr ix
ip) CInt
ipSize CInt
sizeOfip
  where
    t :: Renderer
t = case Maybe Texture
mtexture of
      Just (Texture Renderer
found) -> Renderer
found
      Maybe Texture
Nothing -> forall a. Ptr a
nullPtr

    ipOrNull :: Ptr a -> Ptr a
ipOrNull Ptr a
ip = if CInt
ipSize forall a. Eq a => a -> a -> Bool
== CInt
0 then forall a. Ptr a
nullPtr else Ptr a
ip

    ipSize :: CInt
ipSize = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector ix
indices)

    sizeOfip :: CInt
sizeOfip = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined :: ix)
#endif


-- | Clear the current rendering target with the drawing color.
--
-- See @<https://wiki.libsdl.org/SDL_RenderClear SDL_RenderClear>@ for C documentation.
clear :: (Functor m, MonadIO m) => Renderer -> m ()
clear :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Renderer -> m ()
clear (Renderer Renderer
r) =
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.clear" Text
"SDL_RenderClear" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type). MonadIO m => Renderer -> m CInt
Raw.renderClear Renderer
r
{-# INLINE clear #-}

-- | Get or set the drawing scale for rendering on the current target.
--
-- The drawing coordinates are scaled by the x\/y scaling factors before they are used by the renderer. This allows resolution independent drawing with a single coordinate system.
--
-- If this results in scaling or subpixel drawing by the rendering backend, it will be handled using the appropriate quality hints. For best results use integer scaling factors.
--
-- See @<https://wiki.libsdl.org/SDL_RenderSetScale SDL_RenderSetScale>@ and @<https://wiki.libsdl.org/SDL_RenderGetScale SDL_RenderGetScale>@ for C documentation.
rendererScale :: Renderer -> StateVar (V2 CFloat)
rendererScale :: Renderer -> StateVar (V2 CFloat)
rendererScale (Renderer Renderer
r) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (V2 CFloat)
renderGetScale forall {m :: Type -> Type}. MonadIO m => V2 CFloat -> m ()
renderSetScale
  where
  renderSetScale :: V2 CFloat -> m ()
renderSetScale (V2 CFloat
x CFloat
y) =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetScale" Text
"SDL_RenderSetScale" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> CFloat -> CFloat -> m CInt
Raw.renderSetScale Renderer
r CFloat
x CFloat
y

  renderGetScale :: IO (V2 CFloat)
renderGetScale = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CFloat
w ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CFloat
h -> do
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr CFloat -> Ptr CFloat -> m ()
Raw.renderGetScale Renderer
r Ptr CFloat
w Ptr CFloat
h
      forall a. a -> a -> V2 a
V2 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr CFloat
w forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr CFloat
h

-- | Get or set the clip rectangle for rendering on the specified target.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_RenderSetClipRect SDL_RenderSetClipRect>@ and @<https://wiki.libsdl.org/SDL_RenderGetClipRect SDL_RenderGetClipRect>@ for C documentation.
rendererClipRect :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererClipRect :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererClipRect (Renderer Renderer
r) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (Rectangle CInt))
renderGetClipRect forall {m :: Type -> Type} {b}.
(MonadIO m, Storable b) =>
Maybe b -> m ()
renderSetClipRect
  where
  renderGetClipRect :: IO (Maybe (Rectangle CInt))
renderGetClipRect = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Rect
rPtr -> do
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> m ()
Raw.renderGetClipRect Renderer
r Ptr Rect
rPtr
      forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek forall a. Storable a => Ptr a -> IO a
peek (forall a b. Ptr a -> Ptr b
castPtr Ptr Rect
rPtr)
  renderSetClipRect :: Maybe b -> m ()
renderSetClipRect Maybe b
rect =
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetClipRect" Text
"SDL_RenderSetClipRect" forall a b. (a -> b) -> a -> b
$
    forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe b
rect forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> m CInt
Raw.renderSetClipRect Renderer
r forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr

-- | Get or set the drawing area for rendering on the current target.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_RenderSetViewport SDL_RenderSetViewport>@ and @<https://wiki.libsdl.org/SDL_RenderGetViewport SDL_RenderGetViewport>@ for C documentation.
rendererViewport :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererViewport :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererViewport (Renderer Renderer
r) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (Rectangle CInt))
renderGetViewport forall {m :: Type -> Type} {b}.
(MonadIO m, Storable b) =>
Maybe b -> m ()
renderSetViewport
  where
  renderGetViewport :: IO (Maybe (Rectangle CInt))
renderGetViewport = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Rect
rect -> do
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> m ()
Raw.renderGetViewport Renderer
r Ptr Rect
rect
      forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek forall a. Storable a => Ptr a -> IO a
peek (forall a b. Ptr a -> Ptr b
castPtr Ptr Rect
rect)

  renderSetViewport :: Maybe b -> m ()
renderSetViewport Maybe b
rect =
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetViewport" Text
"SDL_RenderSetViewport" forall a b. (a -> b) -> a -> b
$
    forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe b
rect forall a b. (a -> b) -> a -> b
$ forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Rect -> m CInt
Raw.renderSetViewport Renderer
r forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr

-- | Update the screen with any rendering performed since the previous call.
--
-- SDL\'s rendering functions operate on a backbuffer; that is, calling a rendering function such as 'drawLine' does not directly put a line on the screen, but rather updates the backbuffer. As such, you compose your entire scene and present the composed backbuffer to the screen as a complete picture.
--
-- Therefore, when using SDL's rendering API, one does all drawing intended for the frame, and then calls this function once per frame to present the final drawing to the user.
--
-- The backbuffer should be considered invalidated after each present; do not assume that previous contents will exist between frames. You are strongly encouraged to call 'clear' to initialize the backbuffer before starting each new frame's drawing, even if you plan to overwrite every pixel.
--
-- See @<https://wiki.libsdl.org/SDL_RenderPresent SDL_RenderPresent>@ for C documentation.
present :: MonadIO m => Renderer -> m ()
present :: forall (m :: Type -> Type). MonadIO m => Renderer -> m ()
present (Renderer Renderer
r) = forall (m :: Type -> Type). MonadIO m => Renderer -> m ()
Raw.renderPresent Renderer
r

-- | Copy a portion of the texture to the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL_RenderCopy SDL_RenderCopy>@ for C documentation.
copy :: MonadIO m
     => Renderer -- ^ The rendering context
     -> Texture -- ^ The source texture
     -> Maybe (Rectangle CInt) -- ^ The source rectangle to copy, or 'Nothing' for the whole texture
     -> Maybe (Rectangle CInt) -- ^ The destination rectangle to copy to, or 'Nothing' for the whole rendering target. The texture will be stretched to fill the given rectangle.
     -> m ()
copy :: forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Texture
-> Maybe (Rectangle CInt)
-> Maybe (Rectangle CInt)
-> m ()
copy (Renderer Renderer
r) (Texture Renderer
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CInt)
dstRect =
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copy" Text
"SDL_RenderCopy" forall a b. (a -> b) -> a -> b
$
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
dstRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dst ->
  forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Renderer -> Ptr Rect -> Ptr Rect -> m CInt
Raw.renderCopy Renderer
r Renderer
t (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
dst)

-- | Copy a portion of the texture to the current rendering target, optionally rotating it by angle around the given center and also flipping it top-bottom and/or left-right.
--
-- See @<https://wiki.libsdl.org/SDL_RenderCopyEx SDL_RenderCopyEx>@ for C documentation.
copyEx :: MonadIO m
       => Renderer -- ^ The rendering context
       -> Texture -- ^ The source texture
       -> Maybe (Rectangle CInt) -- ^ The source rectangle to copy, or 'Nothing' for the whole texture
       -> Maybe (Rectangle CInt) -- ^ The destination rectangle to copy to, or 'Nothing' for the whole rendering target. The texture will be stretched to fill the given rectangle.
       -> CDouble -- ^ The angle of rotation in degrees. The rotation will be performed clockwise.
       -> Maybe (Point V2 CInt) -- ^ The point indicating the center of the rotation, or 'Nothing' to rotate around the center of the destination rectangle
       -> V2 Bool -- ^ Whether to flip the texture on the X and/or Y axis
       -> m ()
copyEx :: forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Texture
-> Maybe (Rectangle CInt)
-> Maybe (Rectangle CInt)
-> CDouble
-> Maybe (Point V2 CInt)
-> V2 Bool
-> m ()
copyEx (Renderer Renderer
r) (Texture Renderer
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CInt)
dstRect CDouble
theta Maybe (Point V2 CInt)
center V2 Bool
flips =
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copyEx" Text
"SDL_RenderCopyEx" forall a b. (a -> b) -> a -> b
$
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
dstRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dst ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Point V2 CInt)
center forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CInt)
c ->
  forall (m :: Type -> Type).
MonadIO m =>
Renderer
-> Renderer
-> Ptr Rect
-> Ptr Rect
-> CDouble
-> Ptr Point
-> BlendMode
-> m CInt
Raw.renderCopyEx Renderer
r Renderer
t (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
dst) CDouble
theta (forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CInt)
c)
                   (case V2 Bool
flips of
                      V2 Bool
x Bool
y -> (if Bool
x then BlendMode
Raw.SDL_FLIP_HORIZONTAL else BlendMode
0) forall a. Bits a => a -> a -> a
.|.
                               (if Bool
y then BlendMode
Raw.SDL_FLIP_VERTICAL else BlendMode
0))

-- | Draw a line on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL_RenderDrawLine SDL_RenderDrawLine>@ for C documentation.
drawLine :: (Functor m,MonadIO m)
         => Renderer
         -> Point V2 CInt -- ^ The start point of the line
         -> Point V2 CInt -- ^ The end point of the line
         -> m ()
drawLine :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Renderer -> Point V2 CInt -> Point V2 CInt -> m ()
drawLine (Renderer Renderer
r) (P (V2 CInt
x CInt
y)) (P (V2 CInt
x' CInt
y')) =
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLine" Text
"SDL_RenderDrawLine" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type).
MonadIO m =>
Renderer -> CInt -> CInt -> CInt -> CInt -> m CInt
Raw.renderDrawLine Renderer
r CInt
x CInt
y CInt
x' CInt
y'

-- | Draw a series of connected lines on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL_RenderDrawLines SDL_RenderDrawLines>@ for C documentation.
drawLines :: MonadIO m
          => Renderer
          -> SV.Vector (Point V2 CInt) -- ^ A 'SV.Vector' of points along the line. SDL will draw lines between these points.
          -> m ()
drawLines :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Point V2 CInt) -> m ()
drawLines (Renderer Renderer
r) Vector (Point V2 CInt)
points =
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLines" Text
"SDL_RenderDrawLines" forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CInt)
points forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CInt)
cp ->
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Point -> CInt -> m CInt
Raw.renderDrawLines Renderer
r
                        (forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CInt)
cp)
                        (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Point V2 CInt)
points))

-- | Draw a point on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL_RenderDrawPoint SDL_RenderDrawPoint>@ for C documentation.
drawPoint :: (Functor m, MonadIO m) => Renderer -> Point V2 CInt -> m ()
drawPoint :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Renderer -> Point V2 CInt -> m ()
drawPoint (Renderer Renderer
r) (P (V2 CInt
x CInt
y)) =
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPoint" Text
"SDL_RenderDrawPoint" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type).
MonadIO m =>
Renderer -> CInt -> CInt -> m CInt
Raw.renderDrawPoint Renderer
r CInt
x CInt
y

-- | Draw multiple points on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL_RenderDrawPoints SDL_RenderDrawPoints>@ for C documentation.
drawPoints :: MonadIO m => Renderer -> SV.Vector (Point V2 CInt) -> m ()
drawPoints :: forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Vector (Point V2 CInt) -> m ()
drawPoints (Renderer Renderer
r) Vector (Point V2 CInt)
points =
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPoints" Text
"SDL_RenderDrawPoints" forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CInt)
points forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CInt)
cp ->
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Point -> CInt -> m CInt
Raw.renderDrawPoints Renderer
r
                         (forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CInt)
cp)
                         (forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Storable a => Vector a -> Int
SV.length Vector (Point V2 CInt)
points))

-- | Copy an existing surface into a new one that is optimized for blitting to a surface of a specified pixel format.
--
-- This function is used to optimize images for faster repeat blitting. This is accomplished by converting the original and storing the result as a new surface. The new, optimized surface can then be used as the source for future blits, making them faster.
--
-- See @<https://wiki.libsdl.org/SDL_ConvertSurface SDL_ConvertSurface>@ for C documentation.
convertSurface :: (Functor m,MonadIO m)
               => Surface -- ^ The 'Surface' to convert
               -> SurfacePixelFormat -- ^ The pixel format that the new surface is optimized for
               -> m Surface
convertSurface :: forall (m :: Type -> Type).
(Functor m, MonadIO m) =>
Surface -> SurfacePixelFormat -> m Surface
convertSurface (Surface Ptr Surface
s Maybe (IOVector Word8)
_) (SurfacePixelFormat Ptr PixelFormat
fmt) =
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.Renderer.convertSurface" Text
"SDL_ConvertSurface" forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr PixelFormat -> BlendMode -> m (Ptr Surface)
Raw.convertSurface Ptr Surface
s Ptr PixelFormat
fmt BlendMode
0

-- | Perform a scaled surface copy to a destination surface.
--
-- See @<https://wiki.libsdl.org/SDL_BlitScaled SDL_BlitScaled>@ for C documentation.
surfaceBlitScaled :: MonadIO m
                  => Surface -- ^ The 'Surface' to be copied from
                  -> Maybe (Rectangle CInt) -- ^ The rectangle to be copied, or 'Nothing' to copy the entire surface
                  -> Surface -- ^ The 'Surface' that is the blit target
                  -> Maybe (Rectangle CInt) -- ^ The rectangle that is copied into, or 'Nothing' to copy into the entire surface
                  -> m ()
surfaceBlitScaled :: forall (m :: Type -> Type).
MonadIO m =>
Surface
-> Maybe (Rectangle CInt)
-> Surface
-> Maybe (Rectangle CInt)
-> m ()
surfaceBlitScaled (Surface Ptr Surface
src Maybe (IOVector Word8)
_) Maybe (Rectangle CInt)
srcRect (Surface Ptr Surface
dst Maybe (IOVector Word8)
_) Maybe (Rectangle CInt)
dstRect =
  forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.blitSurface" Text
"SDL_BlitSurface" forall a b. (a -> b) -> a -> b
$
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
srcPtr ->
  forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
dstRect forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dstPtr ->
  forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr Rect -> Ptr Surface -> Ptr Rect -> m CInt
Raw.blitScaled Ptr Surface
src (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
srcPtr) Ptr Surface
dst (forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
dstPtr)

-- | Get or set the color key (transparent pixel color) for a surface.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetColorKey SDL_SetColorKey>@ and @<https://wiki.libsdl.org/SDL_GetColorKey SDL_GetColorKey>@ for C documentation.
surfaceColorKey :: Surface -> StateVar (Maybe (V4 Word8))
surfaceColorKey :: Surface -> StateVar (Maybe (V4 Word8))
surfaceColorKey (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (V4 Word8))
getColorKey forall {m :: Type -> Type}. MonadIO m => Maybe (V4 Word8) -> m ()
setColorKey
  where
  getColorKey :: IO (Maybe (V4 Word8))
getColorKey =
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
keyPtr -> do
      CInt
ret <- forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr BlendMode -> m CInt
Raw.getColorKey Ptr Surface
s Ptr BlendMode
keyPtr
      if CInt
ret forall a. Eq a => a -> a -> Bool
== -CInt
1
        then forall (m :: Type -> Type) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
        else do Ptr PixelFormat
format <- forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (Surface -> Ptr PixelFormat
Raw.surfaceFormat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s)
                BlendMode
mapped <- forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
keyPtr
                forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
r ->
                  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
g ->
                  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
b ->
                  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
a ->
                    do forall (m :: Type -> Type).
MonadIO m =>
BlendMode
-> Ptr PixelFormat
-> Ptr Word8
-> Ptr Word8
-> Ptr Word8
-> Ptr Word8
-> m ()
Raw.getRGBA BlendMode
mapped Ptr PixelFormat
format Ptr Word8
r Ptr Word8
g Ptr Word8
b Ptr Word8
a
                       forall a. a -> Maybe a
Just forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. a -> a -> a -> a -> V4 a
V4 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
r forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
g forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
b forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
a)
  setColorKey :: Maybe (V4 Word8) -> m ()
setColorKey Maybe (V4 Word8)
key =
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.setColorKey" Text
"SDL_SetColorKey" forall a b. (a -> b) -> a -> b
$
    case Maybe (V4 Word8)
key of
      Maybe (V4 Word8)
Nothing ->
        forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
keyPtr -> do
          -- TODO Error checking?
          CInt
ret <- forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr BlendMode -> m CInt
Raw.getColorKey Ptr Surface
s Ptr BlendMode
keyPtr
          if CInt
ret forall a. Eq a => a -> a -> Bool
== -CInt
1
            -- if ret == -1 then there is no key enabled, so we have nothing to
            -- do.
            then forall (m :: Type -> Type) a. Monad m => a -> m a
return CInt
0
            else do BlendMode
key' <- forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
keyPtr
                    forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> CInt -> BlendMode -> m CInt
Raw.setColorKey Ptr Surface
s CInt
0 BlendMode
key'

      Just (V4 Word8
r Word8
g Word8
b Word8
a) -> do
        Ptr PixelFormat
format <- forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (Surface -> Ptr PixelFormat
Raw.surfaceFormat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s)
        forall (m :: Type -> Type).
MonadIO m =>
Ptr PixelFormat -> Word8 -> Word8 -> Word8 -> Word8 -> m BlendMode
Raw.mapRGBA Ptr PixelFormat
format Word8
r Word8
g Word8
b Word8
a forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> CInt -> BlendMode -> m CInt
Raw.setColorKey Ptr Surface
s CInt
1

-- | Get or set the additional color value multiplied into render copy operations.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetTextureColorMod SDL_SetTextureColorMod>@ and @<https://wiki.libsdl.org/SDL_GetTextureColorMod SDL_GetTextureColorMod>@ for C documentation.
textureColorMod :: Texture -> StateVar (V3 Word8)
textureColorMod :: Texture -> StateVar (V3 Word8)
textureColorMod (Texture Renderer
t) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (V3 Word8)
getTextureColorMod forall {m :: Type -> Type}. MonadIO m => V3 Word8 -> m ()
setTextureColorMod
  where
  getTextureColorMod :: IO (V3 Word8)
getTextureColorMod = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
r ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
g ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
b -> do
      forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.getTextureColorMod" Text
"SDL_GetTextureColorMod" forall a b. (a -> b) -> a -> b
$
        forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> m CInt
Raw.getTextureColorMod Renderer
t Ptr Word8
r Ptr Word8
g Ptr Word8
b
      forall a. a -> a -> a -> V3 a
V3 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
r forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
g forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
b

  setTextureColorMod :: V3 Word8 -> m ()
setTextureColorMod (V3 Word8
r Word8
g Word8
b) =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.setTextureColorMod" Text
"SDL_SetTextureColorMod" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Word8 -> Word8 -> Word8 -> m CInt
Raw.setTextureColorMod Renderer
t Word8
r Word8
g Word8
b

data PixelFormat
  = Unknown !Word32
  | Index1LSB
  | Index1MSB
  | Index4LSB
  | Index4MSB
  | Index8
  | RGB332
  | RGB444
  | RGB555
  | BGR555
  | ARGB4444
  | RGBA4444
  | ABGR4444
  | BGRA4444
  | ARGB1555
  | RGBA5551
  | ABGR1555
  | BGRA5551
  | RGB565
  | BGR565
  | RGB24
  | BGR24
  | RGB888
  | RGBX8888
  | BGR888
  | BGRX8888
  | ARGB8888
  | RGBA8888
  | ABGR8888
  | BGRA8888
  | ARGB2101010
  | YV12
  | IYUV
  | YUY2
  | UYVY
  | YVYU
  deriving (Typeable PixelFormat
PixelFormat -> DataType
PixelFormat -> Constr
(forall b. Data b => b -> b) -> PixelFormat -> PixelFormat
forall a.
Typeable a
-> (forall (c :: Type -> Type).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PixelFormat -> u
forall u. (forall d. Data d => d -> u) -> PixelFormat -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PixelFormat
forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PixelFormat -> c PixelFormat
forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PixelFormat)
forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PixelFormat)
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
gmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
$cgmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
gmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
$cgmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PixelFormat -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PixelFormat -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> PixelFormat -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PixelFormat -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
gmapT :: (forall b. Data b => b -> b) -> PixelFormat -> PixelFormat
$cgmapT :: (forall b. Data b => b -> b) -> PixelFormat -> PixelFormat
dataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PixelFormat)
$cdataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PixelFormat)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PixelFormat)
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PixelFormat)
dataTypeOf :: PixelFormat -> DataType
$cdataTypeOf :: PixelFormat -> DataType
toConstr :: PixelFormat -> Constr
$ctoConstr :: PixelFormat -> Constr
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PixelFormat
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PixelFormat
gfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PixelFormat -> c PixelFormat
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PixelFormat -> c PixelFormat
Data, PixelFormat -> PixelFormat -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PixelFormat -> PixelFormat -> Bool
$c/= :: PixelFormat -> PixelFormat -> Bool
== :: PixelFormat -> PixelFormat -> Bool
$c== :: PixelFormat -> PixelFormat -> Bool
Eq, forall x. Rep PixelFormat x -> PixelFormat
forall x. PixelFormat -> Rep PixelFormat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PixelFormat x -> PixelFormat
$cfrom :: forall x. PixelFormat -> Rep PixelFormat x
Generic, Eq PixelFormat
PixelFormat -> PixelFormat -> Bool
PixelFormat -> PixelFormat -> Ordering
PixelFormat -> PixelFormat -> PixelFormat
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PixelFormat -> PixelFormat -> PixelFormat
$cmin :: PixelFormat -> PixelFormat -> PixelFormat
max :: PixelFormat -> PixelFormat -> PixelFormat
$cmax :: PixelFormat -> PixelFormat -> PixelFormat
>= :: PixelFormat -> PixelFormat -> Bool
$c>= :: PixelFormat -> PixelFormat -> Bool
> :: PixelFormat -> PixelFormat -> Bool
$c> :: PixelFormat -> PixelFormat -> Bool
<= :: PixelFormat -> PixelFormat -> Bool
$c<= :: PixelFormat -> PixelFormat -> Bool
< :: PixelFormat -> PixelFormat -> Bool
$c< :: PixelFormat -> PixelFormat -> Bool
compare :: PixelFormat -> PixelFormat -> Ordering
$ccompare :: PixelFormat -> PixelFormat -> Ordering
Ord, ReadPrec [PixelFormat]
ReadPrec PixelFormat
Int -> ReadS PixelFormat
ReadS [PixelFormat]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PixelFormat]
$creadListPrec :: ReadPrec [PixelFormat]
readPrec :: ReadPrec PixelFormat
$creadPrec :: ReadPrec PixelFormat
readList :: ReadS [PixelFormat]
$creadList :: ReadS [PixelFormat]
readsPrec :: Int -> ReadS PixelFormat
$creadsPrec :: Int -> ReadS PixelFormat
Read, Int -> PixelFormat -> ShowS
[PixelFormat] -> ShowS
PixelFormat -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [PixelFormat] -> ShowS
$cshowList :: [PixelFormat] -> ShowS
show :: PixelFormat -> [Char]
$cshow :: PixelFormat -> [Char]
showsPrec :: Int -> PixelFormat -> ShowS
$cshowsPrec :: Int -> PixelFormat -> ShowS
Show, Typeable)

instance FromNumber PixelFormat Word32 where
  fromNumber :: BlendMode -> PixelFormat
fromNumber BlendMode
n' = case BlendMode
n' of
    BlendMode
Raw.SDL_PIXELFORMAT_INDEX1LSB -> PixelFormat
Index1LSB
    BlendMode
Raw.SDL_PIXELFORMAT_INDEX1MSB -> PixelFormat
Index1MSB
    BlendMode
Raw.SDL_PIXELFORMAT_INDEX4LSB -> PixelFormat
Index4LSB
    BlendMode
Raw.SDL_PIXELFORMAT_INDEX4MSB -> PixelFormat
Index4MSB
    BlendMode
Raw.SDL_PIXELFORMAT_INDEX8 -> PixelFormat
Index8
    BlendMode
Raw.SDL_PIXELFORMAT_RGB332 -> PixelFormat
RGB332
    BlendMode
Raw.SDL_PIXELFORMAT_RGB444 -> PixelFormat
RGB444
    BlendMode
Raw.SDL_PIXELFORMAT_RGB555 -> PixelFormat
RGB555
    BlendMode
Raw.SDL_PIXELFORMAT_BGR555 -> PixelFormat
BGR555
    BlendMode
Raw.SDL_PIXELFORMAT_ARGB4444 -> PixelFormat
ARGB4444
    BlendMode
Raw.SDL_PIXELFORMAT_RGBA4444 -> PixelFormat
RGBA4444
    BlendMode
Raw.SDL_PIXELFORMAT_ABGR4444 -> PixelFormat
ABGR4444
    BlendMode
Raw.SDL_PIXELFORMAT_BGRA4444 -> PixelFormat
BGRA4444
    BlendMode
Raw.SDL_PIXELFORMAT_ARGB1555 -> PixelFormat
ARGB1555
    BlendMode
Raw.SDL_PIXELFORMAT_RGBA5551 -> PixelFormat
RGBA5551
    BlendMode
Raw.SDL_PIXELFORMAT_ABGR1555 -> PixelFormat
ABGR1555
    BlendMode
Raw.SDL_PIXELFORMAT_BGRA5551 -> PixelFormat
BGRA5551
    BlendMode
Raw.SDL_PIXELFORMAT_RGB565 -> PixelFormat
RGB565
    BlendMode
Raw.SDL_PIXELFORMAT_BGR565 -> PixelFormat
BGR565
    BlendMode
Raw.SDL_PIXELFORMAT_RGB24 -> PixelFormat
RGB24
    BlendMode
Raw.SDL_PIXELFORMAT_BGR24 -> PixelFormat
BGR24
    BlendMode
Raw.SDL_PIXELFORMAT_RGB888 -> PixelFormat
RGB888
    BlendMode
Raw.SDL_PIXELFORMAT_RGBX8888 -> PixelFormat
RGBX8888
    BlendMode
Raw.SDL_PIXELFORMAT_BGR888 -> PixelFormat
BGR888
    BlendMode
Raw.SDL_PIXELFORMAT_BGRX8888 -> PixelFormat
BGRX8888
    BlendMode
Raw.SDL_PIXELFORMAT_ARGB8888 -> PixelFormat
ARGB8888
    BlendMode
Raw.SDL_PIXELFORMAT_RGBA8888 -> PixelFormat
RGBA8888
    BlendMode
Raw.SDL_PIXELFORMAT_ABGR8888 -> PixelFormat
ABGR8888
    BlendMode
Raw.SDL_PIXELFORMAT_BGRA8888 -> PixelFormat
BGRA8888
    BlendMode
Raw.SDL_PIXELFORMAT_ARGB2101010 -> PixelFormat
ARGB2101010
    BlendMode
Raw.SDL_PIXELFORMAT_YV12 -> PixelFormat
YV12
    BlendMode
Raw.SDL_PIXELFORMAT_IYUV -> PixelFormat
IYUV
    BlendMode
Raw.SDL_PIXELFORMAT_YUY2 -> PixelFormat
YUY2
    BlendMode
Raw.SDL_PIXELFORMAT_UYVY -> PixelFormat
UYVY
    BlendMode
Raw.SDL_PIXELFORMAT_YVYU -> PixelFormat
YVYU
    BlendMode
Raw.SDL_PIXELFORMAT_UNKNOWN -> BlendMode -> PixelFormat
Unknown BlendMode
n'
    BlendMode
_ -> BlendMode -> PixelFormat
Unknown BlendMode
n'

instance ToNumber PixelFormat Word32 where
  toNumber :: PixelFormat -> BlendMode
toNumber PixelFormat
pf = case PixelFormat
pf of
    Unknown BlendMode
_ -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_UNKNOWN
    PixelFormat
Index1LSB -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX1LSB
    PixelFormat
Index1MSB -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX1MSB
    PixelFormat
Index4LSB -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX4LSB
    PixelFormat
Index4MSB -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX4MSB
    PixelFormat
Index8 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX8
    PixelFormat
RGB332 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB332
    PixelFormat
RGB444 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB444
    PixelFormat
RGB555 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB555
    PixelFormat
BGR555 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR555
    PixelFormat
ARGB4444 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB4444
    PixelFormat
RGBA4444 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBA4444
    PixelFormat
ABGR4444 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ABGR4444
    PixelFormat
BGRA4444 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRA4444
    PixelFormat
ARGB1555 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB1555
    PixelFormat
RGBA5551 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBA5551
    PixelFormat
ABGR1555 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ABGR1555
    PixelFormat
BGRA5551 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRA5551
    PixelFormat
RGB565 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB565
    PixelFormat
BGR565 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR565
    PixelFormat
RGB24 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB24
    PixelFormat
BGR24 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR24
    PixelFormat
RGB888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB888
    PixelFormat
RGBX8888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBX8888
    PixelFormat
BGR888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR888
    PixelFormat
BGRX8888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRX8888
    PixelFormat
ARGB8888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB8888
    PixelFormat
RGBA8888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBA8888
    PixelFormat
ABGR8888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ABGR8888
    PixelFormat
BGRA8888 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRA8888
    PixelFormat
ARGB2101010 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB2101010
    PixelFormat
YV12 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_YV12
    PixelFormat
IYUV -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_IYUV
    PixelFormat
YUY2 -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_YUY2
    PixelFormat
UYVY -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_UYVY
    PixelFormat
YVYU -> forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_YVYU

-- | Renderer acceleration mode
data RendererType
  = UnacceleratedRenderer
    -- ^ The renderer does not use hardware acceleration
  | AcceleratedRenderer
    -- ^ The renderer uses hardware acceleration and refresh rate is ignored
  | AcceleratedVSyncRenderer
    -- ^ The renderer uses hardware acceleration and present is synchronized with the refresh rate
  | SoftwareRenderer
    -- ^ The renderer is a software fallback
  deriving (RendererType
forall a. a -> a -> Bounded a
maxBound :: RendererType
$cmaxBound :: RendererType
minBound :: RendererType
$cminBound :: RendererType
Bounded, Typeable RendererType
RendererType -> DataType
RendererType -> Constr
(forall b. Data b => b -> b) -> RendererType -> RendererType
forall a.
Typeable a
-> (forall (c :: Type -> Type).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> RendererType -> u
forall u. (forall d. Data d => d -> u) -> RendererType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererType
forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererType -> c RendererType
forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererType)
forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c RendererType)
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
gmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
$cgmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
gmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
$cgmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RendererType -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RendererType -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> RendererType -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> RendererType -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
gmapT :: (forall b. Data b => b -> b) -> RendererType -> RendererType
$cgmapT :: (forall b. Data b => b -> b) -> RendererType -> RendererType
dataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c RendererType)
$cdataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c RendererType)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererType)
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererType)
dataTypeOf :: RendererType -> DataType
$cdataTypeOf :: RendererType -> DataType
toConstr :: RendererType -> Constr
$ctoConstr :: RendererType -> Constr
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererType
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererType
gfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererType -> c RendererType
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererType -> c RendererType
Data, Int -> RendererType
RendererType -> Int
RendererType -> [RendererType]
RendererType -> RendererType
RendererType -> RendererType -> [RendererType]
RendererType -> RendererType -> RendererType -> [RendererType]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: RendererType -> RendererType -> RendererType -> [RendererType]
$cenumFromThenTo :: RendererType -> RendererType -> RendererType -> [RendererType]
enumFromTo :: RendererType -> RendererType -> [RendererType]
$cenumFromTo :: RendererType -> RendererType -> [RendererType]
enumFromThen :: RendererType -> RendererType -> [RendererType]
$cenumFromThen :: RendererType -> RendererType -> [RendererType]
enumFrom :: RendererType -> [RendererType]
$cenumFrom :: RendererType -> [RendererType]
fromEnum :: RendererType -> Int
$cfromEnum :: RendererType -> Int
toEnum :: Int -> RendererType
$ctoEnum :: Int -> RendererType
pred :: RendererType -> RendererType
$cpred :: RendererType -> RendererType
succ :: RendererType -> RendererType
$csucc :: RendererType -> RendererType
Enum, RendererType -> RendererType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RendererType -> RendererType -> Bool
$c/= :: RendererType -> RendererType -> Bool
== :: RendererType -> RendererType -> Bool
$c== :: RendererType -> RendererType -> Bool
Eq, forall x. Rep RendererType x -> RendererType
forall x. RendererType -> Rep RendererType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RendererType x -> RendererType
$cfrom :: forall x. RendererType -> Rep RendererType x
Generic, Eq RendererType
RendererType -> RendererType -> Bool
RendererType -> RendererType -> Ordering
RendererType -> RendererType -> RendererType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RendererType -> RendererType -> RendererType
$cmin :: RendererType -> RendererType -> RendererType
max :: RendererType -> RendererType -> RendererType
$cmax :: RendererType -> RendererType -> RendererType
>= :: RendererType -> RendererType -> Bool
$c>= :: RendererType -> RendererType -> Bool
> :: RendererType -> RendererType -> Bool
$c> :: RendererType -> RendererType -> Bool
<= :: RendererType -> RendererType -> Bool
$c<= :: RendererType -> RendererType -> Bool
< :: RendererType -> RendererType -> Bool
$c< :: RendererType -> RendererType -> Bool
compare :: RendererType -> RendererType -> Ordering
$ccompare :: RendererType -> RendererType -> Ordering
Ord, ReadPrec [RendererType]
ReadPrec RendererType
Int -> ReadS RendererType
ReadS [RendererType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RendererType]
$creadListPrec :: ReadPrec [RendererType]
readPrec :: ReadPrec RendererType
$creadPrec :: ReadPrec RendererType
readList :: ReadS [RendererType]
$creadList :: ReadS [RendererType]
readsPrec :: Int -> ReadS RendererType
$creadsPrec :: Int -> ReadS RendererType
Read, Int -> RendererType -> ShowS
[RendererType] -> ShowS
RendererType -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [RendererType] -> ShowS
$cshowList :: [RendererType] -> ShowS
show :: RendererType -> [Char]
$cshow :: RendererType -> [Char]
showsPrec :: Int -> RendererType -> ShowS
$cshowsPrec :: Int -> RendererType -> ShowS
Show, Typeable)

-- | The configuration data used when creating windows.
data RendererConfig = RendererConfig
  { RendererConfig -> RendererType
rendererType  :: RendererType
    -- ^ The renderer's acceleration mode
  , RendererConfig -> Bool
rendererTargetTexture :: Bool
    -- ^ The renderer supports rendering to texture
  } deriving (Typeable RendererConfig
RendererConfig -> DataType
RendererConfig -> Constr
(forall b. Data b => b -> b) -> RendererConfig -> RendererConfig
forall a.
Typeable a
-> (forall (c :: Type -> Type).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> RendererConfig -> u
forall u. (forall d. Data d => d -> u) -> RendererConfig -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererConfig
forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererConfig -> c RendererConfig
forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererConfig)
forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c RendererConfig)
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
gmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
$cgmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
gmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
$cgmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> RendererConfig -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> RendererConfig -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> RendererConfig -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> RendererConfig -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
gmapT :: (forall b. Data b => b -> b) -> RendererConfig -> RendererConfig
$cgmapT :: (forall b. Data b => b -> b) -> RendererConfig -> RendererConfig
dataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c RendererConfig)
$cdataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c RendererConfig)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererConfig)
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererConfig)
dataTypeOf :: RendererConfig -> DataType
$cdataTypeOf :: RendererConfig -> DataType
toConstr :: RendererConfig -> Constr
$ctoConstr :: RendererConfig -> Constr
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererConfig
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererConfig
gfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererConfig -> c RendererConfig
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererConfig -> c RendererConfig
Data, RendererConfig -> RendererConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RendererConfig -> RendererConfig -> Bool
$c/= :: RendererConfig -> RendererConfig -> Bool
== :: RendererConfig -> RendererConfig -> Bool
$c== :: RendererConfig -> RendererConfig -> Bool
Eq, forall x. Rep RendererConfig x -> RendererConfig
forall x. RendererConfig -> Rep RendererConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RendererConfig x -> RendererConfig
$cfrom :: forall x. RendererConfig -> Rep RendererConfig x
Generic, Eq RendererConfig
RendererConfig -> RendererConfig -> Bool
RendererConfig -> RendererConfig -> Ordering
RendererConfig -> RendererConfig -> RendererConfig
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RendererConfig -> RendererConfig -> RendererConfig
$cmin :: RendererConfig -> RendererConfig -> RendererConfig
max :: RendererConfig -> RendererConfig -> RendererConfig
$cmax :: RendererConfig -> RendererConfig -> RendererConfig
>= :: RendererConfig -> RendererConfig -> Bool
$c>= :: RendererConfig -> RendererConfig -> Bool
> :: RendererConfig -> RendererConfig -> Bool
$c> :: RendererConfig -> RendererConfig -> Bool
<= :: RendererConfig -> RendererConfig -> Bool
$c<= :: RendererConfig -> RendererConfig -> Bool
< :: RendererConfig -> RendererConfig -> Bool
$c< :: RendererConfig -> RendererConfig -> Bool
compare :: RendererConfig -> RendererConfig -> Ordering
$ccompare :: RendererConfig -> RendererConfig -> Ordering
Ord, ReadPrec [RendererConfig]
ReadPrec RendererConfig
Int -> ReadS RendererConfig
ReadS [RendererConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RendererConfig]
$creadListPrec :: ReadPrec [RendererConfig]
readPrec :: ReadPrec RendererConfig
$creadPrec :: ReadPrec RendererConfig
readList :: ReadS [RendererConfig]
$creadList :: ReadS [RendererConfig]
readsPrec :: Int -> ReadS RendererConfig
$creadsPrec :: Int -> ReadS RendererConfig
Read, Int -> RendererConfig -> ShowS
[RendererConfig] -> ShowS
RendererConfig -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [RendererConfig] -> ShowS
$cshowList :: [RendererConfig] -> ShowS
show :: RendererConfig -> [Char]
$cshow :: RendererConfig -> [Char]
showsPrec :: Int -> RendererConfig -> ShowS
$cshowsPrec :: Int -> RendererConfig -> ShowS
Show, Typeable)

instance FromNumber RendererConfig Word32 where
  fromNumber :: BlendMode -> RendererConfig
fromNumber BlendMode
n = RendererConfig
    { rendererType :: RendererType
rendererType          = Bool -> Bool -> Bool -> RendererType
rendererType'
                                (BlendMode
n forall a. Bits a => a -> a -> a
.&. forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_SOFTWARE forall a. Eq a => a -> a -> Bool
/= BlendMode
0)
                                (BlendMode
n forall a. Bits a => a -> a -> a
.&. forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_ACCELERATED forall a. Eq a => a -> a -> Bool
/= BlendMode
0)
                                (BlendMode
n forall a. Bits a => a -> a -> a
.&. forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_PRESENTVSYNC forall a. Eq a => a -> a -> Bool
/= BlendMode
0)
    , rendererTargetTexture :: Bool
rendererTargetTexture = BlendMode
n forall a. Bits a => a -> a -> a
.&. forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_TARGETTEXTURE forall a. Eq a => a -> a -> Bool
/= BlendMode
0
    }
    where
      rendererType' :: Bool -> Bool -> Bool -> RendererType
rendererType' Bool
s Bool
a Bool
v | Bool
s         = RendererType
SoftwareRenderer
                          | Bool
a Bool -> Bool -> Bool
&& Bool
v    = RendererType
AcceleratedVSyncRenderer
                          | Bool
a         = RendererType
AcceleratedRenderer
                          | Bool
otherwise = RendererType
UnacceleratedRenderer

instance ToNumber RendererConfig Word32 where
  toNumber :: RendererConfig -> BlendMode
toNumber RendererConfig
config = forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a. Bits a => a -> a -> a
(.|.) BlendMode
0
    [ if Bool
isSoftware then forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_SOFTWARE else BlendMode
0
    , if Bool -> Bool
not Bool
isSoftware then forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_ACCELERATED else BlendMode
0
    , if RendererConfig -> RendererType
rendererType RendererConfig
config forall a. Eq a => a -> a -> Bool
== RendererType
AcceleratedVSyncRenderer then forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_PRESENTVSYNC  else BlendMode
0
    , if RendererConfig -> Bool
rendererTargetTexture RendererConfig
config then forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_TARGETTEXTURE else BlendMode
0
    ]
    where
      isSoftware :: Bool
isSoftware = RendererConfig -> RendererType
rendererType RendererConfig
config forall a. Eq a => a -> a -> Bool
== RendererType
SoftwareRenderer

-- | Default options for 'RendererConfig'.
--
-- @
-- 'defaultRenderer' = 'RendererConfig'
--   { 'rendererType'          = 'AcceleratedRenderer'
--   , 'rendererTargetTexture' = False
--   }
-- @
defaultRenderer :: RendererConfig
defaultRenderer :: RendererConfig
defaultRenderer = RendererConfig
  { rendererType :: RendererType
rendererType          = RendererType
AcceleratedRenderer
  , rendererTargetTexture :: Bool
rendererTargetTexture = Bool
False
  }

-- | Information about an instantiated 'Renderer'.
data RendererInfo = RendererInfo
  { RendererInfo -> Text
rendererInfoName              :: Text
    -- ^ The name of the renderer
  , RendererInfo -> RendererConfig
rendererInfoFlags             :: RendererConfig
    -- ^ Supported renderer features
  , RendererInfo -> BlendMode
rendererInfoNumTextureFormats :: Word32
    -- ^ The number of available texture formats
  , RendererInfo -> [PixelFormat]
rendererInfoTextureFormats    :: [PixelFormat]
    -- ^ The available texture formats
  , RendererInfo -> CInt
rendererInfoMaxTextureWidth   :: CInt
    -- ^ The maximum texture width
  , RendererInfo -> CInt
rendererInfoMaxTextureHeight  :: CInt
    -- ^ The maximum texture height
  } deriving (RendererInfo -> RendererInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RendererInfo -> RendererInfo -> Bool
$c/= :: RendererInfo -> RendererInfo -> Bool
== :: RendererInfo -> RendererInfo -> Bool
$c== :: RendererInfo -> RendererInfo -> Bool
Eq, forall x. Rep RendererInfo x -> RendererInfo
forall x. RendererInfo -> Rep RendererInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RendererInfo x -> RendererInfo
$cfrom :: forall x. RendererInfo -> Rep RendererInfo x
Generic, Eq RendererInfo
RendererInfo -> RendererInfo -> Bool
RendererInfo -> RendererInfo -> Ordering
RendererInfo -> RendererInfo -> RendererInfo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RendererInfo -> RendererInfo -> RendererInfo
$cmin :: RendererInfo -> RendererInfo -> RendererInfo
max :: RendererInfo -> RendererInfo -> RendererInfo
$cmax :: RendererInfo -> RendererInfo -> RendererInfo
>= :: RendererInfo -> RendererInfo -> Bool
$c>= :: RendererInfo -> RendererInfo -> Bool
> :: RendererInfo -> RendererInfo -> Bool
$c> :: RendererInfo -> RendererInfo -> Bool
<= :: RendererInfo -> RendererInfo -> Bool
$c<= :: RendererInfo -> RendererInfo -> Bool
< :: RendererInfo -> RendererInfo -> Bool
$c< :: RendererInfo -> RendererInfo -> Bool
compare :: RendererInfo -> RendererInfo -> Ordering
$ccompare :: RendererInfo -> RendererInfo -> Ordering
Ord, ReadPrec [RendererInfo]
ReadPrec RendererInfo
Int -> ReadS RendererInfo
ReadS [RendererInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RendererInfo]
$creadListPrec :: ReadPrec [RendererInfo]
readPrec :: ReadPrec RendererInfo
$creadPrec :: ReadPrec RendererInfo
readList :: ReadS [RendererInfo]
$creadList :: ReadS [RendererInfo]
readsPrec :: Int -> ReadS RendererInfo
$creadsPrec :: Int -> ReadS RendererInfo
Read, Int -> RendererInfo -> ShowS
[RendererInfo] -> ShowS
RendererInfo -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [RendererInfo] -> ShowS
$cshowList :: [RendererInfo] -> ShowS
show :: RendererInfo -> [Char]
$cshow :: RendererInfo -> [Char]
showsPrec :: Int -> RendererInfo -> ShowS
$cshowsPrec :: Int -> RendererInfo -> ShowS
Show, Typeable)

fromRawRendererInfo :: MonadIO m => Raw.RendererInfo -> m RendererInfo
fromRawRendererInfo :: forall (m :: Type -> Type).
MonadIO m =>
RendererInfo -> m RendererInfo
fromRawRendererInfo (Raw.RendererInfo CString
name BlendMode
flgs BlendMode
ntf [BlendMode]
tfs CInt
mtw CInt
mth) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
    Text
name' <- ByteString -> Text
Text.decodeUtf8 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> CString -> IO ByteString
BS.packCString CString
name
    forall (m :: Type -> Type) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
-> RendererConfig
-> BlendMode
-> [PixelFormat]
-> CInt
-> CInt
-> RendererInfo
RendererInfo Text
name' (forall a b. FromNumber a b => b -> a
fromNumber BlendMode
flgs) BlendMode
ntf (forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. FromNumber a b => b -> a
fromNumber [BlendMode]
tfs) CInt
mtw CInt
mth

-- | Get information about a rendering context.
--
-- See @<https://wiki.libsdl.org/SDL_GetRendererInfo SDL_GetRendererInfo>@ for C documentation.
getRendererInfo :: MonadIO m => Renderer -> m RendererInfo
getRendererInfo :: forall (m :: Type -> Type). MonadIO m => Renderer -> m RendererInfo
getRendererInfo (Renderer Renderer
renderer) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr RendererInfo
rptr -> do
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"getRendererInfo" Text
"SDL_GetRendererInfo" forall a b. (a -> b) -> a -> b
$
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr RendererInfo -> m CInt
Raw.getRendererInfo Renderer
renderer Ptr RendererInfo
rptr
    forall a. Storable a => Ptr a -> IO a
peek Ptr RendererInfo
rptr forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: Type -> Type).
MonadIO m =>
RendererInfo -> m RendererInfo
fromRawRendererInfo

-- | Enumerate all known render drivers on the system, and determine their supported features.
--
-- See @<https://wiki.libsdl.org/SDL_GetRenderDriverInfo SDL_GetRenderDriverInfo>@ for C documentation.
getRenderDriverInfo :: MonadIO m => m [RendererInfo]
getRenderDriverInfo :: forall (m :: Type -> Type). MonadIO m => m [RendererInfo]
getRenderDriverInfo = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
  CInt
count <- forall (m :: Type -> Type). MonadIO m => m CInt
Raw.getNumRenderDrivers
  forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse CInt -> IO RendererInfo
go [CInt
0..CInt
countforall a. Num a => a -> a -> a
-CInt
1]
  where
    go :: CInt -> IO RendererInfo
go CInt
idx = forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr RendererInfo
rptr -> do
               forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"getRenderDriverInfo" Text
"SDL_GetRenderDriverInfo" forall a b. (a -> b) -> a -> b
$
                 forall (m :: Type -> Type).
MonadIO m =>
CInt -> Ptr RendererInfo -> m CInt
Raw.getRenderDriverInfo CInt
idx Ptr RendererInfo
rptr
               forall a. Storable a => Ptr a -> IO a
peek Ptr RendererInfo
rptr forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: Type -> Type).
MonadIO m =>
RendererInfo -> m RendererInfo
fromRawRendererInfo

-- | Get or set the additional alpha value multiplied into render copy operations.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetTextureAlphaMod SDL_SetTextureAlphaMod>@ and @<https://wiki.libsdl.org/SDL_GetTextureAlphaMod SDL_GetTextureAlphaMod>@ for C documentation.
textureAlphaMod :: Texture -> StateVar Word8
textureAlphaMod :: Texture -> StateVar Word8
textureAlphaMod (Texture Renderer
t) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO Word8
getTextureAlphaMod forall {m :: Type -> Type}. MonadIO m => Word8 -> m ()
setTextureAlphaMod
  where
  getTextureAlphaMod :: IO Word8
getTextureAlphaMod = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr Word8
x -> do
      forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.getTextureAlphaMod" Text
"SDL_GetTextureAlphaMod" forall a b. (a -> b) -> a -> b
$
        forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr Word8 -> m CInt
Raw.getTextureAlphaMod Renderer
t Ptr Word8
x
      forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
x

  setTextureAlphaMod :: Word8 -> m ()
setTextureAlphaMod Word8
alpha =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.setTextureAlphaMod" Text
"SDL_SetTextureAlphaMod" forall a b. (a -> b) -> a -> b
$
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Word8 -> m CInt
Raw.setTextureAlphaMod Renderer
t Word8
alpha

-- | Get or set the blend mode used for texture copy operations.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetTextureBlendMode SDL_SetTextureBlendMode>@ and @<https://wiki.libsdl.org/SDL_GetTextureBlendMode SDL_GetTextureBlendMode>@ for C documentation.
textureBlendMode :: Texture -> StateVar BlendMode
textureBlendMode :: Texture -> StateVar BlendMode
textureBlendMode (Texture Renderer
t) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO BlendMode
getTextureBlendMode forall {m :: Type -> Type} {a}.
(MonadIO m, ToNumber a BlendMode) =>
a -> m ()
setTextureBlendMode
  where
  getTextureBlendMode :: IO BlendMode
getTextureBlendMode = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
x -> do
      forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.getTextureBlendMode" Text
"SDL_GetTextureBlendMode" forall a b. (a -> b) -> a -> b
$
        forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr BlendMode -> m CInt
Raw.getTextureBlendMode Renderer
t Ptr BlendMode
x
      forall a b. FromNumber a b => b -> a
fromNumber forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
x

  setTextureBlendMode :: a -> m ()
setTextureBlendMode a
bm =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.setTextureBlendMode" Text
"SDL_SetTextureBlendMode" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Renderer -> BlendMode -> m CInt
Raw.setTextureBlendMode Renderer
t (forall a b. ToNumber a b => a -> b
toNumber a
bm)

-- | Get or set the blend mode used for blit operations.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetSurfaceBlendMode SDL_SetSurfaceBlendMode>@ and @<https://wiki.libsdl.org/SDL_GetSurfaceBlendMode SDL_GetSurfaceBlendMode>@ for C documentation.
surfaceBlendMode :: Surface -> StateVar BlendMode
surfaceBlendMode :: Surface -> StateVar BlendMode
surfaceBlendMode (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO BlendMode
getSurfaceBlendMode forall {m :: Type -> Type} {a}.
(MonadIO m, ToNumber a BlendMode) =>
a -> m ()
setSurfaceBlendMode
  where
  getSurfaceBlendMode :: IO BlendMode
getSurfaceBlendMode = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
x -> do
      forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.getSurfaceBlendMode" Text
"SDL_GetSurfaceBlendMode" forall a b. (a -> b) -> a -> b
$
        forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr BlendMode -> m CInt
Raw.getSurfaceBlendMode Ptr Surface
s Ptr BlendMode
x
      forall a b. FromNumber a b => b -> a
fromNumber forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
x

  setSurfaceBlendMode :: a -> m ()
setSurfaceBlendMode a
bm =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.setSurfaceBlendMode" Text
"SDL_SetSurfaceBlendMode" forall a b. (a -> b) -> a -> b
$
    forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> BlendMode -> m CInt
Raw.setSurfaceBlendMode Ptr Surface
s (forall a b. ToNumber a b => a -> b
toNumber a
bm)

-- | Get or set the current render target. 'Nothing' corresponds to the default render target.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_SetRenderTarget SDL_SetRenderTarget>@ and @<https://wiki.libsdl.org/SDL_GetRenderTarget SDL_GetRenderTarget>@ for C documentation.
rendererRenderTarget :: Renderer -> StateVar (Maybe Texture)
rendererRenderTarget :: Renderer -> StateVar (Maybe Texture)
rendererRenderTarget (Renderer Renderer
r) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe Texture)
getRenderTarget forall {m :: Type -> Type}. MonadIO m => Maybe Texture -> m ()
setRenderTarget
  where
  getRenderTarget :: IO (Maybe Texture)
getRenderTarget = do
    Renderer
t <- forall (m :: Type -> Type). MonadIO m => Renderer -> m Renderer
Raw.getRenderTarget Renderer
r
    forall (m :: Type -> Type) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
      if Renderer
t forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr
        then forall a. Maybe a
Nothing
        else forall a. a -> Maybe a
Just (Renderer -> Texture
Texture Renderer
t)

  setRenderTarget :: Maybe Texture -> m ()
setRenderTarget Maybe Texture
texture =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.Renderer.setRenderTarget" Text
"SDL_SetRenderTarget" forall a b. (a -> b) -> a -> b
$
    case Maybe Texture
texture of
      Maybe Texture
Nothing -> forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Renderer -> m CInt
Raw.setRenderTarget Renderer
r forall a. Ptr a
nullPtr
      Just (Texture Renderer
t) -> forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Renderer -> m CInt
Raw.setRenderTarget Renderer
r Renderer
t

-- | Get or set the device independent resolution for rendering.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL_RenderSetLogicalSize SDL_RenderSetLogicalSize>@ and @<https://wiki.libsdl.org/SDL_RenderGetLogicalSize SDL_RenderGetLogicalSize>@ for C documentation.
rendererLogicalSize :: Renderer -> StateVar (Maybe (V2 CInt))
rendererLogicalSize :: Renderer -> StateVar (Maybe (V2 CInt))
rendererLogicalSize (Renderer Renderer
r) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (V2 CInt))
renderGetLogicalSize forall {m :: Type -> Type}. MonadIO m => Maybe (V2 CInt) -> m ()
renderSetLogicalSize
  where
  renderGetLogicalSize :: IO (Maybe (V2 CInt))
renderGetLogicalSize = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
w -> do
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
h -> do
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> Ptr CInt -> Ptr CInt -> m ()
Raw.renderGetLogicalSize Renderer
r Ptr CInt
w Ptr CInt
h
      V2 CInt
v <- forall a. a -> a -> V2 a
V2 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
w forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
h
      forall (m :: Type -> Type) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if V2 CInt
v forall a. Eq a => a -> a -> Bool
== V2 CInt
0 then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just V2 CInt
v

  renderSetLogicalSize :: Maybe (V2 CInt) -> m ()
renderSetLogicalSize Maybe (V2 CInt)
v =
    forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetLogicalSize" Text
"SDL_RenderSetLogicalSize" forall a b. (a -> b) -> a -> b
$ do
      let (CInt
x,CInt
y) = case Maybe (V2 CInt)
v of Just (V2 CInt
vx CInt
vy) -> (CInt
vx, CInt
vy)
                            Maybe (V2 CInt)
Nothing -> (CInt
0,CInt
0)
      forall (m :: Type -> Type).
MonadIO m =>
Renderer -> CInt -> CInt -> m CInt
Raw.renderSetLogicalSize Renderer
r CInt
x CInt
y

-- | Determine whether a window supports the use of render targets.
--
-- See @<https://wiki.libsdl.org/SDL_RenderTargetSupported SDL_RenderTargetSupported>@ for C documentation.
renderTargetSupported :: (MonadIO m) => Renderer -> m Bool
renderTargetSupported :: forall (m :: Type -> Type). MonadIO m => Renderer -> m Bool
renderTargetSupported (Renderer Renderer
r) = forall (m :: Type -> Type). MonadIO m => Renderer -> m Bool
Raw.renderTargetSupported Renderer
r

-- | Convert the given the enumerated pixel format to a bpp value and RGBA masks.
--
-- See @<https://wiki.libsdl.org/SDL_PixelFormatEnumToMasks SDL_PixelFormatEnumToMasks>@ for C documentation.
pixelFormatToMasks :: (MonadIO m) => PixelFormat -> m (CInt, V4 Word32)
pixelFormatToMasks :: forall (m :: Type -> Type).
MonadIO m =>
PixelFormat -> m (CInt, V4 BlendMode)
pixelFormatToMasks PixelFormat
pf = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
bpp ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
r ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
g ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
b ->
  forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
a -> do
    forall (m :: Type -> Type) a.
MonadIO m =>
(a -> Bool) -> Text -> Text -> m a -> m ()
throwIf_ Bool -> Bool
not Text
"SDL.Video.pixelFormatEnumToMasks" Text
"SDL_PixelFormatEnumToMasks" forall a b. (a -> b) -> a -> b
$
      forall (m :: Type -> Type).
MonadIO m =>
BlendMode
-> Ptr CInt
-> Ptr BlendMode
-> Ptr BlendMode
-> Ptr BlendMode
-> Ptr BlendMode
-> m Bool
Raw.pixelFormatEnumToMasks (forall a b. ToNumber a b => a -> b
toNumber PixelFormat
pf) Ptr CInt
bpp Ptr BlendMode
r Ptr BlendMode
g Ptr BlendMode
b Ptr BlendMode
a
    forall {a} {a}. a -> a -> a -> a -> a -> (a, V4 a)
wrap forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
bpp forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
r forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
g forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
b forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
a
    where
      wrap :: a -> a -> a -> a -> a -> (a, V4 a)
wrap a
bpp a
r a
g a
b a
a = (a
bpp, forall a. a -> a -> a -> a -> V4 a
V4 a
r a
g a
b a
a)

-- | Convert a bpp value and RGBA masks to an enumerated pixel format.
--
-- See @<https://wiki.libsdl.org/SDL_MasksToPixelFormatEnum SDL_MasksToPixelFormatEnum>@ for C documentation.
masksToPixelFormat :: (MonadIO m) => CInt -> V4 Word32 -> m PixelFormat
masksToPixelFormat :: forall (m :: Type -> Type).
MonadIO m =>
CInt -> V4 BlendMode -> m PixelFormat
masksToPixelFormat CInt
bpp (V4 BlendMode
r BlendMode
g BlendMode
b BlendMode
a) = forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
  forall a b. FromNumber a b => b -> a
fromNumber forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: Type -> Type).
MonadIO m =>
CInt
-> BlendMode -> BlendMode -> BlendMode -> BlendMode -> m BlendMode
Raw.masksToPixelFormatEnum CInt
bpp BlendMode
r BlendMode
g BlendMode
b BlendMode
a