module Graphics.UI.SDL.Rotozoomer where
import Foreign
import Foreign.C
import Graphics.UI.SDL.Video
import Graphics.UI.SDL.General
import Graphics.UI.SDL.Types
finalizeWhenNotNull :: String -> Ptr SurfaceStruct -> IO Surface
finalizeWhenNotNull :: String -> Ptr SurfaceStruct -> IO Surface
finalizeWhenNotNull errMsg :: String
errMsg image :: Ptr SurfaceStruct
image
= if Ptr SurfaceStruct
image Ptr SurfaceStruct -> Ptr SurfaceStruct -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr SurfaceStruct
forall a. Ptr a
nullPtr
then String -> IO Surface
forall a. String -> IO a
failWithError String
errMsg
else Ptr SurfaceStruct -> IO Surface
mkFinalizedSurface Ptr SurfaceStruct
image
foreign import ccall unsafe "rotozoomSurface" sdlRotozoom
:: Ptr SurfaceStruct -> Double -> Double -> Int -> IO (Ptr SurfaceStruct)
rotozoom :: Surface -> Double -> Double -> Bool -> IO Surface
rotozoom :: Surface -> Double -> Double -> Bool -> IO Surface
rotozoom src :: Surface
src angle :: Double
angle zoom :: Double
zoom smooth :: Bool
smooth
= Surface -> (Ptr SurfaceStruct -> IO Surface) -> IO Surface
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Surface
src ((Ptr SurfaceStruct -> IO Surface) -> IO Surface)
-> (Ptr SurfaceStruct -> IO Surface) -> IO Surface
forall a b. (a -> b) -> a -> b
$ \imgSrc :: Ptr SurfaceStruct
imgSrc ->
Ptr SurfaceStruct
-> Double -> Double -> Int -> IO (Ptr SurfaceStruct)
sdlRotozoom Ptr SurfaceStruct
imgSrc Double
angle Double
zoom (Bool -> Int
forall a. Num a => Bool -> a
fromBool Bool
smooth) IO (Ptr SurfaceStruct)
-> (Ptr SurfaceStruct -> IO Surface) -> IO Surface
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Ptr SurfaceStruct -> IO Surface
finalizeWhenNotNull "rotozoomSurface"
foreign import ccall unsafe "zoomSurface" sdlZoom
:: Ptr SurfaceStruct -> Double -> Double -> Int -> IO (Ptr SurfaceStruct)
zoom :: Surface -> Double -> Double -> Bool -> IO Surface
zoom :: Surface -> Double -> Double -> Bool -> IO Surface
zoom src :: Surface
src zoomx :: Double
zoomx zoomy :: Double
zoomy smooth :: Bool
smooth
= Surface -> (Ptr SurfaceStruct -> IO Surface) -> IO Surface
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Surface
src ((Ptr SurfaceStruct -> IO Surface) -> IO Surface)
-> (Ptr SurfaceStruct -> IO Surface) -> IO Surface
forall a b. (a -> b) -> a -> b
$ \imgSrc :: Ptr SurfaceStruct
imgSrc ->
Ptr SurfaceStruct
-> Double -> Double -> Int -> IO (Ptr SurfaceStruct)
sdlZoom Ptr SurfaceStruct
imgSrc Double
zoomx Double
zoomy (Bool -> Int
forall a. Num a => Bool -> a
fromBool Bool
smooth) IO (Ptr SurfaceStruct)
-> (Ptr SurfaceStruct -> IO Surface) -> IO Surface
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Ptr SurfaceStruct -> IO Surface
finalizeWhenNotNull "zoomSurface"