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

-- | "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
  , rendererIntegerScale
  , 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 (void)
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.Generic.Base as GV
import qualified Data.Vector.Generic.Mutable.Base as GMV
import qualified Data.Vector.Storable as SV
import qualified Data.Vector.Storable.Mutable as MSV
import qualified Data.Vector.Unboxed.Base as UV
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/SDL2/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 = IO (Maybe (Rectangle CInt)) -> m (Maybe (Rectangle CInt))
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (Rectangle CInt)) -> m (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt)) -> m (Maybe (Rectangle CInt))
forall a b. (a -> b) -> a -> b
$
  (Rectangle CInt
 -> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
 -> IO (Maybe (Rectangle CInt)))
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt
-> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect ((Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
 -> IO (Maybe (Rectangle CInt)))
-> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
srcPtr ->
  (Rectangle CInt
 -> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
 -> IO (Maybe (Rectangle CInt)))
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt
-> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with ((Point V2 CInt -> Rectangle CInt)
-> Maybe (Point V2 CInt) -> Maybe (Rectangle CInt)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Point V2 CInt -> V2 CInt -> Rectangle CInt)
-> V2 CInt -> Point V2 CInt -> Rectangle CInt
forall a b c. (a -> b -> c) -> b -> a -> c
flip Point V2 CInt -> V2 CInt -> Rectangle CInt
forall a. Point V2 a -> V2 a -> Rectangle a
Rectangle V2 CInt
0) Maybe (Point V2 CInt)
dstLoc) ((Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
 -> IO (Maybe (Rectangle CInt)))
-> (Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dstPtr -> do
      _ <- Text -> Text -> IO CInt -> IO 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" (IO CInt -> IO CInt) -> IO CInt -> IO CInt
forall a b. (a -> b) -> a -> b
$
           Ptr Surface -> Ptr Rect -> Ptr Surface -> Ptr Rect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr Rect -> Ptr Surface -> Ptr Rect -> m CInt
Raw.blitSurface Ptr Surface
src (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
srcPtr) Ptr Surface
dst (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
dstPtr)
      maybe (pure Nothing) (\Point V2 CInt
_ -> Rectangle CInt -> Maybe (Rectangle CInt)
forall a. a -> Maybe a
Just (Rectangle CInt -> Maybe (Rectangle CInt))
-> IO (Rectangle CInt) -> IO (Maybe (Rectangle CInt))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr (Rectangle CInt) -> IO (Rectangle CInt)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Rectangle CInt)
dstPtr) dstLoc

-- | Create a texture for a rendering context.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
r) PixelFormat
fmt TextureAccess
access (V2 CInt
w CInt
h) =
  (Texture -> Texture) -> m Texture -> m Texture
forall a b. (a -> b) -> m a -> m b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Texture -> Texture
Texture (m Texture -> m Texture) -> m Texture -> m Texture
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> m Texture -> m Texture
forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.Renderer.createTexture" Text
"SDL_CreateTexture" (m Texture -> m Texture) -> m Texture -> m Texture
forall a b. (a -> b) -> a -> b
$
  Texture -> BlendMode -> CInt -> CInt -> CInt -> m Texture
forall (m :: Type -> Type).
MonadIO m =>
Texture -> BlendMode -> CInt -> CInt -> CInt -> m Texture
Raw.createTexture Texture
r (PixelFormat -> BlendMode
forall a b. ToNumber a b => a -> b
toNumber PixelFormat
fmt) (TextureAccess -> CInt
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/SDL2/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 Texture
r) (Surface Ptr Surface
s Maybe (IOVector Word8)
_) =
  (Texture -> Texture) -> m Texture -> m Texture
forall a b. (a -> b) -> m a -> m b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Texture -> Texture
Texture (m Texture -> m Texture) -> m Texture -> m Texture
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> m Texture -> m Texture
forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.createTextureFromSurface" Text
"SDL_CreateTextureFromSurface" (m Texture -> m Texture) -> m Texture -> m Texture
forall a b. (a -> b) -> a -> b
$
  Texture -> Ptr Surface -> m Texture
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Surface -> m Texture
Raw.createTextureFromSurface Texture
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/SDL2/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 Texture
t) =
  Text -> Text -> m CInt -> m ()
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" (m CInt -> m ()) -> m CInt -> m ()
forall a b. (a -> b) -> a -> b
$
  Texture -> Ptr CFloat -> Ptr CFloat -> m CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr CFloat -> Ptr CFloat -> m CInt
Raw.glBindTexture Texture
t Ptr CFloat
forall a. Ptr a
nullPtr Ptr CFloat
forall a. Ptr a
nullPtr

-- | Unbind an OpenGL\/ES\/ES2 texture from the current context.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
t) =
  Text -> Text -> m CInt -> m ()
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" (m CInt -> m ()) -> m CInt -> m ()
forall a b. (a -> b) -> a -> b
$
  Texture -> m CInt
forall (m :: Type -> Type). MonadIO m => Texture -> m CInt
Raw.glUnbindTexture Texture
t

-- | Updates texture rectangle with new pixel data.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
t) Maybe (Rectangle CInt)
rect ByteString
pixels CInt
pitch = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.updateTexture" Text
"SDL_UpdateTexture" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
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 ForeignPtr Word8 -> (Ptr Word8 -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
pixelForeign ((Ptr Word8 -> IO CInt) -> IO CInt)
-> (Ptr Word8 -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
pixelsPtr ->
        Texture -> Ptr Rect -> Texture -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> Texture -> CInt -> m CInt
Raw.updateTexture Texture
t (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rectPtr) (Ptr Word8 -> Texture
forall a b. Ptr a -> Ptr b
castPtr Ptr Word8
pixelsPtr) CInt
pitch

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

-- | Lock a portion of the texture for *write-only* pixel access.
--
-- See @<https://wiki.libsdl.org/SDL2/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 (Texture, CInt)
lockTexture (Texture Texture
t) Maybe (Rectangle CInt)
rect = IO (Texture, CInt) -> m (Texture, CInt)
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO (Texture, CInt) -> m (Texture, CInt))
-> IO (Texture, CInt) -> m (Texture, CInt)
forall a b. (a -> b) -> a -> b
$
  (Ptr Texture -> IO (Texture, CInt)) -> IO (Texture, CInt)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Texture -> IO (Texture, CInt)) -> IO (Texture, CInt))
-> (Ptr Texture -> IO (Texture, CInt)) -> IO (Texture, CInt)
forall a b. (a -> b) -> a -> b
$ \Ptr Texture
pixelsPtr ->
  (Ptr CInt -> IO (Texture, CInt)) -> IO (Texture, CInt)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Texture, CInt)) -> IO (Texture, CInt))
-> (Ptr CInt -> IO (Texture, CInt)) -> IO (Texture, CInt)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
pitchPtr ->
  (Rectangle CInt
 -> (Ptr (Rectangle CInt) -> IO (Texture, CInt))
 -> IO (Texture, CInt))
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO (Texture, CInt))
-> IO (Texture, CInt)
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt
-> (Ptr (Rectangle CInt) -> IO (Texture, CInt))
-> IO (Texture, CInt)
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect ((Ptr (Rectangle CInt) -> IO (Texture, CInt))
 -> IO (Texture, CInt))
-> (Ptr (Rectangle CInt) -> IO (Texture, CInt))
-> IO (Texture, CInt)
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rectPtr -> do
    Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"lockTexture" Text
"SDL_LockTexture" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
      Texture -> Ptr Rect -> Ptr Texture -> Ptr CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> Ptr Texture -> Ptr CInt -> m CInt
Raw.lockTexture Texture
t (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rectPtr) Ptr Texture
pixelsPtr Ptr CInt
pitchPtr
    pixels <- Ptr Texture -> IO Texture
forall a. Storable a => Ptr a -> IO a
peek Ptr Texture
pixelsPtr
    pitch <- peek pitchPtr
    return (pixels, 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/SDL2/SDL_UnlockTexture SDL_UnlockTexture>@ for C documentation.
unlockTexture :: MonadIO m => Texture -> m ()
unlockTexture :: forall (m :: Type -> Type). MonadIO m => Texture -> m ()
unlockTexture (Texture Texture
t) = Texture -> m ()
forall (m :: Type -> Type). MonadIO m => Texture -> m ()
Raw.unlockTexture Texture
t

-- | Set up a surface for directly accessing the pixels.
--
-- See @<https://wiki.libsdl.org/SDL2/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)
_) =
  Text -> Text -> m CInt -> m ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"lockSurface" Text
"SDL_LockSurface" (m CInt -> m ()) -> m CInt -> m ()
forall a b. (a -> b) -> a -> b
$
    Ptr Surface -> m CInt
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/SDL2/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)
_) = Ptr Surface -> m ()
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
TextureAccess -> TextureAccess -> Bounded TextureAccess
forall a. a -> a -> Bounded a
$cminBound :: TextureAccess
minBound :: TextureAccess
$cmaxBound :: TextureAccess
maxBound :: TextureAccess
Bounded, Typeable TextureAccess
Typeable 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 (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c TextureAccess)
-> (TextureAccess -> Constr)
-> (TextureAccess -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> TextureAccess -> TextureAccess)
-> (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 u. (forall d. Data d => d -> u) -> TextureAccess -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> TextureAccess -> u)
-> (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 (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess)
-> Data TextureAccess
TextureAccess -> Constr
TextureAccess -> DataType
(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)
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> 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
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
$ctoConstr :: TextureAccess -> Constr
toConstr :: TextureAccess -> Constr
$cdataTypeOf :: TextureAccess -> DataType
dataTypeOf :: TextureAccess -> DataType
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TextureAccess)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> 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)
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)
$cgmapT :: (forall b. Data b => b -> b) -> TextureAccess -> TextureAccess
gmapT :: (forall b. Data b => b -> b) -> TextureAccess -> TextureAccess
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TextureAccess -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> TextureAccess -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TextureAccess -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TextureAccess -> u
$cgmapM :: forall (m :: Type -> Type).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
Data, Int -> TextureAccess
TextureAccess -> Int
TextureAccess -> [TextureAccess]
TextureAccess -> TextureAccess
TextureAccess -> TextureAccess -> [TextureAccess]
TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
(TextureAccess -> TextureAccess)
-> (TextureAccess -> TextureAccess)
-> (Int -> TextureAccess)
-> (TextureAccess -> Int)
-> (TextureAccess -> [TextureAccess])
-> (TextureAccess -> TextureAccess -> [TextureAccess])
-> (TextureAccess -> TextureAccess -> [TextureAccess])
-> (TextureAccess
    -> TextureAccess -> TextureAccess -> [TextureAccess])
-> Enum 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
$csucc :: TextureAccess -> TextureAccess
succ :: TextureAccess -> TextureAccess
$cpred :: TextureAccess -> TextureAccess
pred :: TextureAccess -> TextureAccess
$ctoEnum :: Int -> TextureAccess
toEnum :: Int -> TextureAccess
$cfromEnum :: TextureAccess -> Int
fromEnum :: TextureAccess -> Int
$cenumFrom :: TextureAccess -> [TextureAccess]
enumFrom :: TextureAccess -> [TextureAccess]
$cenumFromThen :: TextureAccess -> TextureAccess -> [TextureAccess]
enumFromThen :: TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromTo :: TextureAccess -> TextureAccess -> [TextureAccess]
enumFromTo :: TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromThenTo :: TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
enumFromThenTo :: TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
Enum, TextureAccess -> TextureAccess -> Bool
(TextureAccess -> TextureAccess -> Bool)
-> (TextureAccess -> TextureAccess -> Bool) -> Eq TextureAccess
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextureAccess -> TextureAccess -> Bool
== :: TextureAccess -> TextureAccess -> Bool
$c/= :: TextureAccess -> TextureAccess -> Bool
/= :: TextureAccess -> TextureAccess -> Bool
Eq, (forall x. TextureAccess -> Rep TextureAccess x)
-> (forall x. Rep TextureAccess x -> TextureAccess)
-> Generic TextureAccess
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
$cfrom :: forall x. TextureAccess -> Rep TextureAccess x
from :: forall x. TextureAccess -> Rep TextureAccess x
$cto :: forall x. Rep TextureAccess x -> TextureAccess
to :: forall x. Rep TextureAccess x -> TextureAccess
Generic, Eq TextureAccess
Eq TextureAccess =>
(TextureAccess -> TextureAccess -> Ordering)
-> (TextureAccess -> TextureAccess -> Bool)
-> (TextureAccess -> TextureAccess -> Bool)
-> (TextureAccess -> TextureAccess -> Bool)
-> (TextureAccess -> TextureAccess -> Bool)
-> (TextureAccess -> TextureAccess -> TextureAccess)
-> (TextureAccess -> TextureAccess -> TextureAccess)
-> Ord 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
$ccompare :: TextureAccess -> TextureAccess -> Ordering
compare :: TextureAccess -> TextureAccess -> Ordering
$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
>= :: TextureAccess -> TextureAccess -> Bool
$cmax :: TextureAccess -> TextureAccess -> TextureAccess
max :: TextureAccess -> TextureAccess -> TextureAccess
$cmin :: TextureAccess -> TextureAccess -> TextureAccess
min :: TextureAccess -> TextureAccess -> TextureAccess
Ord, ReadPrec [TextureAccess]
ReadPrec TextureAccess
Int -> ReadS TextureAccess
ReadS [TextureAccess]
(Int -> ReadS TextureAccess)
-> ReadS [TextureAccess]
-> ReadPrec TextureAccess
-> ReadPrec [TextureAccess]
-> Read TextureAccess
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TextureAccess
readsPrec :: Int -> ReadS TextureAccess
$creadList :: ReadS [TextureAccess]
readList :: ReadS [TextureAccess]
$creadPrec :: ReadPrec TextureAccess
readPrec :: ReadPrec TextureAccess
$creadListPrec :: ReadPrec [TextureAccess]
readListPrec :: ReadPrec [TextureAccess]
Read, Int -> TextureAccess -> String -> String
[TextureAccess] -> String -> String
TextureAccess -> String
(Int -> TextureAccess -> String -> String)
-> (TextureAccess -> String)
-> ([TextureAccess] -> String -> String)
-> Show TextureAccess
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> TextureAccess -> String -> String
showsPrec :: Int -> TextureAccess -> String -> String
$cshow :: TextureAccess -> String
show :: TextureAccess -> String
$cshowList :: [TextureAccess] -> String -> String
showList :: [TextureAccess] -> String -> String
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
_ -> String -> TextureAccess
forall a. HasCallStack => String -> a
error String
"Unknown value"

instance ToNumber TextureAccess CInt where
  toNumber :: TextureAccess -> CInt
toNumber TextureAccess
t = case TextureAccess
t of
    TextureAccess
TextureAccessStatic -> CInt
forall {a}. (Eq a, Num a) => a
Raw.SDL_TEXTUREACCESS_STATIC
    TextureAccess
TextureAccessStreaming -> CInt
forall {a}. (Eq a, Num a) => a
Raw.SDL_TEXTUREACCESS_STREAMING
    TextureAccess
