From f4b68a7b151c65bc12179a1ebce7157dc0b25a6e Mon Sep 17 00:00:00 2001 From: EvanR Date: Tue, 26 Nov 2019 19:49:02 -0600 Subject: [PATCH] Bindings for some missing parts of the raw SDL2 API Namely the function SDL_ComposeCustomBlendMode and the associated enums, SDL_GetWindowBordersSize, and SDL_GetDisplayUsableBounds. --- src/SDL/Raw/Enum.hsc | 40 ++++++++++++++++++++++++++++++++++++++++ src/SDL/Raw/Video.hs | 18 ++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/SDL/Raw/Enum.hsc b/src/SDL/Raw/Enum.hsc index a0bd3708..42020f8e 100644 --- a/src/SDL/Raw/Enum.hsc +++ b/src/SDL/Raw/Enum.hsc @@ -33,6 +33,27 @@ module SDL.Raw.Enum ( pattern SDL_BLENDMODE_ADD, pattern SDL_BLENDMODE_MOD, + -- ** Blend Operation + BlendOperation, + pattern SDL_BLENDOPERATION_ADD, + pattern SDL_BLENDOPERATION_SUBTRACT, + pattern SDL_BLENDOPERATION_REV_SUBTRACT, + pattern SDL_BLENDOPERATION_MINIMUM, + pattern SDL_BLENDOPERATION_MAXIMUM, + + -- ** Blend Factor + BlendFactor, + pattern SDL_BLENDFACTOR_ZERO, + pattern SDL_BLENDFACTOR_ONE, + pattern SDL_BLENDFACTOR_SRC_COLOR, + pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR, + pattern SDL_BLENDFACTOR_SRC_ALPHA, + pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, + pattern SDL_BLENDFACTOR_DST_COLOR, + pattern SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR, + pattern SDL_BLENDFACTOR_DST_ALPHA, + pattern SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA, + -- ** Endian Detetection pattern SDL_BYTEORDER, pattern SDL_LIL_ENDIAN, @@ -918,6 +939,8 @@ import Foreign.C.Types type AudioFormat = (#type SDL_AudioFormat) type AudioStatus = (#type SDL_AudioStatus) type BlendMode = (#type SDL_BlendMode) +type BlendOperation = (#type SDL_BlendOperation) +type BlendFactor = (#type SDL_BlendFactor) type Endian = CInt type EventAction = (#type SDL_eventaction) type GameControllerAxis = (#type SDL_GameControllerAxis) @@ -959,6 +982,23 @@ pattern SDL_BLENDMODE_BLEND = (#const SDL_BLENDMODE_BLEND) :: BlendMode pattern SDL_BLENDMODE_ADD = (#const SDL_BLENDMODE_ADD) :: BlendMode pattern SDL_BLENDMODE_MOD = (#const SDL_BLENDMODE_MOD) :: BlendMode +pattern SDL_BLENDOPERATION_ADD = (#const SDL_BLENDOPERATION_ADD) :: BlendOperation +pattern SDL_BLENDOPERATION_SUBTRACT = (#const SDL_BLENDOPERATION_SUBTRACT) :: BlendOperation +pattern SDL_BLENDOPERATION_REV_SUBTRACT = (#const SDL_BLENDOPERATION_REV_SUBTRACT) :: BlendOperation +pattern SDL_BLENDOPERATION_MINIMUM = (#const SDL_BLENDOPERATION_MINIMUM) :: BlendOperation +pattern SDL_BLENDOPERATION_MAXIMUM = (#const SDL_BLENDOPERATION_MAXIMUM) :: BlendOperation + +pattern SDL_BLENDFACTOR_ZERO = (#const SDL_BLENDFACTOR_ZERO) :: BlendFactor +pattern SDL_BLENDFACTOR_ONE = (#const SDL_BLENDFACTOR_ONE) :: BlendFactor +pattern SDL_BLENDFACTOR_SRC_COLOR = (#const SDL_BLENDFACTOR_SRC_COLOR) :: BlendFactor +pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = (#const SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR) :: BlendFactor +pattern SDL_BLENDFACTOR_SRC_ALPHA = (#const SDL_BLENDFACTOR_SRC_ALPHA) :: BlendFactor +pattern SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = (#const SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA) :: BlendFactor +pattern SDL_BLENDFACTOR_DST_COLOR = (#const SDL_BLENDFACTOR_DST_COLOR) :: BlendFactor +pattern SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = (#const SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR) :: BlendFactor +pattern SDL_BLENDFACTOR_DST_ALPHA = (#const SDL_BLENDFACTOR_DST_ALPHA) :: BlendFactor +pattern SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = (#const SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA) :: BlendFactor + pattern SDL_BYTEORDER = (#const SDL_BYTEORDER) :: Endian pattern SDL_LIL_ENDIAN = (#const SDL_LIL_ENDIAN) :: Endian pattern SDL_BIG_ENDIAN = (#const SDL_BIG_ENDIAN) :: Endian diff --git a/src/SDL/Raw/Video.hs b/src/SDL/Raw/Video.hs index 08c88556..5b366216 100644 --- a/src/SDL/Raw/Video.hs +++ b/src/SDL/Raw/Video.hs @@ -32,11 +32,13 @@ module SDL.Raw.Video ( getDisplayDPI, getDisplayMode, getDisplayName, + getDisplayUsableBounds, getGrabbedWindow, getNumDisplayModes, getNumVideoDisplays, getNumVideoDrivers, getVideoDriver, + getWindowBordersSize, getWindowBrightness, getWindowData, getWindowDisplayIndex, @@ -81,6 +83,7 @@ module SDL.Raw.Video ( videoQuit, -- * 2D Accelerated Rendering + composeCustomBlendMode, createRenderer, createSoftwareRenderer, createTexture, @@ -247,11 +250,13 @@ foreign import ccall "SDL.h SDL_GetDisplayBounds" getDisplayBoundsFFI :: CInt -> foreign import ccall "SDL.h SDL_GetDisplayDPI" getDisplayDPIFFI :: CInt -> Ptr CFloat -> Ptr CFloat -> Ptr CFloat -> IO CInt foreign import ccall "SDL.h SDL_GetDisplayMode" getDisplayModeFFI :: CInt -> CInt -> Ptr DisplayMode -> IO CInt foreign import ccall "SDL.h SDL_GetDisplayName" getDisplayNameFFI :: CInt -> IO CString +foreign import ccall "SDL.h SDL_GetDisplayUsableBounds" getDisplayUsableBoundsFFI :: CInt -> Ptr Rect -> IO CInt foreign import ccall "SDL.h SDL_GetGrabbedWindow" getGrabbedWindowFFI :: IO Window foreign import ccall "SDL.h SDL_GetNumDisplayModes" getNumDisplayModesFFI :: CInt -> IO CInt foreign import ccall "SDL.h SDL_GetNumVideoDisplays" getNumVideoDisplaysFFI :: IO CInt foreign import ccall "SDL.h SDL_GetNumVideoDrivers" getNumVideoDriversFFI :: IO CInt foreign import ccall "SDL.h SDL_GetVideoDriver" getVideoDriverFFI :: CInt -> IO CString +foreign import ccall "SDL.h SDL_GetWindowBordersSize" getWindowBordersSizeFFI :: Window -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt foreign import ccall "SDL.h SDL_GetWindowBrightness" getWindowBrightnessFFI :: Window -> IO CFloat foreign import ccall "SDL.h SDL_GetWindowData" getWindowDataFFI :: Window -> CString -> IO (Ptr ()) foreign import ccall "SDL.h SDL_GetWindowDisplayIndex" getWindowDisplayIndexFFI :: Window -> IO CInt @@ -295,6 +300,7 @@ foreign import ccall "SDL.h SDL_UpdateWindowSurfaceRects" updateWindowSurfaceRec foreign import ccall "SDL.h SDL_VideoInit" videoInitFFI :: CString -> IO CInt foreign import ccall "SDL.h SDL_VideoQuit" videoQuitFFI :: IO () +foreign import ccall "SDL.h SDL_ComposeCustomBlendMode" composeCustomBlendModeFFI :: BlendFactor -> BlendFactor -> BlendOperation -> BlendFactor -> BlendFactor -> BlendOperation -> IO BlendMode foreign import ccall "SDL.h SDL_CreateRenderer" createRendererFFI :: Window -> CInt -> Word32 -> IO Renderer foreign import ccall "SDL.h SDL_CreateSoftwareRenderer" createSoftwareRendererFFI :: Ptr Surface -> IO Renderer foreign import ccall "SDL.h SDL_CreateTexture" createTextureFFI :: Renderer -> Word32 -> CInt -> CInt -> CInt -> IO Texture @@ -539,6 +545,10 @@ getDisplayName :: MonadIO m => CInt -> m CString getDisplayName v1 = liftIO $ getDisplayNameFFI v1 {-# INLINE getDisplayName #-} +getDisplayUsableBounds :: MonadIO m => CInt -> Ptr Rect -> m CInt +getDisplayUsableBounds v1 v2 = liftIO $ getDisplayUsableBoundsFFI v1 v2 +{-# INLINE getDisplayUsableBounds #-} + getGrabbedWindow :: MonadIO m => m Window getGrabbedWindow = liftIO getGrabbedWindowFFI {-# INLINE getGrabbedWindow #-} @@ -559,6 +569,10 @@ getVideoDriver :: MonadIO m => CInt -> m CString getVideoDriver v1 = liftIO $ getVideoDriverFFI v1 {-# INLINE getVideoDriver #-} +getWindowBordersSize :: MonadIO m => Window -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> m CInt +getWindowBordersSize v1 v2 v3 v4 v5 = liftIO $ getWindowBordersSizeFFI v1 v2 v3 v4 v5 +{-# INLINE getWindowBordersSize #-} + getWindowBrightness :: MonadIO m => Window -> m CFloat getWindowBrightness v1 = liftIO $ getWindowBrightnessFFI v1 {-# INLINE getWindowBrightness #-} @@ -727,6 +741,10 @@ videoQuit :: MonadIO m => m () videoQuit = liftIO videoQuitFFI {-# INLINE videoQuit #-} +composeCustomBlendMode :: MonadIO m => BlendFactor -> BlendFactor -> BlendOperation -> BlendFactor -> BlendFactor -> BlendOperation -> m BlendMode +composeCustomBlendMode v1 v2 v3 v4 v5 v6 = liftIO $ composeCustomBlendModeFFI v1 v2 v3 v4 v5 v6 +{-# INLINE composeCustomBlendMode #-} + createRenderer :: MonadIO m => Window -> CInt -> Word32 -> m Renderer createRenderer v1 v2 v3 = liftIO $ createRendererFFI v1 v2 v3 {-# INLINE createRenderer #-}