bed36d534b84647da6dc733369cdc18a8ec0631b
[mono.git] / mcs / class / Mono.Cairo / Mono.Cairo / Matrix.cs
1 //
2 // Mono.Cairo.Matrix.cs
3 //
4 // Author: Duncan Mak
5 //
6 // (C) Ximian Inc, 2003.
7 //
8 // This is an OO wrapper API for the Cairo API
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 using System;
33 using System.Drawing;
34 using System.Runtime.InteropServices;
35 using Cairo;
36
37 namespace Cairo {
38
39         public class Matrix
40         {
41                 internal IntPtr matrix = IntPtr.Zero;
42
43                 public Matrix ()
44                         : this (Create ())
45                 {                        
46                 }
47
48                 internal Matrix (IntPtr ptr)
49                 {
50                         if (ptr == IntPtr.Zero)
51                                 ptr =  Create ();
52
53                         matrix = ptr;
54                 }
55
56                 public static IntPtr Create ()
57                 {
58                         return CairoAPI.cairo_matrix_create ();
59                 }
60
61                 public void Destroy ()
62                 {
63                         CairoAPI.cairo_matrix_destroy (matrix);
64                 }
65
66                 public Cairo.Status Copy (out Cairo.Matrix other)
67                 {
68                         IntPtr p = IntPtr.Zero;
69                         
70                         Cairo.Status status = CairoAPI.cairo_matrix_copy (matrix, out p);
71
72                         other = new Cairo.Matrix (p);
73
74                         return status;
75                 }
76
77                 public IntPtr Pointer {
78                         get { return matrix; }
79                 }
80
81                 public Cairo.Status SetIdentity ()
82                 {
83                         return CairoAPI.cairo_matrix_set_identity (matrix);
84                 }
85
86                 public Cairo.Status SetAffine (
87                         double a, double b, double c, double d, double tx, double ty)
88                 {
89                         return CairoAPI.cairo_matrix_set_affine (
90                                 matrix, a, b, c, d, tx, ty);
91                 }
92                 
93                 public Cairo.Status GetAffine (
94                         out double a, out double b, out double c, out double d, out double tx, out double ty)
95                 {
96                         return CairoAPI.cairo_matrix_get_affine (
97                                 matrix, out a, out b, out c, out d, out tx, out ty);
98                 }
99
100                 public Cairo.Status Scale (double sx, double sy)
101                 {
102                         return CairoAPI.cairo_matrix_scale (matrix, sx, sy);
103                 }
104
105                 public Cairo.Status Rotate (double radians)
106                 {
107                         return CairoAPI.cairo_matrix_rotate (matrix, radians);
108                 }
109
110                 public Cairo.Status Invert ()
111                 {
112                         return CairoAPI.cairo_matrix_invert (matrix);
113                 }
114
115                 public static Cairo.Status Multiply (
116                         out Cairo.Matrix result, Cairo.Matrix a, Cairo.Matrix b)
117                 {
118                         IntPtr p = IntPtr.Zero;
119                         
120                         Cairo.Status status = CairoAPI.cairo_matrix_multiply (
121                                 out p, a.Pointer, b.Pointer);
122
123                         result = new Cairo.Matrix (p);
124
125                         return status;
126                 }
127
128                 public Cairo.Status TransformDistance (ref double dx, ref double dy)
129                 {
130                         return CairoAPI.cairo_matrix_transform_distance (
131                                 matrix, ref dx, ref dy);
132                 }
133
134                 public Cairo.Status TransformPoint (ref double x, ref double y)
135                 {
136                         return CairoAPI.cairo_matrix_transform_distance (
137                                 matrix, ref x, ref y);
138                 }
139         }
140 }