TextureAccessTarget -> CInt
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
(TextureInfo -> TextureInfo -> Bool)
-> (TextureInfo -> TextureInfo -> Bool) -> Eq TextureInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextureInfo -> TextureInfo -> Bool
== :: TextureInfo -> TextureInfo -> Bool
$c/= :: TextureInfo -> TextureInfo -> Bool
/= :: TextureInfo -> TextureInfo -> Bool
Eq, (forall x. TextureInfo -> Rep TextureInfo x)
-> (forall x. Rep TextureInfo x -> TextureInfo)
-> Generic TextureInfo
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
$cfrom :: forall x. TextureInfo -> Rep TextureInfo x
from :: forall x. TextureInfo -> Rep TextureInfo x
$cto :: forall x. Rep TextureInfo x -> TextureInfo
to :: forall x. Rep TextureInfo x -> TextureInfo
Generic, Eq TextureInfo
Eq TextureInfo =>
(TextureInfo -> TextureInfo -> Ordering)
-> (TextureInfo -> TextureInfo -> Bool)
-> (TextureInfo -> TextureInfo -> Bool)
-> (TextureInfo -> TextureInfo -> Bool)
-> (TextureInfo -> TextureInfo -> Bool)
-> (TextureInfo -> TextureInfo -> TextureInfo)
-> (TextureInfo -> TextureInfo -> TextureInfo)
-> Ord 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
$ccompare :: TextureInfo -> TextureInfo -> Ordering
compare :: TextureInfo -> TextureInfo -> Ordering
$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
>= :: TextureInfo -> TextureInfo -> Bool
$cmax :: TextureInfo -> TextureInfo -> TextureInfo
max :: TextureInfo -> TextureInfo -> TextureInfo
$cmin :: TextureInfo -> TextureInfo -> TextureInfo
min :: TextureInfo -> TextureInfo -> TextureInfo
Ord, ReadPrec [TextureInfo]
ReadPrec TextureInfo
Int -> ReadS TextureInfo
ReadS [TextureInfo]
(Int -> ReadS TextureInfo)
-> ReadS [TextureInfo]
-> ReadPrec TextureInfo
-> ReadPrec [TextureInfo]
-> Read TextureInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TextureInfo
readsPrec :: Int -> ReadS TextureInfo
$creadList :: ReadS [TextureInfo]
readList :: ReadS [TextureInfo]
$creadPrec :: ReadPrec TextureInfo
readPrec :: ReadPrec TextureInfo
$creadListPrec :: ReadPrec [TextureInfo]
readListPrec :: ReadPrec [TextureInfo]
Read, Int -> TextureInfo -> String -> String
[TextureInfo] -> String -> String
TextureInfo -> String
(Int -> TextureInfo -> String -> String)
-> (TextureInfo -> String)
-> ([TextureInfo] -> String -> String)
-> Show TextureInfo
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> TextureInfo -> String -> String
showsPrec :: Int -> TextureInfo -> String -> String
$cshow :: TextureInfo -> String
show :: TextureInfo -> String
$cshowList :: [TextureInfo] -> String -> String
showList :: [TextureInfo] -> String -> String
Show, Typeable)

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

-- | Allocate a new RGB surface.
--
-- See @<https://wiki.libsdl.org/SDL2/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 =
  (Ptr Surface -> Surface) -> m (Ptr Surface) -> m Surface
forall a b. (a -> b) -> m a -> m b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface (m (Ptr Surface) -> m Surface) -> m (Ptr Surface) -> m Surface
forall a b. (a -> b) -> a -> b
$
    Text -> Text -> m (Ptr Surface) -> m (Ptr Surface)
forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.createRGBSurface" Text
"SDL_CreateRGBSurface" (m (Ptr Surface) -> m (Ptr Surface))
-> m (Ptr Surface) -> m (Ptr Surface)
forall a b. (a -> b) -> a -> b
$ do
      (bpp, V4 r g b a) <- PixelFormat -> m (CInt, V4 BlendMode)
forall (m :: Type -> Type).
MonadIO m =>
PixelFormat -> m (CInt, V4 BlendMode)
pixelFormatToMasks PixelFormat
pf
      Raw.createRGBSurface 0 w h bpp r g b a

-- | Allocate a new RGB surface with existing pixel data.
--
-- See @<https://wiki.libsdl.org/SDL2/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 = IO Surface -> m Surface
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO Surface -> m Surface) -> IO Surface -> m Surface
forall a b. (a -> b) -> a -> b
$
  (Ptr Surface -> Surface) -> IO (Ptr Surface) -> IO Surface
forall a b. (a -> b) -> IO a -> IO 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) (IO (Ptr Surface) -> IO Surface) -> IO (Ptr Surface) -> IO Surface
forall a b. (a -> b) -> a -> b
$
    Text -> Text -> IO (Ptr Surface) -> IO (Ptr Surface)
forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.createRGBSurfaceFrom" Text
"SDL_CreateRGBSurfaceFrom" (IO (Ptr Surface) -> IO (Ptr Surface))
-> IO (Ptr Surface) -> IO (Ptr Surface)
forall a b. (a -> b) -> a -> b
$ do
      (bpp, V4 r g b a) <- PixelFormat -> IO (CInt, V4 BlendMode)
forall (m :: Type -> Type).
MonadIO m =>
PixelFormat -> m (CInt, V4 BlendMode)
pixelFormatToMasks PixelFormat
pf
      MSV.unsafeWith pixels $ \Ptr Word8
pixelPtr ->
        Texture
-> CInt
-> CInt
-> CInt
-> CInt
-> BlendMode
-> BlendMode
-> BlendMode
-> BlendMode
-> IO (Ptr Surface)
forall (m :: Type -> Type).
MonadIO m =>
Texture
-> CInt
-> CInt
-> CInt
-> CInt
-> BlendMode
-> BlendMode
-> BlendMode
-> BlendMode
-> m (Ptr Surface)
Raw.createRGBSurfaceFrom (Ptr Word8 -> Texture
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/SDL2/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) = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRect" Text
"SDL_FillRect" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rectPtr -> do
    format <- Surface -> Ptr PixelFormat
Raw.surfaceFormat (Surface -> Ptr PixelFormat) -> IO Surface -> IO (Ptr PixelFormat)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Surface -> IO Surface
forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s
    Raw.mapRGBA format r g b a >>= Raw.fillRect s (castPtr 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/SDL2/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) = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRects" Text
"SDL_FillRects" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CInt)
rects ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rp -> do
      format <- Surface -> Ptr PixelFormat
Raw.surfaceFormat (Surface -> Ptr PixelFormat) -> IO Surface -> IO (Ptr PixelFormat)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Surface -> IO Surface
forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s
      Raw.fillRects s
                    (castPtr rp)
                    (fromIntegral (SV.length rects))
                    =<< Raw.mapRGBA format r g b a

-- | Free an RGB surface.
--
-- If the surface was created using 'createRGBSurfaceFrom' then the pixel data is not freed.
--
-- See @<https://wiki.libsdl.org/SDL2/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)
_) = Ptr Surface -> m ()
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/SDL2/SDL_LoadBMP SDL_LoadBMP>@ for C documentation.
loadBMP :: MonadIO m => FilePath -> m Surface
loadBMP :: forall (m :: Type -> Type). MonadIO m => String -> m Surface
loadBMP String
filePath = IO Surface -> m Surface
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO Surface -> m Surface) -> IO Surface -> m Surface
forall a b. (a -> b) -> a -> b
$
  (Ptr Surface -> Surface) -> IO (Ptr Surface) -> IO Surface
forall a b. (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface (IO (Ptr Surface) -> IO Surface) -> IO (Ptr Surface) -> IO Surface
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO (Ptr Surface) -> IO (Ptr Surface)
forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.loadBMP" Text
"SDL_LoadBMP" (IO (Ptr Surface) -> IO (Ptr Surface))
-> IO (Ptr Surface) -> IO (Ptr Surface)
forall a b. (a -> b) -> a -> b
$
  String -> (CString -> IO (Ptr Surface)) -> IO (Ptr Surface)
forall a. String -> (CString -> IO a) -> IO a
withCString String
filePath ((CString -> IO (Ptr Surface)) -> IO (Ptr Surface))
-> (CString -> IO (Ptr Surface)) -> IO (Ptr Surface)
forall a b. (a -> b) -> a -> b
$ CString -> IO (Ptr Surface)
forall (m :: Type -> Type). MonadIO m => CString -> m (Ptr Surface)
Raw.loadBMP

newtype SurfacePixelFormat = SurfacePixelFormat (Ptr Raw.PixelFormat)
  deriving (SurfacePixelFormat -> SurfacePixelFormat -> Bool
(SurfacePixelFormat -> SurfacePixelFormat -> Bool)
-> (SurfacePixelFormat -> SurfacePixelFormat -> Bool)
-> Eq SurfacePixelFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
== :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
$c/= :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
/= :: 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)
_) = IO (V2 CInt) -> m (V2 CInt)
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO (V2 CInt) -> m (V2 CInt)) -> IO (V2 CInt) -> m (V2 CInt)
forall a b. (a -> b) -> a -> b
$ (CInt -> CInt -> V2 CInt
forall a. a -> a -> V2 a
V2 (CInt -> CInt -> V2 CInt)
-> (Surface -> CInt) -> Surface -> CInt -> V2 CInt
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Surface -> CInt
Raw.surfaceW (Surface -> CInt -> V2 CInt)
-> (Surface -> CInt) -> Surface -> V2 CInt
forall a b. (Surface -> a -> b) -> (Surface -> a) -> Surface -> b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Surface -> CInt
Raw.surfaceH) (Surface -> V2 CInt) -> IO Surface -> IO (V2 CInt)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Surface -> IO Surface
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 Texture
surfacePixels (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = IO Texture -> m Texture
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO Texture -> m Texture) -> IO Texture -> m Texture
forall a b. (a -> b) -> a -> b
$ Surface -> Texture
Raw.surfacePixels (Surface -> Texture) -> IO Surface -> IO Texture
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Surface -> IO Surface
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)
_) = IO SurfacePixelFormat -> m SurfacePixelFormat
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO SurfacePixelFormat -> m SurfacePixelFormat)
-> IO SurfacePixelFormat -> m SurfacePixelFormat
forall a b. (a -> b) -> a -> b
$ Ptr PixelFormat -> SurfacePixelFormat
SurfacePixelFormat (Ptr PixelFormat -> SurfacePixelFormat)
-> (Surface -> Ptr PixelFormat) -> Surface -> SurfacePixelFormat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Surface -> Ptr PixelFormat
Raw.surfaceFormat (Surface -> SurfacePixelFormat)
-> IO Surface -> IO SurfacePixelFormat
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Surface -> IO Surface
forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s

newtype Palette = Palette (Ptr Raw.Palette)
  deriving (Palette -> Palette -> Bool
(Palette -> Palette -> Bool)
-> (Palette -> Palette -> Bool) -> Eq Palette
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Palette -> Palette -> Bool
== :: Palette -> Palette -> Bool
$c/= :: Palette -> Palette -> Bool
/= :: 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) = IO (Maybe Palette) -> m (Maybe Palette)
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Palette) -> m (Maybe Palette))
-> IO (Maybe Palette) -> m (Maybe Palette)
forall a b. (a -> b) -> a -> b
$ Ptr Palette -> Maybe Palette
wrap (Ptr Palette -> Maybe Palette)
-> (PixelFormat -> Ptr Palette) -> PixelFormat -> Maybe Palette
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PixelFormat -> Ptr Palette
Raw.pixelFormatPalette (PixelFormat -> Maybe Palette)
-> IO PixelFormat -> IO (Maybe Palette)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr PixelFormat -> IO PixelFormat
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 Ptr Palette -> Ptr Palette -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr Palette
forall a. Ptr a
nullPtr = Maybe Palette
forall a. Maybe a
Nothing
          | Bool
otherwise = Palette -> Maybe Palette
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) = IO CInt -> m CInt
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO CInt -> m CInt) -> IO CInt -> m CInt
forall a b. (a -> b) -> a -> b
$ Palette -> CInt
Raw.paletteNColors (Palette -> CInt) -> IO Palette -> IO CInt
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Palette -> IO Palette
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
  n <- IO Int -> m Int
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO Int -> m Int) -> IO Int -> m Int
forall a b. (a -> b) -> a -> b
$ CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Palette -> IO CInt
forall (m :: Type -> Type). MonadIO m => Palette -> m CInt
paletteNColors Palette
q
  let wrap Ptr a
p' | Ptr a
p' Ptr a -> Ptr a -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr a
forall a. Ptr a
nullPtr = Maybe (Ptr a)
forall a. Maybe a
Nothing
              | Bool
otherwise     = Ptr a -> Maybe (Ptr a)
forall a. a -> Maybe a
forall (m :: Type -> Type) a. Monad m => a -> m a
return Ptr a
p'
  mv <- liftIO $ wrap . castPtr . Raw.paletteColors <$> peek p
  mColor <- liftIO $ traverse newForeignPtr_ mv
  return $ flip SV.unsafeFromForeignPtr0 n <$> 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
    rp <- IO Palette -> m Palette
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO Palette -> m Palette) -> IO Palette -> m Palette
forall a b. (a -> b) -> a -> b
$ Ptr Palette -> IO Palette
forall a. Storable a => Ptr a -> IO a
peek Ptr Palette
p
    m <- paletteNColors q
    if m > i && i >= 0 then
      liftIO $ fmap return . flip peekElemOff (fromIntegral i) . castPtr . Raw.paletteColors $ rp
    else
      return Nothing

-- | Set a range of colors in a palette.
--
-- See @<https://wiki.libsdl.org/SDL2/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 = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.setPaletteColors" Text
"SDL_SetPaletteColors" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  Vector (V4 Word8) -> (Ptr (V4 Word8) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (V4 Word8)
colors ((Ptr (V4 Word8) -> IO CInt) -> IO CInt)
-> (Ptr (V4 Word8) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (V4 Word8)
cp ->
    Ptr Palette -> Ptr Color -> CInt -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Ptr Palette -> Ptr Color -> CInt -> CInt -> m CInt
Raw.setPaletteColors Ptr Palette
p (Ptr (V4 Word8) -> Ptr Color
forall a b. Ptr a -> Ptr b
castPtr Ptr (V4 Word8)
cp) CInt
first CInt
n
  where
    n :: CInt
n = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> Int -> CInt
forall a b. (a -> b) -> a -> b
$ Vector (V4 Word8) -> Int
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/SDL2/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 Texture
w) =
  (Ptr Surface -> Surface) -> m (Ptr Surface) -> m Surface
forall a b. (a -> b) -> m a -> m b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface (m (Ptr Surface) -> m Surface) -> m (Ptr Surface) -> m Surface
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> m (Ptr Surface) -> m (Ptr Surface)
forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.getWindowSurface" Text
"SDL_GetWindowSurface" (m (Ptr Surface) -> m (Ptr Surface))
-> m (Ptr Surface) -> m (Ptr Surface)
forall a b. (a -> b) -> a -> b
$
  Texture -> m (Ptr Surface)
forall (m :: Type -> Type). MonadIO m => Texture -> m (Ptr Surface)
Raw.getWindowSurface Texture
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/SDL2/SDL_SetRenderDrawBlendMode SDL_SetRenderDrawBlendMode>@ and @<https://wiki.libsdl.org/SDL2/SDL_GetRenderDrawBlendMode SDL_GetRenderDrawBlendMode>@ for C documentation.
rendererDrawBlendMode :: Renderer -> StateVar BlendMode
rendererDrawBlendMode :: Renderer -> StateVar BlendMode
rendererDrawBlendMode (Renderer Texture
r) = IO BlendMode -> (BlendMode -> IO ()) -> StateVar BlendMode
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO BlendMode
getRenderDrawBlendMode BlendMode -> IO ()
setRenderDrawBlendMode
  where
  getRenderDrawBlendMode :: IO BlendMode
getRenderDrawBlendMode =
    (Ptr BlendMode -> IO BlendMode) -> IO BlendMode
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO BlendMode) -> IO BlendMode)
-> (Ptr BlendMode -> IO BlendMode) -> IO BlendMode
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
bmPtr -> do
      Text -> Text -> IO Int -> IO ()
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" (IO Int -> IO ()) -> IO Int -> IO ()
forall a b. (a -> b) -> a -> b
$
        Texture -> Ptr BlendMode -> IO Int
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr BlendMode -> m Int
Raw.getRenderDrawBlendMode Texture
r Ptr BlendMode
bmPtr
      BlendMode -> BlendMode
