Skip to content
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
2 changes: 1 addition & 1 deletion sdl2.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ library
-DRECENT_ISH
if flag(pkgconfig)
pkgconfig-depends:
sdl2 >= 2.0.10
sdl2 >= 2.0.14
else
if flag(pkgconfig)
pkgconfig-depends:
Expand Down
18 changes: 18 additions & 0 deletions src/SDL/Raw/Enum.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,15 @@ module SDL.Raw.Enum (
pattern SDL_SYSTEM_CURSOR_IBEAM,
pattern SDL_SYSTEM_CURSOR_WAIT,

#ifdef RECENT_ISH
-- ** Scale mode
ScaleMode,
-- NB. no idea why this enum uses camel case instead of scream case
pattern SDL_ScaleModeNearest,
pattern SDL_ScaleModeLinear,
pattern SDL_ScaleModeBest,
#endif

-- ** System Cursor
SystemCursor,
pattern SDL_SYSTEM_CURSOR_CROSSHAIR,
Expand Down Expand Up @@ -978,6 +987,9 @@ type LogPriority = (#type SDL_LogPriority)
type PowerState = (#type SDL_PowerState)
type RendererFlip = (#type SDL_RendererFlip)
type Scancode = (#type SDL_Scancode)
#ifdef RECENT_ISH
type ScaleMode = (#type SDL_ScaleMode)
#endif
type SystemCursor = (#type SDL_SystemCursor)
type ThreadPriority = (#type SDL_ThreadPriority)

Expand Down Expand Up @@ -1621,6 +1633,12 @@ pattern SDL_SCANCODE_APP1 = (#const SDL_SCANCODE_APP1) :: Scancode
pattern SDL_SCANCODE_APP2 = (#const SDL_SCANCODE_APP2) :: Scancode
pattern SDL_NUM_SCANCODES = (#const SDL_NUM_SCANCODES) :: Scancode

#ifdef RECENT_ISH
pattern SDL_ScaleModeNearest = (#const SDL_ScaleModeNearest) :: ScaleMode
pattern SDL_ScaleModeLinear = (#const SDL_ScaleModeLinear) :: ScaleMode
pattern SDL_ScaleModeBest = (#const SDL_ScaleModeBest) :: ScaleMode
#endif

pattern SDL_SYSTEM_CURSOR_ARROW = (#const SDL_SYSTEM_CURSOR_ARROW) :: SystemCursor
pattern SDL_SYSTEM_CURSOR_IBEAM = (#const SDL_SYSTEM_CURSOR_IBEAM) :: SystemCursor
pattern SDL_SYSTEM_CURSOR_WAIT = (#const SDL_SYSTEM_CURSOR_WAIT) :: SystemCursor
Expand Down
13 changes: 13 additions & 0 deletions src/SDL/Raw/Video.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ module SDL.Raw.Video (
renderFillRectsF,
renderGeometry,
renderGeometryRaw,
getTextureScaleMode,
setTextureScaleMode,
#endif
renderGetClipRect,
renderGetIntegerScale,
Expand Down Expand Up @@ -365,6 +367,8 @@ foreign import ccall "SDL.h SDL_RenderFillRectF" renderFillRectFFFI :: Renderer
foreign import ccall "SDL.h SDL_RenderFillRectsF" renderFillRectsFFFI :: Renderer -> Ptr FRect -> CInt -> IO CInt
foreign import ccall "SDL.h SDL_RenderGeometry" renderGeometryFFI :: Renderer -> Texture -> Ptr Vertex -> CInt -> Ptr CInt -> CInt -> IO CInt
foreign import ccall "SDL.h SDL_RenderGeometryRaw" renderGeometryRawFFI :: Renderer -> Texture -> Ptr FPoint -> CInt -> Ptr Color -> CInt -> Ptr FPoint -> CInt -> CInt -> Ptr () -> CInt -> CInt -> IO CInt
foreign import ccall "SDL.h SDL_GetTextureScaleMode" getTextureScaleModeFFI :: Texture -> Ptr ScaleMode -> IO CInt
foreign import ccall "SDL.h SDL_SetTextureScaleMode" setTextureScaleModeFFI :: Texture -> ScaleMode -> IO CInt
#endif
foreign import ccall "sqlhelper.c SDLHelper_RenderFillRectEx" renderFillRectExFFI :: Renderer -> CInt -> CInt -> CInt -> CInt -> IO CInt
foreign import ccall "SDL.h SDL_RenderFillRects" renderFillRectsFFI :: Renderer -> Ptr Rect -> CInt -> IO CInt
Expand Down Expand Up @@ -964,6 +968,15 @@ renderGeometry v1 v2 v3 v4 v5 v6 = liftIO $ renderGeometryFFI v1 v2 v3 v4 v5 v6
renderGeometryRaw :: MonadIO m => Renderer -> Texture -> Ptr FPoint -> CInt -> Ptr Color -> CInt -> Ptr FPoint -> CInt -> CInt -> Ptr () -> CInt -> CInt -> m CInt
renderGeometryRaw v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 = liftIO $ renderGeometryRawFFI v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12
{-# INLINE renderGeometryRaw #-}

getTextureScaleMode :: MonadIO m => Texture -> Ptr ScaleMode -> m CInt
getTextureScaleMode t ps = liftIO $ getTextureScaleModeFFI t ps
{-# INLINE getTextureScaleMode #-}

setTextureScaleMode :: MonadIO m => Texture -> ScaleMode -> m CInt
setTextureScaleMode t s = liftIO $ setTextureScaleModeFFI t s
{-# INLINE setTextureScaleMode #-}

#endif


Expand Down
49 changes: 49 additions & 0 deletions src/SDL/Video/Renderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ module SDL.Video.Renderer
, textureBlendMode
, BlendMode(..)
, textureColorMod
#ifdef RECENT_ISH
, textureScaleMode
, ScaleMode(..)
#endif

-- ** Accessing 'Texture' Data
, lockTexture
Expand Down Expand Up @@ -1335,6 +1339,51 @@ textureBlendMode (Texture t) = makeStateVar getTextureBlendMode setTextureBlendM
throwIfNeg_ "SDL.Video.Renderer.setTextureBlendMode" "SDL_SetTextureBlendMode" $
Raw.setTextureBlendMode t (toNumber bm)

#ifdef RECENT_ISH

-- | Scale modes used in copy operations
data ScaleMode
= ScaleModeNearest
-- ^ Nearest-neighbor scaling
| ScaleModeLinear
-- ^ Linear scaling
| ScaleModeBest
-- ^ anisotropic filtering
deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show, Typeable)

instance FromNumber ScaleMode Word32 where
fromNumber n = case n of
Raw.SDL_ScaleModeNearest -> ScaleModeNearest
Raw.SDL_ScaleModeLinear -> ScaleModeLinear
Raw.SDL_ScaleModeBest -> ScaleModeBest
_ -> error $ "fromNumber <ScaleMode>: unkonwn scale mode: " ++ (show n)

instance ToNumber ScaleMode Word32 where
toNumber ScaleModeNearest = Raw.SDL_ScaleModeNearest
toNumber ScaleModeLinear = Raw.SDL_ScaleModeLinear
toNumber ScaleModeBest = Raw.SDL_ScaleModeBest

-- | Get or set the scale mode use for texture scale operations.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
--
-- See @<https://wiki.libsdl.org/SDL2/SDL_GetTextureScaleMode SDL_GetTextureScaleMode>@ and @<https://wiki.libsdl.org/SDL2/SDL_SetTextureScaleMode SDL_SetTextureScaleMode>@
textureScaleMode :: Texture -> StateVar ScaleMode
textureScaleMode (Texture t) = makeStateVar getTextureScaleMode setTextureScaleMode
where
getTextureScaleMode =
alloca $ \x -> do
throwIfNeg_ "SDL.Video.Renderer.getTextureScaleMode" "SDL_GetTextureScaleMode" $
Raw.getTextureScaleMode t x
fromNumber <$> peek x

setTextureScaleMode sm =
throwIfNeg_ "SDL.Video.Renderer.setTextureScaleMode" "SDL_SetTextureScaleMode" $
Raw.setTextureScaleMode t (toNumber sm)

#endif


-- | Get or set the blend mode used for blit operations.
--
-- This 'StateVar' can be modified using '$=' and the current value retrieved with 'get'.
Expand Down
Loading