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

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

module SDL.Video.Renderer
  ( Renderer

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

  -- * Drawing Primitives
  , clear
  , copy
  , copyEx
  , drawLine
  , drawLines
  , drawPoint
  , drawPoints
  , drawRect
  , drawRects
  , fillRect
  , fillRects
  , present

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

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

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

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

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

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

  -- * Textures
  , Texture

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

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

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

  , Rectangle(..)

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

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

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

-- | Perform a fast surface copy to a destination surface.
--
-- See @<https://wiki.libsdl.org/SDL_BlitSurface SDL_BlitSurface>@ for C documentation.
surfaceBlit :: MonadIO m
            => Surface -- ^ The 'Surface' to be copied from
            -> Maybe (Rectangle CInt) -- ^ The rectangle to be copied, or 'Nothing' to copy the entire surface
            -> Surface -- ^ The 'Surface' that is the blit target
            -> Maybe (Point V2 CInt) -- ^ The position to blit to
            -> m (Maybe (Rectangle CInt))
surfaceBlit :: Surface
-> Maybe (Rectangle CInt)
-> Surface
-> Maybe (Point V2 CInt)
-> m (Maybe (Rectangle CInt))
surfaceBlit (Surface src :: Ptr Surface
src _) srcRect :: Maybe (Rectangle CInt)
srcRect (Surface dst :: Ptr Surface
dst _) dstLoc :: Maybe (Point V2 CInt)
dstLoc = IO (Maybe (Rectangle CInt)) -> m (Maybe (Rectangle CInt))
forall (m :: * -> *) 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
$ \srcPtr :: 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 (f :: * -> *) 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 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
$ \dstPtr :: Ptr (Rectangle CInt)
dstPtr -> do
      CInt
_ <- Text -> Text -> IO CInt -> IO CInt
forall (m :: * -> *) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m a
throwIfNeg "SDL.Video.blitSurface" "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 :: * -> *).
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)
      IO (Maybe (Rectangle CInt))
-> (Point V2 CInt -> IO (Maybe (Rectangle CInt)))
-> Maybe (Point V2 CInt)
-> IO (Maybe (Rectangle CInt))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (Rectangle CInt) -> IO (Maybe (Rectangle CInt))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Rectangle CInt)
forall a. Maybe a
Nothing) (\_ -> 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 :: * -> *) 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) Maybe (Point V2 CInt)
dstLoc

-- | Create a texture for a rendering context.
--
-- See @<https://wiki.libsdl.org/SDL_CreateTexture SDL_CreateTexture>@ for C documentation.
createTexture :: (Functor m,MonadIO m)
              => Renderer -- ^ The rendering context.
              -> PixelFormat
              -> TextureAccess
              -> V2 CInt -- ^ The size of the texture.
              -> m Texture
createTexture :: Renderer -> PixelFormat -> TextureAccess -> V2 CInt -> m Texture
createTexture (Renderer r :: Renderer
r) fmt :: PixelFormat
fmt access :: TextureAccess
access (V2 w :: CInt
w h :: CInt
h) =
  (Renderer -> Texture) -> m Renderer -> m Texture
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Renderer -> Texture
Texture (m Renderer -> m Texture) -> m Renderer -> m Texture
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> m Renderer -> m Renderer
forall (m :: * -> *) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull "SDL.Video.Renderer.createTexture" "SDL_CreateTexture" (m Renderer -> m Renderer) -> m Renderer -> m Renderer
forall a b. (a -> b) -> a -> b
$
  Renderer -> Word32 -> CInt -> CInt -> CInt -> m Renderer
