module SFML.Graphics.View
(
createView
, viewFromRect
, copyView
, destroy
, setViewCenter
, setViewSize
, setViewRotation
, setViewport
, resetView
, getViewCenter
, getViewSize
, getViewRotation
, getViewViewport
, moveView
, rotateView
, zoomView
)
where
import SFML.Graphics.Rect
import SFML.Graphics.Types
import SFML.SFResource
import SFML.System.Vector2
import Control.Monad ((>=>))
import Foreign.C.Types
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Utils (with)
import Foreign.Ptr
import Foreign.Storable (peek)
createView :: IO View
createView = sfView_create
foreign import ccall unsafe "sfView_create"
sfView_create :: IO View
viewFromRect
:: FloatRect
-> IO View
viewFromRect rect = with rect sfView_createFromRect
foreign import ccall unsafe "sfView_createFromRect_helper"
sfView_createFromRect :: Ptr FloatRect -> IO View
copyView :: View -> IO View
copyView = sfView_copy
foreign import ccall unsafe "sfView_copy"
sfView_copy :: View -> IO View
instance SFResource View where
destroy = sfView_destroy
foreign import ccall unsafe "sfView_destroy"
sfView_destroy :: View -> IO ()
setViewCenter :: View -> Vec2f -> IO ()
setViewCenter view center = with center $ sfView_setCenter_helper view
foreign import ccall unsafe "sfView_setCenter_helper"
sfView_setCenter_helper :: View -> Ptr Vec2f -> IO ()
setViewSize :: View -> Vec2f -> IO ()
setViewSize view size = with size $ sfView_setSize_helper view
foreign import ccall unsafe "sfView_setSize_helper"
sfView_setSize_helper :: View -> Ptr Vec2f -> IO ()
setViewRotation
:: View
-> Float
-> IO ()
setViewRotation v r = sfView_setRotation v (realToFrac r)
foreign import ccall unsafe "sfView_setRotation"
sfView_setRotation :: View -> CFloat -> IO ()
setViewport
:: View
-> FloatRect
-> IO ()
setViewport view rect = with rect $ sfView_setViewport_helper view
foreign import ccall unsafe "sfView_setViewport_helper"
sfView_setViewport_helper :: View -> Ptr FloatRect -> IO ()
resetView
:: View
-> FloatRect
-> IO ()
resetView view rect = with rect $ sfView_reset_helper view
foreign import ccall unsafe "sfView_reset_helper"
sfView_reset_helper :: View -> Ptr FloatRect -> IO ()
getViewCenter :: View -> IO Vec2f
getViewCenter view = alloca $ \ptr -> sfView_getCenter view ptr >> peek ptr
foreign import ccall unsafe "sfView_getCenter"
sfView_getCenter :: View -> Ptr Vec2f -> IO ()
getViewSize :: View -> IO Vec2f
getViewSize view = alloca $ \ptr -> sfView_getSize_helper view ptr >> peek ptr
foreign import ccall unsafe "sfView_getSize_helper"
sfView_getSize_helper :: View -> Ptr Vec2f -> IO ()
getViewRotation :: View -> IO Float
getViewRotation = sfView_getRotation >=> return . realToFrac
foreign import ccall unsafe "sfView_getRotation"
sfView_getRotation :: View -> IO CFloat
getViewViewport :: View -> IO FloatRect
getViewViewport view = alloca $ \ptr -> sfView_getViewport_helper view ptr >> peek ptr
foreign import ccall unsafe "sfView_getViewport_helper"
sfView_getViewport_helper :: View -> Ptr FloatRect -> IO ()
moveView
:: View
-> Vec2f
-> IO ()
moveView view pos = with pos $ sfView_move_helper view
foreign import ccall unsafe "sfView_move_helper"
sfView_move_helper :: View -> Ptr Vec2f -> IO ()
rotateView
:: View
-> Float
-> IO ()
rotateView v a = sfView_rotate v (realToFrac a)
foreign import ccall unsafe "sfView_rotate"
sfView_rotate :: View -> CFloat -> IO ()
zoomView
:: View
-> Float
-> IO ()
zoomView v z = sfView_zoom v (realToFrac z)
foreign import ccall unsafe "sfView_zoom"
sfView_zoom :: View -> CFloat -> IO ()