Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bindings for some missing parts of the raw SDL2 API #205

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/SDL/Raw/Enum.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -934,6 +955,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)
Expand Down Expand Up @@ -975,6 +998,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
Expand Down
18 changes: 17 additions & 1 deletion src/SDL/Raw/Video.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module SDL.Raw.Video (
getDisplayDPI,
getDisplayMode,
getDisplayName,
getDisplayUsableBounds,
getGrabbedWindow,
getNumDisplayModes,
getNumVideoDisplays,
Expand Down Expand Up @@ -82,6 +83,7 @@ module SDL.Raw.Video (
videoQuit,

-- * 2D Accelerated Rendering
composeCustomBlendMode,
createRenderer,
createSoftwareRenderer,
createTexture,
Expand Down Expand Up @@ -248,12 +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" getWindowBordersSize :: Window -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt
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
Expand Down Expand Up @@ -297,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
Expand Down Expand Up @@ -541,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 #-}
Expand All @@ -561,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 #-}
Expand Down Expand Up @@ -729,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 #-}
Expand Down