forall (m :: * -> *).
MonadIO m =>
Renderer -> Word32 -> CInt -> CInt -> CInt -> m Renderer
Raw.createTexture Renderer
r (PixelFormat -> Word32
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/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 :: Renderer -> Surface -> m Texture
createTextureFromSurface (Renderer r :: Renderer
r) (Surface s :: Ptr Surface
s _) =
  (Renderer -> Texture) -> m Renderer -> m Texture
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Renderer -> Texture
Texture (m Renderer -> m Texture) -> m Renderer -> m Texture
forall a b. (a -> b) -> a -> b
$
  Text -> Text -> m Renderer -> m Renderer
forall (m :: * -> *) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull "SDL.Video.createTextureFromSurface" "SDL_CreateTextureFromSurface" (m Renderer -> m Renderer) -> m Renderer -> m Renderer
forall a b. (a -> b) -> a -> b
$
  Renderer -> Ptr Surface -> m Renderer
forall (m :: * -> *).
MonadIO m =>
Renderer -> Ptr Surface -> m Renderer
Raw.createTextureFromSurface Renderer
r Ptr Surface
s

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

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

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

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

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

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

-- | Release a surface after directly accessing the pixels.
--
-- See @<https://wiki.libsdl.org/SDL_UnlockSurface SDL_UnlockSurface>@ for C documentation.
unlockSurface :: MonadIO m => Surface -> m ()
unlockSurface :: Surface -> m ()
unlockSurface (Surface s :: Ptr Surface
s _) = Ptr Surface -> m ()
forall (m :: * -> *). 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
maxBound :: TextureAccess
$cmaxBound :: TextureAccess
minBound :: TextureAccess
$cminBound :: TextureAccess
Bounded, Typeable TextureAccess
Constr
DataType
Typeable TextureAccess =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> TextureAccess -> c TextureAccess)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c TextureAccess)
-> (TextureAccess -> Constr)
-> (TextureAccess -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c TextureAccess))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    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 :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess)
-> (forall (m :: * -> *).
    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 d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> c TextureAccess
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    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 :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    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 :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> c TextureAccess
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TextureAccess)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c TextureAccess)
$cTextureAccessTarget :: Constr
$cTextureAccessStreaming :: Constr
$cTextureAccessStatic :: Constr
$tTextureAccess :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
gmapMp :: (forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
gmapM :: (forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TextureAccess -> m TextureAccess
gmapQi :: Int -> (forall d. Data d => d -> u) -> TextureAccess -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TextureAccess -> u
gmapQ :: (forall d. Data d => d -> u) -> TextureAccess -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TextureAccess -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> TextureAccess -> r
gmapT :: (forall b. Data b => b -> b) -> TextureAccess -> TextureAccess
$cgmapT :: (forall b. Data b => b -> b) -> TextureAccess -> TextureAccess
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c TextureAccess)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c TextureAccess)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c TextureAccess)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TextureAccess)
dataTypeOf :: TextureAccess -> DataType
$cdataTypeOf :: TextureAccess -> DataType
toConstr :: TextureAccess -> Constr
$ctoConstr :: TextureAccess -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TextureAccess
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> c TextureAccess
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TextureAccess -> c TextureAccess
$cp1Data :: Typeable 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
enumFromThenTo :: TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromThenTo :: TextureAccess -> TextureAccess -> TextureAccess -> [TextureAccess]
enumFromTo :: TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromTo :: TextureAccess -> TextureAccess -> [TextureAccess]
enumFromThen :: TextureAccess -> TextureAccess -> [TextureAccess]
$cenumFromThen :: TextureAccess -> TextureAccess -> [TextureAccess]
enumFrom :: TextureAccess -> [TextureAccess]
$cenumFrom :: TextureAccess -> [TextureAccess]
fromEnum :: TextureAccess -> Int
$cfromEnum :: TextureAccess -> Int
toEnum :: Int -> TextureAccess
$ctoEnum :: Int -> TextureAccess
pred :: TextureAccess -> TextureAccess
$cpred :: TextureAccess -> TextureAccess
succ :: TextureAccess -> TextureAccess
$csucc :: TextureAccess -> TextureAccess
Enum, TextureAccess -> TextureAccess -> Bool
(TextureAccess -> TextureAccess -> Bool)
-> (TextureAccess -> TextureAccess -> Bool) -> Eq TextureAccess
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextureAccess -> TextureAccess -> Bool
$c/= :: TextureAccess -> TextureAccess -> Bool
== :: TextureAccess -> TextureAccess -> Bool
$c== :: TextureAccess -> TextureAccess -> Bool
Eq, (forall x. 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
$cto :: forall x. Rep TextureAccess x -> TextureAccess
$cfrom :: forall x. TextureAccess -> Rep TextureAccess x
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
min :: TextureAccess -> TextureAccess -> TextureAccess
$cmin :: TextureAccess -> TextureAccess -> TextureAccess
max :: TextureAccess -> TextureAccess -> TextureAccess
$cmax :: TextureAccess -> TextureAccess -> TextureAccess
>= :: TextureAccess -> TextureAccess -> Bool
$c>= :: TextureAccess -> TextureAccess -> Bool
> :: TextureAccess -> TextureAccess -> Bool
$c> :: TextureAccess -> TextureAccess -> Bool
<= :: TextureAccess -> TextureAccess -> Bool
$c<= :: TextureAccess -> TextureAccess -> Bool
< :: TextureAccess -> TextureAccess -> Bool
$c< :: TextureAccess -> TextureAccess -> Bool
compare :: TextureAccess -> TextureAccess -> Ordering
$ccompare :: TextureAccess -> TextureAccess -> Ordering
$cp1Ord :: Eq 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
readListPrec :: ReadPrec [TextureAccess]
$creadListPrec :: ReadPrec [TextureAccess]
readPrec :: ReadPrec TextureAccess
$creadPrec :: ReadPrec TextureAccess
readList :: ReadS [TextureAccess]
$creadList :: ReadS [TextureAccess]
readsPrec :: Int -> ReadS TextureAccess
$creadsPrec :: Int -> ReadS TextureAccess
Read, Int -> TextureAccess -> ShowS
[TextureAccess] -> ShowS
TextureAccess -> String
(Int -> TextureAccess -> ShowS)
-> (TextureAccess -> String)
-> ([TextureAccess] -> ShowS)
-> Show TextureAccess
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TextureAccess] -> ShowS
$cshowList :: [TextureAccess] -> ShowS
show :: TextureAccess -> String
$cshow :: TextureAccess -> String
showsPrec :: Int -> TextureAccess -> ShowS
$cshowsPrec :: Int -> TextureAccess -> ShowS
Show, Typeable)

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

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