forall a b. FromNumber a b => b -> a
fromNumber (BlendMode -> BlendMode) -> IO BlendMode -> IO BlendMode
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr BlendMode -> IO BlendMode
forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
bmPtr

  setRenderDrawBlendMode :: BlendMode -> IO ()
setRenderDrawBlendMode BlendMode
bm =
    Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Texture -> BlendMode -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> BlendMode -> m CInt
Raw.setRenderDrawBlendMode Texture
r (BlendMode -> BlendMode
forall a b. ToNumber a b => a -> b
toNumber BlendMode
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/SDL2/SDL_SetRenderDrawColor SDL_SetRenderDrawColor>@ and @<https://wiki.libsdl.org/SDL2/SDL_GetRenderDrawColor SDL_GetRenderDrawColor>@ for C documentation.
rendererDrawColor :: Renderer -> StateVar (V4 Word8)
rendererDrawColor :: Renderer -> StateVar (V4 Word8)
rendererDrawColor (Renderer Texture
re) = IO (V4 Word8) -> (V4 Word8 -> IO ()) -> StateVar (V4 Word8)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (V4 Word8)
getRenderDrawColor V4 Word8 -> IO ()
setRenderDrawColor
  where
  getRenderDrawColor :: IO (V4 Word8)
getRenderDrawColor =
    (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8))
-> (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
r ->
    (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8))
-> (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
g ->
    (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8))
-> (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
b ->
    (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8))
-> (Ptr Word8 -> IO (V4 Word8)) -> IO (V4 Word8)
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
a -> do
      Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
        Texture
-> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture
-> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> m CInt
Raw.getRenderDrawColor Texture
re Ptr Word8
r Ptr Word8
g Ptr Word8
b Ptr Word8
a
      Word8 -> Word8 -> Word8 -> Word8 -> V4 Word8
forall a. a -> a -> a -> a -> V4 a
V4 (Word8 -> Word8 -> Word8 -> Word8 -> V4 Word8)
-> IO Word8 -> IO (Word8 -> Word8 -> Word8 -> V4 Word8)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
r IO (Word8 -> Word8 -> Word8 -> V4 Word8)
-> IO Word8 -> IO (Word8 -> Word8 -> V4 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
g IO (Word8 -> Word8 -> V4 Word8)
-> IO Word8 -> IO (Word8 -> V4 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
b IO (Word8 -> V4 Word8) -> IO Word8 -> IO (V4 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
a

  setRenderDrawColor :: V4 Word8 -> IO ()
setRenderDrawColor (V4 Word8
r Word8
g Word8
b Word8
a) =
    Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.setRenderDrawColor" Text
"SDL_SetRenderDrawColor" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Texture -> Word8 -> Word8 -> Word8 -> Word8 -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Word8 -> Word8 -> Word8 -> Word8 -> m CInt
Raw.setRenderDrawColor Texture
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/SDL2/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 Texture
w) =
  Text -> Text -> m CInt -> m ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.updateWindowSurface" Text
"SDL_UpdateWindowSurface" (m CInt -> m ()) -> m CInt -> m ()
forall a b. (a -> b) -> a -> b
$
    Texture -> m CInt
forall (m :: Type -> Type). MonadIO m => Texture -> m CInt
Raw.updateWindowSurface Texture
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
BlendMode -> BlendMode -> Bounded BlendMode
forall a. a -> a -> Bounded a
$cminBound :: BlendMode
minBound :: BlendMode
$cmaxBound :: BlendMode
maxBound :: BlendMode
Bounded, Typeable BlendMode
Typeable 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 (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BlendMode)
-> (BlendMode -> Constr)
-> (BlendMode -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> BlendMode -> BlendMode)
-> (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 u. (forall d. Data d => d -> u) -> BlendMode -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BlendMode -> u)
-> (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 (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BlendMode -> m BlendMode)
-> Data BlendMode
BlendMode -> Constr
BlendMode -> DataType
(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)
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BlendMode -> 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
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BlendMode
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BlendMode
$ctoConstr :: BlendMode -> Constr
toConstr :: BlendMode -> Constr
$cdataTypeOf :: BlendMode -> DataType
dataTypeOf :: BlendMode -> DataType
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BlendMode)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> 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)
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)
$cgmapT :: (forall b. Data b => b -> b) -> BlendMode -> BlendMode
gmapT :: (forall b. Data b => b -> b) -> BlendMode -> BlendMode
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BlendMode -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BlendMode -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BlendMode -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BlendMode -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BlendMode -> u
$cgmapM :: forall (m :: Type -> Type).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BlendMode -> m BlendMode
Data, Int -> BlendMode
BlendMode -> Int
BlendMode -> [BlendMode]
BlendMode -> BlendMode
BlendMode -> BlendMode -> [BlendMode]
BlendMode -> BlendMode -> BlendMode -> [BlendMode]
(BlendMode -> BlendMode)
-> (BlendMode -> BlendMode)
-> (Int -> BlendMode)
-> (BlendMode -> Int)
-> (BlendMode -> [BlendMode])
-> (BlendMode -> BlendMode -> [BlendMode])
-> (BlendMode -> BlendMode -> [BlendMode])
-> (BlendMode -> BlendMode -> BlendMode -> [BlendMode])
-> Enum 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
$csucc :: BlendMode -> BlendMode
succ :: BlendMode -> BlendMode
$cpred :: BlendMode -> BlendMode
pred :: BlendMode -> BlendMode
$ctoEnum :: Int -> BlendMode
toEnum :: Int -> BlendMode
$cfromEnum :: BlendMode -> Int
fromEnum :: BlendMode -> Int
$cenumFrom :: BlendMode -> [BlendMode]
enumFrom :: BlendMode -> [BlendMode]
$cenumFromThen :: BlendMode -> BlendMode -> [BlendMode]
enumFromThen :: BlendMode -> BlendMode -> [BlendMode]
$cenumFromTo :: BlendMode -> BlendMode -> [BlendMode]
enumFromTo :: BlendMode -> BlendMode -> [BlendMode]
$cenumFromThenTo :: BlendMode -> BlendMode -> BlendMode -> [BlendMode]
enumFromThenTo :: BlendMode -> BlendMode -> BlendMode -> [BlendMode]
Enum, BlendMode -> BlendMode -> Bool
(BlendMode -> BlendMode -> Bool)
-> (BlendMode -> BlendMode -> Bool) -> Eq BlendMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlendMode -> BlendMode -> Bool
== :: BlendMode -> BlendMode -> Bool
$c/= :: BlendMode -> BlendMode -> Bool
/= :: BlendMode -> BlendMode -> Bool
Eq, (forall x. BlendMode -> Rep BlendMode x)
-> (forall x. Rep BlendMode x -> BlendMode) -> Generic BlendMode
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
$cfrom :: forall x. BlendMode -> Rep BlendMode x
from :: forall x. BlendMode -> Rep BlendMode x
$cto :: forall x. Rep BlendMode x -> BlendMode
to :: forall x. Rep BlendMode x -> BlendMode
Generic, Eq BlendMode
Eq BlendMode =>
(BlendMode -> BlendMode -> Ordering)
-> (BlendMode -> BlendMode -> Bool)
-> (BlendMode -> BlendMode -> Bool)
-> (BlendMode -> BlendMode -> Bool)
-> (BlendMode -> BlendMode -> Bool)
-> (BlendMode -> BlendMode -> BlendMode)
-> (BlendMode -> BlendMode -> BlendMode)
-> Ord 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
$ccompare :: BlendMode -> BlendMode -> Ordering
compare :: BlendMode -> BlendMode -> Ordering
$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
>= :: BlendMode -> BlendMode -> Bool
$cmax :: BlendMode -> BlendMode -> BlendMode
max :: BlendMode -> BlendMode -> BlendMode
$cmin :: BlendMode -> BlendMode -> BlendMode
min :: BlendMode -> BlendMode -> BlendMode
Ord, ReadPrec [BlendMode]
ReadPrec BlendMode
Int -> ReadS BlendMode
ReadS [BlendMode]
(Int -> ReadS BlendMode)
-> ReadS [BlendMode]
-> ReadPrec BlendMode
-> ReadPrec [BlendMode]
-> Read BlendMode
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS BlendMode
readsPrec :: Int -> ReadS BlendMode
$creadList :: ReadS [BlendMode]
readList :: ReadS [BlendMode]
$creadPrec :: ReadPrec BlendMode
readPrec :: ReadPrec BlendMode
$creadListPrec :: ReadPrec [BlendMode]
readListPrec :: ReadPrec [BlendMode]
Read, Int -> BlendMode -> String -> String
[BlendMode] -> String -> String
BlendMode -> String
(Int -> BlendMode -> String -> String)
-> (BlendMode -> String)
-> ([BlendMode] -> String -> String)
-> Show BlendMode
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> BlendMode -> String -> String
showsPrec :: Int -> BlendMode -> String -> String
$cshow :: BlendMode -> String
show :: BlendMode -> String
$cshowList :: [BlendMode] -> String -> String
showList :: [BlendMode] -> String -> String
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
_ -> String -> BlendMode
forall a. HasCallStack => String -> a
error (String -> BlendMode) -> String -> BlendMode
forall a b. (a -> b) -> a -> b
$ String
"fromNumber<BlendMode>: unknown blend mode: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ BlendMode -> String
forall a. Show a => a -> String
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
(Rectangle a -> Rectangle a -> Bool)
-> (Rectangle a -> Rectangle a -> Bool) -> Eq (Rectangle a)
forall a. Eq a => Rectangle a -> Rectangle a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$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
/= :: Rectangle a -> Rectangle a -> Bool
Eq, (forall a b. (a -> b) -> Rectangle a -> Rectangle b)
-> (forall a b. a -> Rectangle b -> Rectangle a)
-> Functor Rectangle
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
$cfmap :: forall a b. (a -> b) -> Rectangle a -> Rectangle b
fmap :: forall a b. (a -> b) -> Rectangle a -> Rectangle b
$c<$ :: forall a b. a -> Rectangle b -> Rectangle a
<$ :: forall a b. a -> Rectangle b -> Rectangle a
Functor, (forall x. Rectangle a -> Rep (Rectangle a) x)
-> (forall x. Rep (Rectangle a) x -> Rectangle a)
-> Generic (Rectangle a)
forall x. Rep (Rectangle a) x -> Rectangle a
forall x. Rectangle a -> Rep (Rectangle a) x
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
$cfrom :: forall a x. Rectangle a -> Rep (Rectangle a) x
from :: forall x. Rectangle a -> Rep (Rectangle a) x
$cto :: forall a x. Rep (Rectangle a) x -> Rectangle a
to :: forall x. Rep (Rectangle a) x -> Rectangle a
Generic, Eq (Rectangle a)
Eq (Rectangle a) =>
(Rectangle a -> Rectangle a -> Ordering)
-> (Rectangle a -> Rectangle a -> Bool)
-> (Rectangle a -> Rectangle a -> Bool)
-> (Rectangle a -> Rectangle a -> Bool)
-> (Rectangle a -> Rectangle a -> Bool)
-> (Rectangle a -> Rectangle a -> Rectangle a)
-> (Rectangle a -> Rectangle a -> Rectangle a)
-> Ord (Rectangle a)
Rectangle a -> Rectangle a -> Bool
Rectangle a -> Rectangle a -> Ordering
Rectangle a -> Rectangle a -> Rectangle a
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
$ccompare :: forall a. Ord a => Rectangle a -> Rectangle a -> Ordering
compare :: Rectangle a -> Rectangle a -> Ordering
$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
>= :: Rectangle a -> Rectangle a -> Bool
$cmax :: forall a. Ord a => Rectangle a -> Rectangle a -> Rectangle a
max :: Rectangle a -> Rectangle a -> Rectangle a
$cmin :: forall a. Ord a => Rectangle a -> Rectangle a -> Rectangle a
min :: Rectangle a -> Rectangle a -> Rectangle a
Ord, ReadPrec [Rectangle a]
ReadPrec (Rectangle a)
Int -> ReadS (Rectangle a)
ReadS [Rectangle a]
(Int -> ReadS (Rectangle a))
-> ReadS [Rectangle a]
-> ReadPrec (Rectangle a)
-> ReadPrec [Rectangle a]
-> Read (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
$creadsPrec :: forall a. Read a => Int -> ReadS (Rectangle a)
readsPrec :: Int -> ReadS (Rectangle a)
$creadList :: forall a. Read a => ReadS [Rectangle a]
readList :: ReadS [Rectangle a]
$creadPrec :: forall a. Read a => ReadPrec (Rectangle a)
readPrec :: ReadPrec (Rectangle a)
$creadListPrec :: forall a. Read a => ReadPrec [Rectangle a]
readListPrec :: ReadPrec [Rectangle a]
Read, Int -> Rectangle a -> String -> String
[Rectangle a] -> String -> String
Rectangle a -> String
(Int -> Rectangle a -> String -> String)
-> (Rectangle a -> String)
-> ([Rectangle a] -> String -> String)
-> Show (Rectangle a)
forall a. Show a => Int -> Rectangle a -> String -> String
forall a. Show a => [Rectangle a] -> String -> String
forall a. Show a => Rectangle a -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Rectangle a -> String -> String
showsPrec :: Int -> Rectangle a -> String -> String
$cshow :: forall a. Show a => Rectangle a -> String
show :: Rectangle a -> String
$cshowList :: forall a. Show a => [Rectangle a] -> String -> String
showList :: [Rectangle a] -> String -> String
Show, Typeable)

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

newtype instance MVector s (Rectangle a) = MV_Rectangle (MVector s (Point V2 a, V2 a))
newtype instance Vector (Rectangle a) = V_Rectangle (Vector (Point V2 a, V2 a))

instance UV.Unbox a => GMV.MVector MVector (Rectangle a) where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  basicLength :: forall s. MVector s (Rectangle a) -> Int
basicLength (MV_Rectangle MVector s (Point V2 a, V2 a)
v) = MVector s (Point V2 a, V2 a) -> Int
forall s. MVector s (Point V2 a, V2 a) -> Int
forall (v :: Type -> Type -> Type) a s. MVector v a => v s a -> Int
GMV.basicLength MVector s (Point V2 a, V2 a)
v
  basicUnsafeSlice :: forall s.
