{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- The t'GI.Clutter.Objects.TextNode.TextNode' structure is an opaque
-- type whose members cannot be directly accessed.
-- 
-- /Since: 1.10/

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

module GI.Clutter.Objects.TextureNode
    ( 

-- * Exported types
    TextureNode(..)                         ,
    IsTextureNode                           ,
    toTextureNode                           ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [addChild]("GI.Clutter.Objects.PaintNode#g:method:addChild"), [addRectangle]("GI.Clutter.Objects.PaintNode#g:method:addRectangle"), [addTextureRectangle]("GI.Clutter.Objects.PaintNode#g:method:addTextureRectangle"), [ref]("GI.Clutter.Objects.PaintNode#g:method:ref"), [unref]("GI.Clutter.Objects.PaintNode#g:method:unref").
-- 
-- ==== Getters
-- /None/.
-- 
-- ==== Setters
-- [setName]("GI.Clutter.Objects.PaintNode#g:method:setName").

#if defined(ENABLE_OVERLOADING)
    ResolveTextureNodeMethod                ,
#endif

-- ** new #method:new#

    textureNodeNew                          ,




    ) 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.GArray as B.GArray
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.Coerce as Coerce
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 GHC.Records as R

import {-# SOURCE #-} qualified GI.Clutter.Enums as Clutter.Enums
import {-# SOURCE #-} qualified GI.Clutter.Objects.PaintNode as Clutter.PaintNode
import {-# SOURCE #-} qualified GI.Clutter.Objects.PipelineNode as Clutter.PipelineNode
import {-# SOURCE #-} qualified GI.Clutter.Structs.Color as Clutter.Color
import qualified GI.Cogl.Interfaces.Texture as Cogl.Texture

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

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

foreign import ccall "clutter_texture_node_get_type"
    c_clutter_texture_node_get_type :: IO B.Types.GType

instance B.Types.TypedObject TextureNode where
    glibType :: IO GType
glibType = IO GType
c_clutter_texture_node_get_type

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

instance O.HasParentTypes TextureNode
type instance O.ParentTypes TextureNode = '[Clutter.PipelineNode.PipelineNode, Clutter.PaintNode.PaintNode]

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

--- XXX Missing getter and/or setter, so no GValue instance could be generated.
#if defined(ENABLE_OVERLOADING)
type family ResolveTextureNodeMethod (t :: Symbol) (o :: *) :: * where
    ResolveTextureNodeMethod "addChild" o = Clutter.PaintNode.PaintNodeAddChildMethodInfo
    ResolveTextureNodeMethod "addRectangle" o = Clutter.PaintNode.PaintNodeAddRectangleMethodInfo
    ResolveTextureNodeMethod "addTextureRectangle" o = Clutter.PaintNode.PaintNodeAddTextureRectangleMethodInfo
    ResolveTextureNodeMethod "ref" o = Clutter.PaintNode.PaintNodeRefMethodInfo
    ResolveTextureNodeMethod "unref" o = Clutter.PaintNode.PaintNodeUnrefMethodInfo
    ResolveTextureNodeMethod "setName" o = Clutter.PaintNode.PaintNodeSetNameMethodInfo
    ResolveTextureNodeMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveTextureNodeMethod t TextureNode, O.OverloadedMethod info TextureNode p, R.HasField t TextureNode p) => R.HasField t TextureNode p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveTextureNodeMethod t TextureNode, O.OverloadedMethodInfo info TextureNode) => OL.IsLabel t (O.MethodProxy info TextureNode) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

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


-- method TextureNode::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "texture"
--           , argType =
--               TInterface Name { namespace = "Cogl" , name = "Texture" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #CoglTexture" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "color"
--           , argType =
--               TInterface Name { namespace = "Clutter" , name = "Color" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #ClutterColor used for blending, or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "min_filter"
--           , argType =
--               TInterface Name { namespace = "Clutter" , name = "ScalingFilter" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the minification filter for the texture"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "mag_filter"
--           , argType =
--               TInterface Name { namespace = "Clutter" , name = "ScalingFilter" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the magnification filter for the texture"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Clutter" , name = "PaintNode" })
-- throws : False
-- Skip return : False

foreign import ccall "clutter_texture_node_new" clutter_texture_node_new :: 
    Ptr Cogl.Texture.Texture ->             -- texture : TInterface (Name {namespace = "Cogl", name = "Texture"})
    Ptr Clutter.Color.Color ->              -- color : TInterface (Name {namespace = "Clutter", name = "Color"})
    CUInt ->                                -- min_filter : TInterface (Name {namespace = "Clutter", name = "ScalingFilter"})
    CUInt ->                                -- mag_filter : TInterface (Name {namespace = "Clutter", name = "ScalingFilter"})
    IO (Ptr Clutter.PaintNode.PaintNode)

-- | Creates a new t'GI.Clutter.Objects.PaintNode.PaintNode' that will paint the passed /@texture@/.
-- 
-- This function will take a reference on /@texture@/, so it is safe to
-- call @/cogl_object_unref()/@ on /@texture@/ when it returns.
-- 
-- The /@color@/ must not be pre-multiplied with its t'GI.Clutter.Structs.Color.Color'.@/alpha/@
-- channel value; if /@color@/ is 'P.Nothing', a fully opaque white color will
-- be used for blending.
-- 
-- /Since: 1.10/
textureNodeNew ::
    (B.CallStack.HasCallStack, MonadIO m, Cogl.Texture.IsTexture a) =>
    a
    -- ^ /@texture@/: a @/CoglTexture/@
    -> Maybe (Clutter.Color.Color)
    -- ^ /@color@/: a t'GI.Clutter.Structs.Color.Color' used for blending, or 'P.Nothing'
    -> Clutter.Enums.ScalingFilter
    -- ^ /@minFilter@/: the minification filter for the texture
    -> Clutter.Enums.ScalingFilter
    -- ^ /@magFilter@/: the magnification filter for the texture
    -> m Clutter.PaintNode.PaintNode
    -- ^ __Returns:__ the newly created t'GI.Clutter.Objects.PaintNode.PaintNode'.
    --   Use 'GI.Clutter.Objects.PaintNode.paintNodeUnref' when done
textureNodeNew :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTexture a) =>
a -> Maybe Color -> ScalingFilter -> ScalingFilter -> m PaintNode
textureNodeNew a
texture Maybe Color
color ScalingFilter
minFilter ScalingFilter
magFilter = IO PaintNode -> m PaintNode
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO PaintNode -> m PaintNode) -> IO PaintNode -> m PaintNode
forall a b. (a -> b) -> a -> b
$ do
    Ptr Texture
texture' <- a -> IO (Ptr Texture)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
texture
    Ptr Color
maybeColor <- case Maybe Color
color of
        Maybe Color
Nothing -> Ptr Color -> IO (Ptr Color)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Color
forall a. Ptr a
nullPtr
        Just Color
jColor -> do
            Ptr Color
jColor' <- Color -> IO (Ptr Color)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Color
jColor
            Ptr Color -> IO (Ptr Color)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Color
jColor'
    let minFilter' :: CUInt
minFilter' = (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt) -> (ScalingFilter -> Int) -> ScalingFilter -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScalingFilter -> Int
forall a. Enum a => a -> Int
fromEnum) ScalingFilter
minFilter
    let magFilter' :: CUInt
magFilter' = (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt) -> (ScalingFilter -> Int) -> ScalingFilter -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScalingFilter -> Int
forall a. Enum a => a -> Int
fromEnum) ScalingFilter
magFilter
    Ptr PaintNode
result <- Ptr Texture -> Ptr Color -> CUInt -> CUInt -> IO (Ptr PaintNode)
clutter_texture_node_new Ptr Texture
texture' Ptr Color
maybeColor CUInt
minFilter' CUInt
magFilter'
    Text -> Ptr PaintNode -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"textureNodeNew" Ptr PaintNode
result
    PaintNode
result' <- ((ManagedPtr PaintNode -> PaintNode)
-> Ptr PaintNode -> IO PaintNode
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr PaintNode -> PaintNode
Clutter.PaintNode.PaintNode) Ptr PaintNode
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
texture
    Maybe Color -> (Color -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Color
color Color -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    PaintNode -> IO PaintNode
forall (m :: * -> *) a. Monad m => a -> m a
return PaintNode
result'

#if defined(ENABLE_OVERLOADING)
#endif