text transform, headless session
[mono.git] / mcs / class / System.Drawing / System.Drawing / TextureBrush.cs
1 //
2 // System.Drawing.TextureBrush.cs
3 //
4 // Author:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Ravindra (rkumar@novell.com)
7 //
8 // (C) 2002 Ximian, Inc
9 // (C) 2004 Novell, Inc.
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System;
36 using System.Drawing.Drawing2D;
37 using System.Drawing.Imaging;
38
39 namespace System.Drawing
40 {
41         /// <summary>
42         /// Summary description for TextureBrush.
43         /// </summary>
44         public sealed class TextureBrush : Brush
45         {
46                 private Image image;
47
48                 internal TextureBrush (IntPtr ptr) : base (ptr)
49                 {
50                         // get image from IntPtr
51                         // image could be Bitmap or Metafile
52                         image = Image;
53                 }
54
55                 public TextureBrush (Image image) : this (image, WrapMode.Tile)
56                 {
57                 }
58
59                 public TextureBrush (Image image, Rectangle dstRect)
60                 {
61                         this.image = image;
62                         Status status = GDIPlus.GdipCreateTextureIAI (image.nativeObject, IntPtr.Zero, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, out nativeObject);
63                         GDIPlus.CheckStatus (status);                   
64                 }
65
66                 public TextureBrush (Image image, RectangleF dstRect)
67                 {
68                         this.image = image;
69                         Status status = GDIPlus.GdipCreateTextureIA (image.nativeObject, IntPtr.Zero, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, out nativeObject);
70                         GDIPlus.CheckStatus (status);
71                 }
72
73                 public TextureBrush (Image image, WrapMode wrapMode)
74                 {
75                         this.image = image;
76                         Status status = GDIPlus.GdipCreateTexture (image.nativeObject, wrapMode, out nativeObject);
77                         GDIPlus.CheckStatus (status);
78                 }
79
80                 public TextureBrush (Image image, Rectangle dstRect, ImageAttributes imageAttr)
81                 {
82                         this.image = image;
83                         Status status = GDIPlus.GdipCreateTextureIAI (image.nativeObject, imageAttr.NativeObject, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, out nativeObject);
84                         GDIPlus.CheckStatus (status);
85                 }
86
87                 public TextureBrush (Image image, RectangleF dstRect, ImageAttributes imageAttr)
88                 {       
89                         this.image = image;
90                         Status status = GDIPlus.GdipCreateTextureIA (image.nativeObject, imageAttr.NativeObject, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, out nativeObject);
91                         GDIPlus.CheckStatus (status);                   
92                 }
93
94                 public TextureBrush (Image image, WrapMode wrapMode, Rectangle dstRect)
95                 {
96                         this.image = image;
97                         Status status = GDIPlus.GdipCreateTexture2I (image.nativeObject, wrapMode, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, out nativeObject);
98                         GDIPlus.CheckStatus (status);
99                 }
100
101                 public TextureBrush (Image image, WrapMode wrapMode, RectangleF dstRect)
102                 {
103                         this.image = image;
104                         Status status = GDIPlus.GdipCreateTexture2 (image.nativeObject, wrapMode, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, out nativeObject);
105                         GDIPlus.CheckStatus (status);
106                 }
107
108                 // properties
109
110                 public Image Image {
111                         get {
112                                 if (image == null) {
113                                         IntPtr img;
114                                         Status status = GDIPlus.GdipGetTextureImage (nativeObject, out img);
115                                         GDIPlus.CheckStatus (status);
116                                         image = new Bitmap (img);
117                                 }
118                                 return image;
119                         }
120                 }
121
122                 public Matrix Transform {
123                         get {
124                                 Matrix matrix = new Matrix ();
125                                 Status status = GDIPlus.GdipGetTextureTransform (nativeObject, matrix.nativeMatrix);
126                                 GDIPlus.CheckStatus (status);
127
128                                 return matrix;
129                         }
130                         set {
131                                 Status status = GDIPlus.GdipSetTextureTransform (nativeObject, value.nativeMatrix);
132                                 GDIPlus.CheckStatus (status);
133                         }
134                 }
135
136                 public WrapMode WrapMode {
137                         get {
138                                 WrapMode mode = WrapMode.Tile;
139                                 Status status = GDIPlus.GdipGetTextureWrapMode (nativeObject, out mode);
140                                 GDIPlus.CheckStatus (status);
141                                 return mode;
142                         }
143                         set {
144                                 Status status = GDIPlus.GdipSetTextureWrapMode (nativeObject, value);
145                                 GDIPlus.CheckStatus (status);
146                         }
147                 }
148
149                 // public methods
150
151                 public override object Clone ()
152                 {
153                         IntPtr clonePtr;
154                         Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
155                         GDIPlus.CheckStatus (status);
156
157                         TextureBrush clone = new TextureBrush (clonePtr);
158                         if (image != null)
159                                 clone.image = (Image) image.Clone ();
160                         
161                         return clone;
162                 }
163
164                 public void MultiplyTransform (Matrix matrix)
165                 {
166                         MultiplyTransform (matrix, MatrixOrder.Prepend);
167                 }
168
169                 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
170                 {
171                         Status status = GDIPlus.GdipMultiplyTextureTransform (nativeObject, matrix.nativeMatrix, order);
172                         GDIPlus.CheckStatus (status);
173                 }
174
175                 public void ResetTransform ()
176                 {
177                         Status status = GDIPlus.GdipResetTextureTransform (nativeObject);
178                         GDIPlus.CheckStatus (status);
179                 }
180
181                 public void RotateTransform (float angle)
182                 {
183                         RotateTransform (angle, MatrixOrder.Prepend);
184                 }
185
186                 public void RotateTransform (float angle, MatrixOrder order)
187                 {
188                         Status status = GDIPlus.GdipRotateTextureTransform (nativeObject, angle, order);
189                         GDIPlus.CheckStatus (status);
190                 }
191
192                 public void ScaleTransform (float sx, float sy)
193                 {
194                         ScaleTransform (sx, sy, MatrixOrder.Prepend);
195                 }
196
197                 public void ScaleTransform (float sx, float sy, MatrixOrder order)
198                 {
199                         Status status = GDIPlus.GdipScaleTextureTransform (nativeObject, sx, sy, order);
200                         GDIPlus.CheckStatus (status);
201                 }
202
203                 public void TranslateTransform (float dx, float dy)
204                 {
205                         TranslateTransform (dx, dy, MatrixOrder.Prepend);
206                 }
207
208                 public void TranslateTransform (float dx, float dy, MatrixOrder order)
209                 {
210                         Status status = GDIPlus.GdipTranslateTextureTransform (nativeObject, dx, dy, order);
211                         GDIPlus.CheckStatus (status);
212                 }
213         }
214 }