Int -> Int -> MVector s (Rectangle a) -> MVector s (Rectangle a)
basicUnsafeSlice Int
m Int
n (MV_Rectangle MVector s (Point V2 a, V2 a)
v) = MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a)
forall s a. MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a)
MV_Rectangle (Int
-> Int
-> MVector s (Point V2 a, V2 a)
-> MVector s (Point V2 a, V2 a)
forall s.
Int
-> Int
-> MVector s (Point V2 a, V2 a)
-> MVector s (Point V2 a, V2 a)
forall (v :: Type -> Type -> Type) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
GMV.basicUnsafeSlice Int
m Int
n MVector s (Point V2 a, V2 a)
v)
  basicOverlaps :: forall s.
MVector s (Rectangle a) -> MVector s (Rectangle a) -> Bool
basicOverlaps (MV_Rectangle MVector s (Point V2 a, V2 a)
v) (MV_Rectangle MVector s (Point V2 a, V2 a)
u) = MVector s (Point V2 a, V2 a)
-> MVector s (Point V2 a, V2 a) -> Bool
forall s.
MVector s (Point V2 a, V2 a)
-> MVector s (Point V2 a, V2 a) -> Bool
forall (v :: Type -> Type -> Type) a s.
MVector v a =>
v s a -> v s a -> Bool
GMV.basicOverlaps MVector s (Point V2 a, V2 a)
v MVector s (Point V2 a, V2 a)
u
  basicUnsafeNew :: forall s. Int -> ST s (MVector s (Rectangle a))
