diff --git a/sdl2.cabal b/sdl2.cabal index 558eae3..c6537b7 100644 --- a/sdl2.cabal +++ b/sdl2.cabal @@ -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: diff --git a/src/SDL/Raw/Enum.hsc b/src/SDL/Raw/Enum.hsc index 557e21b..076b2b0 100644 --- a/src/SDL/Raw/Enum.hsc +++ b/src/SDL/Raw/Enum.hsc @@ -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, @@ -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) @@ -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 diff --git a/src/SDL/Raw/Video.hs b/src/SDL/Raw/Video.hs index b0bd136..6494037 100644 --- a/src/SDL/Raw/Video.hs +++ b/src/SDL/Raw/Video.hs @@ -132,6 +132,8 @@ module SDL.Raw.Video ( renderFillRectsF, renderGeometry, renderGeometryRaw, + getTextureScaleMode, + setTextureScaleMode, #endif renderGetClipRect, renderGetIntegerScale, @@ -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 @@ -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 diff --git a/src/SDL/Video/Renderer.hs b/src/SDL/Video/Renderer.hs index b2e3725..501d7e1 100644 --- a/src/SDL/Video/Renderer.hs +++ b/src/SDL/Video/Renderer.hs @@ -118,6 +118,10 @@ module SDL.Video.Renderer , textureBlendMode , BlendMode(..) , textureColorMod +#ifdef RECENT_ISH + , textureScaleMode + , ScaleMode(..) +#endif -- ** Accessing 'Texture' Data , lockTexture @@ -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 : 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 @@ and @@ +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'.