This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / System.Drawing / System.Drawing.Drawing2D / PathGradientBrush.cs
1 //
2 // System.Drawing.Drawing2D.PathGradientBrush.cs
3 //
4 // Authors:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //   Ravindra (rkumar@novell.com)
8 //
9 // Copyright (C) 2002/3 Ximian, Inc. http://www.ximian.com
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.Drawing;
35 using System.Runtime.InteropServices;
36
37 namespace System.Drawing.Drawing2D
38 {
39         /// <summary>
40         /// Summary description for PathGradientBrush.
41         /// </summary>
42         public sealed class PathGradientBrush : Brush
43         {
44                 Blend blend;
45                 Color centerColor;
46                 PointF center;
47                 PointF focus;
48                 RectangleF rectangle;
49                 Color [] surroundColors;
50                 ColorBlend interpolationColors;
51                 Matrix transform;
52                 WrapMode wrapMode;
53                 
54                 internal PathGradientBrush (IntPtr native) : base (native)
55                 {
56                 }
57
58                 public PathGradientBrush (GraphicsPath path)
59                 {
60                         Status status = GDIPlus.GdipCreatePathGradientFromPath (path.NativeObject, out nativeObject);
61                         GDIPlus.CheckStatus (status);
62  
63                         status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
64                         GDIPlus.CheckStatus (status);
65                 }
66
67                 public PathGradientBrush (Point [] points) : this (points, WrapMode.Clamp)
68                 {
69                 }
70
71                 public PathGradientBrush (PointF [] points) : this (points, WrapMode.Clamp)
72                 {
73                 }
74
75                 public PathGradientBrush (Point [] points, WrapMode wrapMode)
76                 {
77                         Status status = GDIPlus.GdipCreatePathGradientI (points, points.Length, wrapMode, out nativeObject);
78                         GDIPlus.CheckStatus (status);
79
80                         Rectangle rect;
81                         status = GDIPlus.GdipGetPathGradientRectI (nativeObject, out rect);
82                         GDIPlus.CheckStatus (status);
83                         rectangle = (RectangleF) rect;
84                 }
85
86                 public PathGradientBrush (PointF [] points, WrapMode wrapMode)
87                 {
88                         Status status = GDIPlus.GdipCreatePathGradient (points, points.Length, wrapMode, out nativeObject);
89                         GDIPlus.CheckStatus (status);
90
91                         status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
92                         GDIPlus.CheckStatus (status);
93                 }
94
95                 // Properties
96
97                 public Blend Blend {
98                         get {
99                                 return blend;
100                         }
101                         set {
102                                 Status status = GDIPlus.GdipSetPathGradientBlend (nativeObject, value.Factors, value.Positions, value.Factors.Length);
103                                 GDIPlus.CheckStatus (status);
104                                 blend = value;
105                         }
106                 }
107
108                 public Color CenterColor {
109                         get {
110                                 return centerColor;
111                         }
112                         set {
113                                 Status status = GDIPlus.GdipSetPathGradientCenterColor (nativeObject, value.ToArgb ());
114                                 GDIPlus.CheckStatus (status);
115                                 centerColor = value;
116                         }
117                 }
118
119                 public PointF CenterPoint {
120                         get {
121                                 return center;
122                         }
123                         set {
124                                 Status status = GDIPlus.GdipSetPathGradientCenterPoint (nativeObject, ref value);
125                                 GDIPlus.CheckStatus (status);
126                                 center = value;
127                         }
128                 }
129
130                 public PointF FocusScales {
131                         get {
132                                 return focus;
133                         }
134                         set {
135                                 Status status = GDIPlus.GdipSetPathGradientFocusScales (nativeObject, value.X, value.Y);
136                                 GDIPlus.CheckStatus (status);
137                                 focus = value;
138                         }
139                 }
140
141                 public ColorBlend InterpolationColors {
142                         get {
143                                 return interpolationColors;
144                         }
145                         set {
146                                 Color [] colors = value.Colors;
147                                 int [] blend = new int [colors.Length];
148                                 for (int i = 0; i < colors.Length; i++)
149                                         blend [i] = colors [i].ToArgb ();
150
151                                 Status status = GDIPlus.GdipSetPathGradientPresetBlend (nativeObject, blend, value.Positions, blend.Length);
152                                 GDIPlus.CheckStatus (status);
153                                 interpolationColors = value;
154                         }
155                 }
156
157                 public RectangleF Rectangle {
158                         get {
159                                 return rectangle;
160                         }
161                 }
162
163                 public Color [] SurroundColors {
164                         get {
165                                 return surroundColors;
166                         }
167                         set {
168                                 int length = value.Length;
169                                 int [] colors = new int [length];
170                                 for (int i = 0; i < length; i++)
171                                         colors [i] = value [i].ToArgb ();
172
173                                 Status status = GDIPlus.GdipSetPathGradientSurroundColorsWithCount (nativeObject, colors, ref length);
174                                 GDIPlus.CheckStatus (status);
175                                 surroundColors = value;
176                         }
177                 }
178
179                 public Matrix Transform {
180                         get {
181                                 return transform;
182                         }
183                         set {
184                                 Status status = GDIPlus.GdipSetPathGradientTransform (nativeObject, value.nativeMatrix);
185                                 GDIPlus.CheckStatus (status);
186                                 transform = value;
187                         }
188                 }
189
190                 public WrapMode WrapMode {
191                         get {
192                                 return wrapMode;
193                         }
194                         set {
195                                 Status status = GDIPlus.GdipSetPathGradientWrapMode (nativeObject, value);
196                                 GDIPlus.CheckStatus (status);
197                                 wrapMode = value;
198                         }
199                 }
200
201                 // Methods
202
203                 public void MultiplyTransform (Matrix matrix)
204                 {
205                         MultiplyTransform (matrix, MatrixOrder.Prepend);
206                 }
207
208                 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
209                 {
210                         Status status = GDIPlus.GdipMultiplyPathGradientTransform (nativeObject, matrix.nativeMatrix, order);
211                         GDIPlus.CheckStatus (status);
212                 }
213
214                 public void ResetTransform ()
215                 {
216                         Status status = GDIPlus.GdipResetPathGradientTransform (nativeObject);
217                         GDIPlus.CheckStatus (status);
218                 }
219
220                 public void RotateTransform (float angle)
221                 {
222                         RotateTransform (angle, MatrixOrder.Prepend);
223                 }
224
225                 public void RotateTransform (float angle, MatrixOrder order)
226                 {
227                         Status status = GDIPlus.GdipRotatePathGradientTransform (nativeObject, angle, order);
228                         GDIPlus.CheckStatus (status);
229                 }
230
231                 public void ScaleTransform (float sx, float sy)
232                 {
233                         ScaleTransform (sx, sy, MatrixOrder.Prepend);
234                 }
235
236                 public void ScaleTransform (float sx, float sy, MatrixOrder order)
237                 {
238                         Status status = GDIPlus.GdipScalePathGradientTransform (nativeObject, sx, sy, order);
239                         GDIPlus.CheckStatus (status);
240                 }
241
242                 public void SetBlendTriangularShape (float focus)
243                 {
244                         SetBlendTriangularShape (focus, 1.0F);
245                 }
246
247                 public void SetBlendTriangularShape (float focus, float scale)
248                 {
249                         if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
250                                 throw new ArgumentException ("Invalid parameter passed.");
251
252                         Status status = GDIPlus.GdipSetPathGradientLinearBlend (nativeObject, focus, scale);
253                         GDIPlus.CheckStatus (status);
254                 }
255
256                 public void SetSigmaBellShape (float focus)
257                 {
258                         SetSigmaBellShape (focus, 1.0F);
259                 }
260
261                 public void SetSigmaBellShape (float focus, float scale)
262                 {
263                         if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
264                                 throw new ArgumentException ("Invalid parameter passed.");
265
266                         Status status = GDIPlus.GdipSetPathGradientSigmaBlend (nativeObject, focus, scale);
267                         GDIPlus.CheckStatus (status);
268                 }
269
270                 public void TranslateTransform (float dx, float dy)
271                 {
272                         TranslateTransform (dx, dy, MatrixOrder.Prepend);
273                 }
274
275                 public void TranslateTransform (float dx, float dy, MatrixOrder order)
276                 {
277                         Status status = GDIPlus.GdipTranslatePathGradientTransform (nativeObject, dx, dy, order);
278                         GDIPlus.CheckStatus (status);
279                 }
280
281                 public override object Clone ()
282                 {
283                         IntPtr clonePtr;
284                         Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
285                         GDIPlus.CheckStatus (status);
286
287                         PathGradientBrush clone = new PathGradientBrush (clonePtr);
288                         return clone;
289                 }
290         }
291 }