basicUnsafeNew Int
n = MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a)
forall s a. MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a)
MV_Rectangle (MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a))
-> ST s (MVector s (Point V2 a, V2 a))
-> ST s (MVector s (Rectangle a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ST s (MVector s (Point V2 a, V2 a))
forall s. Int -> ST s (MVector s (Point V2 a, V2 a))
forall (v :: Type -> Type -> Type) a s.
MVector v a =>
Int -> ST s (v s a)
GMV.basicUnsafeNew Int
n
  basicUnsafeRead :: forall s. MVector s (Rectangle a) -> Int -> ST s (Rectangle a)
basicUnsafeRead (MV_Rectangle MVector s (Point V2 a, V2 a)
v) Int
i = (Point V2 a -> V2 a -> Rectangle a)
-> (Point V2 a, V2 a) -> Rectangle a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Point V2 a -> V2 a -> Rectangle a
forall a. Point V2 a -> V2 a -> Rectangle a
Rectangle ((Point V2 a, V2 a) -> Rectangle a)
-> ST s (Point V2 a, V2 a) -> ST s (Rectangle a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector s (Point V2 a, V2 a) -> Int -> ST s (Point V2 a, V2 a)
forall s.
MVector s (Point V2 a, V2 a) -> Int -> ST s (Point V2 a, V2 a)
forall (v :: Type -> Type -> Type) a s.
MVector v a =>
v s a -> Int -> ST s a
GMV.basicUnsafeRead MVector s (Point V2 a, V2 a)
v Int
i
  basicUnsafeWrite :: forall s. MVector s (Rectangle a) -> Int -> Rectangle a -> ST s ()
basicUnsafeWrite (MV_Rectangle MVector s (Point V2 a, V2 a)
v) Int
i (Rectangle Point V2 a
p V2 a
e) = MVector s (Point V2 a, V2 a)
-> Int -> (Point V2 a, V2 a) -> ST s ()
forall s.
MVector s (Point V2 a, V2 a)
-> Int -> (Point V2 a, V2 a) -> ST s ()
forall (v :: Type -> Type -> Type) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
GMV.basicUnsafeWrite MVector s (Point V2 a, V2 a)
v Int
i (Point V2 a
p, V2 a
e)
#if MIN_VERSION_vector(0,11,0)
  {-# INLINE basicInitialize #-}
  basicInitialize :: forall s. MVector s (Rectangle a) -> ST s ()
basicInitialize (MV_Rectangle MVector s (Point V2 a, V2 a)
v) = MVector s (Point V2 a, V2 a) -> ST s ()
forall s. MVector s (Point V2 a, V2 a) -> ST s ()
forall (v :: Type -> Type -> Type) a s.
MVector v a =>
v s a -> ST s ()
GMV.basicInitialize MVector s (Point V2 a, V2 a)
v
#endif

instance UV.Unbox a => GV.Vector Vector (Rectangle a) where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw   #-}
  {-# INLINE basicLength       #-}
  {-# INLINE basicUnsafeSlice  #-}
  {-# INLINE basicUnsafeIndexM #-}
  basicUnsafeFreeze :: forall s.
Mutable Vector s (Rectangle a) -> ST s (Vector (Rectangle a))
basicUnsafeFreeze (MV_Rectangle MVector s (Point V2 a, V2 a)
v) = Vector (Point V2 a, V2 a) -> Vector (Rectangle a)
forall a. Vector (Point V2 a, V2 a) -> Vector (Rectangle a)
V_Rectangle (Vector (Point V2 a, V2 a) -> Vector (Rectangle a))
-> ST s (Vector (Point V2 a, V2 a)) -> ST s (Vector (Rectangle a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Mutable Vector s (Point V2 a, V2 a)
-> ST s (Vector (Point V2 a, V2 a))
forall s.
Mutable Vector s (Point V2 a, V2 a)
-> ST s (Vector (Point V2 a, V2 a))
forall (v :: Type -> Type) a s.
Vector v a =>
Mutable v s a -> ST s (v a)
GV.basicUnsafeFreeze MVector s (Point V2 a, V2 a)
Mutable Vector s (Point V2 a, V2 a)
v
  basicUnsafeThaw :: forall s.
Vector (Rectangle a) -> ST s (Mutable Vector s (Rectangle a))
basicUnsafeThaw (V_Rectangle Vector (Point V2 a, V2 a)
v) = MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a)
forall s a. MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a)
MV_Rectangle (MVector s (Point V2 a, V2 a) -> MVector s (Rectangle a))
-> ST s (MVector s (Point V2 a, V2 a))
-> ST s (MVector s (Rectangle a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector (Point V2 a, V2 a)
-> ST s (Mutable Vector s (Point V2 a, V2 a))
forall s.
Vector (Point V2 a, V2 a)
-> ST s (Mutable Vector s (Point V2 a, V2 a))
forall (v :: Type -> Type) a s.
Vector v a =>
v a -> ST s (Mutable v s a)
GV.basicUnsafeThaw Vector (Point V2 a, V2 a)
v
  basicLength :: Vector (Rectangle a) -> Int
basicLength (V_Rectangle Vector (Point V2 a, V2 a)
v) = Vector (Point V2 a, V2 a) -> Int
forall (v :: Type -> Type) a. Vector v a => v a -> Int
GV.basicLength Vector (Point V2 a, V2 a)
v
  basicUnsafeSlice :: Int -> Int -> Vector (Rectangle a) -> Vector (Rectangle a)
basicUnsafeSlice Int
m Int
n (V_Rectangle Vector (Point V2 a, V2 a)
v) = Vector (Point V2 a, V2 a) -> Vector (Rectangle a)
forall a. Vector (Point V2 a, V2 a) -> Vector (Rectangle a)
V_Rectangle (Int
-> Int -> Vector (Point V2 a, V2 a) -> Vector (Point V2 a, V2 a)
forall (v :: Type -> Type) a.
Vector v a =>
Int -> Int -> v a -> v a
GV.basicUnsafeSlice Int
m Int
n Vector (Point V2 a, V2 a)
v)
  basicUnsafeIndexM :: Vector (Rectangle a) -> Int -> Box (Rectangle a)
basicUnsafeIndexM (V_Rectangle Vector (Point V2 a, V2 a)
v) Int
i = (Point V2 a -> V2 a -> Rectangle a)
-> (Point V2 a, V2 a) -> Rectangle a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Point V2 a -> V2 a -> Rectangle a
forall a. Point V2 a -> V2 a -> Rectangle a
Rectangle ((Point V2 a, V2 a) -> Rectangle a)
-> Box (Point V2 a, V2 a) -> Box (Rectangle a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector (Point V2 a, V2 a) -> Int -> Box (Point V2 a, V2 a)
forall (v :: Type -> Type) a. Vector v a => v a -> Int -> Box a
GV.basicUnsafeIndexM Vector (Point V2 a, V2 a)
v Int
i

instance UV.Unbox a => UV.Unbox (Rectangle a)

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 Maybe (IOVector Word8)
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 (IOVector Word8 -> Maybe (IOVector Word8)
forall a. a -> Maybe a
Just IOVector Word8
p)

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

-- | Draw a rectangle outline on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
r) Maybe (Rectangle CInt)
rect = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRect" Text
"SDL_RenderDrawRect" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect (Texture -> Ptr Rect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> m CInt
Raw.renderDrawRect Texture
r (Ptr Rect -> IO CInt)
-> (Ptr (Rectangle CInt) -> Ptr Rect)
-> Ptr (Rectangle CInt)
-> IO CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr)

-- | Draw some number of rectangles on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
r) Vector (Rectangle CInt)
rects = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRects" Text
"SDL_RenderDrawRects" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  Vector (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CInt)
rects ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rp ->
    Texture -> Ptr Rect -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> CInt -> m CInt
Raw.renderDrawRects Texture
r
                        (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rp)
                        (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Rectangle CInt) -> Int
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/SDL2/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 Texture
r) Maybe (Rectangle CInt)
rect =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRect" Text
"SDL_RenderFillRect" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  case Maybe (Rectangle CInt)
rect of
    Maybe (Rectangle CInt)
Nothing -> Texture -> Ptr Rect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> m CInt
Raw.renderFillRect Texture
r Ptr Rect
forall a. Ptr a
nullPtr
    Just (Rectangle (P (V2 CInt
x CInt
y)) (V2 CInt
w CInt
h)) -> Texture -> CInt -> CInt -> CInt -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> CInt -> CInt -> CInt -> CInt -> m CInt
Raw.renderFillRectEx Texture
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/SDL2/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 Texture
r) Vector (Rectangle CInt)
rects = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRects" Text
"SDL_RenderFillRects" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CInt)
rects ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
rp ->
      Texture -> Ptr Rect -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> CInt -> m CInt
Raw.renderFillRects Texture
r
                          (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
rp)
                          (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Rectangle CInt) -> Int
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 Texture
r) (Texture Texture
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CFloat)
dstRect = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copyF" Text
"SDL_RenderCopyF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
      (Rectangle CFloat
 -> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CFloat)
-> (Ptr (Rectangle CFloat) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CFloat -> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CFloat)
dstRect ((Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
dst ->
        Texture -> Texture -> Ptr Rect -> Ptr FRect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Texture -> Ptr Rect -> Ptr FRect -> m CInt
Raw.renderCopyF Texture
r Texture
t (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (Ptr (Rectangle CFloat) -> Ptr FRect
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 Texture
r) (Texture Texture
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CFloat)
dstRect CDouble
theta Maybe (Point V2 CFloat)
center V2 Bool
flips =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copyExF" Text
"SDL_RenderCopyExF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
  (Rectangle CFloat
 -> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CFloat)
-> (Ptr (Rectangle CFloat) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CFloat -> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CFloat)
dstRect ((Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
dst ->
  (Point V2 CFloat -> (Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt)
-> Maybe (Point V2 CFloat)
-> (Ptr (Point V2 CFloat) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Point V2 CFloat -> (Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Point V2 CFloat)
center ((Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CFloat)
c ->
  Texture
-> Texture
-> Ptr Rect
-> Ptr FRect
-> CDouble
-> Ptr FPoint
-> BlendMode
-> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture
-> Texture
-> Ptr Rect
-> Ptr FRect
-> CDouble
-> Ptr FPoint
-> BlendMode
-> m CInt
Raw.renderCopyExF Texture
r Texture
t (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (Ptr (Rectangle CFloat) -> Ptr FRect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
dst) CDouble
theta (Ptr (Point V2 CFloat) -> Ptr FPoint
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) BlendMode -> BlendMode -> BlendMode
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 Texture
r) (P (V2 CFloat
x CFloat
y)) (P (V2 CFloat
x' CFloat
y')) = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLineF" Text
"SDL_RenderDrawLineF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Texture -> CFloat -> CFloat -> CFloat -> CFloat -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> CFloat -> CFloat -> CFloat -> CFloat -> m CInt
Raw.renderDrawLineF Texture
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 Texture
r) Vector (Point V2 CFloat)
points = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLinesF" Text
"SDL_RenderDrawLinesF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector (Point V2 CFloat)
-> (Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CFloat)
points ((Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CFloat)
p ->
      Texture -> Ptr FPoint -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr FPoint -> CInt -> m CInt
Raw.renderDrawLinesF Texture
r (Ptr (Point V2 CFloat) -> Ptr FPoint
forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CFloat)
p) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Point V2 CFloat) -> Int
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 Texture
r) (P (V2 CFloat
x CFloat
y)) = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPointF" Text
"SDL_RenderDrawPointF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Texture -> CFloat -> CFloat -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> CFloat -> CFloat -> m CInt
Raw.renderDrawPointF Texture
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 Texture
r) Vector (Point V2 CFloat)
points = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPointsF" Text
"SDL_RenderDrawPointsF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector (Point V2 CFloat)
-> (Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CFloat)
points ((Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Point V2 CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CFloat)
p ->
      Texture -> Ptr FPoint -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr FPoint -> CInt -> m CInt
Raw.renderDrawPointsF Texture
r (Ptr (Point V2 CFloat) -> Ptr FPoint
forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CFloat)
p) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Point V2 CFloat) -> Int
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 Texture
r) Rectangle CFloat
rect = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRectF" Text
"SDL_RenderDrawRectF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Rectangle CFloat -> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Rectangle CFloat
rect ((Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rectPtr ->
      Texture -> Ptr FRect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr FRect -> m CInt
Raw.renderDrawRectF Texture
r (Ptr (Rectangle CFloat) -> Ptr FRect
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 Texture
r) Vector (Rectangle CFloat)
rects = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawRectsF" Text
"SDL_RenderDrawRectsF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector (Rectangle CFloat)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CFloat)
rects ((Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rp ->
      Texture -> Ptr FRect -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr FRect -> CInt -> m CInt
Raw.renderDrawRectsF Texture
r (Ptr (Rectangle CFloat) -> Ptr FRect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
rp) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Rectangle CFloat) -> Int
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 Texture
r) Rectangle CFloat
rect = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRectF" Text
"SDL_RenderFillRectF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Rectangle CFloat -> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Rectangle CFloat
rect ((Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rectPtr ->
      Texture -> Ptr FRect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr FRect -> m CInt
Raw.renderFillRectF Texture
r (Ptr (Rectangle CFloat) -> Ptr FRect
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 Texture
r) Vector (Rectangle CFloat)
rects = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.fillRectsF" Text
"SDL_RenderFillRectsF" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector (Rectangle CFloat)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Rectangle CFloat)
rects ((Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CFloat) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CFloat)
rp ->
      Texture -> Ptr FRect -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr FRect -> CInt -> m CInt
Raw.renderFillRectsF Texture
r (Ptr (Rectangle CFloat) -> Ptr FRect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CFloat)
rp) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Rectangle CFloat) -> Int
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 Texture
r) Maybe Texture
mtexture Vector Vertex
vertices Vector CInt
indices = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderGeometry" Text
"SDL_RenderGeometry" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector Vertex -> (Ptr Vertex -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector Vertex
vertices ((Ptr Vertex -> IO CInt) -> IO CInt)
-> (Ptr Vertex -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Vertex
vp ->
      Vector CInt -> (Ptr CInt -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector CInt
indices ((Ptr CInt -> IO CInt) -> IO CInt)
-> (Ptr CInt -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
ip ->
        Texture
-> Texture -> Ptr Vertex -> CInt -> Ptr CInt -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture
-> Texture -> Ptr Vertex -> CInt -> Ptr CInt -> CInt -> m CInt
Raw.renderGeometry Texture
r Texture
t Ptr Vertex
vp (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector Vertex -> Int
forall a. Storable a => Vector a -> Int
SV.length Vector Vertex
vertices)) (Ptr CInt -> Ptr CInt
ipOrNull Ptr CInt
ip) CInt
ipSize
  where
    t :: Texture
t = case Maybe Texture
mtexture of
      Just (Texture Texture
found) -> Texture
found
      Maybe Texture
Nothing -> Texture
forall a. Ptr a
nullPtr

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

    ipSize :: CInt
ipSize = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector CInt -> Int
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 Texture
r) Maybe Texture
mtexture Ptr FPoint
xy CInt
xyStride Ptr Color
color CInt
colorStride Ptr FPoint
uv CInt
uvStride CInt
numVertices Vector ix
indices = IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderGeometryRaw" Text
"SDL_RenderGeometryRaw" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Vector ix -> (Ptr ix -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector ix
indices ((Ptr ix -> IO CInt) -> IO CInt) -> (Ptr ix -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr ix
ip ->
      Texture
-> Texture
-> Ptr FPoint
-> CInt
-> Ptr Color
-> CInt
-> Ptr FPoint
-> CInt
-> CInt
-> Texture
-> CInt
-> CInt
-> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture
-> Texture
-> Ptr FPoint
-> CInt
-> Ptr Color
-> CInt
-> Ptr FPoint
-> CInt
-> CInt
-> Texture
-> CInt
-> CInt
-> m CInt
Raw.renderGeometryRaw Texture
r Texture
t Ptr FPoint
xy CInt
xyStride Ptr Color
color CInt
colorStride Ptr FPoint
uv CInt
uvStride CInt
numVertices (Ptr ix -> Texture
forall a b. Ptr a -> Ptr b
castPtr (Ptr ix -> Texture) -> Ptr ix -> Texture
forall a b. (a -> b) -> a -> b
$ Ptr ix -> Ptr ix
ipOrNull Ptr ix
ip) CInt
ipSize CInt
sizeOfip
  where
    t :: Texture
t = case Maybe Texture
mtexture of
      Just (Texture Texture
found) -> Texture
found
      Maybe Texture
Nothing -> Texture
forall a. Ptr a
nullPtr

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

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

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


-- | Clear the current rendering target with the drawing color.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
r) =
  Text -> Text -> m CInt -> m ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.clear" Text
"SDL_RenderClear" (m CInt -> m ()) -> m CInt -> m ()
forall a b. (a -> b) -> a -> b
$
  Texture -> m CInt
forall (m :: Type -> Type). MonadIO m => Texture -> m CInt
Raw.renderClear Texture
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/SDL2/SDL_RenderSetScale SDL_RenderSetScale>@ and @<https://wiki.libsdl.org/SDL2/SDL_RenderGetScale SDL_RenderGetScale>@ for C documentation.
rendererScale :: Renderer -> StateVar (V2 CFloat)
rendererScale :: Renderer -> StateVar (V2 CFloat)
rendererScale (Renderer Texture
r) = IO (V2 CFloat) -> (V2 CFloat -> IO ()) -> StateVar (V2 CFloat)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (V2 CFloat)
renderGetScale V2 CFloat -> IO ()
renderSetScale
  where
  renderSetScale :: V2 CFloat -> IO ()
renderSetScale (V2 CFloat
x CFloat
y) =
    Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetScale" Text
"SDL_RenderSetScale" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Texture -> CFloat -> CFloat -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> CFloat -> CFloat -> m CInt
Raw.renderSetScale Texture
r CFloat
x CFloat
y

  renderGetScale :: IO (V2 CFloat)
renderGetScale =
    (Ptr CFloat -> IO (V2 CFloat)) -> IO (V2 CFloat)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CFloat -> IO (V2 CFloat)) -> IO (V2 CFloat))
-> (Ptr CFloat -> IO (V2 CFloat)) -> IO (V2 CFloat)
forall a b. (a -> b) -> a -> b
$ \Ptr CFloat
w ->
    (Ptr CFloat -> IO (V2 CFloat)) -> IO (V2 CFloat)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CFloat -> IO (V2 CFloat)) -> IO (V2 CFloat))
-> (Ptr CFloat -> IO (V2 CFloat)) -> IO (V2 CFloat)
forall a b. (a -> b) -> a -> b
$ \Ptr CFloat
h -> do
      Texture -> Ptr CFloat -> Ptr CFloat -> IO ()
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr CFloat -> Ptr CFloat -> m ()
Raw.renderGetScale Texture
r Ptr CFloat
w Ptr CFloat
h
      CFloat -> CFloat -> V2 CFloat
forall a. a -> a -> V2 a
V2 (CFloat -> CFloat -> V2 CFloat)
-> IO CFloat -> IO (CFloat -> V2 CFloat)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CFloat -> IO CFloat
forall a. Storable a => Ptr a -> IO a
peek Ptr CFloat
w IO (CFloat -> V2 CFloat) -> IO CFloat -> IO (V2 CFloat)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr CFloat -> IO CFloat
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/SDL2/SDL_RenderSetClipRect SDL_RenderSetClipRect>@ and @<https://wiki.libsdl.org/SDL2/SDL_RenderGetClipRect SDL_RenderGetClipRect>@ for C documentation.
rendererClipRect :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererClipRect :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererClipRect (Renderer Texture
r) = IO (Maybe (Rectangle CInt))
-> (Maybe (Rectangle CInt) -> IO ())
-> StateVar (Maybe (Rectangle CInt))
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (Rectangle CInt))
renderGetClipRect Maybe (Rectangle CInt) -> IO ()
renderSetClipRect
  where
  renderGetClipRect :: IO (Maybe (Rectangle CInt))
renderGetClipRect =
    (Ptr Rect -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Rect -> IO (Maybe (Rectangle CInt)))
 -> IO (Maybe (Rectangle CInt)))
-> (Ptr Rect -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr Rect
rPtr -> do
      Texture -> Ptr Rect -> IO ()
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> m ()
Raw.renderGetClipRect Texture
r Ptr Rect
rPtr
      (Ptr (Rectangle CInt) -> IO (Rectangle CInt))
-> Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt))
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr (Rectangle CInt) -> IO (Rectangle CInt)
forall a. Storable a => Ptr a -> IO a
peek (Ptr Rect -> Ptr (Rectangle CInt)
forall a b. Ptr a -> Ptr b
castPtr Ptr Rect
rPtr)
  renderSetClipRect :: Maybe (Rectangle CInt) -> IO ()
renderSetClipRect Maybe (Rectangle CInt)
rect =
    Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetClipRect" Text
"SDL_RenderSetClipRect" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Texture -> Ptr Rect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> m CInt
Raw.renderSetClipRect Texture
r (Ptr Rect -> IO CInt)
-> (Ptr (Rectangle CInt) -> Ptr Rect)
-> Ptr (Rectangle CInt)
-> IO CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr (Rectangle CInt) -> Ptr Rect
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/SDL2/SDL_RenderSetViewport SDL_RenderSetViewport>@ and @<https://wiki.libsdl.org/SDL2/SDL_RenderGetViewport SDL_RenderGetViewport>@ for C documentation.
rendererViewport :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererViewport :: Renderer -> StateVar (Maybe (Rectangle CInt))
rendererViewport (Renderer Texture
r) = IO (Maybe (Rectangle CInt))
-> (Maybe (Rectangle CInt) -> IO ())
-> StateVar (Maybe (Rectangle CInt))
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (Rectangle CInt))
renderGetViewport Maybe (Rectangle CInt) -> IO ()
renderSetViewport
  where
  renderGetViewport :: IO (Maybe (Rectangle CInt))
renderGetViewport =
    (Ptr Rect -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Rect -> IO (Maybe (Rectangle CInt)))
 -> IO (Maybe (Rectangle CInt)))
-> (Ptr Rect -> IO (Maybe (Rectangle CInt)))
-> IO (Maybe (Rectangle CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr Rect
rect -> do
      Texture -> Ptr Rect -> IO ()
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> m ()
Raw.renderGetViewport Texture
r Ptr Rect
rect
      (Ptr (Rectangle CInt) -> IO (Rectangle CInt))
-> Ptr (Rectangle CInt) -> IO (Maybe (Rectangle CInt))
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr (Rectangle CInt) -> IO (Rectangle CInt)
forall a. Storable a => Ptr a -> IO a
peek (Ptr Rect -> Ptr (Rectangle CInt)
forall a b. Ptr a -> Ptr b
castPtr Ptr Rect
rect)

  renderSetViewport :: Maybe (Rectangle CInt) -> IO ()
renderSetViewport Maybe (Rectangle CInt)
rect =
    Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetViewport" Text
"SDL_RenderSetViewport" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
rect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Texture -> Ptr Rect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Rect -> m CInt
Raw.renderSetViewport Texture
r (Ptr Rect -> IO CInt)
-> (Ptr (Rectangle CInt) -> Ptr Rect)
-> Ptr (Rectangle CInt)
-> IO CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr (Rectangle CInt) -> Ptr Rect
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/SDL2/SDL_RenderPresent SDL_RenderPresent>@ for C documentation.
present :: MonadIO m => Renderer -> m ()
present :: forall (m :: Type -> Type). MonadIO m => Renderer -> m ()
present (Renderer Texture
r) = Texture -> m ()
forall (m :: Type -> Type). MonadIO m => Texture -> m ()
Raw.renderPresent Texture
r

-- | Copy a portion of the texture to the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
r) (Texture Texture
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CInt)
dstRect =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copy" Text
"SDL_RenderCopy" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
dstRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dst ->
  Texture -> Texture -> Ptr Rect -> Ptr Rect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Texture -> Ptr Rect -> Ptr Rect -> m CInt
Raw.renderCopy Texture
r Texture
t (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (Ptr (Rectangle CInt) -> Ptr Rect
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/SDL2/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 Texture
r) (Texture Texture
t) Maybe (Rectangle CInt)
srcRect Maybe (Rectangle CInt)
dstRect CDouble
theta Maybe (Point V2 CInt)
center V2 Bool
flips =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.copyEx" Text
"SDL_RenderCopyEx" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
src ->
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
dstRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dst ->
  (Point V2 CInt -> (Ptr (Point V2 CInt) -> IO CInt) -> IO CInt)
-> Maybe (Point V2 CInt)
-> (Ptr (Point V2 CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Point V2 CInt -> (Ptr (Point V2 CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Point V2 CInt)
center ((Ptr (Point V2 CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Point V2 CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CInt)
c ->
  Texture
-> Texture
-> Ptr Rect
-> Ptr Rect
-> CDouble
-> Ptr Point
-> BlendMode
-> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture
-> Texture
-> Ptr Rect
-> Ptr Rect
-> CDouble
-> Ptr Point
-> BlendMode
-> m CInt
Raw.renderCopyEx Texture
r Texture
t (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
src) (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
dst) CDouble
theta (Ptr (Point V2 CInt) -> Ptr Point
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) BlendMode -> BlendMode -> BlendMode
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/SDL2/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 Texture
r) (P (V2 CInt
x CInt
y)) (P (V2 CInt
x' CInt
y')) =
  Text -> Text -> m CInt -> m ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLine" Text
"SDL_RenderDrawLine" (m CInt -> m ()) -> m CInt -> m ()
forall a b. (a -> b) -> a -> b
$
  Texture -> CInt -> CInt -> CInt -> CInt -> m CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> CInt -> CInt -> CInt -> CInt -> m CInt
Raw.renderDrawLine Texture
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/SDL2/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 Texture
r) Vector (Point V2 CInt)
points =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawLines" Text
"SDL_RenderDrawLines" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  Vector (Point V2 CInt)
-> (Ptr (Point V2 CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CInt)
points ((Ptr (Point V2 CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Point V2 CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CInt)
cp ->
    Texture -> Ptr Point -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Point -> CInt -> m CInt
Raw.renderDrawLines Texture
r
                        (Ptr (Point V2 CInt) -> Ptr Point
forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CInt)
cp)
                        (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Point V2 CInt) -> Int
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/SDL2/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 Texture
r) (P (V2 CInt
x CInt
y)) =
  Text -> Text -> m CInt -> m ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPoint" Text
"SDL_RenderDrawPoint" (m CInt -> m ()) -> m CInt -> m ()
forall a b. (a -> b) -> a -> b
$
  Texture -> CInt -> CInt -> m CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> CInt -> CInt -> m CInt
Raw.renderDrawPoint Texture
r CInt
x CInt
y

-- | Draw multiple points on the current rendering target.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
r) Vector (Point V2 CInt)
points =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.drawPoints" Text
"SDL_RenderDrawPoints" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  Vector (Point V2 CInt)
-> (Ptr (Point V2 CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
SV.unsafeWith Vector (Point V2 CInt)
points ((Ptr (Point V2 CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Point V2 CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Point V2 CInt)
cp ->
    Texture -> Ptr Point -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Point -> CInt -> m CInt
Raw.renderDrawPoints Texture
r
                         (Ptr (Point V2 CInt) -> Ptr Point
forall a b. Ptr a -> Ptr b
castPtr Ptr (Point V2 CInt)
cp)
                         (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Vector (Point V2 CInt) -> Int
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/SDL2/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) =
  (Ptr Surface -> Surface) -> m (Ptr Surface) -> m Surface
forall a b. (a -> b) -> m a -> m b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Ptr Surface -> Surface
unmanagedSurface (m (Ptr Surface) -> m Surface) -> m (Ptr Surface) -> m Surface
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> m (Ptr Surface) -> m (Ptr Surface)
forall (m :: Type -> Type) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull Text
"SDL.Video.Renderer.convertSurface" Text
"SDL_ConvertSurface" (m (Ptr Surface) -> m (Ptr Surface))
-> m (Ptr Surface) -> m (Ptr Surface)
forall a b. (a -> b) -> a -> b
$
  Ptr Surface -> Ptr PixelFormat -> BlendMode -> m (Ptr Surface)
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/SDL2/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 =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.blitSurface" Text
"SDL_BlitSurface" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
srcRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
srcPtr ->
  (Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> Maybe (Rectangle CInt)
-> (Ptr (Rectangle CInt) -> IO CInt)
-> IO CInt
forall a b c.
(a -> (Ptr b -> IO c) -> IO c)
-> Maybe a -> (Ptr b -> IO c) -> IO c
maybeWith Rectangle CInt -> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Maybe (Rectangle CInt)
dstRect ((Ptr (Rectangle CInt) -> IO CInt) -> IO CInt)
-> (Ptr (Rectangle CInt) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr (Rectangle CInt)
dstPtr ->
  Ptr Surface -> Ptr Rect -> Ptr Surface -> Ptr Rect -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr Rect -> Ptr Surface -> Ptr Rect -> m CInt
Raw.blitScaled Ptr Surface
src (Ptr (Rectangle CInt) -> Ptr Rect
forall a b. Ptr a -> Ptr b
castPtr Ptr (Rectangle CInt)
srcPtr) Ptr Surface
dst (Ptr (Rectangle CInt) -> Ptr Rect
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/SDL2/SDL_SetColorKey SDL_SetColorKey>@ and @<https://wiki.libsdl.org/SDL2/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)
_) = IO (Maybe (V4 Word8))
-> (Maybe (V4 Word8) -> IO ()) -> StateVar (Maybe (V4 Word8))
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (V4 Word8))
getColorKey Maybe (V4 Word8) -> IO ()
setColorKey
  where
  getColorKey :: IO (Maybe (V4 Word8))
getColorKey =
    (Ptr BlendMode -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8)))
-> (Ptr BlendMode -> IO (Maybe (V4 Word8)))
-> IO (Maybe (V4 Word8))
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
keyPtr -> do
      ret <- Ptr Surface -> Ptr BlendMode -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr BlendMode -> m CInt
Raw.getColorKey Ptr Surface
s Ptr BlendMode
keyPtr
      if ret == -1
        then return Nothing
        else do format <- liftIO (Raw.surfaceFormat <$> peek s)
                mapped <- peek keyPtr
                alloca $ \Ptr Word8
r ->
                  (Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8)))
-> (Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8))
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
g ->
                  (Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8)))
-> (Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8))
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
b ->
                  (Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8)))
-> (Ptr Word8 -> IO (Maybe (V4 Word8))) -> IO (Maybe (V4 Word8))
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
a ->
                    do BlendMode
-> Ptr PixelFormat
-> Ptr Word8
-> Ptr Word8
-> Ptr Word8
-> Ptr Word8
-> IO ()
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
                       V4 Word8 -> Maybe (V4 Word8)
forall a. a -> Maybe a
Just (V4 Word8 -> Maybe (V4 Word8))
-> IO (V4 Word8) -> IO (Maybe (V4 Word8))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (Word8 -> Word8 -> Word8 -> Word8 -> V4 Word8
forall a. a -> a -> a -> a -> V4 a
V4 (Word8 -> Word8 -> Word8 -> Word8 -> V4 Word8)
-> IO Word8 -> IO (Word8 -> Word8 -> Word8 -> V4 Word8)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
r IO (Word8 -> Word8 -> Word8 -> V4 Word8)
-> IO Word8 -> IO (Word8 -> Word8 -> V4 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
g IO (Word8 -> Word8 -> V4 Word8)
-> IO Word8 -> IO (Word8 -> V4 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
b IO (Word8 -> V4 Word8) -> IO Word8 -> IO (V4 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
a)
  setColorKey :: Maybe (V4 Word8) -> IO ()
setColorKey Maybe (V4 Word8)
key =
    Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    case Maybe (V4 Word8)
key of
      Maybe (V4 Word8)
Nothing ->
        (Ptr BlendMode -> IO CInt) -> IO CInt
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO CInt) -> IO CInt)
-> (Ptr BlendMode -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
keyPtr -> do
          -- TODO Error checking?
          ret <- Ptr Surface -> Ptr BlendMode -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr BlendMode -> m CInt
Raw.getColorKey Ptr Surface
s Ptr BlendMode
keyPtr
          if ret == -1
            -- if ret == -1 then there is no key enabled, so we have nothing to
            -- do.
            then return 0
            else do key' <- peek keyPtr
                    Raw.setColorKey s 0 key'

      Just (V4 Word8
r Word8
g Word8
b Word8
a) -> do
        format <- IO (Ptr PixelFormat) -> IO (Ptr PixelFormat)
forall a. IO a -> IO a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (Surface -> Ptr PixelFormat
Raw.surfaceFormat (Surface -> Ptr PixelFormat) -> IO Surface -> IO (Ptr PixelFormat)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Surface -> IO Surface
forall a. Storable a => Ptr a -> IO a
peek Ptr Surface
s)
        Raw.mapRGBA format r g b a >>= Raw.setColorKey s 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/SDL2/SDL_SetTextureColorMod SDL_SetTextureColorMod>@ and @<https://wiki.libsdl.org/SDL2/SDL_GetTextureColorMod SDL_GetTextureColorMod>@ for C documentation.
textureColorMod :: Texture -> StateVar (V3 Word8)
textureColorMod :: Texture -> StateVar (V3 Word8)
textureColorMod (Texture Texture
t) = IO (V3 Word8) -> (V3 Word8 -> IO ()) -> StateVar (V3 Word8)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (V3 Word8)
getTextureColorMod V3 Word8 -> IO ()
setTextureColorMod
  where
  getTextureColorMod :: IO (V3 Word8)
getTextureColorMod =
    (Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8))
-> (Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8)
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
r ->
    (Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8))
-> (Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8)
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
g ->
    (Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8))
-> (Ptr Word8 -> IO (V3 Word8)) -> IO (V3 Word8)
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
b -> do
      Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
        Texture -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> m CInt
Raw.getTextureColorMod Texture
t Ptr Word8
r Ptr Word8
g Ptr Word8
b
      Word8 -> Word8 -> Word8 -> V3 Word8
forall a. a -> a -> a -> V3 a
V3 (Word8 -> Word8 -> Word8 -> V3 Word8)
-> IO Word8 -> IO (Word8 -> Word8 -> V3 Word8)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
r IO (Word8 -> Word8 -> V3 Word8)
-> IO Word8 -> IO (Word8 -> V3 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
g IO (Word8 -> V3 Word8) -> IO Word8 -> IO (V3 Word8)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
b

  setTextureColorMod :: V3 Word8 -> IO ()
setTextureColorMod (V3 Word8
r Word8
g Word8
b) =
    Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Texture -> Word8 -> Word8 -> Word8 -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Word8 -> Word8 -> Word8 -> m CInt
Raw.setTextureColorMod Texture
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
Typeable 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 (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PixelFormat)
-> (PixelFormat -> Constr)
-> (PixelFormat -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> PixelFormat -> PixelFormat)
-> (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 u. (forall d. Data d => d -> u) -> PixelFormat -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PixelFormat -> u)
-> (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 (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat)
-> Data PixelFormat
PixelFormat -> Constr
PixelFormat -> DataType
(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)
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PixelFormat -> 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
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PixelFormat
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PixelFormat
$ctoConstr :: PixelFormat -> Constr
toConstr :: PixelFormat -> Constr
$cdataTypeOf :: PixelFormat -> DataType
dataTypeOf :: PixelFormat -> DataType
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PixelFormat)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> 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)
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)
$cgmapT :: (forall b. Data b => b -> b) -> PixelFormat -> PixelFormat
gmapT :: (forall b. Data b => b -> b) -> PixelFormat -> PixelFormat
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PixelFormat -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PixelFormat -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PixelFormat -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PixelFormat -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PixelFormat -> u
$cgmapM :: forall (m :: Type -> Type).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PixelFormat -> m PixelFormat
Data, PixelFormat -> PixelFormat -> Bool
(PixelFormat -> PixelFormat -> Bool)
-> (PixelFormat -> PixelFormat -> Bool) -> Eq PixelFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PixelFormat -> PixelFormat -> Bool
== :: PixelFormat -> PixelFormat -> Bool
$c/= :: PixelFormat -> PixelFormat -> Bool
/= :: PixelFormat -> PixelFormat -> Bool
Eq, (forall x. PixelFormat -> Rep PixelFormat x)
-> (forall x. Rep PixelFormat x -> PixelFormat)
-> Generic PixelFormat
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
$cfrom :: forall x. PixelFormat -> Rep PixelFormat x
from :: forall x. PixelFormat -> Rep PixelFormat x
$cto :: forall x. Rep PixelFormat x -> PixelFormat
to :: forall x. Rep PixelFormat x -> PixelFormat
Generic, Eq PixelFormat
Eq PixelFormat =>
(PixelFormat -> PixelFormat -> Ordering)
-> (PixelFormat -> PixelFormat -> Bool)
-> (PixelFormat -> PixelFormat -> Bool)
-> (PixelFormat -> PixelFormat -> Bool)
-> (PixelFormat -> PixelFormat -> Bool)
-> (PixelFormat -> PixelFormat -> PixelFormat)
-> (PixelFormat -> PixelFormat -> PixelFormat)
-> Ord 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
$ccompare :: PixelFormat -> PixelFormat -> Ordering
compare :: PixelFormat -> PixelFormat -> Ordering
$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
>= :: PixelFormat -> PixelFormat -> Bool
$cmax :: PixelFormat -> PixelFormat -> PixelFormat
max :: PixelFormat -> PixelFormat -> PixelFormat
$cmin :: PixelFormat -> PixelFormat -> PixelFormat
min :: PixelFormat -> PixelFormat -> PixelFormat
Ord, ReadPrec [PixelFormat]
ReadPrec PixelFormat
Int -> ReadS PixelFormat
ReadS [PixelFormat]
(Int -> ReadS PixelFormat)
-> ReadS [PixelFormat]
-> ReadPrec PixelFormat
-> ReadPrec [PixelFormat]
-> Read PixelFormat
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PixelFormat
readsPrec :: Int -> ReadS PixelFormat
$creadList :: ReadS [PixelFormat]
readList :: ReadS [PixelFormat]
$creadPrec :: ReadPrec PixelFormat
readPrec :: ReadPrec PixelFormat
$creadListPrec :: ReadPrec [PixelFormat]
readListPrec :: ReadPrec [PixelFormat]
Read, Int -> PixelFormat -> String -> String
[PixelFormat] -> String -> String
PixelFormat -> String
(Int -> PixelFormat -> String -> String)
-> (PixelFormat -> String)
-> ([PixelFormat] -> String -> String)
-> Show PixelFormat
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> PixelFormat -> String -> String
showsPrec :: Int -> PixelFormat -> String -> String
$cshow :: PixelFormat -> String
show :: PixelFormat -> String
$cshowList :: [PixelFormat] -> String -> String
showList :: [PixelFormat] -> String -> String
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
_ -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_UNKNOWN
    PixelFormat
Index1LSB -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX1LSB
    PixelFormat
Index1MSB -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX1MSB
    PixelFormat
Index4LSB -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX4LSB
    PixelFormat
Index4MSB -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX4MSB
    PixelFormat
Index8 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_INDEX8
    PixelFormat
RGB332 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB332
    PixelFormat
RGB444 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB444
    PixelFormat
RGB555 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB555
    PixelFormat
BGR555 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR555
    PixelFormat
ARGB4444 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB4444
    PixelFormat
RGBA4444 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBA4444
    PixelFormat
ABGR4444 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ABGR4444
    PixelFormat
BGRA4444 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRA4444
    PixelFormat
ARGB1555 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB1555
    PixelFormat
RGBA5551 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBA5551
    PixelFormat
ABGR1555 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ABGR1555
    PixelFormat
BGRA5551 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRA5551
    PixelFormat
RGB565 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB565
    PixelFormat
BGR565 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR565
    PixelFormat
RGB24 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB24
    PixelFormat
BGR24 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR24
    PixelFormat
RGB888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGB888
    PixelFormat
RGBX8888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBX8888
    PixelFormat
BGR888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGR888
    PixelFormat
BGRX8888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRX8888
    PixelFormat
ARGB8888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB8888
    PixelFormat
RGBA8888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_RGBA8888
    PixelFormat
ABGR8888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ABGR8888
    PixelFormat
BGRA8888 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_BGRA8888
    PixelFormat
ARGB2101010 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_ARGB2101010
    PixelFormat
YV12 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_YV12
    PixelFormat
IYUV -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_IYUV
    PixelFormat
YUY2 -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_YUY2
    PixelFormat
UYVY -> BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_PIXELFORMAT_UYVY
    PixelFormat
YVYU -> BlendMode
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
RendererType -> RendererType -> Bounded RendererType
forall a. a -> a -> Bounded a
$cminBound :: RendererType
minBound :: RendererType
$cmaxBound :: RendererType
maxBound :: RendererType
Bounded, Typeable RendererType
Typeable 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 (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c RendererType)
-> (RendererType -> Constr)
-> (RendererType -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> RendererType -> RendererType)
-> (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 u. (forall d. Data d => d -> u) -> RendererType -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> RendererType -> u)
-> (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 (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> RendererType -> m RendererType)
-> Data RendererType
RendererType -> Constr
RendererType -> DataType
(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)
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererType -> 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
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererType
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererType
$ctoConstr :: RendererType -> Constr
toConstr :: RendererType -> Constr
$cdataTypeOf :: RendererType -> DataType
dataTypeOf :: RendererType -> DataType
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererType)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> 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)
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)
$cgmapT :: (forall b. Data b => b -> b) -> RendererType -> RendererType
gmapT :: (forall b. Data b => b -> b) -> RendererType -> RendererType
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererType -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> RendererType -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> RendererType -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RendererType -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RendererType -> u
$cgmapM :: forall (m :: Type -> Type).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RendererType -> m RendererType
Data, Int -> RendererType
RendererType -> Int
RendererType -> [RendererType]
RendererType -> RendererType
RendererType -> RendererType -> [RendererType]
RendererType -> RendererType -> RendererType -> [RendererType]
(RendererType -> RendererType)
-> (RendererType -> RendererType)
-> (Int -> RendererType)
-> (RendererType -> Int)
-> (RendererType -> [RendererType])
-> (RendererType -> RendererType -> [RendererType])
-> (RendererType -> RendererType -> [RendererType])
-> (RendererType -> RendererType -> RendererType -> [RendererType])
-> Enum 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
$csucc :: RendererType -> RendererType
succ :: RendererType -> RendererType
$cpred :: RendererType -> RendererType
pred :: RendererType -> RendererType
$ctoEnum :: Int -> RendererType
toEnum :: Int -> RendererType
$cfromEnum :: RendererType -> Int
fromEnum :: RendererType -> Int
$cenumFrom :: RendererType -> [RendererType]
enumFrom :: RendererType -> [RendererType]
$cenumFromThen :: RendererType -> RendererType -> [RendererType]
enumFromThen :: RendererType -> RendererType -> [RendererType]
$cenumFromTo :: RendererType -> RendererType -> [RendererType]
enumFromTo :: RendererType -> RendererType -> [RendererType]
$cenumFromThenTo :: RendererType -> RendererType -> RendererType -> [RendererType]
enumFromThenTo :: RendererType -> RendererType -> RendererType -> [RendererType]
Enum, RendererType -> RendererType -> Bool
(RendererType -> RendererType -> Bool)
-> (RendererType -> RendererType -> Bool) -> Eq RendererType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RendererType -> RendererType -> Bool
== :: RendererType -> RendererType -> Bool
$c/= :: RendererType -> RendererType -> Bool
/= :: RendererType -> RendererType -> Bool
Eq, (forall x. RendererType -> Rep RendererType x)
-> (forall x. Rep RendererType x -> RendererType)
-> Generic RendererType
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
$cfrom :: forall x. RendererType -> Rep RendererType x
from :: forall x. RendererType -> Rep RendererType x
$cto :: forall x. Rep RendererType x -> RendererType
to :: forall x. Rep RendererType x -> RendererType
Generic, Eq RendererType
Eq RendererType =>
(RendererType -> RendererType -> Ordering)
-> (RendererType -> RendererType -> Bool)
-> (RendererType -> RendererType -> Bool)
-> (RendererType -> RendererType -> Bool)
-> (RendererType -> RendererType -> Bool)
-> (RendererType -> RendererType -> RendererType)
-> (RendererType -> RendererType -> RendererType)
-> Ord 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
$ccompare :: RendererType -> RendererType -> Ordering
compare :: RendererType -> RendererType -> Ordering
$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
>= :: RendererType -> RendererType -> Bool
$cmax :: RendererType -> RendererType -> RendererType
max :: RendererType -> RendererType -> RendererType
$cmin :: RendererType -> RendererType -> RendererType
min :: RendererType -> RendererType -> RendererType
Ord, ReadPrec [RendererType]
ReadPrec RendererType
Int -> ReadS RendererType
ReadS [RendererType]
(Int -> ReadS RendererType)
-> ReadS [RendererType]
-> ReadPrec RendererType
-> ReadPrec [RendererType]
-> Read RendererType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RendererType
readsPrec :: Int -> ReadS RendererType
$creadList :: ReadS [RendererType]
readList :: ReadS [RendererType]
$creadPrec :: ReadPrec RendererType
readPrec :: ReadPrec RendererType
$creadListPrec :: ReadPrec [RendererType]
readListPrec :: ReadPrec [RendererType]
Read, Int -> RendererType -> String -> String
[RendererType] -> String -> String
RendererType -> String
(Int -> RendererType -> String -> String)
-> (RendererType -> String)
-> ([RendererType] -> String -> String)
-> Show RendererType
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> RendererType -> String -> String
showsPrec :: Int -> RendererType -> String -> String
$cshow :: RendererType -> String
show :: RendererType -> String
$cshowList :: [RendererType] -> String -> String
showList :: [RendererType] -> String -> String
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
Typeable 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 (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c RendererConfig)
-> (RendererConfig -> Constr)
-> (RendererConfig -> DataType)
-> (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))
-> ((forall b. Data b => b -> b)
    -> RendererConfig -> RendererConfig)
