{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.Cogl.Objects.Bitmap
(
Bitmap(..) ,
IsBitmap ,
toBitmap ,
#if defined(ENABLE_OVERLOADING)
ResolveBitmapMethod ,
#endif
bitmapGetSizeFromFile ,
bitmapNewFromFile ,
) 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.GHashTable as B.GHT
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
newtype Bitmap = Bitmap (SP.ManagedPtr Bitmap)
deriving (Bitmap -> Bitmap -> Bool
(Bitmap -> Bitmap -> Bool)
-> (Bitmap -> Bitmap -> Bool) -> Eq Bitmap
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Bitmap -> Bitmap -> Bool
== :: Bitmap -> Bitmap -> Bool
$c/= :: Bitmap -> Bitmap -> Bool
/= :: Bitmap -> Bitmap -> Bool
Eq)
instance SP.ManagedPtrNewtype Bitmap where
toManagedPtr :: Bitmap -> ManagedPtr Bitmap
toManagedPtr (Bitmap ManagedPtr Bitmap
p) = ManagedPtr Bitmap
p
foreign import ccall "cogl_bitmap_get_gtype"
c_cogl_bitmap_get_gtype :: IO B.Types.GType
instance B.Types.TypedObject Bitmap where
glibType :: IO GType
glibType = IO GType
c_cogl_bitmap_get_gtype
class (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf Bitmap o) => IsBitmap o
instance (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf Bitmap o) => IsBitmap o
instance O.HasParentTypes Bitmap
type instance O.ParentTypes Bitmap = '[]
toBitmap :: (MIO.MonadIO m, IsBitmap o) => o -> m Bitmap
toBitmap :: forall (m :: * -> *) o. (MonadIO m, IsBitmap o) => o -> m Bitmap
toBitmap = IO Bitmap -> m Bitmap
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO Bitmap -> m Bitmap) -> (o -> IO Bitmap) -> o -> m Bitmap
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Bitmap -> Bitmap) -> o -> IO Bitmap
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr Bitmap -> Bitmap
Bitmap
#if defined(ENABLE_OVERLOADING)
type family ResolveBitmapMethod (t :: Symbol) (o :: *) :: * where
ResolveBitmapMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveBitmapMethod t Bitmap, O.OverloadedMethod info Bitmap p) => OL.IsLabel t (Bitmap -> 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 ~ ResolveBitmapMethod t Bitmap, O.OverloadedMethod info Bitmap p, R.HasField t Bitmap p) => R.HasField t Bitmap p where
getField = O.overloadedMethod @info
#endif
instance (info ~ ResolveBitmapMethod t Bitmap, O.OverloadedMethodInfo info Bitmap) => OL.IsLabel t (O.MethodProxy info Bitmap) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.MethodProxy
#else
fromLabel _ = O.MethodProxy
#endif
#endif
instance BoxedPtr Bitmap where
boxedPtrCopy :: Bitmap -> IO Bitmap
boxedPtrCopy = Bitmap -> IO Bitmap
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
boxedPtrFree :: Bitmap -> IO ()
boxedPtrFree = \Bitmap
_x -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
foreign import ccall "cogl_bitmap_new_from_file" cogl_bitmap_new_from_file ::
CString ->
Ptr (Ptr GError) ->
IO (Ptr Bitmap)
bitmapNewFromFile ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
-> m Bitmap
bitmapNewFromFile :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Text -> m Bitmap
bitmapNewFromFile Text
filename = IO Bitmap -> m Bitmap
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bitmap -> m Bitmap) -> IO Bitmap -> m Bitmap
forall a b. (a -> b) -> a -> b
$ do
CString
filename' <- Text -> IO CString
textToCString Text
filename
IO Bitmap -> IO () -> IO Bitmap
forall a b. IO a -> IO b -> IO a
onException (do
Ptr Bitmap
result <- (Ptr (Ptr GError) -> IO (Ptr Bitmap)) -> IO (Ptr Bitmap)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Bitmap)) -> IO (Ptr Bitmap))
-> (Ptr (Ptr GError) -> IO (Ptr Bitmap)) -> IO (Ptr Bitmap)
forall a b. (a -> b) -> a -> b
$ CString -> Ptr (Ptr GError) -> IO (Ptr Bitmap)
cogl_bitmap_new_from_file CString
filename'
Text -> Ptr Bitmap -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"bitmapNewFromFile" Ptr Bitmap
result
Bitmap
result' <- ((ManagedPtr Bitmap -> Bitmap) -> Ptr Bitmap -> IO Bitmap
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr Bitmap -> Bitmap
Bitmap) Ptr Bitmap
result
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
filename'
Bitmap -> IO Bitmap
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bitmap
result'
) (do
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
filename'
)
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "cogl_bitmap_get_size_from_file" cogl_bitmap_get_size_from_file ::
CString ->
Ptr Int32 ->
Ptr Int32 ->
IO Int32
bitmapGetSizeFromFile ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
-> m ((Int32, Int32, Int32))
bitmapGetSizeFromFile :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> m (Int32, Int32, Int32)
bitmapGetSizeFromFile Text
filename = IO (Int32, Int32, Int32) -> m (Int32, Int32, Int32)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Int32, Int32, Int32) -> m (Int32, Int32, Int32))
-> IO (Int32, Int32, Int32) -> m (Int32, Int32, Int32)
forall a b. (a -> b) -> a -> b
$ do
CString
filename' <- Text -> IO CString
textToCString Text
filename
Ptr Int32
width <- IO (Ptr Int32)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Int32)
Ptr Int32
height <- IO (Ptr Int32)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Int32)
Int32
result <- CString -> Ptr Int32 -> Ptr Int32 -> IO Int32
cogl_bitmap_get_size_from_file CString
filename' Ptr Int32
width Ptr Int32
height
Int32
width' <- Ptr Int32 -> IO Int32
forall a. Storable a => Ptr a -> IO a
peek Ptr Int32
width
Int32
height' <- Ptr Int32 -> IO Int32
forall a. Storable a => Ptr a -> IO a
peek Ptr Int32
height
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
filename'
Ptr Int32 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Int32
width
Ptr Int32 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Int32
height
(Int32, Int32, Int32) -> IO (Int32, Int32, Int32)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int32
result, Int32
width', Int32
height')
#if defined(ENABLE_OVERLOADING)
#endif