packages feed

OpenVG 0.5.0 → 0.6.0

raw patch · 18 files changed

+277/−151 lines, 18 filesdep ~OpenVGRaw

Dependency ranges changed: OpenVGRaw

Files

Changes view
@@ -1,4 +1,15 @@ +version 0.6.0 (17 Jan 2010):+  * Revised the RenderingQuality module to use an opaque matrix+    type rather than a raw pointer. Acknowledgement - the code +    and interface is derived from the Matrix class in HOpenGL.+  +  * Revised Image module - PixelData is now an opaque type rather+    than a raw pointer.++  * Work on Path module - pathBounds implemented. This module is+    entirely untested and may change again in the future.+ version 0.5.0 (16 Jan 2010):   * Split into 2 packages OpenVG (this package) and OpenVGRaw. 
OpenVG.cabal view
@@ -1,5 +1,5 @@ name:             OpenVG-version:          0.5.0+version:          0.6.0 license:          BSD3 license-file:     LICENSE copyright:        Stephen Tetley <stephen.tetley@gmail.com>@@ -11,41 +11,28 @@   A Haskell binding for the OpenVG vector graphics API version    1.0.1, specifically the ShivaVG-0.2.1 implementation.   .-  This version (0.5.0) is NOT compatible with the Haskell Platform +  This version (0.6.0) is NOT compatible with the Haskell Platform    (2009.2.0.2) - it uses the split OpenGL packages (RAW, StateVar,    etc.).   .-  \*\* WARNING - major changes to previous version. Also -  significant changes likely in next revision. \*\*.+  \*\* WARNING - large parts of the API (particular the Paths +  module) are untested and may be revised in future. \*\*.   .   Changelog-  0.4.0 to 0.5.0-  . -  * Significantly reworked. Changed to use OpenVGRaw.    .+  0.5.0 to 0.6.0   .-  0.3.0 to 0.4.0 +  * Added an opaque matrix type to RenderingQuality. +    Acknowledgement - this was derived from the Matrix class+    in HOpenGL.   .-  * LinearGradient type changed to be Vector4 VGfloat.-  . -  * RadialGradient changed to (Vector4 VGfloat, VGfloat).+  * Revised Image module - PixelData is now an opaque type rather+    than a raw pointer.   .-  * Removed Marshal and Unmarshal type classes, marshallBool and -    unmarshalBool moved out of the BasicTypes module.+  * Work on Path module - pathBounds implemented. This module is+    entirely untested and may change again in the future.   .-  * Type change for colorRampStops.   .-  * Name change - maxStops changed to maxColorRampStops.-  .-  * PathType(..) changed to PathAbsRel(..).-  . -  * Substantial changes to Haddock docs.-  .-  * Error handling in VGU redone - the original code in -    ErrorsInternal was taken wholesale from Sven Panne\'s -    OpenGL binding to help me bootstrap the OpenVG binding. -    Regrettably I forgot to replace it or attribute it --    I've now replaced it. Sincere apologies to Sven Panne.   build-type:         Simple stability:          experimental@@ -66,7 +53,7 @@                       OpenGLRaw >= 1.1.0.1 && < 2,                        StateVar  >= 1.0.0.0 && < 2,                       Tensor    >= 1.0.0.1 && < 2,-                      OpenVGRaw >= 0.1.0+                      OpenVGRaw >= 0.2.0      exposed-modules:     Graphics.Rendering.OpenVG,
demo/VguUtils.hs view
@@ -34,7 +34,8 @@ 
 
 testCreatePath :: IO VGPath
-testCreatePath = createPath VG.Float 1.0 0.0 0 0 [CapabilityAll]
+testCreatePath = 
+    createPath (PathProperties VG.Float 1.0 0.0 0 0 [CapabilityAll])
 
 testDestoryPaths :: [VGPath] -> IO ()
 testDestoryPaths = mapM_ destroyPath