-> (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 u.
    (forall d. Data d => d -> u) -> RendererConfig -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> RendererConfig -> u)
-> (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 (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> RendererConfig -> m RendererConfig)
-> Data RendererConfig
RendererConfig -> Constr
RendererConfig -> DataType
(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)
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RendererConfig -> 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
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererConfig
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RendererConfig
$ctoConstr :: RendererConfig -> Constr
toConstr :: RendererConfig -> Constr
$cdataTypeOf :: RendererConfig -> DataType
dataTypeOf :: RendererConfig -> DataType
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RendererConfig)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> 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)
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)
$cgmapT :: (forall b. Data b => b -> b) -> RendererConfig -> RendererConfig
gmapT :: (forall b. Data b => b -> b) -> RendererConfig -> RendererConfig
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RendererConfig -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> RendererConfig -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> RendererConfig -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> RendererConfig -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> RendererConfig -> u
$cgmapM :: forall (m :: Type -> Type).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> RendererConfig -> m RendererConfig
Data, RendererConfig -> RendererConfig -> Bool
(RendererConfig -> RendererConfig -> Bool)
-> (RendererConfig -> RendererConfig -> Bool) -> Eq RendererConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RendererConfig -> RendererConfig -> Bool
== :: RendererConfig -> RendererConfig -> Bool
$c/= :: RendererConfig -> RendererConfig -> Bool
/= :: RendererConfig -> RendererConfig -> Bool
Eq, (forall x. RendererConfig -> Rep RendererConfig x)
-> (forall x. Rep RendererConfig x -> RendererConfig)
-> Generic RendererConfig
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
$cfrom :: forall x. RendererConfig -> Rep RendererConfig x
from :: forall x. RendererConfig -> Rep RendererConfig x
$cto :: forall x. Rep RendererConfig x -> RendererConfig
to :: forall x. Rep RendererConfig x -> RendererConfig
Generic, Eq RendererConfig
Eq RendererConfig =>
(RendererConfig -> RendererConfig -> Ordering)
-> (RendererConfig -> RendererConfig -> Bool)
-> (RendererConfig -> RendererConfig -> Bool)
-> (RendererConfig -> RendererConfig -> Bool)
-> (RendererConfig -> RendererConfig -> Bool)
-> (RendererConfig -> RendererConfig -> RendererConfig)
-> (RendererConfig -> RendererConfig -> RendererConfig)
-> Ord 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
$ccompare :: RendererConfig -> RendererConfig -> Ordering
compare :: RendererConfig -> RendererConfig -> Ordering
$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
>= :: RendererConfig -> RendererConfig -> Bool
$cmax :: RendererConfig -> RendererConfig -> RendererConfig
max :: RendererConfig -> RendererConfig -> RendererConfig
$cmin :: RendererConfig -> RendererConfig -> RendererConfig
min :: RendererConfig -> RendererConfig -> RendererConfig
Ord, ReadPrec [RendererConfig]
ReadPrec RendererConfig
Int -> ReadS RendererConfig
ReadS [RendererConfig]
(Int -> ReadS RendererConfig)
-> ReadS [RendererConfig]
-> ReadPrec RendererConfig
-> ReadPrec [RendererConfig]
-> Read RendererConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RendererConfig
readsPrec :: Int -> ReadS RendererConfig
$creadList :: ReadS [RendererConfig]
readList :: ReadS [RendererConfig]
$creadPrec :: ReadPrec RendererConfig
readPrec :: ReadPrec RendererConfig
$creadListPrec :: ReadPrec [RendererConfig]
readListPrec :: ReadPrec [RendererConfig]
Read, Int -> RendererConfig -> String -> String
[RendererConfig] -> String -> String
RendererConfig -> String
(Int -> RendererConfig -> String -> String)
-> (RendererConfig -> String)
-> ([RendererConfig] -> String -> String)
-> Show RendererConfig
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> RendererConfig -> String -> String
showsPrec :: Int -> RendererConfig -> String -> String
$cshow :: RendererConfig -> String
show :: RendererConfig -> String
$cshowList :: [RendererConfig] -> String -> String
showList :: [RendererConfig] -> String -> String
Show, Typeable)

