#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
&& !defined(__HADDOCK_VERSION__))
module GI.Poppler.Structs.Point
(
Point(..) ,
newZeroPoint ,
noPoint ,
#if ENABLE_OVERLOADING
PointCopyMethodInfo ,
#endif
pointCopy ,
#if ENABLE_OVERLOADING
PointFreeMethodInfo ,
#endif
pointFree ,
pointNew ,
getPointX ,
#if ENABLE_OVERLOADING
point_x ,
#endif
setPointX ,
getPointY ,
#if ENABLE_OVERLOADING
point_y ,
#endif
setPointY ,
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
newtype Point = Point (ManagedPtr Point)
foreign import ccall "poppler_point_get_type" c_poppler_point_get_type ::
IO GType
instance BoxedObject Point where
boxedType _ = c_poppler_point_get_type
newZeroPoint :: MonadIO m => m Point
newZeroPoint = liftIO $ callocBoxedBytes 16 >>= wrapBoxed Point
instance tag ~ 'AttrSet => Constructible Point tag where
new _ attrs = do
o <- newZeroPoint
GI.Attributes.set o attrs
return o
noPoint :: Maybe Point
noPoint = Nothing
getPointX :: MonadIO m => Point -> m Double
getPointX s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO CDouble
let val' = realToFrac val
return val'
setPointX :: MonadIO m => Point -> Double -> m ()
setPointX s val = liftIO $ withManagedPtr s $ \ptr -> do
let val' = realToFrac val
poke (ptr `plusPtr` 0) (val' :: CDouble)
#if ENABLE_OVERLOADING
data PointXFieldInfo
instance AttrInfo PointXFieldInfo where
type AttrAllowedOps PointXFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint PointXFieldInfo = (~) Double
type AttrBaseTypeConstraint PointXFieldInfo = (~) Point
type AttrGetType PointXFieldInfo = Double
type AttrLabel PointXFieldInfo = "x"
type AttrOrigin PointXFieldInfo = Point
attrGet _ = getPointX
attrSet _ = setPointX
attrConstruct = undefined
attrClear _ = undefined
point_x :: AttrLabelProxy "x"
point_x = AttrLabelProxy
#endif
getPointY :: MonadIO m => Point -> m Double
getPointY s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 8) :: IO CDouble
let val' = realToFrac val
return val'
setPointY :: MonadIO m => Point -> Double -> m ()
setPointY s val = liftIO $ withManagedPtr s $ \ptr -> do
let val' = realToFrac val
poke (ptr `plusPtr` 8) (val' :: CDouble)
#if ENABLE_OVERLOADING
data PointYFieldInfo
instance AttrInfo PointYFieldInfo where
type AttrAllowedOps PointYFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint PointYFieldInfo = (~) Double
type AttrBaseTypeConstraint PointYFieldInfo = (~) Point
type AttrGetType PointYFieldInfo = Double
type AttrLabel PointYFieldInfo = "y"
type AttrOrigin PointYFieldInfo = Point
attrGet _ = getPointY
attrSet _ = setPointY
attrConstruct = undefined
attrClear _ = undefined
point_y :: AttrLabelProxy "y"
point_y = AttrLabelProxy
#endif
#if ENABLE_OVERLOADING
instance O.HasAttributeList Point
type instance O.AttributeList Point = PointAttributeList
type PointAttributeList = ('[ '("x", PointXFieldInfo), '("y", PointYFieldInfo)] :: [(Symbol, *)])
#endif
foreign import ccall "poppler_point_new" poppler_point_new ::
IO (Ptr Point)
pointNew ::
(B.CallStack.HasCallStack, MonadIO m) =>
m Point
pointNew = liftIO $ do
result <- poppler_point_new
checkUnexpectedReturnNULL "pointNew" result
result' <- (wrapBoxed Point) result
return result'
#if ENABLE_OVERLOADING
#endif
foreign import ccall "poppler_point_copy" poppler_point_copy ::
Ptr Point ->
IO (Ptr Point)
pointCopy ::
(B.CallStack.HasCallStack, MonadIO m) =>
Point
-> m Point
pointCopy point = liftIO $ do
point' <- unsafeManagedPtrGetPtr point
result <- poppler_point_copy point'
checkUnexpectedReturnNULL "pointCopy" result
result' <- (wrapBoxed Point) result
touchManagedPtr point
return result'
#if ENABLE_OVERLOADING
data PointCopyMethodInfo
instance (signature ~ (m Point), MonadIO m) => O.MethodInfo PointCopyMethodInfo Point signature where
overloadedMethod _ = pointCopy
#endif
foreign import ccall "poppler_point_free" poppler_point_free ::
Ptr Point ->
IO ()
pointFree ::
(B.CallStack.HasCallStack, MonadIO m) =>
Point
-> m ()
pointFree point = liftIO $ do
point' <- unsafeManagedPtrGetPtr point
poppler_point_free point'
touchManagedPtr point
return ()
#if ENABLE_OVERLOADING
data PointFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo PointFreeMethodInfo Point signature where
overloadedMethod _ = pointFree
#endif
#if ENABLE_OVERLOADING
type family ResolvePointMethod (t :: Symbol) (o :: *) :: * where
ResolvePointMethod "copy" o = PointCopyMethodInfo
ResolvePointMethod "free" o = PointFreeMethodInfo
ResolvePointMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolvePointMethod t Point, O.MethodInfo info Point p) => OL.IsLabel t (Point -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif