{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- /No description available in the introspection data./

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Gsk.Objects.CairoNode
    ( 

-- * Exported types
    CairoNode(..)                           ,
    IsCairoNode                             ,
    toCairoNode                             ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveCairoNodeMethod                  ,
#endif


-- ** getDrawContext #method:getDrawContext#

#if defined(ENABLE_OVERLOADING)
    CairoNodeGetDrawContextMethodInfo       ,
#endif
    cairoNodeGetDrawContext                 ,


-- ** new #method:new#

    cairoNodeNew                            ,


-- ** peekSurface #method:peekSurface#

#if defined(ENABLE_OVERLOADING)
    CairoNodePeekSurfaceMethodInfo          ,
#endif
    cairoNodePeekSurface                    ,




    ) 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.BasicTypes as B.Types
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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

import qualified GI.Cairo.Structs.Context as Cairo.Context
import qualified GI.Cairo.Structs.Surface as Cairo.Surface
import qualified GI.Graphene.Structs.Rect as Graphene.Rect
import {-# SOURCE #-} qualified GI.Gsk.Objects.RenderNode as Gsk.RenderNode

-- | Memory-managed wrapper type.
newtype CairoNode = CairoNode (SP.ManagedPtr CairoNode)
    deriving (CairoNode -> CairoNode -> Bool
(CairoNode -> CairoNode -> Bool)
-> (CairoNode -> CairoNode -> Bool) -> Eq CairoNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CairoNode -> CairoNode -> Bool
$c/= :: CairoNode -> CairoNode -> Bool
== :: CairoNode -> CairoNode -> Bool
$c== :: CairoNode -> CairoNode -> Bool
Eq)

instance SP.ManagedPtrNewtype CairoNode where
    toManagedPtr :: CairoNode -> ManagedPtr CairoNode
toManagedPtr (CairoNode ManagedPtr CairoNode
p) = ManagedPtr CairoNode
p

foreign import ccall "gsk_cairo_node_get_type"
    c_gsk_cairo_node_get_type :: IO B.Types.GType

instance B.Types.TypedObject CairoNode where
    glibType :: IO GType
glibType = IO GType
c_gsk_cairo_node_get_type

-- | Type class for types which can be safely cast to `CairoNode`, for instance with `toCairoNode`.
class (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf CairoNode o) => IsCairoNode o
instance (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf CairoNode o) => IsCairoNode o

instance O.HasParentTypes CairoNode
type instance O.ParentTypes CairoNode = '[Gsk.RenderNode.RenderNode]

-- | Cast to `CairoNode`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toCairoNode :: (MonadIO m, IsCairoNode o) => o -> m CairoNode
toCairoNode :: o -> m CairoNode
toCairoNode = IO CairoNode -> m CairoNode
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CairoNode -> m CairoNode)
-> (o -> IO CairoNode) -> o -> m CairoNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr CairoNode -> CairoNode) -> o -> IO CairoNode
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr CairoNode -> CairoNode
CairoNode

#if defined(ENABLE_OVERLOADING)
type family ResolveCairoNodeMethod (t :: Symbol) (o :: *) :: * where
    ResolveCairoNodeMethod "draw" o = Gsk.RenderNode.RenderNodeDrawMethodInfo
    ResolveCairoNodeMethod "peekSurface" o = CairoNodePeekSurfaceMethodInfo
    ResolveCairoNodeMethod "ref" o = Gsk.RenderNode.RenderNodeRefMethodInfo
    ResolveCairoNodeMethod "serialize" o = Gsk.RenderNode.RenderNodeSerializeMethodInfo
    ResolveCairoNodeMethod "unref" o = Gsk.RenderNode.RenderNodeUnrefMethodInfo
    ResolveCairoNodeMethod "writeToFile" o = Gsk.RenderNode.RenderNodeWriteToFileMethodInfo
    ResolveCairoNodeMethod "getBounds" o = Gsk.RenderNode.RenderNodeGetBoundsMethodInfo
    ResolveCairoNodeMethod "getDrawContext" o = CairoNodeGetDrawContextMethodInfo
    ResolveCairoNodeMethod "getNodeType" o = Gsk.RenderNode.RenderNodeGetNodeTypeMethodInfo
    ResolveCairoNodeMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCairoNodeMethod t CairoNode, O.MethodInfo info CairoNode p) => OL.IsLabel t (CairoNode -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif

-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance BoxedPtr CairoNode where
    boxedPtrCopy :: CairoNode -> IO CairoNode
boxedPtrCopy = CairoNode -> IO CairoNode
forall (m :: * -> *) a. Monad m => a -> m a
return
    boxedPtrFree :: CairoNode -> IO ()
boxedPtrFree = \CairoNode
_x -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- method CairoNode::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "bounds"
--           , argType =
--               TInterface Name { namespace = "Graphene" , name = "Rect" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the rectangle to render to"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gsk" , name = "CairoNode" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_cairo_node_new" gsk_cairo_node_new :: 
    Ptr Graphene.Rect.Rect ->               -- bounds : TInterface (Name {namespace = "Graphene", name = "Rect"})
    IO (Ptr CairoNode)

-- | Creates a t'GI.Gsk.Objects.RenderNode.RenderNode' that will render a cairo surface
-- into the area given by /@bounds@/. You can draw to the cairo
-- surface using 'GI.Gsk.Objects.CairoNode.cairoNodeGetDrawContext'
cairoNodeNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Graphene.Rect.Rect
    -- ^ /@bounds@/: the rectangle to render to
    -> m CairoNode
    -- ^ __Returns:__ A new t'GI.Gsk.Objects.RenderNode.RenderNode'
cairoNodeNew :: Rect -> m CairoNode
cairoNodeNew Rect
bounds = IO CairoNode -> m CairoNode
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CairoNode -> m CairoNode) -> IO CairoNode -> m CairoNode
forall a b. (a -> b) -> a -> b
$ do
    Ptr Rect
bounds' <- Rect -> IO (Ptr Rect)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Rect
bounds
    Ptr CairoNode
result <- Ptr Rect -> IO (Ptr CairoNode)
gsk_cairo_node_new Ptr Rect
bounds'
    Text -> Ptr CairoNode -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"cairoNodeNew" Ptr CairoNode
result
    CairoNode
result' <- ((ManagedPtr CairoNode -> CairoNode)
-> Ptr CairoNode -> IO CairoNode
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr CairoNode -> CairoNode
CairoNode) Ptr CairoNode
result
    Rect -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Rect