instance FromNumber RendererConfig Word32 where
  fromNumber :: BlendMode -> RendererConfig
fromNumber BlendMode
n = RendererConfig
    { rendererType :: RendererType
rendererType          = Bool -> Bool -> Bool -> RendererType
rendererType'
                                (BlendMode
n BlendMode -> BlendMode -> BlendMode
forall a. Bits a => a -> a -> a
.&. BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_SOFTWARE BlendMode -> BlendMode -> Bool
forall a. Eq a => a -> a -> Bool
/= BlendMode
0)
                                (BlendMode
n BlendMode -> BlendMode -> BlendMode
forall a. Bits a => a -> a -> a
.&. BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_ACCELERATED BlendMode -> BlendMode -> Bool
forall a. Eq a => a -> a -> Bool
/= BlendMode
0)
                                (BlendMode
n BlendMode -> BlendMode -> BlendMode
forall a. Bits a => a -> a -> a
.&. BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_PRESENTVSYNC BlendMode -> BlendMode -> Bool
forall a. Eq a => a -> a -> Bool
/= BlendMode
0)
    , rendererTargetTexture :: Bool
rendererTargetTexture = BlendMode
n BlendMode -> BlendMode -> BlendMode
forall a. Bits a => a -> a -> a
.&. BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_TARGETTEXTURE BlendMode -> BlendMode -> Bool
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 = (BlendMode -> BlendMode -> BlendMode)
-> BlendMode -> [BlendMode] -> BlendMode
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr BlendMode -> BlendMode -> BlendMode
forall a. Bits a => a -> a -> a
(.|.) BlendMode
0
    [ if Bool
isSoftware then BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_SOFTWARE else BlendMode
0
    , if Bool -> Bool
not Bool
isSoftware then BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_ACCELERATED else BlendMode
0
    , if RendererConfig -> RendererType
rendererType RendererConfig
config RendererType -> RendererType -> Bool
forall a. Eq a => a -> a -> Bool
== RendererType
AcceleratedVSyncRenderer then BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_PRESENTVSYNC  else BlendMode
0
    , if RendererConfig -> Bool
rendererTargetTexture RendererConfig
config then BlendMode
forall {a}. (Eq a, Num a) => a
Raw.SDL_RENDERER_TARGETTEXTURE else BlendMode
0
    ]
    where
      isSoftware :: Bool
isSoftware = RendererConfig -> RendererType
rendererType RendererConfig
config RendererType -> RendererType -> Bool
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
(RendererInfo -> RendererInfo -> Bool)
-> (RendererInfo -> RendererInfo -> Bool) -> Eq RendererInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RendererInfo -> RendererInfo -> Bool
== :: RendererInfo -> RendererInfo -> Bool
$c/= :: RendererInfo -> RendererInfo -> Bool
/= :: RendererInfo -> RendererInfo -> Bool
Eq, (forall x. RendererInfo -> Rep RendererInfo x)
-> (forall x. Rep RendererInfo x -> RendererInfo)
-> Generic RendererInfo
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
$cfrom :: forall x. RendererInfo -> Rep RendererInfo x
from :: forall x. RendererInfo -> Rep RendererInfo x
$cto :: forall x. Rep RendererInfo x -> RendererInfo
to :: forall x. Rep RendererInfo x -> RendererInfo
Generic, Eq RendererInfo
Eq RendererInfo =>
(RendererInfo -> RendererInfo -> Ordering)
-> (RendererInfo -> RendererInfo -> Bool)
-> (RendererInfo -> RendererInfo -> Bool)
-> (RendererInfo -> RendererInfo -> Bool)
-> (RendererInfo -> RendererInfo -> Bool)
-> (RendererInfo -> RendererInfo -> RendererInfo)
-> (RendererInfo -> RendererInfo -> RendererInfo)
-> Ord 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
$ccompare :: RendererInfo -> RendererInfo -> Ordering
compare :: RendererInfo -> RendererInfo -> Ordering
$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
>= :: RendererInfo -> RendererInfo -> Bool
$cmax :: RendererInfo -> RendererInfo -> RendererInfo
max :: RendererInfo -> RendererInfo -> RendererInfo
$cmin :: RendererInfo -> RendererInfo -> RendererInfo
min :: RendererInfo -> RendererInfo -> RendererInfo
Ord, ReadPrec [RendererInfo]
ReadPrec RendererInfo
Int -> ReadS RendererInfo
ReadS [RendererInfo]
(Int -> ReadS RendererInfo)
-> ReadS [RendererInfo]
-> ReadPrec RendererInfo
-> ReadPrec [RendererInfo]
-> Read RendererInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RendererInfo
readsPrec :: Int -> ReadS RendererInfo
$creadList :: ReadS [RendererInfo]
readList :: ReadS [RendererInfo]
$creadPrec :: ReadPrec RendererInfo
readPrec :: ReadPrec RendererInfo
$creadListPrec :: ReadPrec [RendererInfo]
readListPrec :: ReadPrec [RendererInfo]
Read, Int -> RendererInfo -> String -> String
[RendererInfo] -> String -> String
RendererInfo -> String
(Int -> RendererInfo -> String -> String)
-> (RendererInfo -> String)
-> ([RendererInfo] -> String -> String)
-> Show RendererInfo
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> RendererInfo -> String -> String
showsPrec :: Int -> RendererInfo -> String -> String
$cshow :: RendererInfo -> String
show :: RendererInfo -> String
$cshowList :: [RendererInfo] -> String -> String
showList :: [RendererInfo] -> String -> String
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) = IO RendererInfo -> m RendererInfo
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO RendererInfo -> m RendererInfo)
-> IO RendererInfo -> m RendererInfo
forall a b. (a -> b) -> a -> b
$ do
    name' <- ByteString -> Text
Text.decodeUtf8 (ByteString -> Text) -> IO ByteString -> IO Text
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> CString -> IO ByteString
BS.packCString CString
name
    return $ RendererInfo name' (fromNumber flgs) ntf (fmap fromNumber tfs) mtw mth

-- | Get information about a rendering context.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
renderer) = IO RendererInfo -> m RendererInfo
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO RendererInfo -> m RendererInfo)
-> IO RendererInfo -> m RendererInfo
forall a b. (a -> b) -> a -> b
$
  (Ptr RendererInfo -> IO RendererInfo) -> IO RendererInfo
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr RendererInfo -> IO RendererInfo) -> IO RendererInfo)
-> (Ptr RendererInfo -> IO RendererInfo) -> IO RendererInfo
forall a b. (a -> b) -> a -> b
$ \Ptr RendererInfo
rptr -> do
    Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"getRendererInfo" Text
"SDL_GetRendererInfo" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
      Texture -> Ptr RendererInfo -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr RendererInfo -> m CInt
Raw.getRendererInfo Texture
renderer Ptr RendererInfo
rptr
    Ptr RendererInfo -> IO RendererInfo
forall a. Storable a => Ptr a -> IO a
peek Ptr RendererInfo
rptr IO RendererInfo
-> (RendererInfo -> IO RendererInfo) -> IO RendererInfo
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= RendererInfo -> IO RendererInfo
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/SDL2/SDL_GetRenderDriverInfo SDL_GetRenderDriverInfo>@ for C documentation.
getRenderDriverInfo :: MonadIO m => m [RendererInfo]
getRenderDriverInfo :: forall (m :: Type -> Type). MonadIO m => m [RendererInfo]
getRenderDriverInfo = IO [RendererInfo] -> m [RendererInfo]
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO [RendererInfo] -> m [RendererInfo])
-> IO [RendererInfo] -> m [RendererInfo]
forall a b. (a -> b) -> a -> b
$ do
  count <- IO CInt
forall (m :: Type -> Type). MonadIO m => m CInt
Raw.getNumRenderDrivers
  traverse go [0..count-1]
  where
    go :: CInt -> IO RendererInfo
go CInt
idx = (Ptr RendererInfo -> IO RendererInfo) -> IO RendererInfo
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr RendererInfo -> IO RendererInfo) -> IO RendererInfo)
-> (Ptr RendererInfo -> IO RendererInfo) -> IO RendererInfo
forall a b. (a -> b) -> a -> b
$ \Ptr RendererInfo
rptr -> do
               Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"getRenderDriverInfo" Text
"SDL_GetRenderDriverInfo" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
                 CInt -> Ptr RendererInfo -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
CInt -> Ptr RendererInfo -> m CInt
Raw.getRenderDriverInfo CInt
idx Ptr RendererInfo
rptr
               Ptr RendererInfo -> IO RendererInfo
