fix typo
[mcs.git] / class / System.Drawing / System.Drawing / TextureBrush.cs
blob3982e5747b49fb484154b4be3118b82d93422d6a
1 //
2 // System.Drawing.TextureBrush.cs
3 //
4 // Authors:
5 // Dennis Hayes (dennish@Raytek.com)
6 // Ravindra (rkumar@novell.com)
7 // Sebastien Pouliot <sebastien@ximian.com>
8 //
9 // (C) 2002 Ximian, Inc
10 // Copyright (C) 2004,2006-2007 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:
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.
32 using System.ComponentModel;
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
36 namespace System.Drawing {
38 public sealed class TextureBrush : Brush {
40 internal TextureBrush (IntPtr ptr) :
41 base (ptr)
45 public TextureBrush (Image bitmap) :
46 this (bitmap, WrapMode.Tile)
50 public TextureBrush (Image image, Rectangle dstRect) :
51 this (image, WrapMode.Tile, dstRect)
55 public TextureBrush (Image image, RectangleF dstRect) :
56 this (image, WrapMode.Tile, dstRect)
60 public TextureBrush (Image image, WrapMode wrapMode)
62 if (image == null)
63 throw new ArgumentNullException ("image");
64 if ((wrapMode < WrapMode.Tile) || (wrapMode > WrapMode.Clamp))
65 throw new InvalidEnumArgumentException ("WrapMode");
67 Status status = GDIPlus.GdipCreateTexture (image.nativeObject, wrapMode, out nativeObject);
68 GDIPlus.CheckStatus (status);
71 [MonoLimitation ("ImageAttributes are ignored when using libgdiplus")]
72 public TextureBrush (Image image, Rectangle dstRect, ImageAttributes imageAttr)
74 if (image == null)
75 throw new ArgumentNullException ("image");
77 IntPtr attr = imageAttr == null ? IntPtr.Zero : imageAttr.NativeObject;
78 Status status = GDIPlus.GdipCreateTextureIAI (image.nativeObject, attr, dstRect.X, dstRect.Y,
79 dstRect.Width, dstRect.Height, out nativeObject);
80 GDIPlus.CheckStatus (status);
83 [MonoLimitation ("ImageAttributes are ignored when using libgdiplus")]
84 public TextureBrush (Image image, RectangleF dstRect, ImageAttributes imageAttr)
86 if (image == null)
87 throw new ArgumentNullException ("image");
89 IntPtr attr = imageAttr == null ? IntPtr.Zero : imageAttr.NativeObject;
90 Status status = GDIPlus.GdipCreateTextureIA (image.nativeObject, attr, dstRect.X, dstRect.Y,
91 dstRect.Width, dstRect.Height, out nativeObject);
92 GDIPlus.CheckStatus (status);
95 public TextureBrush (Image image, WrapMode wrapMode, Rectangle dstRect)
97 if (image == null)
98 throw new ArgumentNullException ("image");
99 if ((wrapMode < WrapMode.Tile) || (wrapMode > WrapMode.Clamp))
100 throw new InvalidEnumArgumentException ("WrapMode");
102 Status status = GDIPlus.GdipCreateTexture2I (image.nativeObject, wrapMode, dstRect.X, dstRect.Y,
103 dstRect.Width, dstRect.Height, out nativeObject);
104 GDIPlus.CheckStatus (status);
107 public TextureBrush (Image image, WrapMode wrapMode, RectangleF dstRect)
109 if (image == null)
110 throw new ArgumentNullException ("image");
111 if ((wrapMode < WrapMode.Tile) || (wrapMode > WrapMode.Clamp))
112 throw new InvalidEnumArgumentException ("WrapMode");
114 Status status = GDIPlus.GdipCreateTexture2 (image.nativeObject, wrapMode, dstRect.X, dstRect.Y,
115 dstRect.Width, dstRect.Height, out nativeObject);
116 GDIPlus.CheckStatus (status);
119 // properties
121 public Image Image {
122 get {
123 // this check is required here as GDI+ doesn't check for it
124 if (nativeObject == IntPtr.Zero)
125 throw new ArgumentException ("Object was disposed");
127 IntPtr img;
128 Status status = GDIPlus.GdipGetTextureImage (nativeObject, out img);
129 GDIPlus.CheckStatus (status);
130 return new Bitmap (img);
134 public Matrix Transform {
135 get {
136 Matrix matrix = new Matrix ();
137 Status status = GDIPlus.GdipGetTextureTransform (nativeObject, matrix.nativeMatrix);
138 GDIPlus.CheckStatus (status);
140 return matrix;
142 set {
143 if (value == null)
144 throw new ArgumentNullException ("Transform");
146 Status status = GDIPlus.GdipSetTextureTransform (nativeObject, value.nativeMatrix);
147 GDIPlus.CheckStatus (status);
151 public WrapMode WrapMode {
152 get {
153 WrapMode mode;
154 Status status = GDIPlus.GdipGetTextureWrapMode (nativeObject, out mode);
155 GDIPlus.CheckStatus (status);
156 return mode;
158 set {
159 if ((value < WrapMode.Tile) || (value > WrapMode.Clamp))
160 throw new InvalidEnumArgumentException ("WrapMode");
162 Status status = GDIPlus.GdipSetTextureWrapMode (nativeObject, value);
163 GDIPlus.CheckStatus (status);
167 // public methods
169 public override object Clone ()
171 IntPtr clonePtr;
172 Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
173 GDIPlus.CheckStatus (status);
175 return new TextureBrush (clonePtr);
178 public void MultiplyTransform (Matrix matrix)
180 MultiplyTransform (matrix, MatrixOrder.Prepend);
183 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
185 if (matrix == null)
186 throw new ArgumentNullException ("matrix");
188 Status status = GDIPlus.GdipMultiplyTextureTransform (nativeObject, matrix.nativeMatrix, order);
189 GDIPlus.CheckStatus (status);
192 public void ResetTransform ()
194 Status status = GDIPlus.GdipResetTextureTransform (nativeObject);
195 GDIPlus.CheckStatus (status);
198 public void RotateTransform (float angle)
200 RotateTransform (angle, MatrixOrder.Prepend);
203 public void RotateTransform (float angle, MatrixOrder order)
205 Status status = GDIPlus.GdipRotateTextureTransform (nativeObject, angle, order);
206 GDIPlus.CheckStatus (status);
209 public void ScaleTransform (float sx, float sy)
211 ScaleTransform (sx, sy, MatrixOrder.Prepend);
214 public void ScaleTransform (float sx, float sy, MatrixOrder order)
216 Status status = GDIPlus.GdipScaleTextureTransform (nativeObject, sx, sy, order);
217 GDIPlus.CheckStatus (status);
220 public void TranslateTransform (float dx, float dy)
222 TranslateTransform (dx, dy, MatrixOrder.Prepend);
225 public void TranslateTransform (float dx, float dy, MatrixOrder order)
227 Status status = GDIPlus.GdipTranslateTextureTransform (nativeObject, dx, dy, order);
228 GDIPlus.CheckStatus (status);