-- | Query the attributes of a texture.
--
-- See @<https://wiki.libsdl.org/SDL_QueryTexture SDL_QueryTexture>@ for C documentation.
queryTexture :: MonadIO m => Texture -> m TextureInfo
queryTexture :: Texture -> m TextureInfo
queryTexture (Texture tex :: Renderer
tex) = IO TextureInfo -> m TextureInfo
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO TextureInfo -> m TextureInfo)
-> IO TextureInfo -> m TextureInfo
forall a b. (a -> b) -> a -> b
$
  (Ptr Word32 -> IO TextureInfo) -> IO TextureInfo
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Word32 -> IO TextureInfo) -> IO TextureInfo)
-> (Ptr Word32 -> IO TextureInfo) -> IO TextureInfo
forall a b. (a -> b) -> a -> b
$ \pfPtr :: Ptr Word32
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
$ \acPtr :: 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
$ \wPtr :: 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
$ \hPtr :: Ptr CInt
hPtr -> do
    Text -> Text -> IO CInt -> IO ()
forall (m :: * -> *) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ "SDL.Video.queryTexture" "SDL_QueryTexture" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
      Renderer
-> Ptr Word32 -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt
forall (m :: * -> *).
MonadIO m =>
Renderer
-> Ptr Word32 -> Ptr CInt -> Ptr CInt -> Ptr CInt -> m CInt
Raw.queryTexture Renderer
tex Ptr Word32
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 :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      (Word32 -> PixelFormat) -> IO Word32 -> IO PixelFormat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> PixelFormat
forall a b. FromNumber a b => b -> a
fromNumber (Ptr Word32 -> IO Word32
forall a. Storable a => Ptr a -> IO a
peek Ptr Word32
pfPtr) IO (TextureAccess -> CInt -> CInt -> TextureInfo)
-> IO TextureAccess -> IO (CInt -> CInt -> TextureInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
      (CInt -> TextureAccess) -> IO CInt -> IO TextureAccess
forall (f :: * -> *) 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 (f :: * -> *) 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 (f :: * -> *) 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/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 :: V2 CInt -> PixelFormat -> m Surface
createRGBSurface (V2 w :: CInt
w h :: CInt
h) pf :: PixelFormat
pf =
  (Ptr Surface -> Surface) -> m (Ptr Surface) -> m Surface
forall (f :: * -> *) 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 :: * -> *) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull "SDL.Video.createRGBSurface" "SDL_CreateRGBSurface" (m (Ptr Surface) -> m (Ptr Surface))
-> m (Ptr Surface) -> m (Ptr Surface)
forall a b. (a -> b) -> a -> b
$ do
      (bpp :: CInt
bpp, V4 r :: Word32
r g :: Word32
g b :: Word32
b a :: Word32
a) <- PixelFormat -> m (CInt, V4 Word32)
forall (m :: * -> *).
MonadIO m =>
PixelFormat -> m (CInt, V4 Word32)
pixelFormatToMasks PixelFormat
pf
      Word32