forall a. Storable a => Ptr a -> IO a
peek Ptr RendererInfo
rptr IO RendererInfo
-> (RendererInfo -> IO RendererInfo) -> IO RendererInfo
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= RendererInfo -> IO RendererInfo
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/SDL2/SDL_SetTextureAlphaMod SDL_SetTextureAlphaMod>@ and @<https://wiki.libsdl.org/SDL2/SDL_GetTextureAlphaMod SDL_GetTextureAlphaMod>@ for C documentation.
textureAlphaMod :: Texture -> StateVar Word8
textureAlphaMod :: Texture -> StateVar Word8
textureAlphaMod (Texture Texture
t) = IO Word8 -> (Word8 -> IO ()) -> StateVar Word8
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO Word8
getTextureAlphaMod Word8 -> IO ()
setTextureAlphaMod
  where
  getTextureAlphaMod :: IO Word8
getTextureAlphaMod =
    (Ptr Word8 -> IO Word8) -> IO Word8
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word8 -> IO Word8) -> IO Word8)
-> (Ptr Word8 -> IO Word8) -> IO Word8
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
x -> do
      Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
        Texture -> Ptr Word8 -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr Word8 -> m CInt
Raw.getTextureAlphaMod Texture
t Ptr Word8
x
      Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
peek Ptr Word8
x

  setTextureAlphaMod :: Word8 -> IO ()
setTextureAlphaMod Word8
alpha =
    Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
      Texture -> Word8 -> IO CInt
forall (m :: Type -> Type). MonadIO m => Texture -> Word8 -> m CInt
Raw.setTextureAlphaMod Texture
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/SDL2/SDL_SetTextureBlendMode SDL_SetTextureBlendMode>@ and @<https://wiki.libsdl.org/SDL2/SDL_GetTextureBlendMode SDL_GetTextureBlendMode>@ for C documentation.
textureBlendMode :: Texture -> StateVar BlendMode
textureBlendMode :: Texture -> StateVar BlendMode
textureBlendMode (Texture Texture
t) = IO BlendMode -> (BlendMode -> IO ()) -> StateVar BlendMode
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO BlendMode
getTextureBlendMode BlendMode -> IO ()
setTextureBlendMode
  where
  getTextureBlendMode :: IO BlendMode
getTextureBlendMode =
    (Ptr BlendMode -> IO BlendMode) -> IO BlendMode
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO BlendMode) -> IO BlendMode)
-> (Ptr BlendMode -> IO BlendMode) -> IO BlendMode
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
x -> do
      Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
        Texture -> Ptr BlendMode -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr BlendMode -> m CInt
Raw.getTextureBlendMode Texture
t Ptr BlendMode
x
      BlendMode -> BlendMode
forall a b. FromNumber a b => b -> a
fromNumber (BlendMode -> BlendMode) -> IO BlendMode -> IO BlendMode
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr BlendMode -> IO BlendMode
forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
x

  setTextureBlendMode :: BlendMode -> IO ()
setTextureBlendMode BlendMode
bm =
    Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Texture -> BlendMode -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> BlendMode -> m CInt
Raw.setTextureBlendMode Texture
t (BlendMode -> BlendMode
forall a b. ToNumber a b => a -> b
toNumber BlendMode
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/SDL2/SDL_SetSurfaceBlendMode SDL_SetSurfaceBlendMode>@ and @<https://wiki.libsdl.org/SDL2/SDL_GetSurfaceBlendMode SDL_GetSurfaceBlendMode>@ for C documentation.
surfaceBlendMode :: Surface -> StateVar BlendMode
surfaceBlendMode :: Surface -> StateVar BlendMode
surfaceBlendMode (Surface Ptr Surface
s Maybe (IOVector Word8)
_) = IO BlendMode -> (BlendMode -> IO ()) -> StateVar BlendMode
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO BlendMode
getSurfaceBlendMode BlendMode -> IO ()
setSurfaceBlendMode
  where
  getSurfaceBlendMode :: IO BlendMode
getSurfaceBlendMode =
    (Ptr BlendMode -> IO BlendMode) -> IO BlendMode
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO BlendMode) -> IO BlendMode)
-> (Ptr BlendMode -> IO BlendMode) -> IO BlendMode
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
x -> do
      Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
        Ptr Surface -> Ptr BlendMode -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> Ptr BlendMode -> m CInt
Raw.getSurfaceBlendMode Ptr Surface
s Ptr BlendMode
x
      BlendMode -> BlendMode
forall a b. FromNumber a b => b -> a
fromNumber (BlendMode -> BlendMode) -> IO BlendMode -> IO BlendMode
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr BlendMode -> IO BlendMode
forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
x

  setSurfaceBlendMode :: BlendMode -> IO ()
setSurfaceBlendMode BlendMode
bm =
    Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    Ptr Surface -> BlendMode -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Ptr Surface -> BlendMode -> m CInt
Raw.setSurfaceBlendMode Ptr Surface
s (BlendMode -> BlendMode
forall a b. ToNumber a b => a -> b
toNumber BlendMode
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/SDL2/SDL_SetRenderTarget SDL_SetRenderTarget>@ and @<https://wiki.libsdl.org/SDL2/SDL_GetRenderTarget SDL_GetRenderTarget>@ for C documentation.
rendererRenderTarget :: Renderer -> StateVar (Maybe Texture)
rendererRenderTarget :: Renderer -> StateVar (Maybe Texture)
rendererRenderTarget (Renderer Texture
r) = IO (Maybe Texture)
-> (Maybe Texture -> IO ()) -> StateVar (Maybe Texture)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe Texture)
getRenderTarget Maybe Texture -> IO ()
setRenderTarget
  where
  getRenderTarget :: IO (Maybe Texture)
getRenderTarget = do
    t <- Texture -> IO Texture
forall (m :: Type -> Type). MonadIO m => Texture -> m Texture
Raw.getRenderTarget Texture
r
    return $
      if t == nullPtr
        then Nothing
        else Just (Texture t)

  setRenderTarget :: Maybe Texture -> IO ()
setRenderTarget Maybe Texture
texture =
    Text -> Text -> IO CInt -> IO ()
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" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
    case Maybe Texture
texture of
      Maybe Texture
Nothing -> Texture -> Texture -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Texture -> m CInt
Raw.setRenderTarget Texture
r Texture
forall a. Ptr a
nullPtr
      Just (Texture Texture
t) -> Texture -> Texture -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Texture -> m CInt
Raw.setRenderTarget Texture
r Texture
t

-- | Get or set whether to force integer scales for resolution-independent rendering.
-- It may be desirable to enable integer scales when using device independent resolution
-- via 'rendererLogicalSize' so that pixel sizing is consistent.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL2/SDL_RenderSetIntegerScale SDL_RenderSetIntegerScale>@ and @<https://wiki.libsdl.org/SDL2/SDL_RenderGetIntegerScale SDL_RenderGetIntegerScale>@ for C documentation.
rendererIntegerScale :: Renderer -> StateVar Bool
rendererIntegerScale :: Renderer -> StateVar Bool
rendererIntegerScale (Renderer Texture
r) = IO Bool -> (Bool -> IO ()) -> StateVar Bool
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO Bool
renderGetIntegerScale Bool -> IO ()
renderSetIntegerScale
  where
  renderGetIntegerScale :: IO Bool
renderGetIntegerScale = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
1) (CInt -> Bool) -> IO CInt -> IO Bool
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Texture -> IO CInt
forall (m :: Type -> Type). MonadIO m => Texture -> m CInt
Raw.renderGetIntegerScale Texture
r

  renderSetIntegerScale :: Bool -> IO ()
renderSetIntegerScale Bool
True = IO CInt -> IO ()
forall (f :: Type -> Type) a. Functor f => f a -> f ()
void (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$ Texture -> CInt -> IO CInt
forall (m :: Type -> Type). MonadIO m => Texture -> CInt -> m CInt
Raw.renderSetIntegerScale Texture
r CInt
1
  renderSetIntegerScale Bool
False = IO CInt -> IO ()
forall (f :: Type -> Type) a. Functor f => f a -> f ()
void (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$ Texture -> CInt -> IO CInt
forall (m :: Type -> Type). MonadIO m => Texture -> CInt -> m CInt
Raw.renderSetIntegerScale Texture
r CInt
0

-- | Get or set the device independent resolution for rendering. When using this setting,
-- it may be desirable to also enable integer scales via 'rendererIntegerScale' so that
-- pixel sizing is consistent.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL2/SDL_RenderSetLogicalSize SDL_RenderSetLogicalSize>@ and @<https://wiki.libsdl.org/SDL2/SDL_RenderGetLogicalSize SDL_RenderGetLogicalSize>@ for C documentation.
rendererLogicalSize :: Renderer -> StateVar (Maybe (V2 CInt))
rendererLogicalSize :: Renderer -> StateVar (Maybe (V2 CInt))
rendererLogicalSize (Renderer Texture
r) = IO (Maybe (V2 CInt))
-> (Maybe (V2 CInt) -> IO ()) -> StateVar (Maybe (V2 CInt))
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (V2 CInt))
renderGetLogicalSize Maybe (V2 CInt) -> IO ()
renderSetLogicalSize
  where
  renderGetLogicalSize :: IO (Maybe (V2 CInt))
renderGetLogicalSize =
    (Ptr CInt -> IO (Maybe (V2 CInt))) -> IO (Maybe (V2 CInt))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Maybe (V2 CInt))) -> IO (Maybe (V2 CInt)))
-> (Ptr CInt -> IO (Maybe (V2 CInt))) -> IO (Maybe (V2 CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
w -> do
    (Ptr CInt -> IO (Maybe (V2 CInt))) -> IO (Maybe (V2 CInt))
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (Maybe (V2 CInt))) -> IO (Maybe (V2 CInt)))
-> (Ptr CInt -> IO (Maybe (V2 CInt))) -> IO (Maybe (V2 CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
h -> do
      Texture -> Ptr CInt -> Ptr CInt -> IO ()
forall (m :: Type -> Type).
MonadIO m =>
Texture -> Ptr CInt -> Ptr CInt -> m ()
Raw.renderGetLogicalSize Texture
r Ptr CInt
w Ptr CInt
h
      v <- CInt -> CInt -> V2 CInt
forall a. a -> a -> V2 a
V2 (CInt -> CInt -> V2 CInt) -> IO CInt -> IO (CInt -> V2 CInt)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
w IO (CInt -> V2 CInt) -> IO CInt -> IO (V2 CInt)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
h
      return $ if v == 0 then Nothing else Just v

  renderSetLogicalSize :: Maybe (V2 CInt) -> IO ()
renderSetLogicalSize Maybe (V2 CInt)
v =
    Text -> Text -> IO CInt -> IO ()
forall (m :: Type -> Type) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ Text
"SDL.Video.renderSetLogicalSize" Text
"SDL_RenderSetLogicalSize" (IO CInt -> IO ()) -> IO CInt -> IO ()
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)
      Texture -> CInt -> CInt -> IO CInt
forall (m :: Type -> Type).
MonadIO m =>
Texture -> CInt -> CInt -> m CInt
Raw.renderSetLogicalSize Texture
r CInt
x CInt
y

-- | Determine whether a window supports the use of render targets.
--
-- See @<https://wiki.libsdl.org/SDL2/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 Texture
r) = Texture -> m Bool
forall (m :: Type -> Type). MonadIO m => Texture -> m Bool
Raw.renderTargetSupported Texture
r

-- | Convert the given the enumerated pixel format to a bpp value and RGBA masks.
--
-- See @<https://wiki.libsdl.org/SDL2/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 = IO (CInt, V4 BlendMode) -> m (CInt, V4 BlendMode)
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO (CInt, V4 BlendMode) -> m (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode) -> m (CInt, V4 BlendMode)
forall a b. (a -> b) -> a -> b
$
  (Ptr CInt -> IO (CInt, V4 BlendMode)) -> IO (CInt, V4 BlendMode)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (CInt, V4 BlendMode)) -> IO (CInt, V4 BlendMode))
-> (Ptr CInt -> IO (CInt, V4 BlendMode)) -> IO (CInt, V4 BlendMode)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
bpp ->
  (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO (CInt, V4 BlendMode))
 -> IO (CInt, V4 BlendMode))
-> (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
r ->
  (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO (CInt, V4 BlendMode))
 -> IO (CInt, V4 BlendMode))
-> (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
g ->
  (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO (CInt, V4 BlendMode))
 -> IO (CInt, V4 BlendMode))
-> (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
b ->
  (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr BlendMode -> IO (CInt, V4 BlendMode))
 -> IO (CInt, V4 BlendMode))
-> (Ptr BlendMode -> IO (CInt, V4 BlendMode))
-> IO (CInt, V4 BlendMode)
forall a b. (a -> b) -> a -> b
$ \Ptr BlendMode
a -> do
    (Bool -> Bool) -> Text -> Text -> IO Bool -> IO ()
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" (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$
      BlendMode
-> Ptr CInt
-> Ptr BlendMode
-> Ptr BlendMode
-> Ptr BlendMode
-> Ptr BlendMode
-> IO Bool
forall (m :: Type -> Type).
MonadIO m =>
BlendMode
-> Ptr CInt
-> Ptr BlendMode
-> Ptr BlendMode
-> Ptr BlendMode
-> Ptr BlendMode
-> m Bool
Raw.pixelFormatEnumToMasks (PixelFormat -> BlendMode
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
    CInt
-> BlendMode
-> BlendMode
-> BlendMode
-> BlendMode
-> (CInt, V4 BlendMode)
forall {a} {a}. a -> a -> a -> a -> a -> (a, V4 a)
wrap (CInt
 -> BlendMode
 -> BlendMode
 -> BlendMode
 -> BlendMode
 -> (CInt, V4 BlendMode))
-> IO CInt
-> IO
     (BlendMode
      -> BlendMode -> BlendMode -> BlendMode -> (CInt, V4 BlendMode))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
bpp IO
  (BlendMode
   -> BlendMode -> BlendMode -> BlendMode -> (CInt, V4 BlendMode))
-> IO BlendMode
-> IO (BlendMode -> BlendMode -> BlendMode -> (CInt, V4 BlendMode))
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr BlendMode -> IO BlendMode
forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
r IO (BlendMode -> BlendMode -> BlendMode -> (CInt, V4 BlendMode))
-> IO BlendMode
-> IO (BlendMode -> BlendMode -> (CInt, V4 BlendMode))
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr BlendMode -> IO BlendMode
forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
g IO (BlendMode -> BlendMode -> (CInt, V4 BlendMode))
-> IO BlendMode -> IO (BlendMode -> (CInt, V4 BlendMode))
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr BlendMode -> IO BlendMode
forall a. Storable a => Ptr a -> IO a
peek Ptr BlendMode
b IO (BlendMode -> (CInt, V4 BlendMode))
-> IO BlendMode -> IO (CInt, V4 BlendMode)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Ptr BlendMode -> IO BlendMode
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, a -> a -> a -> a -> V4 a
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/SDL2/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) = IO PixelFormat -> m PixelFormat
forall a. IO a -> m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO PixelFormat -> m PixelFormat)
-> IO PixelFormat -> m PixelFormat
forall a b. (a -> b) -> a -> b
$
  BlendMode -> PixelFormat
forall a b. FromNumber a b => b -> a
fromNumber (BlendMode -> PixelFormat) -> IO BlendMode -> IO PixelFormat
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> CInt
-> BlendMode -> BlendMode -> BlendMode -> BlendMode -> IO BlendMode
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