module SFML.Graphics.CircleShape
(
module SFML.Utils
, CircleShapeException(..)
, createCircleShape
, copy
, destroy
, setPosition
, setRotation
, setScale
, setOrigin
, getPosition
, getRotation
, getScale
, getOrigin
, move
, rotate
, scale
, getTransform
, getInverseTransform
, setTexture
, setTextureRect
, getTexture
, getTextureRect
, setFillColor
, setOutlineColor
, setOutlineThickness
, getFillColor
, getOutlineColor
, getOutlineThickness
, getPointCount
, getPoint
, setRadius
, getRadius
, setPointCount
, getLocalBounds
, getGlobalBounds
)
where
import SFML.Graphics.SFBounded
import SFML.Graphics.Color
import SFML.Graphics.Rect
import SFML.Graphics.SFShape
import SFML.Graphics.SFShapeResizable
import SFML.Graphics.SFTexturable
import SFML.Graphics.Transform
import SFML.Graphics.Transformable
import SFML.Graphics.Types
import SFML.SFCopyable
import SFML.SFResource
import SFML.System.Vector2
import SFML.Utils
import Control.Exception
import Control.Monad ((>=>))
import Data.Typeable
import Foreign.C.Types
import Foreign.Ptr (Ptr, nullPtr)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Utils (with)
import Foreign.Storable (peek)
checkNull :: CircleShape -> Maybe CircleShape
checkNull cs@(CircleShape ptr) = if ptr == nullPtr then Nothing else Just cs
checkNullTexture :: Texture -> Maybe Texture
checkNullTexture tex@(Texture ptr) = if ptr == nullPtr then Nothing else Just tex
data CircleShapeException = CircleShapeException String deriving (Show, Typeable)
instance Exception CircleShapeException
createCircleShape :: IO (Either CircleShapeException CircleShape)
createCircleShape =
let err = CircleShapeException "Failed creating circle shape"
in fmap (tagErr err . checkNull) sfCircleShape_create
foreign import ccall unsafe "sfCircleShape_create"
sfCircleShape_create :: IO CircleShape
instance SFCopyable CircleShape where
copy = sfCircleShape_copy
foreign import ccall unsafe "sfCircleShape_copy"
sfCircleShape_copy :: CircleShape -> IO CircleShape
instance SFResource CircleShape where
destroy = sfCircleShape_destroy
foreign import ccall unsafe "sfCircleShape_destroy"
sfCircleShape_destroy :: CircleShape -> IO ()
instance Transformable CircleShape where
setPosition c p = with p $ sfCircleShape_setPosition_helper c
setRotation c r = sfCircleShape_setRotation c (realToFrac r)
setScale c s = with s $ sfCircleShape_setScale_helper c
setOrigin c o = with o $ sfCircleShape_setOrigin_helper c
getPosition c = alloca $ \ptr -> sfCircleShape_getPosition_helper c ptr >> peek ptr
getRotation = sfCircleShape_getRotation >=> return . realToFrac
getScale c = alloca $ \ptr -> sfCircleShape_getScale_helper c ptr >> peek ptr
getOrigin c = alloca $ \ptr -> sfCircleShape_getOrigin_helper c ptr >> peek ptr
move c off = with off $ sfCircleShape_move_helper c
rotate c a = sfCircleShape_rotate c (realToFrac a)
scale c s = with s $ sfCircleShape_scale_helper c
getTransform c = alloca $ \ptr -> sfCircleShape_getTransform_helper c ptr >> peek ptr
getInverseTransform c = alloca $ \ptr -> sfCircleShape_getInverseTransform_helper c ptr >> peek ptr
foreign import ccall unsafe "sfCircleShape_setPosition_helper"
sfCircleShape_setPosition_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_setRotation"
sfCircleShape_setRotation :: CircleShape -> CFloat -> IO ()
foreign import ccall unsafe "sfCircleShape_setScale_helper"
sfCircleShape_setScale_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_setOrigin_helper"
sfCircleShape_setOrigin_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_getPosition_helper"
sfCircleShape_getPosition_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_getRotation"
sfCircleShape_getRotation :: CircleShape -> IO CFloat
foreign import ccall unsafe "sfCircleShape_getScale_helper"
sfCircleShape_getScale_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_getOrigin_helper"
sfCircleShape_getOrigin_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_move_helper"
sfCircleShape_move_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_rotate"
sfCircleShape_rotate :: CircleShape -> CFloat -> IO ()
foreign import ccall unsafe "sfCircleShape_scale_helper"
sfCircleShape_scale_helper :: CircleShape -> Ptr Vec2f -> IO ()
foreign import ccall unsafe "sfCircleShape_getTransform_helper"
sfCircleShape_getTransform_helper :: CircleShape -> Ptr Transform -> IO ()
foreign import ccall unsafe "sfCircleShape_getInverseTransform_helper"
sfCircleShape_getInverseTransform_helper :: CircleShape -> Ptr Transform -> IO ()
instance SFTexturable CircleShape where
setTexture c tex reset = sfCircleShape_setTexture c tex (fromIntegral . fromEnum $ reset)
setTextureRect c rect = with rect $ sfCircleShape_setTextureRect_helper c
getTexture = sfCircleShape_getTexture >=> return . checkNullTexture
getTextureRect c = alloca $ \ptr -> sfCircleShape_getTextureRect_helper c ptr >> peek ptr
foreign import ccall unsafe "sfCircleShape_setTexture"
sfCircleShape_setTexture :: CircleShape -> Texture -> CInt -> IO ()
foreign import ccall unsafe "sfCircleShape_setTextureRect_helper"
sfCircleShape_setTextureRect_helper :: CircleShape -> Ptr IntRect -> IO ()
foreign import ccall unsafe "sfCircleShape_getTexture"
sfCircleShape_getTexture :: CircleShape -> IO Texture
foreign import ccall unsafe "sfCircleShape_getTextureRect_helper"
sfCircleShape_getTextureRect_helper :: CircleShape -> Ptr IntRect -> IO ()
instance SFShape CircleShape where
setFillColor c color = with color $ sfCircleShape_setFillColor_helper c
setOutlineColor c color = with color $ sfCircleShape_setOutlineColor_helper c
setOutlineThickness c t = sfCircleShape_setOutlineThickness c (realToFrac t)
getFillColor c = alloca $ \ptr -> sfCircleShape_getFillColor_helper c ptr >> peek ptr
getOutlineColor c = alloca $ \ptr -> sfCircleShape_getOutlineColor_helper c ptr >> peek ptr
getOutlineThickness = sfCircleShape_getOutlineThickness >=> return . realToFrac
getPointCount = sfCircleShape_getPointCount >=> return . fromIntegral
getPoint c idx = alloca $ \ptr -> sfCircleShape_getPoint_helper c (fromIntegral idx) ptr >> peek ptr
foreign import ccall unsafe "sfCircleShape_setFillColor_helper"
sfCircleShape_setFillColor_helper :: CircleShape -> Ptr Color -> IO ()
foreign import ccall unsafe "sfCircleShape_setOutlineColor_helper"
sfCircleShape_setOutlineColor_helper :: CircleShape -> Ptr Color -> IO ()
foreign import ccall unsafe "sfCircleShape_setOutlineThickness"
sfCircleShape_setOutlineThickness :: CircleShape -> CFloat -> IO ()
foreign import ccall unsafe "sfCircleShape_getFillColor_helper"
sfCircleShape_getFillColor_helper :: CircleShape -> Ptr Color -> IO ()
foreign import ccall unsafe "sfCircleShape_getOutlineColor_helper"
sfCircleShape_getOutlineColor_helper :: CircleShape -> Ptr Color -> IO ()
foreign import ccall unsafe "sfCircleShape_getOutlineThickness"
sfCircleShape_getOutlineThickness :: CircleShape -> IO CFloat
foreign import ccall unsafe "sfCircleShape_getPointCount"
sfCircleShape_getPointCount :: CircleShape -> IO CUInt
foreign import ccall unsafe "sfCircleShape_getPoint_helper"
sfCircleShape_getPoint_helper :: CircleShape -> CUInt -> Ptr Vec2f -> IO ()
setRadius
:: CircleShape
-> Float
-> IO ()
setRadius c r = sfCircleShape_setRadius c (realToFrac r)
foreign import ccall unsafe "sfCircleShape_setRadius"
sfCircleShape_setRadius :: CircleShape -> CFloat -> IO ()
getRadius
:: CircleShape
-> IO Float
getRadius = sfCircleShape_getRadius >=> return . realToFrac
foreign import ccall unsafe "sfCircleShape_getRadius"
sfCircleShape_getRadius :: CircleShape -> IO CFloat
instance SFShapeResizable CircleShape where
setPointCount c count = sfCircleShape_setPointCount c (fromIntegral count)
foreign import ccall unsafe "sfCircleShape_setPointCount"
sfCircleShape_setPointCount :: CircleShape -> CUInt -> IO ()
instance SFBounded CircleShape where
getLocalBounds c = alloca $ \ptr -> sfCircleShape_getLocalBounds_helper c ptr >> peek ptr
getGlobalBounds c = alloca $ \ptr -> sfCircleShape_getGlobalBounds_helper c ptr >> peek ptr
foreign import ccall unsafe "sfCircleShape_getLocalBounds_helper"
sfCircleShape_getLocalBounds_helper :: CircleShape -> Ptr FloatRect -> IO ()
foreign import ccall unsafe "sfCircleShape_getGlobalBounds_helper"
sfCircleShape_getGlobalBounds_helper :: CircleShape -> Ptr FloatRect -> IO ()