{-# LINE 1 "Graphics/X11/Xrender.hsc" #-}
-----------------------------------------------------------------------------
-- Module      :  Graphics.X11.Xrender
-- Copyright   :  Clemens Fruhwirth <clemens@endorphin.org> 2007
--
-- Haskell bindings for the Xrender extension.
--
-----------------------------------------------------------------------------

module Graphics.X11.Xrender (
  peekCUShort,
  pokeCUShort,
  peekCShort,
  pokeCShort,
  XRenderColor (..),
  XGlyphInfo (..),
  XRenderDirectFormat (..),
) where

import Foreign
import Foreign.C



peekCUShort :: Ptr a -> CInt -> IO Int
peekCUShort ptr off = do
        v <- peekByteOff ptr (fromIntegral off)
        return (fromIntegral (v::CUShort))

pokeCUShort :: Ptr a -> CInt -> Int -> IO ()
pokeCUShort ptr off v =
        pokeByteOff ptr (fromIntegral off) (fromIntegral v::CUShort)

peekCShort :: Ptr a -> CInt -> IO Int
peekCShort ptr off = do
        v <- peekByteOff ptr (fromIntegral off)
        return (fromIntegral (v::CShort))

pokeCShort :: Ptr a -> CInt -> Int -> IO ()
pokeCShort ptr off v =
        pokeByteOff ptr (fromIntegral off) (fromIntegral v::CShort)

data XRenderColor = XRenderColor {
      xrendercolor_red   :: Int,
      xrendercolor_green :: Int,
      xrendercolor_blue  :: Int,
      xrendercolor_alpha :: Int
}

instance Storable XRenderColor where
        sizeOf _ = (8)
{-# LINE 51 "Graphics/X11/Xrender.hsc" #-}
        alignment _ = alignment (undefined::CInt)
        peek p = do
                red   <- peekCUShort p (0)
{-# LINE 54 "Graphics/X11/Xrender.hsc" #-}
                blue  <- peekCUShort p (4)
{-# LINE 55 "Graphics/X11/Xrender.hsc" #-}
                green <- peekCUShort p (2)
{-# LINE 56 "Graphics/X11/Xrender.hsc" #-}
                alpha <- peekCUShort p (6)
{-# LINE 57 "Graphics/X11/Xrender.hsc" #-}
                return (XRenderColor red green blue alpha)
        poke p (XRenderColor red green blue alpha) = do
                pokeCUShort p (0) red
{-# LINE 60 "Graphics/X11/Xrender.hsc" #-}
                pokeCUShort p (4) blue
{-# LINE 61 "Graphics/X11/Xrender.hsc" #-}
                pokeCUShort p (2) green
{-# LINE 62 "Graphics/X11/Xrender.hsc" #-}
                pokeCUShort p (6) alpha
{-# LINE 63 "Graphics/X11/Xrender.hsc" #-}

data XGlyphInfo = XGlyphInfo {
      xglyphinfo_width  :: Int,
      xglyphinfo_height :: Int,
      xglyphinfo_x      :: Int,
      xglyphinfo_y      :: Int,
      xglyphinfo_xOff   :: Int,
      xglyphinfo_yOff   :: Int
}

instance Storable XGlyphInfo where
        sizeOf _ = (12)
{-# LINE 75 "Graphics/X11/Xrender.hsc" #-}
        alignment _ = alignment (undefined::CInt)
        peek p = do
                width  <- peekCUShort p (0)
{-# LINE 78 "Graphics/X11/Xrender.hsc" #-}
                height <- peekCUShort p (2)
{-# LINE 79 "Graphics/X11/Xrender.hsc" #-}
                x <- peekCShort p (4)
{-# LINE 80 "Graphics/X11/Xrender.hsc" #-}
                y <- peekCShort p (6)
{-# LINE 81 "Graphics/X11/Xrender.hsc" #-}
                xOff <- peekCShort p (8)
{-# LINE 82 "Graphics/X11/Xrender.hsc" #-}
                yOff <- peekCShort p (10)
{-# LINE 83 "Graphics/X11/Xrender.hsc" #-}
                return (XGlyphInfo width height x y xOff yOff)
        poke p (XGlyphInfo width height x y xOff yOff) = do
                pokeCUShort p (0) width
{-# LINE 86 "Graphics/X11/Xrender.hsc" #-}
                pokeCUShort p (2) height
{-# LINE 87 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (4) x
{-# LINE 88 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (6) y
{-# LINE 89 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (8) xOff
{-# LINE 90 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (10) yOff
{-# LINE 91 "Graphics/X11/Xrender.hsc" #-}


data XRenderDirectFormat = XRenderDirectFormat {
     xrenderdirectformat_red       :: Int,
     xrenderdirectformat_redMask   :: Int,
     xrenderdirectformat_green     :: Int,
     xrenderdirectformat_greenMask :: Int,
     xrenderdirectformat_blue      :: Int,
     xrenderdirectformat_blueMask  :: Int,
     xrenderdirectformat_alpha     :: Int,
     xrenderdirectformat_alphaMask :: Int
}

instance Storable XRenderDirectFormat where
        sizeOf _ = (16)
{-# LINE 106 "Graphics/X11/Xrender.hsc" #-}
        alignment _ = alignment (undefined::CInt)
        peek p = do
                red  <- peekCShort p (0)
{-# LINE 109 "Graphics/X11/Xrender.hsc" #-}
                redMask  <- peekCShort p (2)
{-# LINE 110 "Graphics/X11/Xrender.hsc" #-}
                green  <- peekCShort p (4)
{-# LINE 111 "Graphics/X11/Xrender.hsc" #-}
                greenMask  <- peekCShort p (6)
{-# LINE 112 "Graphics/X11/Xrender.hsc" #-}
                blue  <- peekCShort p (8)
{-# LINE 113 "Graphics/X11/Xrender.hsc" #-}
                blueMask  <- peekCShort p (10)
{-# LINE 114 "Graphics/X11/Xrender.hsc" #-}
                alpha  <- peekCShort p (12)
{-# LINE 115 "Graphics/X11/Xrender.hsc" #-}
                alphaMask  <- peekCShort p (14)
{-# LINE 116 "Graphics/X11/Xrender.hsc" #-}
                return (XRenderDirectFormat red redMask green greenMask blue blueMask alpha alphaMask)
        poke p (XRenderDirectFormat red redMask green greenMask blue blueMask alpha alphaMask) = do
                pokeCShort p (0) red
{-# LINE 119 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (2) redMask
{-# LINE 120 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (8) blue
{-# LINE 121 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (10) blueMask
{-# LINE 122 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (4) green
{-# LINE 123 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (6) greenMask
{-# LINE 124 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (12) alpha
{-# LINE 125 "Graphics/X11/Xrender.hsc" #-}
                pokeCShort p (14) alphaMask
{-# LINE 126 "Graphics/X11/Xrender.hsc" #-}