bounds
    CairoNode -> IO CairoNode
forall (m :: * -> *) a. Monad m => a -> m a
return CairoNode
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method CairoNode::get_draw_context
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "CairoNode" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GskRenderNode for a Cairo surface"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "cairo" , name = "Context" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_cairo_node_get_draw_context" gsk_cairo_node_get_draw_context :: 
    Ptr CairoNode ->                        -- node : TInterface (Name {namespace = "Gsk", name = "CairoNode"})
    IO (Ptr Cairo.Context.Context)

-- | Creates a Cairo context for drawing using the surface associated
-- to the render node.
-- 
-- If no surface exists yet, a surface will be created optimized for
-- rendering to /@renderer@/.
cairoNodeGetDrawContext ::
    (B.CallStack.HasCallStack, MonadIO m, IsCairoNode a) =>
    a
    -- ^ /@node@/: a t'GI.Gsk.Objects.RenderNode.RenderNode' for a Cairo surface
    -> m Cairo.Context.Context
    -- ^ __Returns:__ a Cairo context used for drawing; use
    --   @/cairo_destroy()/@ when done drawing
cairoNodeGetDrawContext :: a -> m Context
cairoNodeGetDrawContext a
node = IO Context -> m Context
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Context -> m Context) -> IO Context -> m Context
forall a b. (a -> b) -> a -> b
$ do
    Ptr CairoNode
node' <- a -> IO (Ptr CairoNode)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
node
    Ptr Context
result <- Ptr CairoNode -> IO (Ptr Context)
gsk_cairo_node_get_draw_context Ptr CairoNode
node'
    Text -> Ptr Context -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"cairoNodeGetDrawContext" Ptr Context
result
    Context
result' <- ((ManagedPtr Context -> Context) -> Ptr Context -> IO Context
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Context -> Context
Cairo.Context.Context) Ptr Context
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
node
    Context -> IO Context
forall (m :: * -> *) a. Monad m => a -> m a
return Context
result'

#if defined(ENABLE_OVERLOADING)
data CairoNodeGetDrawContextMethodInfo
instance (signature ~ (m Cairo.Context.Context), MonadIO m, IsCairoNode a) => O.MethodInfo CairoNodeGetDrawContextMethodInfo a signature where
    overloadedMethod = cairoNodeGetDrawContext

#endif

-- method CairoNode::peek_surface
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "CairoNode" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GskRenderNode for a Cairo surface"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "cairo" , name = "Surface" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_cairo_node_peek_surface" gsk_cairo_node_peek_surface :: 
    Ptr CairoNode ->                        -- node : TInterface (Name {namespace = "Gsk", name = "CairoNode"})
    IO (Ptr Cairo.Surface.Surface)

-- | Retrieves the Cairo surface used by the render node.
cairoNodePeekSurface ::
    (B.CallStack.HasCallStack, MonadIO m, IsCairoNode a) =>
    a
    -- ^ /@node@/: a t'GI.Gsk.Objects.RenderNode.RenderNode' for a Cairo surface
    -> m Cairo.Surface.Surface
    -- ^ __Returns:__ a Cairo surface
cairoNodePeekSurface :: a -> m Surface
cairoNodePeekSurface a
node = IO Surface -> m Surface
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Surface -> m Surface) -> IO Surface -> m Surface
forall a b. (a -> b) -> a -> b
$ do
    Ptr CairoNode
node' <- a -> IO (Ptr CairoNode)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
node
    Ptr Surface
result <- Ptr CairoNode -> IO (Ptr Surface)
gsk_cairo_node_peek_surface Ptr CairoNode
node'
    Text -> Ptr Surface -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"cairoNodePeekSurface" Ptr Surface
result
    Surface
result' <- ((ManagedPtr Surface -> Surface) -> Ptr Surface -> IO Surface
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Surface -> Surface
Cairo.Surface.Surface) Ptr Surface
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
node
    Surface -> IO Surface
forall (m :: * -> *) a. Monad m => a -> m a
return Surface
result'

#if defined(ENABLE_OVERLOADING)
data CairoNodePeekSurfaceMethodInfo
instance (signature ~ (m Cairo.Surface.Surface), MonadIO m, IsCairoNode a) => O.MethodInfo CairoNodePeekSurfaceMethodInfo a signature where
    overloadedMethod = cairoNodePeekSurface

#endif