{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

An opaque struct representing a simple animation.
-}

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

module GI.GdkPixbuf.Objects.PixbufSimpleAnim
    (

-- * Exported types
    PixbufSimpleAnim(..)                    ,
    IsPixbufSimpleAnim                      ,
    toPixbufSimpleAnim                      ,
    noPixbufSimpleAnim                      ,


 -- * Methods
-- ** addFrame #method:addFrame#

#if ENABLE_OVERLOADING
    PixbufSimpleAnimAddFrameMethodInfo      ,
#endif
    pixbufSimpleAnimAddFrame                ,


-- ** getLoop #method:getLoop#

#if ENABLE_OVERLOADING
    PixbufSimpleAnimGetLoopMethodInfo       ,
#endif
    pixbufSimpleAnimGetLoop                 ,


-- ** new #method:new#

    pixbufSimpleAnimNew                     ,


-- ** setLoop #method:setLoop#

#if ENABLE_OVERLOADING
    PixbufSimpleAnimSetLoopMethodInfo       ,
#endif
    pixbufSimpleAnimSetLoop                 ,




 -- * Properties
-- ** loop #attr:loop#
{- | Whether the animation should loop when it reaches the end.

/Since: 2.18/
-}
#if ENABLE_OVERLOADING
    PixbufSimpleAnimLoopPropertyInfo        ,
#endif
    constructPixbufSimpleAnimLoop           ,
    getPixbufSimpleAnimLoop                 ,
#if ENABLE_OVERLOADING
    pixbufSimpleAnimLoop                    ,
#endif
    setPixbufSimpleAnimLoop                 ,




    ) 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

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.GdkPixbuf.Objects.Pixbuf as GdkPixbuf.Pixbuf
import {-# SOURCE #-} qualified GI.GdkPixbuf.Objects.PixbufAnimation as GdkPixbuf.PixbufAnimation

-- | Memory-managed wrapper type.
newtype PixbufSimpleAnim = PixbufSimpleAnim (ManagedPtr PixbufSimpleAnim)
foreign import ccall "gdk_pixbuf_simple_anim_get_type"
    c_gdk_pixbuf_simple_anim_get_type :: IO GType

instance GObject PixbufSimpleAnim where
    gobjectType = c_gdk_pixbuf_simple_anim_get_type


-- | Type class for types which can be safely cast to `PixbufSimpleAnim`, for instance with `toPixbufSimpleAnim`.
class (GObject o, O.IsDescendantOf PixbufSimpleAnim o) => IsPixbufSimpleAnim o
instance (GObject o, O.IsDescendantOf PixbufSimpleAnim o) => IsPixbufSimpleAnim o

instance O.HasParentTypes PixbufSimpleAnim
type instance O.ParentTypes PixbufSimpleAnim = '[GdkPixbuf.PixbufAnimation.PixbufAnimation, GObject.Object.Object]

-- | Cast to `PixbufSimpleAnim`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toPixbufSimpleAnim :: (MonadIO m, IsPixbufSimpleAnim o) => o -> m PixbufSimpleAnim
toPixbufSimpleAnim = liftIO . unsafeCastTo PixbufSimpleAnim

-- | A convenience alias for `Nothing` :: `Maybe` `PixbufSimpleAnim`.
noPixbufSimpleAnim :: Maybe PixbufSimpleAnim
noPixbufSimpleAnim = Nothing

#if ENABLE_OVERLOADING
type family ResolvePixbufSimpleAnimMethod (t :: Symbol) (o :: *) :: * where
    ResolvePixbufSimpleAnimMethod "addFrame" o = PixbufSimpleAnimAddFrameMethodInfo
    ResolvePixbufSimpleAnimMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolvePixbufSimpleAnimMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolvePixbufSimpleAnimMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolvePixbufSimpleAnimMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolvePixbufSimpleAnimMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolvePixbufSimpleAnimMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolvePixbufSimpleAnimMethod "isStaticImage" o = GdkPixbuf.PixbufAnimation.PixbufAnimationIsStaticImageMethodInfo
    ResolvePixbufSimpleAnimMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolvePixbufSimpleAnimMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolvePixbufSimpleAnimMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolvePixbufSimpleAnimMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolvePixbufSimpleAnimMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolvePixbufSimpleAnimMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolvePixbufSimpleAnimMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolvePixbufSimpleAnimMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolvePixbufSimpleAnimMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolvePixbufSimpleAnimMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolvePixbufSimpleAnimMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolvePixbufSimpleAnimMethod "getHeight" o = GdkPixbuf.PixbufAnimation.PixbufAnimationGetHeightMethodInfo
    ResolvePixbufSimpleAnimMethod "getIter" o = GdkPixbuf.PixbufAnimation.PixbufAnimationGetIterMethodInfo
    ResolvePixbufSimpleAnimMethod "getLoop" o = PixbufSimpleAnimGetLoopMethodInfo
    ResolvePixbufSimpleAnimMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolvePixbufSimpleAnimMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolvePixbufSimpleAnimMethod "getStaticImage" o = GdkPixbuf.PixbufAnimation.PixbufAnimationGetStaticImageMethodInfo
    ResolvePixbufSimpleAnimMethod "getWidth" o = GdkPixbuf.PixbufAnimation.PixbufAnimationGetWidthMethodInfo
    ResolvePixbufSimpleAnimMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolvePixbufSimpleAnimMethod "setLoop" o = PixbufSimpleAnimSetLoopMethodInfo
    ResolvePixbufSimpleAnimMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolvePixbufSimpleAnimMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolvePixbufSimpleAnimMethod t PixbufSimpleAnim, O.MethodInfo info PixbufSimpleAnim p) => OL.IsLabel t (PixbufSimpleAnim -> 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

-- VVV Prop "loop"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Just False,Just False)

