Skip to content

Commit 3f00354

Browse files
authored
Bindings for some missing parts of the raw SDL2 API (#205)
Namely the function SDL_ComposeCustomBlendMode and the associated enums, SDL_GetWindowBordersSize, and SDL_GetDisplayUsableBounds.
1 parent 5a19fb9 commit 3f00354

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/SDL/Raw/Enum.hsc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ module SDL.Raw.Enum (
3333
pattern SDL_BLENDMODE_ADD,
3434
pattern SDL_BLENDMODE_MOD,
3535

36+
-- ** Blend Operation
37+
BlendOperation,
38+
pattern SDL_BLENDOPERATION_ADD,
39+
pattern SDL_BLENDOPERATION_SUBTRACT,
40+
pattern SDL_BLENDOPERATION_REV_SUBTRACT,
41+
pattern SDL_BLENDOPERATION_MINIMUM,
42+
pattern SDL_BLENDOPERATION_MAXIMUM,
43+
44+
-- ** Blend Factor
45+
BlendFactor,
46+
pattern SDL_BLENDFACTOR_ZERO,
47+
pattern SDL_BLENDFACTOR_ONE,
48+
pattern SDL_BLENDFACTOR_SRC_COLOR,
49+
pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR,
50+
pattern SDL_BLENDFACTOR_SRC_ALPHA,
51+
pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
52+
pattern SDL_BLENDFACTOR_DST_COLOR,
53+
pattern SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR,
54+
pattern SDL_BLENDFACTOR_DST_ALPHA,
55+
pattern SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA,
56+
3657
-- ** Endian Detetection
3758
pattern SDL_BYTEORDER,
3859
pattern SDL_LIL_ENDIAN,
@@ -934,6 +955,8 @@ import Foreign.C.Types
934955
type AudioFormat = (#type SDL_AudioFormat)
935956
type AudioStatus = (#type SDL_AudioStatus)
936957
type BlendMode = (#type SDL_BlendMode)
958+
type BlendOperation = (#type SDL_BlendOperation)
959+
type BlendFactor = (#type SDL_BlendFactor)
937960
type Endian = CInt
938961
type EventAction = (#type SDL_eventaction)
939962
type GameControllerAxis = (#type SDL_GameControllerAxis)
@@ -975,6 +998,23 @@ pattern SDL_BLENDMODE_BLEND = (#const SDL_BLENDMODE_BLEND) :: BlendMode
975998
pattern SDL_BLENDMODE_ADD = (#const SDL_BLENDMODE_ADD) :: BlendMode
976999
pattern SDL_BLENDMODE_MOD = (#const SDL_BLENDMODE_MOD) :: BlendMode
9771000

1001+
pattern SDL_BLENDOPERATION_ADD = (#const SDL_BLENDOPERATION_ADD) :: BlendOperation
1002+
pattern SDL_BLENDOPERATION_SUBTRACT = (#const SDL_BLENDOPERATION_SUBTRACT) :: BlendOperation
1003+
pattern SDL_BLENDOPERATION_REV_SUBTRACT = (#const SDL_BLENDOPERATION_REV_SUBTRACT) :: BlendOperation
1004+
pattern SDL_BLENDOPERATION_MINIMUM = (#const SDL_BLENDOPERATION_MINIMUM) :: BlendOperation
1005+
pattern SDL_BLENDOPERATION_MAXIMUM = (#const SDL_BLENDOPERATION_MAXIMUM) :: BlendOperation
1006+
1007+
pattern SDL_BLENDFACTOR_ZERO = (#const SDL_BLENDFACTOR_ZERO) :: BlendFactor
1008+
pattern SDL_BLENDFACTOR_ONE = (#const SDL_BLENDFACTOR_ONE) :: BlendFactor
1009+
pattern SDL_BLENDFACTOR_SRC_COLOR = (#const SDL_BLENDFACTOR_SRC_COLOR) :: BlendFactor
1010+
pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = (#const SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR) :: BlendFactor
1011+
pattern SDL_BLENDFACTOR_SRC_ALPHA = (#const SDL_BLENDFACTOR_SRC_ALPHA) :: BlendFactor
1012+
pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = (#const SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA) :: BlendFactor
1013+
pattern SDL_BLENDFACTOR_DST_COLOR = (#const SDL_BLENDFACTOR_DST_COLOR) :: BlendFactor
1014+
pattern SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = (#const SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR) :: BlendFactor
1015+
pattern SDL_BLENDFACTOR_DST_ALPHA = (#const SDL_BLENDFACTOR_DST_ALPHA) :: BlendFactor
1016+
pattern SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = (#const SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA) :: BlendFactor
1017+
9781018
pattern SDL_BYTEORDER = (#const SDL_BYTEORDER) :: Endian
9791019
pattern SDL_LIL_ENDIAN = (#const SDL_LIL_ENDIAN) :: Endian
9801020
pattern SDL_BIG_ENDIAN = (#const SDL_BIG_ENDIAN) :: Endian

src/SDL/Raw/Video.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module SDL.Raw.Video (
3232
getDisplayDPI,
3333
getDisplayMode,
3434
getDisplayName,
35+
getDisplayUsableBounds,
3536
getGrabbedWindow,
3637
getNumDisplayModes,
3738
getNumVideoDisplays,
@@ -82,6 +83,7 @@ module SDL.Raw.Video (
8283
videoQuit,
8384

8485
-- * 2D Accelerated Rendering
86+
composeCustomBlendMode,
8587
createRenderer,
8688
createSoftwareRenderer,
8789
createTexture,
@@ -248,12 +250,13 @@ foreign import ccall "SDL.h SDL_GetDisplayBounds" getDisplayBoundsFFI :: CInt ->
248250
foreign import ccall "SDL.h SDL_GetDisplayDPI" getDisplayDPIFFI :: CInt -> Ptr CFloat -> Ptr CFloat -> Ptr CFloat -> IO CInt
249251
foreign import ccall "SDL.h SDL_GetDisplayMode" getDisplayModeFFI :: CInt -> CInt -> Ptr DisplayMode -> IO CInt
250252
foreign import ccall "SDL.h SDL_GetDisplayName" getDisplayNameFFI :: CInt -> IO CString
253+
foreign import ccall "SDL.h SDL_GetDisplayUsableBounds" getDisplayUsableBoundsFFI :: CInt -> Ptr Rect -> IO CInt
251254
foreign import ccall "SDL.h SDL_GetGrabbedWindow" getGrabbedWindowFFI :: IO Window
252255
foreign import ccall "SDL.h SDL_GetNumDisplayModes" getNumDisplayModesFFI :: CInt -> IO CInt
253256
foreign import ccall "SDL.h SDL_GetNumVideoDisplays" getNumVideoDisplaysFFI :: IO CInt
254257
foreign import ccall "SDL.h SDL_GetNumVideoDrivers" getNumVideoDriversFFI :: IO CInt
255258
foreign import ccall "SDL.h SDL_GetVideoDriver" getVideoDriverFFI :: CInt -> IO CString
256-
foreign import ccall "SDL.h SDL_GetWindowBordersSize" getWindowBordersSize :: Window -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt
259+
foreign import ccall "SDL.h SDL_GetWindowBordersSize" getWindowBordersSizeFFI :: Window -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt
257260
foreign import ccall "SDL.h SDL_GetWindowBrightness" getWindowBrightnessFFI :: Window -> IO CFloat
258261
foreign import ccall "SDL.h SDL_GetWindowData" getWindowDataFFI :: Window -> CString -> IO (Ptr ())
259262
foreign import ccall "SDL.h SDL_GetWindowDisplayIndex" getWindowDisplayIndexFFI :: Window -> IO CInt
@@ -297,6 +300,7 @@ foreign import ccall "SDL.h SDL_UpdateWindowSurfaceRects" updateWindowSurfaceRec
297300
foreign import ccall "SDL.h SDL_VideoInit" videoInitFFI :: CString -> IO CInt
298301
foreign import ccall "SDL.h SDL_VideoQuit" videoQuitFFI :: IO ()
299302

303+
foreign import ccall "SDL.h SDL_ComposeCustomBlendMode" composeCustomBlendModeFFI :: BlendFactor -> BlendFactor -> BlendOperation -> BlendFactor -> BlendFactor -> BlendOperation -> IO BlendMode
300304
foreign import ccall "SDL.h SDL_CreateRenderer" createRendererFFI :: Window -> CInt -> Word32 -> IO Renderer
301305
foreign import ccall "SDL.h SDL_CreateSoftwareRenderer" createSoftwareRendererFFI :: Ptr Surface -> IO Renderer
302306
foreign import ccall "SDL.h SDL_CreateTexture" createTextureFFI :: Renderer -> Word32 -> CInt -> CInt -> CInt -> IO Texture
@@ -541,6 +545,10 @@ getDisplayName :: MonadIO m => CInt -> m CString
541545
getDisplayName v1 = liftIO $ getDisplayNameFFI v1
542546
{-# INLINE getDisplayName #-}
543547

548+
getDisplayUsableBounds :: MonadIO m => CInt -> Ptr Rect -> m CInt
549+
getDisplayUsableBounds v1 v2 = liftIO $ getDisplayUsableBoundsFFI v1 v2
550+
{-# INLINE getDisplayUsableBounds #-}
551+
544552
getGrabbedWindow :: MonadIO m => m Window
545553
getGrabbedWindow = liftIO getGrabbedWindowFFI
546554
{-# INLINE getGrabbedWindow #-}
@@ -561,6 +569,10 @@ getVideoDriver :: MonadIO m => CInt -> m CString
561569
getVideoDriver v1 = liftIO $ getVideoDriverFFI v1
562570
{-# INLINE getVideoDriver #-}
563571

572+
getWindowBordersSize :: MonadIO m => Window -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> m CInt
573+
getWindowBordersSize v1 v2 v3 v4 v5 = liftIO $ getWindowBordersSizeFFI v1 v2 v3 v4 v5
574+
{-# INLINE getWindowBordersSize #-}
575+
564576
getWindowBrightness :: MonadIO m => Window -> m CFloat
565577
getWindowBrightness v1 = liftIO $ getWindowBrightnessFFI v1
566578
{-# INLINE getWindowBrightness #-}
@@ -729,6 +741,10 @@ videoQuit :: MonadIO m => m ()
729741
videoQuit = liftIO videoQuitFFI
730742
{-# INLINE videoQuit #-}
731743

744+
composeCustomBlendMode :: MonadIO m => BlendFactor -> BlendFactor -> BlendOperation -> BlendFactor -> BlendFactor -> BlendOperation -> m BlendMode
745+
composeCustomBlendMode v1 v2 v3 v4 v5 v6 = liftIO $ composeCustomBlendModeFFI v1 v2 v3 v4 v5 v6
746+
{-# INLINE composeCustomBlendMode #-}
747+
732748
createRenderer :: MonadIO m => Window -> CInt -> Word32 -> m Renderer
733749
createRenderer v1 v2 v3 = liftIO $ createRendererFFI v1 v2 v3
734750
{-# INLINE createRenderer #-}

0 commit comments

Comments
 (0)