-> CInt
-> CInt
-> CInt
-> Word32
-> Word32
-> Word32
-> Word32
-> m (Ptr Surface)
forall (m :: * -> *).
MonadIO m =>
Word32
-> CInt
-> CInt
-> CInt
-> Word32
-> Word32
-> Word32
-> Word32
-> m (Ptr Surface)
Raw.createRGBSurface 0 CInt
w CInt
h CInt
bpp Word32
r Word32
g Word32
b Word32
a

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

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

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

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

-- | Load a surface from a BMP file.
--
-- See @<https://wiki.libsdl.org/SDL_LoadBMP SDL_LoadBMP>@ for C documentation.
loadBMP :: MonadIO m => FilePath -> m Surface
loadBMP :: String -> m Surface
loadBMP filePath :: String
filePath = IO Surface -> m Surface
forall (m :: * -> *) 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 (f :: * -> *) 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 :: * -> *) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull "SDL.Video.loadBMP" "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 :: * -> *). 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
/= :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
$c/= :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
== :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
$c== :: SurfacePixelFormat -> SurfacePixelFormat -> Bool
Eq, Typeable)

-- It's possible we could use unsafePerformIO here, but I'm not
-- sure. surface->{w,h} are immutable, but do we need to guarantee that pointers
-- aren't reused by *different* surfaces.
-- | Retrive the width and height of a 'Surface'.
surfaceDimensions :: MonadIO m => Surface -> m (V2 CInt)
surfaceDimensions :: Surface -> m (V2 CInt)
surfaceDimensions (Surface s :: Ptr Surface
s _) = IO (V2 CInt) -> m (V2 CInt)
forall (m :: * -> *) 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 :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Surface -> CInt
Raw.surfaceW (Surface -> CInt -> V2 CInt)
-> (Surface -> CInt) -> Surface -> V2 CInt
forall (f :: * -> *) 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 :: * -> *) 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 :: Surface -> m Renderer
surfacePixels (Surface s :: Ptr Surface
s _) = IO Renderer -> m Renderer
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Renderer -> m Renderer) -> IO Renderer -> m Renderer
forall a b. (a -> b) -> a -> b
$ Surface -> Renderer
Raw.surfacePixels (Surface -> Renderer) -> IO Surface -> IO Renderer
forall (f :: * -> *) 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 :: Surface -> m SurfacePixelFormat
surfaceFormat (Surface s :: Ptr Surface
s _) = IO SurfacePixelFormat -> m SurfacePixelFormat
forall (m :: * -> *) 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 :: * -> *) 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
/= :: Palette -> Palette -> Bool
$c/= :: Palette -> Palette -> Bool
== :: Palette -> Palette -> Bool
$c== :: Palette -> Palette -> Bool
Eq, Typeable)

