Skip to content

Commit 941327b

Browse files
authored
Add missing floating point variants of render functions (#271)
We already had copyExF, this also adds * copyF * drawLineF * drawLinesF * drawPointF * drawPointsF * drawRectF * drawRectsF * fillRectF * fillRectsF
1 parent a9e8fd6 commit 941327b

File tree

2 files changed

+169
-38
lines changed

2 files changed

+169
-38
lines changed

src/SDL/Raw/Video.hs

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ module SDL.Raw.Video (
108108
renderClear,
109109
renderCopy,
110110
renderCopyEx,
111-
#ifdef RECENT_ISH
112-
renderCopyExF,
113-
#endif
114111
renderDrawLine,
115112
renderDrawLines,
116113
renderDrawPoint,
@@ -120,6 +117,18 @@ module SDL.Raw.Video (
120117
renderFillRect,
121118
renderFillRectEx,
122119
renderFillRects,
120+
#ifdef RECENT_ISH
121+
renderCopyF,
122+
renderCopyExF,
123+
renderDrawLineF,
124+
renderDrawLinesF,
125+
renderDrawPointF,
126+
renderDrawPointsF,
127+
renderDrawRectF,
128+
renderDrawRectsF,
129+
renderFillRectF,
130+
renderFillRectsF,
131+
#endif
123132
renderGetClipRect,
124133
renderGetLogicalSize,
125134
renderGetScale,
@@ -328,16 +337,25 @@ foreign import ccall "SDL.h SDL_QueryTexture" queryTextureFFI :: Texture -> Ptr
328337
foreign import ccall "SDL.h SDL_RenderClear" renderClearFFI :: Renderer -> IO CInt
329338
foreign import ccall "SDL.h SDL_RenderCopy" renderCopyFFI :: Renderer -> Texture -> Ptr Rect -> Ptr Rect -> IO CInt
330339
foreign import ccall "SDL.h SDL_RenderCopyEx" renderCopyExFFI :: Renderer -> Texture -> Ptr Rect -> Ptr Rect -> CDouble -> Ptr Point -> RendererFlip -> IO CInt
331-
#ifdef RECENT_ISH
332-
foreign import ccall "SDL.h SDL_RenderCopyExF" renderCopyExFFFI :: Renderer -> Texture -> Ptr Rect -> Ptr FRect -> CDouble -> Ptr FPoint -> RendererFlip -> IO CInt
333-
#endif
334340
foreign import ccall "SDL.h SDL_RenderDrawLine" renderDrawLineFFI :: Renderer -> CInt -> CInt -> CInt -> CInt -> IO CInt
335341
foreign import ccall "SDL.h SDL_RenderDrawLines" renderDrawLinesFFI :: Renderer -> Ptr Point -> CInt -> IO CInt
336342
foreign import ccall "SDL.h SDL_RenderDrawPoint" renderDrawPointFFI :: Renderer -> CInt -> CInt -> IO CInt
337343
foreign import ccall "SDL.h SDL_RenderDrawPoints" renderDrawPointsFFI :: Renderer -> Ptr Point -> CInt -> IO CInt
338344
foreign import ccall "SDL.h SDL_RenderDrawRect" renderDrawRectFFI :: Renderer -> Ptr Rect -> IO CInt
339345
foreign import ccall "SDL.h SDL_RenderDrawRects" renderDrawRectsFFI :: Renderer -> Ptr Rect -> CInt -> IO CInt
340346
foreign import ccall "SDL.h SDL_RenderFillRect" renderFillRectFFI :: Renderer -> Ptr Rect -> IO CInt
347+
#ifdef RECENT_ISH
348+
foreign import ccall "SDL.h SDL_RenderCopyF" renderCopyFFFI :: Renderer -> Texture -> Ptr Rect -> Ptr FRect -> IO CInt
349+
foreign import ccall "SDL.h SDL_RenderCopyExF" renderCopyExFFFI :: Renderer -> Texture -> Ptr Rect -> Ptr FRect -> CDouble -> Ptr FPoint -> RendererFlip -> IO CInt
350+
foreign import ccall "SDL.h SDL_RenderDrawLineF" renderDrawLineFFFI :: Renderer -> CFloat -> CFloat -> CFloat -> CFloat -> IO CInt
351+
foreign import ccall "SDL.h SDL_RenderDrawLinesF" renderDrawLinesFFFI :: Renderer -> Ptr FPoint -> CInt -> IO CInt
352+
foreign import ccall "SDL.h SDL_RenderDrawPointF" renderDrawPointFFFI :: Renderer -> CFloat -> CFloat -> IO CInt
353+
foreign import ccall "SDL.h SDL_RenderDrawPointsF" renderDrawPointsFFFI :: Renderer -> Ptr FPoint -> CInt -> IO CInt
354+
foreign import ccall "SDL.h SDL_RenderDrawRectF" renderDrawRectFFFI :: Renderer -> Ptr FRect -> IO CInt
355+
foreign import ccall "SDL.h SDL_RenderDrawRectsF" renderDrawRectsFFFI :: Renderer -> Ptr FRect -> CInt -> IO CInt
356+
foreign import ccall "SDL.h SDL_RenderFillRectF" renderFillRectFFFI :: Renderer -> Ptr FRect -> IO CInt
357+
foreign import ccall "SDL.h SDL_RenderFillRectsF" renderFillRectsFFFI :: Renderer -> Ptr FRect -> CInt -> IO CInt
358+
#endif
341359
foreign import ccall "sqlhelper.c SDLHelper_RenderFillRectEx" renderFillRectExFFI :: Renderer -> CInt -> CInt -> CInt -> CInt -> IO CInt
342360
foreign import ccall "SDL.h SDL_RenderFillRects" renderFillRectsFFI :: Renderer -> Ptr Rect -> CInt -> IO CInt
343361
foreign import ccall "SDL.h SDL_RenderGetClipRect" renderGetClipRectFFI :: Renderer -> Ptr Rect -> IO ()
@@ -841,12 +859,6 @@ renderCopyEx :: MonadIO m => Renderer -> Texture -> Ptr Rect -> Ptr Rect -> CDou
841859
renderCopyEx v1 v2 v3 v4 v5 v6 v7 = liftIO $ renderCopyExFFI v1 v2 v3 v4 v5 v6 v7
842860
{-# INLINE renderCopyEx #-}
843861

844-
#ifdef RECENT_ISH
845-
renderCopyExF :: MonadIO m => Renderer -> Texture -> Ptr Rect -> Ptr FRect -> CDouble -> Ptr FPoint -> RendererFlip -> m CInt
846-
renderCopyExF v1 v2 v3 v4 v5 v6 v7 = liftIO $ renderCopyExFFFI v1 v2 v3 v4 v5 v6 v7
847-
{-# INLINE renderCopyExF #-}
848-
#endif
849-
850862
renderDrawLine :: MonadIO m => Renderer -> CInt -> CInt -> CInt -> CInt -> m CInt
851863
renderDrawLine v1 v2 v3 v4 v5 = liftIO $ renderDrawLineFFI v1 v2 v3 v4 v5
852864
{-# INLINE renderDrawLine #-}
@@ -883,6 +895,51 @@ renderFillRects :: MonadIO m => Renderer -> Ptr Rect -> CInt -> m CInt
883895
renderFillRects v1 v2 v3 = liftIO $ renderFillRectsFFI v1 v2 v3
884896
{-# INLINE renderFillRects #-}
885897

898+
#ifdef RECENT_ISH
899+
900+
renderCopyF :: MonadIO m => Renderer -> Texture -> Ptr Rect -> Ptr FRect -> m CInt
901+
renderCopyF v1 v2 v3 v4 = liftIO $ renderCopyFFFI v1 v2 v3 v4
902+
{-# INLINE renderCopyF #-}
903+
904+
renderCopyExF :: MonadIO m => Renderer -> Texture -> Ptr Rect -> Ptr FRect -> CDouble -> Ptr FPoint -> RendererFlip -> m CInt
905+
renderCopyExF v1 v2 v3 v4 v5 v6 v7 = liftIO $ renderCopyExFFFI v1 v2 v3 v4 v5 v6 v7
906+
{-# INLINE renderCopyExF #-}
907+
908+
renderDrawLineF :: MonadIO m => Renderer -> CFloat -> CFloat -> CFloat -> CFloat -> m CInt
909+
renderDrawLineF v1 v2 v3 v4 v5 = liftIO $ renderDrawLineFFFI v1 v2 v3 v4 v5
910+
{-# INLINE renderDrawLineF #-}
911+
912+
renderDrawLinesF :: MonadIO m => Renderer -> Ptr FPoint -> CInt -> m CInt
913+
renderDrawLinesF v1 v2 v3 = liftIO $ renderDrawLinesFFFI v1 v2 v3
914+
{-# INLINE renderDrawLinesF #-}
915+
916+
renderDrawPointF :: MonadIO m => Renderer -> CFloat -> CFloat -> m CInt
917+
renderDrawPointF v1 v2 v3 = liftIO $ renderDrawPointFFFI v1 v2 v3
918+
{-# INLINE renderDrawPointF #-}
919+
920+
renderDrawPointsF :: MonadIO m => Renderer -> Ptr FPoint -> CInt -> m CInt
921+
renderDrawPointsF v1 v2 v3 = liftIO $ renderDrawPointsFFFI v1 v2 v3
922+
{-# INLINE renderDrawPointsF #-}
923+
924+
renderDrawRectF :: MonadIO m => Renderer -> Ptr FRect -> m CInt
925+
renderDrawRectF v1 v2 = liftIO $ renderDrawRectFFFI v1 v2
926+
{-# INLINE renderDrawRectF #-}
927+
928+
renderDrawRectsF :: MonadIO m => Renderer -> Ptr FRect -> CInt -> m CInt
929+
renderDrawRectsF v1 v2 v3 = liftIO $ renderDrawRectsFFFI v1 v2 v3
930+
{-# INLINE renderDrawRectsF #-}
931+
932+
renderFillRectF :: MonadIO m => Renderer -> Ptr FRect -> m CInt
933+
renderFillRectF v1 v2 = liftIO $ renderFillRectFFFI v1 v2
934+
{-# INLINE renderFillRectF #-}
935+
936+
renderFillRectsF :: MonadIO m => Renderer -> Ptr FRect -> CInt -> m CInt
937+
renderFillRectsF v1 v2 v3 = liftIO $ renderFillRectsFFFI v1 v2 v3
938+
{-# INLINE renderFillRectsF #-}
939+
940+
#endif
941+
942+
886943
renderGetClipRect :: MonadIO m => Renderer -> Ptr Rect -> m ()
887944
renderGetClipRect v1 v2 = liftIO $ renderGetClipRectFFI v1 v2
888945
{-# INLINE renderGetClipRect #-}

src/SDL/Video/Renderer.hs

Lines changed: 100 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ module SDL.Video.Renderer
2323
, clear
2424
, copy
2525
, copyEx
26-
#ifdef RECENT_ISH
27-
, copyExF
28-
#endif
2926
, drawLine
3027
, drawLines
3128
, drawPoint
@@ -34,6 +31,18 @@ module SDL.Video.Renderer
3431
, drawRects
3532
, fillRect
3633
, fillRects
34+
#ifdef RECENT_ISH
35+
, copyF
36+
, copyExF
37+
, drawLineF
38+
, drawLinesF
39+
, drawPointF
40+
, drawPointsF
41+
, drawRectF
42+
, drawRectsF
43+
, fillRectF
44+
, fillRectsF
45+
#endif
3746
, present
3847

3948
-- * 'Renderer' State
@@ -650,6 +659,94 @@ fillRects (Renderer r) rects = liftIO $
650659
(castPtr rp)
651660
(fromIntegral (SV.length rects))
652661

662+
#ifdef RECENT_ISH
663+
664+
-- | Copy a portion of the texture to the current rendering target.
665+
copyF :: MonadIO m => Renderer -> Texture -> Maybe (Rectangle CInt) -> Maybe (Rectangle CFloat) -> m ()
666+
copyF (Renderer r) (Texture t) srcRect dstRect = liftIO $
667+
throwIfNeg_ "SDL.Video.copyF" "SDL_RenderCopyF" $
668+
maybeWith with srcRect $ \src ->
669+
maybeWith with dstRect $ \dst ->
670+
Raw.renderCopyF r t (castPtr src) (castPtr dst)
671+
672+
-- | 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.
673+
copyExF :: MonadIO m
674+
=> Renderer -- ^ The rendering context
675+
-> Texture -- ^ The source texture
676+
-> Maybe (Rectangle CInt) -- ^ The source rectangle to copy, or 'Nothing' for the whole texture
677+
-> Maybe (Rectangle CFloat) -- ^ The destination rectangle to copy to, or 'Nothing' for the whole rendering target. The texture will be stretched to fill the given rectangle.
678+
-> CDouble -- ^ The angle of rotation in degrees. The rotation will be performed clockwise.
679+
-> Maybe (Point V2 CFloat) -- ^ The point indicating the center of the rotation, or 'Nothing' to rotate around the center of the destination rectangle
680+
-> V2 Bool -- ^ Whether to flip the texture on the X and/or Y axis
681+
-> m ()
682+
copyExF (Renderer r) (Texture t) srcRect dstRect theta center flips =
683+
liftIO $
684+
throwIfNeg_ "SDL.Video.copyExF" "SDL_RenderCopyExF" $
685+
maybeWith with srcRect $ \src ->
686+
maybeWith with dstRect $ \dst ->
687+
maybeWith with center $ \c ->
688+
Raw.renderCopyExF r t (castPtr src) (castPtr dst) theta (castPtr c)
689+
(case flips of
690+
V2 x y -> (if x then Raw.SDL_FLIP_HORIZONTAL else 0) .|.
691+
(if y then Raw.SDL_FLIP_VERTICAL else 0))
692+
693+
-- | Draw a line between two points on the current rendering target.
694+
drawLineF :: MonadIO m => Renderer -> Point V2 CFloat -> Point V2 CFloat -> m ()
695+
drawLineF (Renderer r) (P (V2 x y)) (P (V2 x' y')) = liftIO $
696+
throwIfNeg_ "SDL.Video.drawLineF" "SDL_RenderDrawLineF" $
697+
Raw.renderDrawLineF r x y x' y'
698+
699+
-- | Draw a series of connected lines on the current rendering target.
700+
drawLinesF :: MonadIO m => Renderer -> SV.Vector (Point V2 CFloat) -> m ()
701+
drawLinesF (Renderer r) points = liftIO $
702+
throwIfNeg_ "SDL.Video.drawLinesF" "SDL_RenderDrawLinesF" $
703+
SV.unsafeWith points $ \p ->
704+
Raw.renderDrawLinesF r (castPtr p) (fromIntegral (SV.length points))
705+
706+
-- | Draw a point on the current rendering target.
707+
drawPointF :: MonadIO m => Renderer -> Point V2 CFloat -> m ()
708+
drawPointF (Renderer r) (P (V2 x y)) = liftIO $
709+
throwIfNeg_ "SDL.Video.drawPointF" "SDL_RenderDrawPointF" $
710+
Raw.renderDrawPointF r x y
711+
712+
-- | Draw a collection of points on the current rendering target.
713+
drawPointsF :: MonadIO m => Renderer -> SV.Vector (Point V2 CFloat) -> m ()
714+
drawPointsF (Renderer r) points = liftIO $
715+
throwIfNeg_ "SDL.Video.drawPointsF" "SDL_RenderDrawPointsF" $
716+
SV.unsafeWith points $ \p ->
717+
Raw.renderDrawPointsF r (castPtr p) (fromIntegral (SV.length points))
718+
719+
-- | Draw the outline of a rectangle on the current rendering target.
720+
drawRectF :: MonadIO m => Renderer -> Rectangle CFloat -> m ()
721+
drawRectF (Renderer r) rect = liftIO $
722+
throwIfNeg_ "SDL.Video.drawRectF" "SDL_RenderDrawRectF" $
723+
with rect $ \rectPtr ->
724+
Raw.renderDrawRectF r (castPtr rectPtr)
725+
726+
-- | Draw a series of rectangle outlines on the current rendering target.
727+
drawRectsF :: MonadIO m => Renderer -> SV.Vector (Rectangle CFloat) -> m ()
728+
drawRectsF (Renderer r) rects = liftIO $
729+
throwIfNeg_ "SDL.Video.drawRectsF" "SDL_RenderDrawRectsF" $
730+
SV.unsafeWith rects $ \rp ->
731+
Raw.renderDrawRectsF r (castPtr rp) (fromIntegral (SV.length rects))
732+
733+
-- | Draw a filled rectangle on the current rendering target.
734+
fillRectF :: MonadIO m => Renderer -> Rectangle CFloat -> m ()
735+
fillRectF (Renderer r) rect = liftIO $
736+
throwIfNeg_ "SDL.Video.fillRectF" "SDL_RenderFillRectF" $
737+
with rect $ \rectPtr ->
738+
Raw.renderFillRectF r (castPtr rectPtr)
739+
740+
-- | Draw a series of filled rectangles on the current rendering target.
741+
fillRectsF :: MonadIO m => Renderer -> SV.Vector (Rectangle CFloat) -> m ()
742+
fillRectsF (Renderer r) rects = liftIO $
743+
throwIfNeg_ "SDL.Video.fillRectsF" "SDL_RenderFillRectsF" $
744+
SV.unsafeWith rects $ \rp ->
745+
Raw.renderFillRectsF r (castPtr rp) (fromIntegral (SV.length rects))
746+
747+
#endif
748+
749+
653750
-- | Clear the current rendering target with the drawing color.
654751
--
655752
-- See @<https://wiki.libsdl.org/SDL_RenderClear SDL_RenderClear>@ for C documentation.
@@ -765,29 +862,6 @@ copyEx (Renderer r) (Texture t) srcRect dstRect theta center flips =
765862
V2 x y -> (if x then Raw.SDL_FLIP_HORIZONTAL else 0) .|.
766863
(if y then Raw.SDL_FLIP_VERTICAL else 0))
767864

768-
#ifdef RECENT_ISH
769-
-- | 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.
770-
copyExF :: MonadIO m
771-
=> Renderer -- ^ The rendering context
772-
-> Texture -- ^ The source texture
773-
-> Maybe (Rectangle CInt) -- ^ The source rectangle to copy, or 'Nothing' for the whole texture
774-
-> Maybe (Rectangle CFloat) -- ^ The destination rectangle to copy to, or 'Nothing' for the whole rendering target. The texture will be stretched to fill the given rectangle.
775-
-> CDouble -- ^ The angle of rotation in degrees. The rotation will be performed clockwise.
776-
-> Maybe (Point V2 CFloat) -- ^ The point indicating the center of the rotation, or 'Nothing' to rotate around the center of the destination rectangle
777-
-> V2 Bool -- ^ Whether to flip the texture on the X and/or Y axis
778-
-> m ()
779-
copyExF (Renderer r) (Texture t) srcRect dstRect theta center flips =
780-
liftIO $
781-
throwIfNeg_ "SDL.Video.copyExF" "SDL_RenderCopyExF" $
782-
maybeWith with srcRect $ \src ->
783-
maybeWith with dstRect $ \dst ->
784-
maybeWith with center $ \c ->
785-
Raw.renderCopyExF r t (castPtr src) (castPtr dst) theta (castPtr c)
786-
(case flips of
787-
V2 x y -> (if x then Raw.SDL_FLIP_HORIZONTAL else 0) .|.
788-
(if y then Raw.SDL_FLIP_VERTICAL else 0))
789-
#endif
790-
791865
-- | Draw a line on the current rendering target.
792866
--
793867
-- See @<https://wiki.libsdl.org/SDL_RenderDrawLine SDL_RenderDrawLine>@ for C documentation.

0 commit comments

Comments
 (0)