2 // Mono.Cairo.Matrix.cs
5 // Hisham Mardam Bey (hisham.mardambey@gmail.com)
6 // (C) Ximian Inc, 2003 - 2005.
8 // This is an OO wrapper API for the Cairo API
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Runtime.InteropServices;
38 [StructLayout(LayoutKind.Sequential)]
39 internal struct Matrix_T
53 internal Matrix_T matrix;
60 internal Matrix (Matrix_T ptr)
68 public void CreateIdentify ()
70 CairoAPI.cairo_matrix_init_identity (ref matrix);
73 public void Init (double xx, double yx, double xy, double yy,
76 matrix.xx = xx; matrix.yx = yx; matrix.xy = xy;
77 matrix.yy = yy; matrix.x0 = x0; matrix.y0 = y0;
80 public void InitTranslate (double tx, double ty)
82 CairoAPI.cairo_matrix_init_translate (ref matrix, tx, ty);
85 public void Translate (double tx, double ty)
87 CairoAPI.cairo_matrix_translate (ref matrix, tx, ty);
90 public void InitScale (double sx, double sy)
92 CairoAPI.cairo_matrix_init_scale (ref matrix, sx, sy);
95 public void Scale (double sx, double sy)
97 CairoAPI.cairo_matrix_scale (ref matrix, sx, sy);
100 public void InitRotate (double radians)
102 CairoAPI.cairo_matrix_init_rotate (ref matrix, radians);
105 public void Rotate (double radians)
107 CairoAPI.cairo_matrix_rotate (ref matrix, radians);
110 public Cairo.Status Invert ()
112 return CairoAPI.cairo_matrix_invert (ref matrix);
116 public static void Multiply (ref Cairo.Matrix res,
117 ref Cairo.Matrix a, ref Cairo.Matrix b)
122 CairoAPI.cairo_matrix_multiply (ref res.matrix,
127 public void TransformDistance (ref double dx, ref double dy)
129 CairoAPI.cairo_matrix_transform_distance (ref matrix, ref dx, ref dy);
132 public void TransformPoint (ref double x, ref double y)
134 CairoAPI.cairo_matrix_transform_point (ref matrix, ref x, ref y);
137 internal Matrix_T Pointer {
138 get { return matrix; }
139 set { matrix = value; }
144 IntPtr p = Marshal.AllocCoTaskMem ( Marshal.SizeOf (matrix));
145 Marshal.StructureToPtr (matrix, p, true);