formatPalette :: MonadIO m => SurfacePixelFormat -> m (Maybe Palette)
formatPalette :: SurfacePixelFormat -> m (Maybe Palette)
formatPalette (SurfacePixelFormat f :: Ptr PixelFormat
f) = IO (Maybe Palette) -> m (Maybe Palette)
forall (m :: * -> *) 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 :: * -> *) 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 p :: 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 :: Palette -> m CInt
paletteNColors (Palette p :: Ptr Palette
p) = IO CInt -> m CInt
forall (m :: * -> *) 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 :: * -> *) 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 :: Palette -> m (Maybe (Vector (V4 Word8)))
paletteColors q :: Palette
q@(Palette p :: Ptr Palette
p) = do
  Int
n <- IO Int -> m Int
forall (m :: * -> *) 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 :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Palette -> IO CInt
forall (m :: * -> *). MonadIO m => Palette -> m CInt
paletteNColors Palette
q
  let wrap :: Ptr a -> Maybe (Ptr a)
wrap p' :: 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 (m :: * -> *) a. Monad m => a -> m a
return Ptr a
p'
  Maybe (Ptr (V4 Word8))
mv <- IO (Maybe (Ptr (V4 Word8))) -> m (Maybe (Ptr (V4 Word8)))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (Ptr (V4 Word8))) -> m (Maybe (Ptr (V4 Word8))))
-> IO (Maybe (Ptr (V4 Word8))) -> m (Maybe (Ptr (V4 Word8)))
forall a b. (a -> b) -> a -> b
$ Ptr (V4 Word8) -> Maybe (Ptr (V4 Word8))
forall a. Ptr a -> Maybe (Ptr a)
wrap (Ptr (V4 Word8) -> Maybe (Ptr (V4 Word8)))
-> (Palette -> Ptr (V4 Word8)) -> Palette -> Maybe (Ptr (V4 Word8))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr Color -> Ptr (V4 Word8)
forall a b. Ptr a -> Ptr b
castPtr (Ptr Color -> Ptr (V4 Word8))
-> (Palette -> Ptr Color) -> Palette -> Ptr (V4 Word8)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Palette -> Ptr Color
Raw.paletteColors (Palette -> Maybe (Ptr (V4 Word8)))
-> IO Palette -> IO (Maybe (Ptr (V4 Word8)))
forall (f :: * -> *) 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
  Maybe (ForeignPtr (V4 Word8))
mColor <- IO (Maybe (ForeignPtr (V4 Word8)))
-> m (Maybe (ForeignPtr (V4 Word8)))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (ForeignPtr (V4 Word8)))
 -> m (Maybe (ForeignPtr (V4 Word8))))
-> IO (Maybe (ForeignPtr (V4 Word8)))
-> m (Maybe (ForeignPtr (V4 Word8)))
forall a b. (a -> b) -> a -> b
$ (Ptr (V4 Word8) -> IO (ForeignPtr (V4 Word8)))
-> Maybe (Ptr (V4 Word8)) -> IO (Maybe (ForeignPtr (V4 Word8)))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Ptr (V4 Word8) -> IO (ForeignPtr (V4 Word8))
forall a. Ptr a -> IO (ForeignPtr a)
newForeignPtr_ Maybe (Ptr (V4 Word8))
mv
  Maybe (Vector (V4 Word8)) -> m (Maybe (Vector (V4 Word8)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Vector (V4 Word8)) -> m (Maybe (Vector (V4 Word8))))
