Skip to content

Put copyExF under a package flag #250

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

Merged
merged 1 commit into from
Mar 10, 2022
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
17 changes: 15 additions & 2 deletions sdl2.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ source-repository head
flag examples
description: Build examples (except opengl-example)
default: False
manual: True

flag opengl-example
description: Build opengl-example
default: False
manual: True

flag no-linear
description: Do not depend on 'linear' library
default: False
manual: True

flag recent-ish
description: Use features from a more recent libsdl2 release.
default: True
manual: False

library
-- ghc-options: -Wall

Expand Down Expand Up @@ -120,8 +127,14 @@ library
extra-libraries:
SDL2

pkgconfig-depends:
sdl2 >= 2.0.6
if flag(recent-ish)
cpp-options:
-D RECENT_ISH
pkgconfig-depends:
sdl2 >= 2.0.10
else
pkgconfig-depends:
sdl2 >= 2.0.6

build-depends:
base >= 4.7 && < 5,
Expand Down
8 changes: 8 additions & 0 deletions src/SDL/Raw/Video.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

module SDL.Raw.Video (
-- * Display and Window Management
createWindow,
Expand Down Expand Up @@ -106,7 +108,9 @@ module SDL.Raw.Video (
renderClear,
renderCopy,
renderCopyEx,
#ifdef RECENT_ISH
renderCopyExF,
#endif
renderDrawLine,
renderDrawLines,
renderDrawPoint,
Expand Down Expand Up @@ -324,7 +328,9 @@ foreign import ccall "SDL.h SDL_QueryTexture" queryTextureFFI :: Texture -> Ptr
foreign import ccall "SDL.h SDL_RenderClear" renderClearFFI :: Renderer -> IO CInt
foreign import ccall "SDL.h SDL_RenderCopy" renderCopyFFI :: Renderer -> Texture -> Ptr Rect -> Ptr Rect -> IO CInt
foreign import ccall "SDL.h SDL_RenderCopyEx" renderCopyExFFI :: Renderer -> Texture -> Ptr Rect -> Ptr Rect -> CDouble -> Ptr Point -> RendererFlip -> IO CInt
#ifdef RECENT_ISH
foreign import ccall "SDL.h SDL_RenderCopyExF" renderCopyExFFFI :: Renderer -> Texture -> Ptr Rect -> Ptr FRect -> CDouble -> Ptr FPoint -> RendererFlip -> IO CInt
#endif
foreign import ccall "SDL.h SDL_RenderDrawLine" renderDrawLineFFI :: Renderer -> CInt -> CInt -> CInt -> CInt -> IO CInt
foreign import ccall "SDL.h SDL_RenderDrawLines" renderDrawLinesFFI :: Renderer -> Ptr Point -> CInt -> IO CInt
foreign import ccall "SDL.h SDL_RenderDrawPoint" renderDrawPointFFI :: Renderer -> CInt -> CInt -> IO CInt
Expand Down Expand Up @@ -835,9 +841,11 @@ renderCopyEx :: MonadIO m => Renderer -> Texture -> Ptr Rect -> Ptr Rect -> CDou
renderCopyEx v1 v2 v3 v4 v5 v6 v7 = liftIO $ renderCopyExFFI v1 v2 v3 v4 v5 v6 v7
{-# INLINE renderCopyEx #-}

#ifdef RECENT_ISH
renderCopyExF :: MonadIO m => Renderer -> Texture -> Ptr Rect -> Ptr FRect -> CDouble -> Ptr FPoint -> RendererFlip -> m CInt
renderCopyExF v1 v2 v3 v4 v5 v6 v7 = liftIO $ renderCopyExFFFI v1 v2 v3 v4 v5 v6 v7
{-# INLINE renderCopyExF #-}
#endif

renderDrawLine :: MonadIO m => Renderer -> CInt -> CInt -> CInt -> CInt -> m CInt
renderDrawLine v1 v2 v3 v4 v5 = liftIO $ renderDrawLineFFI v1 v2 v3 v4 v5
Expand Down
4 changes: 4 additions & 0 deletions src/SDL/Video/Renderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ module SDL.Video.Renderer
, clear
, copy
, copyEx
#ifdef RECENT_ISH
, copyExF
#endif
, drawLine
, drawLines
, drawPoint
Expand Down Expand Up @@ -765,6 +767,7 @@ copyEx (Renderer r) (Texture t) srcRect dstRect theta center flips =
V2 x y -> (if x then Raw.SDL_FLIP_HORIZONTAL else 0) .|.
(if y then Raw.SDL_FLIP_VERTICAL else 0))

#ifdef RECENT_ISH
-- | Copy a portion of the texture to the current rendering target, optionally rotating it by angle around the given center and also flipping it top-bottom and/or left-right.
copyExF :: MonadIO m
=> Renderer -- ^ The rendering context
Expand All @@ -785,6 +788,7 @@ copyExF (Renderer r) (Texture t) srcRect dstRect theta center flips =
(case flips of
V2 x y -> (if x then Raw.SDL_FLIP_HORIZONTAL else 0) .|.
(if y then Raw.SDL_FLIP_VERTICAL else 0))
#endif

-- | Draw a line on the current rendering target.
--
Expand Down