{- |
Get the value of the “@loop@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' pixbufSimpleAnim #loop
@
-}
getPixbufSimpleAnimLoop :: (MonadIO m, IsPixbufSimpleAnim o) => o -> m Bool
getPixbufSimpleAnimLoop obj = liftIO $ B.Properties.getObjectPropertyBool obj "loop"

{- |
Set the value of the “@loop@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' pixbufSimpleAnim [ #loop 'Data.GI.Base.Attributes.:=' value ]
@
-}
setPixbufSimpleAnimLoop :: (MonadIO m, IsPixbufSimpleAnim o) => o -> Bool -> m ()
setPixbufSimpleAnimLoop obj val = liftIO $ B.Properties.setObjectPropertyBool obj "loop" val

{- |
Construct a `GValueConstruct` with valid value for the “@loop@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructPixbufSimpleAnimLoop :: (IsPixbufSimpleAnim o) => Bool -> IO (GValueConstruct o)
constructPixbufSimpleAnimLoop val = B.Properties.constructObjectPropertyBool "loop" val

#if ENABLE_OVERLOADING
data PixbufSimpleAnimLoopPropertyInfo
instance AttrInfo PixbufSimpleAnimLoopPropertyInfo where
    type AttrAllowedOps PixbufSimpleAnimLoopPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint PixbufSimpleAnimLoopPropertyInfo = (~) Bool
    type AttrBaseTypeConstraint PixbufSimpleAnimLoopPropertyInfo = IsPixbufSimpleAnim
    type AttrGetType PixbufSimpleAnimLoopPropertyInfo = Bool
    type AttrLabel PixbufSimpleAnimLoopPropertyInfo = "loop"
    type AttrOrigin PixbufSimpleAnimLoopPropertyInfo = PixbufSimpleAnim
    attrGet _ = getPixbufSimpleAnimLoop
    attrSet _ = setPixbufSimpleAnimLoop
    attrConstruct _ = constructPixbufSimpleAnimLoop
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList PixbufSimpleAnim
type instance O.AttributeList PixbufSimpleAnim = PixbufSimpleAnimAttributeList
type PixbufSimpleAnimAttributeList = ('[ '("loop", PixbufSimpleAnimLoopPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
pixbufSimpleAnimLoop :: AttrLabelProxy "loop"
pixbufSimpleAnimLoop = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList PixbufSimpleAnim = PixbufSimpleAnimSignalList
type PixbufSimpleAnimSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method PixbufSimpleAnim::new
-- method type : Constructor
-- Args : [Arg {argCName = "width", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the width of the animation", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "height", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the height of the animation", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "rate", argType = TBasicType TFloat, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the speed of the animation, in frames per second", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GdkPixbuf", name = "PixbufSimpleAnim"}))
-- throws : False
-- Skip return : False

foreign import ccall "gdk_pixbuf_simple_anim_new" gdk_pixbuf_simple_anim_new ::
    Int32 ->                                -- width : TBasicType TInt
    Int32 ->                                -- height : TBasicType TInt
    CFloat ->                               -- rate : TBasicType TFloat
    IO (Ptr PixbufSimpleAnim)

{- |
Creates a new, empty animation.

/Since: 2.8/
-}
pixbufSimpleAnimNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Int32
    {- ^ /@width@/: the width of the animation -}
    -> Int32
    {- ^ /@height@/: the height of the animation -}
    -> Float
    {- ^ /@rate@/: the speed of the animation, in frames per second -}
    -> m PixbufSimpleAnim
    {- ^ __Returns:__ a newly allocated 'GI.GdkPixbuf.Objects.PixbufSimpleAnim.PixbufSimpleAnim' -}
pixbufSimpleAnimNew width height rate = liftIO $ do
    let rate' = realToFrac rate
    result <- gdk_pixbuf_simple_anim_new width height rate'
    checkUnexpectedReturnNULL "pixbufSimpleAnimNew" result
    result' <- (wrapObject PixbufSimpleAnim) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method PixbufSimpleAnim::add_frame
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "animation", argType = TInterface (Name {namespace = "GdkPixbuf", name = "PixbufSimpleAnim"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkPixbufSimpleAnim", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "pixbuf", argType = TInterface (Name {namespace = "GdkPixbuf", name = "Pixbuf"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the pixbuf to add", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gdk_pixbuf_simple_anim_add_frame" gdk_pixbuf_simple_anim_add_frame ::
    Ptr PixbufSimpleAnim ->                 -- animation : TInterface (Name {namespace = "GdkPixbuf", name = "PixbufSimpleAnim"})
    Ptr GdkPixbuf.Pixbuf.Pixbuf ->          -- pixbuf : TInterface (Name {namespace = "GdkPixbuf", name = "Pixbuf"})
    IO ()

{- |
Adds a new frame to /@animation@/. The /@pixbuf@/ must
have the dimensions specified when the animation
was constructed.

/Since: 2.8/
-}
pixbufSimpleAnimAddFrame ::
    (B.CallStack.HasCallStack, MonadIO m, IsPixbufSimpleAnim a, GdkPixbuf.Pixbuf.IsPixbuf b) =>
    a
    {- ^ /@animation@/: a 'GI.GdkPixbuf.Objects.PixbufSimpleAnim.PixbufSimpleAnim' -}
    -> b
    {- ^ /@pixbuf@/: the pixbuf to add -}
    -> m ()
pixbufSimpleAnimAddFrame animation pixbuf = liftIO $ do
    animation' <- unsafeManagedPtrCastPtr animation
    pixbuf' <- unsafeManagedPtrCastPtr pixbuf
    gdk_pixbuf_simple_anim_add_frame animation' pixbuf'
    touchManagedPtr animation
    touchManagedPtr pixbuf
    return ()

#if ENABLE_OVERLOADING
data PixbufSimpleAnimAddFrameMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsPixbufSimpleAnim a, GdkPixbuf.Pixbuf.IsPixbuf b) => O.MethodInfo PixbufSimpleAnimAddFrameMethodInfo a signature where
    overloadedMethod _ = pixbufSimpleAnimAddFrame

#endif

-- method PixbufSimpleAnim::get_loop
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "animation", argType = TInterface (Name {namespace = "GdkPixbuf", name = "PixbufSimpleAnim"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkPixbufSimpleAnim", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gdk_pixbuf_simple_anim_get_loop" gdk_pixbuf_simple_anim_get_loop ::
    Ptr PixbufSimpleAnim ->                 -- animation : TInterface (Name {namespace = "GdkPixbuf", name = "PixbufSimpleAnim"})
    IO CInt

{- |
Gets whether /@animation@/ should loop indefinitely when it reaches the end.

/Since: 2.18/
-}
pixbufSimpleAnimGetLoop ::
    (B.CallStack.HasCallStack, MonadIO m, IsPixbufSimpleAnim a) =>
    a
    {- ^ /@animation@/: a 'GI.GdkPixbuf.Objects.PixbufSimpleAnim.PixbufSimpleAnim' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the animation loops forever, 'False' otherwise -}
pixbufSimpleAnimGetLoop animation = liftIO $ do
    animation' <- unsafeManagedPtrCastPtr animation
    result <- gdk_pixbuf_simple_anim_get_loop animation'
    let result' = (/= 0) result
    touchManagedPtr animation
    return result'

#if ENABLE_OVERLOADING
data PixbufSimpleAnimGetLoopMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsPixbufSimpleAnim a) => O.MethodInfo PixbufSimpleAnimGetLoopMethodInfo a signature where
    overloadedMethod _ = pixbufSimpleAnimGetLoop

#endif

-- method PixbufSimpleAnim::set_loop
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "animation", argType = TInterface (Name {namespace = "GdkPixbuf", name = "PixbufSimpleAnim"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkPixbufSimpleAnim", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "loop", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "whether to loop the animation", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gdk_pixbuf_simple_anim_set_loop" gdk_pixbuf_simple_anim_set_loop ::
    Ptr PixbufSimpleAnim ->                 -- animation : TInterface (Name {namespace = "GdkPixbuf", name = "PixbufSimpleAnim"})
    CInt ->                                 -- loop : TBasicType TBoolean
    IO ()

{- |
Sets whether /@animation@/ should loop indefinitely when it reaches the end.

/Since: 2.18/
-}
pixbufSimpleAnimSetLoop ::
    (B.CallStack.HasCallStack, MonadIO m, IsPixbufSimpleAnim a) =>
    a
    {- ^ /@animation@/: a 'GI.GdkPixbuf.Objects.PixbufSimpleAnim.PixbufSimpleAnim' -}
    -> Bool
    {- ^ /@loop@/: whether to loop the animation -}
    -> m ()
pixbufSimpleAnimSetLoop animation loop = liftIO $ do
    animation' <- unsafeManagedPtrCastPtr animation
    let loop' = (fromIntegral . fromEnum) loop
    gdk_pixbuf_simple_anim_set_loop animation' loop'
    touchManagedPtr animation
    return ()

#if ENABLE_OVERLOADING
data PixbufSimpleAnimSetLoopMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsPixbufSimpleAnim a) => O.MethodInfo PixbufSimpleAnimSetLoopMethodInfo a signature where
    overloadedMethod _ = pixbufSimpleAnimSetLoop

#endif