-> Maybe (Vector (V4 Word8)) -> m (Maybe (Vector (V4 Word8)))
forall a b. (a -> b) -> a -> b
$ (ForeignPtr (V4 Word8) -> Int -> Vector (V4 Word8))
-> Int -> ForeignPtr (V4 Word8) -> Vector (V4 Word8)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ForeignPtr (V4 Word8) -> Int -> Vector (V4 Word8)
forall a. Storable a => ForeignPtr a -> Int -> Vector a
SV.unsafeFromForeignPtr0 Int
n (ForeignPtr (V4 Word8) -> Vector (V4 Word8))
-> Maybe (ForeignPtr (V4 Word8)) -> Maybe (Vector (V4 Word8))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (ForeignPtr (V4 Word8))
mColor

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

-- | Set a range of colors in a palette.
--
-- See @<https://wiki.libsdl.org/SDL_SetPaletteColors SDL_SetPaletteColors>@ for C documentation.
setPaletteColors :: MonadIO m
                 => Palette -- ^ The 'Palette' to modify
                 -> (SV.Vector (V4 Word8)) -- ^ A 'SV.Vector' of colours to copy into the palette
                 -> CInt -- ^ The index of the first palette entry to modify
                 -> m ()
setPaletteColors :: Palette -> Vector (V4 Word8) -> CInt -> m ()
setPaletteColors (Palette p :: Ptr Palette
p) colors :: Vector (V4 Word8)
colors first :: CInt
first = IO () -> m ()
forall (m :: * -> *) 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 :: * -> *) a.
(MonadIO m, Num a, Ord a) =>
Text -> Text -> m a -> m ()
throwIfNeg_ "SDL.Video.setPaletteColors" "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
$ \cp :: Ptr (V4 Word8)
cp ->
    Ptr Palette -> Ptr Color -> CInt -> CInt -> IO CInt
forall (m :: * -> *).
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/SDL_GetWindowSurface SDL_GetWindowSurface>@ for C documentation.
getWindowSurface :: (Functor m, MonadIO m) => Window -> m Surface
getWindowSurface :: Window -> m Surface
getWindowSurface (Window w :: Renderer
w) =
  (Ptr Surface -> Surface) -> m (Ptr Surface) -> m Surface
forall (f :: * -> *) 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 :: * -> *) a.
MonadIO m =>
Text -> Text -> m (Ptr a) -> m (Ptr a)
throwIfNull "SDL.Video.getWindowSurface" "SDL_GetWindowSurface" (m (Ptr Surface) -> m (Ptr Surface))
-> m (Ptr Surface) -> m (Ptr Surface)
forall a b. (a -> b) -> a -> b
$
  Renderer -> m (Ptr Surface)
forall (m :: * -> *). MonadIO m => Renderer -> m (Ptr Surface)
Raw.getWindowSurface Renderer
w

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

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

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

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

-- | Blend modes used in 'copy' and drawing operations.
data BlendMode
  = BlendNone
    -- ^ No blending
  | BlendAlphaBlend
    -- ^ Alpha blending.
    --
    -- @
    -- dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
    -- dstA = srcA + (dstA * (1-srcA))
    -- @
  | BlendAdditive
    -- ^ Additive blending
    --
    -- @
    -- dstRGB = (srcRGB * srcA) + dstRGB
    -- dstA = dstA
    -- @
  | BlendMod
    -- ^ Color modulate
    --
    -- @
    -- dstRGB = srcRGB * dstRGB
    -- dstA = dstA
    --
  deriving (BlendMode
BlendMode -> BlendMode -> Bounded BlendMode
forall a. a -> a -> Bounded a
maxBound :: BlendMode
$cmaxBound :: BlendMode
minBound :: BlendMode
$cminBound :: BlendMode
Bounded, Typeable BlendMode
Constr
DataType
Typeable BlendMode =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BlendMode -> c BlendMode)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BlendMode)
-> (BlendMode -> Constr)
-> (BlendMode -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BlendMode))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    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 :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BlendMode -> m BlendMode)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BlendMode -> m BlendMode)
-> (forall (m :: * -> *).
    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 d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BlendMode -> c BlendMode
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BlendMode
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    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'