minimung-0.0: Mac/QuickDraw.hsc
{-# LANGUAGE ForeignFunctionInterface #-}
-- |
-- Module : Mac.QuickDraw
-- Maintainer : Yakov Z <>
-- Stability : experimental
--
module Mac.QuickDraw (
-- * QuickDraw
GDHandle,
PixMap(..),
--TO-DO hide
PixMapHandle,
-- ** Hiding and Showing Cursors
initCursor,
-- ** Getting the Available Graphics Devices
getMainDevice,
-- ** Managing and Offscreen Graphics World's Pixel Image
getPixBaseAddr,
lockPixels,
-- ** Miscellaneous
getPortPixMap,
getPixRowBytes
) where
import Foreign.Ptr
import Foreign.C.Types
import Foreign.Storable
import Mac.Carbon
#include <QuickTime/QuickTime.h>
type GDHandle = Ptr ()
-- | Contains information about the dimensions and contents of a pixel image, as well as
-- its storage format, depth, resolution, and color usage.
--
-- For an onscreen pixel image, 'baseAddr' is a pointer to the first byte of the image. For optimal performance,
-- this should be multiple of 4.
--
-- The 'baseAddr' of the 'PixMap' for an /offscreen/ graphics world contains a handle instead of a pointer.
--
-- Your application should never directly access the 'baseAddr' for an /offscreen/ graphics world.
--
-- <http://developer.apple.com/documentation/QuickTime/Reference/QTRef_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/PixMap>
--
data PixMap = PixMap { baseAddr :: Ptr (),
rowBytes :: CShort
}
instance Storable PixMap where
sizeOf _ = #const sizeof(PixMap)
alignment _ = alignment (undefined :: CInt) -- ???
peek p = do
baseAddr' <- (#peek PixMap, baseAddr) p
rowBytes' <- (#peek PixMap, rowBytes) p
return PixMap { baseAddr = baseAddr', rowBytes = rowBytes' }
type PixMapPtr = Ptr PixMap
type PixMapHandle = Ptr PixMapPtr
-- | Sets the cursor to the standard arrow and makes the cursor visible.
foreign import ccall unsafe "InitCursor" initCursor :: IO ()
-- | Obtains a handle to the GDevice structure for the main screen.
--
-- Deprecated in Mac OS X v10.4
foreign import ccall unsafe "GetMainDevice" getMainDevice :: IO GDHandle
foreign import ccall unsafe "GetPixBaseAddr" getPixBaseAddr :: PixMapHandle -> IO (Ptr ())
foreign import ccall unsafe "LockPixels" lockPixels :: PixMapHandle -> IO Boolean
foreign import ccall unsafe "GetPortPixMap" getPortPixMap :: CGrafPtr -> IO PixMapHandle
foreign import ccall unsafe "GetPixRowBytes" getPixRowBytes :: PixMapHandle -> IO CInt