src/Graphics/Rendering/OpenVG/VG.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/Blending.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Blending--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/DrawingContext.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.ShivaExtensions--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/Extending.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Extending--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/Images.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Images--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>@@ -23,7 +23,12 @@      -- * Image formats   ImageFormat(..),-  ++  -- * Pixel data+  Stride,+  PixelData,   ++   -- * Creating and destroying images   maxImageWidth,    maxImageHeight, @@ -49,7 +54,7 @@   -- * Copying pixels between images   copyImage,    -  -- * Drawing iamges to the drawing surface+  -- * Drawing images to the drawing surface   ImageMode(..),   drawImageMode,    drawImage,@@ -160,6 +165,26 @@    deriving ( Eq, Ord, Show )    +--------------------------------------------------------------------------------+-- Pixel data+++-- Derived from HOpenGL+-- NOTES - How do you create PixelData ?++type Stride = VGint++-- Opaque handle to pixel data. +--+-- \*\* NOTE - ShivaVG currently only supports @sRGBA_8888@. \*\*+--+data PixelData a = PixelData ImageFormat Stride (Ptr a)+   deriving ( Eq, Ord, Show )++withPixelData :: PixelData a -> (VGenum -> Stride -> Ptr a -> b) -> b+withPixelData (PixelData image_format stride ptr) f = +    f (marshalImageFormat image_format) stride ptr+       --------------------------------------------------------------------------------@@ -216,6 +241,9 @@ -- 'createImage' corresponds to the OpenVG function  -- @vgCreateImage@. --+-- \*\* NOTE - ShivaVG currently only supports @sRGBA_8888@ - +-- this function throws a runtime error for other formats. \*\*+-- createImage :: ImageFormat -> Size -> [ImageQuality] -> IO VGImage  createImage SRGBA8888 sz qs =      unSizeM (\w h -> vgCreateImage (marshalImageFormat SRGBA8888)@@ -303,10 +331,10 @@ -- 'imageSubData' corresponds to the OpenVG function  -- @vgImageSubData@.  ---imageSubData :: VGImage -> Ptr a -> VGint -> ImageFormat-                  -> Position -> Size -> IO ()-imageSubData image imgdata stride fmt (Position x y) =-    unSizeM $ vgImageSubData image imgdata stride (marshalImageFormat fmt) x y+imageSubData :: VGImage -> PixelData a -> Position -> Size -> IO ()+imageSubData image pd (Position x y) =+    unSizeM $ withPixelData pd $ \format_enum stride pixel_data -> +                vgImageSubData image pixel_data stride format_enum x y   @@ -316,10 +344,10 @@ -- 'getImageSubData' corresponds to the OpenVG function  -- @vgGetImageSubData@.  ---getImageSubData :: VGImage -> Ptr a -> VGint -> ImageFormat-                    -> Position -> Size -> IO ()-getImageSubData image imgdata stride fmt (Position x y) = -    unSizeM $ vgGetImageSubData image imgdata stride (marshalImageFormat fmt) x y+getImageSubData :: VGImage -> PixelData a -> Position -> Size -> IO ()+getImageSubData image pd (Position x y) = +    unSizeM $ withPixelData pd $ \format_enum stride pixel_data ->+                vgGetImageSubData image pixel_data stride format_enum x y     -------------------------------------------------------------------------------- @@ -333,13 +361,13 @@ -- -- 'copyImage' corresponds to the OpenVG function @vgCopyImage@. ---copyImage :: VGImage -> Position -> VGImage -> Position-                -> Size -> Bool -> IO ()+copyImage :: VGImage -> Position -> VGImage -> Position -> Size -> Bool -> IO () copyImage dst (Position dx dy) src (Position sx sy) sz dither = -    unSizeM (\w h -> vgCopyImage dst dx dy src sx sy w h (marshalBool dither)) sz+    (unSizeM `flip` sz) $ \w h -> +        vgCopyImage dst dx dy src sx sy w h (marshalBool dither)  ----------------------------------------------------------------------------------- Drawing iamges to the drawing surface+-- Drawing images to the drawing surface  -- | Styles of image drawing    data ImageMode = @@ -372,6 +400,7 @@ -------------------------------------------------------------------------------- -- Reading and writing drawing surface pixels + -- | Copy pixel data from the image to the drawing surface. -- -- 'setPixels' corresponds to the OpenVG function @vgSetPixels@. @@ -385,15 +414,17 @@ -- -- 'writePixels' corresponds to the OpenVG function @vgWritePixels@. ---writePixels :: Ptr a -> VGint -> ImageFormat -> Position -> Size -> IO ()-writePixels pixeldata stride fmt (Position dx dy) =  -    unSizeM $ vgWritePixels pixeldata stride (marshalImageFormat fmt) dx dy+writePixels :: PixelData a -> Position -> Size -> IO ()+writePixels pd (Position dx dy) = +    unSizeM $ withPixelData pd $ \format_enum stride pixel_data ->+                vgWritePixels pixel_data stride format_enum dx dy + -- | Retrieve pixel information from the drawing surface.  --  -- 'getPixels' corresponds to the OpenVG function @vgGetPixels@. ---getPixels :: VGImage  -> Position -> Position -> Size -> IO ()+getPixels :: VGImage -> Position -> Position -> Size -> IO () getPixels dst (Position dx dy) (Position sx sy) =       unSizeM $ vgGetPixels dst dx dy sx sy @@ -402,9 +433,12 @@ --  -- 'readPixels' corresponds to the OpenVG function @vgReadPixels@. ---readPixels :: Ptr a -> VGint -> ImageFormat -> Position -> Size -> IO ()-readPixels pixeldata stride fmt (Position sx sy) = unSizeM $-    vgReadPixels pixeldata stride (marshalImageFormat fmt) sx sy+readPixels :: PixelData a -> Position -> Size -> IO ()+readPixels pd (Position sx sy)  = +    unSizeM $ withPixelData pd $ \format_enum stride pixel_data -> +                vgReadPixels pixel_data stride format_enum sx sy ++  -------------------------------------------------------------------------------- -- Copying portions of the drawing surface
src/Graphics/Rendering/OpenVG/VG/Paint.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Paint--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/Parameters.hs view
@@ -1,10 +1,9 @@-{-# LANGUAGE ForeignFunctionInterface #-} {-# OPTIONS -Wall #-}  -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Parameters--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/Paths.hs view
@@ -1,11 +1,10 @@-{-# LANGUAGE ExistentialQuantification #-}-{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE TypeSynonymInstances       #-} {-# OPTIONS -Wall #-}  -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Paths--- Copyright   :  (c) Stephen Tetley 2008, 2009, 2010+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>@@ -15,12 +14,7 @@ -- This module corresponds to section 8 (Paths)  -- of the OpenVG 1.0.1 specs. ----- \*\* WARNING - this module is due to be changed significantly. ----- This is unfortunate as the module defines the most significant --- data types for vectors - the @Paths@. \*\*------ --------------------------------------------------------------------------------  @@ -34,16 +28,19 @@      -- * Creating and destroying paths   PathCapabilities(..),+  PathProperties(..),+   withPath,   createPath,    clearPath,    destroyPath,    -- * Path queries-  format, -  datatype, +  pathFormat, +  pathDatatype,    pathScale, -  bias, +  pathBias, +   numSegments,    numCoords, @@ -64,6 +61,11 @@   -- * Transforming a path   transformPath,   +  -- * Querying the bounds of a path +  BoundingBox(..),+  pathBounds, +  pathTransformedBounds,+     -- * Interpolating between paths   interpolatePath,   @@ -88,8 +90,10 @@   drawPath,   fillPath,   strokePath,-  fillStrokePath+  fillStrokePath, +  marshalPathSegment+ ) where  import Graphics.Rendering.OpenVG.VG.Parameters@@ -105,11 +109,13 @@     GettableStateVar, makeGettableStateVar,     ( $= ) )  -import Control.Applicative import Control.Monad import Data.Int ( Int8, Int16, Int32 )++import Foreign.Marshal.Alloc ( alloca ) import Foreign.Marshal.Array ( newArray )-import Foreign.Storable ( Storable )+import Foreign.Ptr ( Ptr )+import Foreign.Storable ( Storable, peek )  -------------------------------------------------------------------------------- -- Datatypes@@ -132,6 +138,9 @@    | Relative    deriving ( Eq, Ord, Show ) +-- | 'PathSegment' corresponds to the OpenVG enumeration +-- @VGPathSegment@.     +-- data PathSegment =       ClosePath    | MoveTo @@ -148,8 +157,9 @@    | LCWArcTo    deriving ( Eq, Ord, Show ) --- | 'PathCommand' corresponds to the OpenVG enumeration @VGPathCommand@,--- but includes ClosePath aka @VG_CLOSE_PATH@.      +-- | 'PathCommand' corresponds to the OpenVG enumeration +-- @VGPathCommand@.     +-- data PathCommand =       MoveToAbs    | MoveToRel@@ -200,18 +210,15 @@    | CapabilityAll    deriving ( Eq, Ord, Show ) +data PathProperties +     = PathProperties PathDatatype VGfloat VGfloat VGint VGint [PathCapabilities]+  deriving (Eq,Ord)  + -- | @withPath@ - create a path, run an action on it, destroy the path.-withPath :: PathDatatype -         -> VGfloat -         -> VGfloat-         -> VGint -         -> VGint -         -> [PathCapabilities]-         -> (VGPath -> IO a) -         -> IO a-withPath typ scl bi sch cch cs action = do-    path  <- createPath typ scl bi sch cch cs+withPath :: PathProperties -> (VGPath -> IO a) -> IO a+withPath props action = do+    path  <- createPath props     ans   <- action path     destroyPath path     return ans@@ -220,14 +227,9 @@ -- | @createPath@ - corresponds to the OpenVG function @vgCreatePath@. -- @createPath@ can only create paths in the standard format  -- (VG_PATH_FORMAT_STANDARD), extensions are not supported.   -createPath :: PathDatatype -           -> VGfloat -           -> VGfloat-           -> VGint -           -> VGint -           -> [PathCapabilities] -           -> IO VGPath-createPath typ scl bi sch cch cs = +--+createPath :: PathProperties -> IO VGPath+createPath (PathProperties typ scl bi sch cch cs) =      vgCreatePath fmt (marshalPathDatatype typ) scl bi sch cch caps   where     -- Other paths formats maybe defined as extensions, for the present@@ -248,23 +250,27 @@ -------------------------------------------------------------------------------- --  Path queries   --- | @format@ - get the path format. Currently the only supported --- format is @VG_PATH_FORMAT_STANDARD@ - 0. -format :: VGPath -> GettableStateVar VGint-format = makeGettableStateVar . flip getParameteri vg_PATH_FORMAT+-- | @pathFormat@ - get the path format. Currently the only supported +-- format is @VG_PATH_FORMAT_STANDARD@ - 0.+--+pathFormat :: VGPath -> GettableStateVar VGint+pathFormat = makeGettableStateVar . flip getParameteri vg_PATH_FORMAT --- | @datatype@ - get the PathDatatype.-datatype :: VGPath -> GettableStateVar PathDatatype-datatype = makeGettableStateVar . liftM (unmarshalPathDatatype . fromIntegral)  -                                . (getParameteri `flip` vg_PATH_DATATYPE)+-- | @pathDatatype@ - get the PathDatatype.+--+pathDatatype :: VGPath -> GettableStateVar PathDatatype+pathDatatype = makeGettableStateVar . liftM (unmarshalPathDatatype . fromIntegral)  +                                    . (getParameteri `flip` vg_PATH_DATATYPE)  -- | @pathScale@ - get the scaling factor of the path.    +-- pathScale :: VGPath -> GettableStateVar VGfloat pathScale = makeGettableStateVar . flip getParameterf vg_PATH_SCALE --- | @bias@ - get the bias factor of the path. -bias :: VGPath -> GettableStateVar VGfloat-bias = makeGettableStateVar . flip getParameterf vg_PATH_BIAS+-- | @pathBias@ - get the bias factor of the path. +--+pathBias :: VGPath -> GettableStateVar VGfloat+pathBias = makeGettableStateVar . flip getParameterf vg_PATH_BIAS  -- | @numSegments@ - get the number of segments stored in the path.      numSegments :: VGPath -> GettableStateVar VGint @@ -281,8 +287,8 @@ -- | @getPathCapabilities@ corresponds to the OpenVG  -- function @vgGetPathCapabilities@.  getPathCapabilities :: VGPath -> IO [PathCapabilities]-getPathCapabilities h = -    unbits32 unmarshalPathCapabilities <$> vgGetPathCapabilities h+getPathCapabilities = +    liftM (unbits32 unmarshalPathCapabilities) . vgGetPathCapabilities      -- | @removePathCapabilities@ corresponds to the OpenVG  -- function @vgRemovePathCapabilities@.  @@ -309,21 +315,9 @@ instance StorablePathData Int32 instance StorablePathData VGfloat -data PathData = S_8     Int8-              | S_16    Int16-              | S_32    Int32-              | F_float Float-  deriving (Eq,Ord,Show)--{---- final ptr is @const void * pathData@ --appendPathData :: VGPath -> VGint -> Ptr VGubyte -> Ptr a -> IO ()-appendPathData = vgAppendPathData--}-+-- TODO is this implementation valid? --- | @appendPathData@ - TODO is this implementation valid?+-- | @appendPathData@  appendPathData :: StorablePathData a => VGPath -> [PathCommand] -> [a] -> IO () appendPathData h cs ds = do      cmd_arr <- newArray (map (fromIntegral . marshalPathCommand) cs)@@ -350,15 +344,49 @@ -------------------------------------------------------------------------------- -- Querying the bounding box of a path --- pathBounds __ TODO -                 --- pathTransformedBounds __ TODO +data BoundingBox = +      BoundingBox { +          min_x     :: VGfloat, +          min_y     :: VGfloat,+          width_bb  :: VGfloat,+          height_bb :: VGfloat+        }+  deriving (Eq,Ord,Show) ++alloca4 :: Storable a => (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO b) -> IO b+alloca4 f = alloca $ \ca ->+              alloca $ \cb -> +                alloca $ \cc ->+                  alloca $ \cd -> f ca cb cc cd++++pathBounds :: VGPath -> IO BoundingBox+pathBounds path = alloca4 $ \px py pw ph -> do+    vgPathBounds path px py pw ph+    x <- peek px+    y <- peek py+    w <- peek pw+    h <- peek ph+    return $ BoundingBox x y w h      +++pathTransformedBounds :: VGPath -> IO BoundingBox+pathTransformedBounds path = alloca4 $ \px py pw ph -> do+    vgPathTransformedBounds path px py pw ph+    x <- peek px+    y <- peek py+    w <- peek pw+    h <- peek ph+    return $ BoundingBox x y w h      ++ -------------------------------------------------------------------------------- -- Interpolating between paths interpolatePath :: VGPath -> VGPath -> VGPath -> VGfloat -> IO Bool interpolatePath dst start end amount =-    unmarshalBool <$> vgInterpolatePath dst start end amount+    liftM unmarshalBool $ vgInterpolatePath dst start end amount             --------------------------------------------------------------------------------
src/Graphics/Rendering/OpenVG/VG/RenderingQuality.hs view
@@ -3,16 +3,18 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.RenderingQuality--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com> -- Stability   :  unstable -- Portability :  GHC ----- This module corresponds to section 6 (Rendering Quality and Antialiasing) --- of the OpenVG 1.0.1 specs.+-- This module corresponds to section 6 (Rendering Quality and +-- Antialiasing) of the OpenVG 1.0.1 specs. --+-- Acknowledgement - the matrix code is derived from Sven +-- Panne\'s HOpenGL. -- -------------------------------------------------------------------------------- @@ -27,12 +29,17 @@   pixelLayout,      -- * Matrix manipulation+  VGmatrix,+  withNewMatrix,+  withMatrix,+  newMatrix,+  getMatrixComponents,+   MatrixMode(..),   matrixMode,       loadIdentity,-  loadMatrix,-  getMatrix,+  matrix,   multMatrix,   translate,    scale, @@ -49,7 +56,10 @@ import Data.StateVar (     StateVar(), makeStateVar, SettableStateVar, makeSettableStateVar )    -import Control.Applicative+import Control.Monad+import Foreign.ForeignPtr ( +    ForeignPtr, withForeignPtr, mallocForeignPtrArray )+import Foreign.Marshal.Array ( peekArray, pokeArray ) import Foreign.Ptr ( Ptr )     @@ -99,7 +109,8 @@ pixelLayout = makeStateVar getPixelLayout setPixelLayout   where     getPixelLayout :: IO PixelLayout-    getPixelLayout = unmarshalPixelLayout . fromIntegral <$> geti ScreenLayout+    getPixelLayout = liftM (unmarshalPixelLayout . fromIntegral) +                           (geti ScreenLayout)              setPixelLayout :: PixelLayout -> IO ()       setPixelLayout = seti ScreenLayout . fromIntegral . marshalPixelLayout@@ -107,6 +118,62 @@ -------------------------------------------------------------------------------- -- Matrix manipulation +-- NOTE - VGmatrix is simpler than the corresponding GLmatrix.+-- Firstly VGmatrix only needs to store Floats (GLmatrix has to +-- store Floats or Doubles). Secondly VG matrices are always +-- stored in the same order (GL matrices can be row-major or+-- column-major).+++-- Represent a 3x3 matrix.+--+-- > { sx, shy, w0, shx, sy, w1, tx, ty, w2 }+--+-- > | sx  shx tx  |+-- > | shy sy  ty  |+-- > | w0  w1  w2  |+--+newtype VGmatrix = VGmatrix (ForeignPtr VGfloat)+  deriving (Eq,Ord,Show)++-- |  Create a new matrix (containing undefined elements)+-- and call the action to fill it with 3x3 elements.+--+-- (See HOpenGL\'s @withNewMatrix@).+--+withNewMatrix :: (Ptr VGfloat -> IO ()) -> IO VGmatrix+withNewMatrix f = do+    fp <- mallocForeignPtrArray 9+    withForeignPtr fp f+    return $ VGmatrix fp++-- | Call the action with the given matrix. +-- /Note:/ The action is /not/ allowed to modify the matrix +-- elements!+-- +-- (See HOpenGL\'s @withMatrix@).+--+withMatrix :: VGmatrix -> (Ptr VGfloat -> IO a) -> IO a+withMatrix (VGmatrix fp) f = withForeignPtr fp f++-- | Create a new matrix (as a foreign pointer) from the supplied+-- list of components. The list should have 9 elements and be in+-- the form:+--+-- > [ sx, shy, w0, shx, sy, w1, tx, ty, w2 ]+--+newMatrix :: [VGfloat] -> IO VGmatrix+newMatrix components = withNewMatrix $ flip pokeArray (take 9 components)+++-- | Extract the components from a matrix.+--+getMatrixComponents :: VGmatrix -> IO [VGfloat]+getMatrixComponents mat = withMatrix mat $ \p -> peekArray 9 p++++ -- | 'MatrixMode' enumerates the manipulable matrices.   data MatrixMode =      PathUserToSurface@@ -124,6 +191,7 @@ matrixMode = makeSettableStateVar $       seti MatrixMode . fromIntegral . marshalMatrixMode + -- | Set the current matrix to the identity matrix. -- -- 'loadIdentity' corresponds to the OpenVG function @@ -132,39 +200,37 @@ loadIdentity :: IO () loadIdentity = vgLoadIdentity --- NOTE--- See Graphics.Rendering.OpenGL.GL.CoordTrans+-- | Query and set the current matrix.+-- +-- 'matrix' is a read-write state variable corresponding to +-- OpenVG operations @vgGetMatrix@ (query) and vgLoadMatrix (set). +--+matrix :: StateVar VGmatrix+matrix = makeStateVar getMatrix loadMatrix  ++ -- | Set the current matrix to the supplied matrix. -- -- 'loadMatrix' corresponds to the OpenVG function @vgLoadMatrix@. -- --- \*\* Note - this function has an unfortunate type and should--- be wrapped. \*\* ----loadMatrix :: Ptr VGfloat -> IO ()-loadMatrix = vgLoadMatrix+loadMatrix :: VGmatrix -> IO ()+loadMatrix mat = withMatrix mat vgLoadMatrix  -- | Get the current matrix. -- -- 'getMatrix' corresponds to the OpenVG function @vgGetMatrix@.--- --- \*\* Note - this function has an unfortunate type and should--- be wrapped. \*\*  ---getMatrix :: IO (Ptr VGfloat)-getMatrix = vgGetMatrix+getMatrix :: IO VGmatrix+getMatrix = withNewMatrix vgGetMatrix  -- | Multiply the current matrix by the supplied matrix. --  -- 'multMatrix' corresponds to the OpenVG function @vgMultMatrix@.--- --- \*\* Note - this function has an unfortunate type and should--- be wrapped. \*\*  ---multMatrix :: Ptr VGfloat -> IO ()-multMatrix = vgMultMatrix+multMatrix :: VGmatrix -> IO ()+multMatrix mat = withMatrix mat vgMultMatrix  -- | Apply a translation to the current matrix. --
src/Graphics/Rendering/OpenVG/VG/Scissoring.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Scissoring--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/ShivaExtensions.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.ShivaExtensions--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VG/Utils.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.Utils--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VGU.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VGU--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VGU/ErrorsInternal.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VG.ErrorsInternal--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
src/Graphics/Rendering/OpenVG/VGU/VGU.hs view
@@ -3,7 +3,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Graphics.Rendering.OpenVG.VGU.VGU--- Copyright   :  (c) Stephen Tetley 2008, 2009+-- Copyright   :  (c) Stephen Tetley 2008-2010 -- License     :  BSD3 -- -- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>