fixing visible window for containers
[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.Drawing;
34
35 namespace System.Drawing.Drawing2D
36 {
37         /// <summary>
38         /// Summary description for PathGradientBrush.
39         /// </summary>
40         public sealed class PathGradientBrush : Brush
41         {
42                 internal PathGradientBrush (IntPtr native) : base (native)
43                 {
44                 }
45
46                 public PathGradientBrush (GraphicsPath path)
47                 {
48                         Status status = GDIPlus.GdipCreatePathGradientFromPath (path.NativeObject, out nativeObject);
49                         GDIPlus.CheckStatus (status);
50                 }
51
52                 public PathGradientBrush (Point [] points) : this (points, WrapMode.Clamp)
53                 {
54                 }
55
56                 public PathGradientBrush (PointF [] points) : this (points, WrapMode.Clamp)
57                 {
58                 }
59
60                 public PathGradientBrush (Point [] points, WrapMode wrapMode)
61                 {
62                         Status status = GDIPlus.GdipCreatePathGradientI (points, points.Length, wrapMode, out nativeObject);
63                         GDIPlus.CheckStatus (status);
64                 }
65
66                 public PathGradientBrush (PointF [] points, WrapMode wrapMode)
67                 {
68                         Status status = GDIPlus.GdipCreatePathGradient (points, points.Length, wrapMode, out nativeObject);
69                         GDIPlus.CheckStatus (status);
70                 }
71
72                 // Properties
73
74                 public Blend Blend {
75                         get {
76                                 int count;
77                                 Status status = GDIPlus.GdipGetPathGradientBlendCount (nativeObject, out count);
78                                 GDIPlus.CheckStatus (status);
79                                 float [] factors = new float [count];
80                                 float [] positions = new float [count];
81                                 status = GDIPlus.GdipGetPathGradientBlend (nativeObject, factors, positions, count);
82                                 GDIPlus.CheckStatus (status);
83
84                                 Blend blend = new Blend ();
85                                 blend.Factors = factors;
86                                 blend.Positions = positions;
87
88                                 return blend;
89                         }
90                         set {
91                                 int count;
92                                 float [] factors = value.Factors;
93                                 float [] positions = value.Positions;
94                                 count = factors.Length;
95
96                                 if (count == 0 || positions.Length == 0)
97                                         throw new ArgumentException ("Invalid Blend object. It should have at least 2 elements in each of the factors and positions arrays.");
98
99                                 if (count != positions.Length)
100                                         throw new ArgumentException ("Invalid Blend object. It should contain the same number of factors and positions values.");
101
102                                 if (positions [0] != 0.0F)
103                                         throw new ArgumentException ("Invalid Blend object. The positions array must have 0.0 as its first element.");
104
105                                 if (positions [count - 1] != 1.0F)
106                                         throw new ArgumentException ("Invalid Blend object. The positions array must have 1.0 as its last element.");
107
108                                 Status status = GDIPlus.GdipSetPathGradientBlend (nativeObject, factors, positions, count);
109                                 GDIPlus.CheckStatus (status);
110                         }
111                 }
112
113                 public Color CenterColor {
114                         get {
115                                 int centerColor;
116                                 Status status = GDIPlus.GdipGetPathGradientCenterColor (nativeObject, out centerColor);
117                                 GDIPlus.CheckStatus (status);
118                                 return Color.FromArgb (centerColor);
119                         }
120                         set {
121                                 Status status = GDIPlus.GdipSetPathGradientCenterColor (nativeObject, value.ToArgb ());
122                                 GDIPlus.CheckStatus (status);
123                         }
124                 }
125
126                 public PointF CenterPoint {
127                         get {
128                                 PointF center;
129                                 Status status = GDIPlus.GdipGetPathGradientCenterPoint (nativeObject, out center);
130                                 GDIPlus.CheckStatus (status);
131
132                                 return center;
133                         }
134                         set {
135                                 PointF center = value;
136                                 Status status = GDIPlus.GdipSetPathGradientCenterPoint (nativeObject, ref center);
137                                 GDIPlus.CheckStatus (status);
138                         }
139                 }
140
141                 public PointF FocusScales {
142                         get {
143                                 float xScale;
144                                 float yScale;
145                                 Status status = GDIPlus.GdipGetPathGradientFocusScales (nativeObject, out xScale, out yScale);
146                                 GDIPlus.CheckStatus (status);
147
148                                 return new PointF (xScale, yScale);
149                         }
150                         set {
151                                 Status status = GDIPlus.GdipSetPathGradientFocusScales (nativeObject, value.X, value.Y);
152                                 GDIPlus.CheckStatus (status);
153                         }
154                 }
155
156                 public ColorBlend InterpolationColors {
157                         get {
158                                 int count;
159                                 Status status = GDIPlus.GdipGetPathGradientPresetBlendCount (nativeObject, out count);
160                                 GDIPlus.CheckStatus (status);
161                                 int [] intcolors = new int [count];
162                                 float [] positions = new float [count];
163                                 status = GDIPlus.GdipGetPathGradientPresetBlend (nativeObject, intcolors, positions, count);
164                                 GDIPlus.CheckStatus (status);
165
166                                 ColorBlend interpolationColors = new ColorBlend ();
167                                 Color [] colors = new Color [count];
168                                 for (int i = 0; i < count; i++)
169                                         colors [i] = Color.FromArgb (intcolors [i]);
170                                 interpolationColors.Colors = colors;
171                                 interpolationColors.Positions = positions;
172
173                                 return interpolationColors;
174                         }
175                         set {
176                                 int count;
177                                 Color [] colors = value.Colors;
178                                 float [] positions = value.Positions;
179                                 count = colors.Length;
180
181                                 if (count == 0 || positions.Length == 0)
182                                         throw new ArgumentException ("Invalid ColorBlend object. It should have at least 2 elements in each of the colors and positions arrays.");
183
184                                 if (count != positions.Length)
185                                         throw new ArgumentException ("Invalid ColorBlend object. It should contain the same number of positions and color values.");
186
187                                 if (positions [0] != 0.0F)
188                                         throw new ArgumentException ("Invalid ColorBlend object. The positions array must have 0.0 as its first element.");
189
190                                 if (positions [count - 1] != 1.0F)
191                                         throw new ArgumentException ("Invalid ColorBlend object. The positions array must have 1.0 as its last element.");
192
193                                 int [] blend = new int [colors.Length];
194                                 for (int i = 0; i < colors.Length; i++)
195                                         blend [i] = colors [i].ToArgb ();
196
197                                 Status status = GDIPlus.GdipSetPathGradientPresetBlend (nativeObject, blend, positions, count);
198                                 GDIPlus.CheckStatus (status);
199                         }
200                 }
201
202                 public RectangleF Rectangle {
203                         get {
204                                 RectangleF rect;
205                                 Status status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rect);
206                                 GDIPlus.CheckStatus (status);
207
208                                 return rect;
209                         }
210                 }
211
212                 public Color [] SurroundColors {
213                         get {
214                                 int count;
215                                 Status status = GDIPlus.GdipGetPathGradientSurroundColorCount (nativeObject, out count);
216                                 GDIPlus.CheckStatus (status);
217
218                                 int [] intcolors = new int [count];
219                                 status = GDIPlus.GdipGetPathGradientSurroundColorsWithCount (nativeObject, intcolors, ref count);
220                                 GDIPlus.CheckStatus (status);
221
222                                 Color [] colors = new Color [count];
223                                 for (int i = 0; i < count; i++)
224                                         colors [i] = Color.FromArgb (intcolors [i]);
225
226                                 return colors;
227                         }
228                         set {
229                                 int count = value.Length;
230                                 int [] colors = new int [count];
231                                 for (int i = 0; i < count; i++)
232                                         colors [i] = value [i].ToArgb ();
233
234                                 Status status = GDIPlus.GdipSetPathGradientSurroundColorsWithCount (nativeObject, colors, ref count);
235                                 GDIPlus.CheckStatus (status);
236                         }
237                 }
238
239                 public Matrix Transform {
240                         get {
241                                 Matrix matrix = new Matrix ();
242                                 Status status = GDIPlus.GdipGetPathGradientTransform (nativeObject, matrix.nativeMatrix);
243                                 GDIPlus.CheckStatus (status);
244
245                                 return matrix;
246                         }
247                         set {
248                                 Status status = GDIPlus.GdipSetPathGradientTransform (nativeObject, value.nativeMatrix);
249                                 GDIPlus.CheckStatus (status);
250                         }
251                 }
252
253                 public WrapMode WrapMode {
254                         get {
255                                 WrapMode wrapMode;
256                                 Status status = GDIPlus.GdipGetPathGradientWrapMode (nativeObject, out wrapMode);
257                                 GDIPlus.CheckStatus (status);
258
259                                 return wrapMode;
260                         }
261                         set {
262                                 Status status = GDIPlus.GdipSetPathGradientWrapMode (nativeObject, value);
263                                 GDIPlus.CheckStatus (status);
264                         }
265                 }
266
267                 // Methods
268
269                 public void MultiplyTransform (Matrix matrix)
270                 {
271                         MultiplyTransform (matrix, MatrixOrder.Prepend);
272                 }
273
274                 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
275                 {
276                         Status status = GDIPlus.GdipMultiplyPathGradientTransform (nativeObject, matrix.nativeMatrix, order);
277                         GDIPlus.CheckStatus (status);
278                 }
279
280                 public void ResetTransform ()
281                 {
282                         Status status = GDIPlus.GdipResetPathGradientTransform (nativeObject);
283                         GDIPlus.CheckStatus (status);
284                 }
285
286                 public void RotateTransform (float angle)
287                 {
288                         RotateTransform (angle, MatrixOrder.Prepend);
289                 }
290
291                 public void RotateTransform (float angle, MatrixOrder order)
292                 {
293                         Status status = GDIPlus.GdipRotatePathGradientTransform (nativeObject, angle, order);
294                         GDIPlus.CheckStatus (status);
295                 }
296
297                 public void ScaleTransform (float sx, float sy)
298                 {
299                         ScaleTransform (sx, sy, MatrixOrder.Prepend);
300                 }
301
302                 public void ScaleTransform (float sx, float sy, MatrixOrder order)
303                 {
304                         Status status = GDIPlus.GdipScalePathGradientTransform (nativeObject, sx, sy, order);
305                         GDIPlus.CheckStatus (status);
306                 }
307
308                 public void SetBlendTriangularShape (float focus)
309                 {
310                         SetBlendTriangularShape (focus, 1.0F);
311                 }
312
313                 public void SetBlendTriangularShape (float focus, float scale)
314                 {
315                         if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
316                                 throw new ArgumentException ("Invalid parameter passed.");
317
318                         Status status = GDIPlus.GdipSetPathGradientLinearBlend (nativeObject, focus, scale);
319                         GDIPlus.CheckStatus (status);
320                 }
321
322                 public void SetSigmaBellShape (float focus)
323                 {
324                         SetSigmaBellShape (focus, 1.0F);
325                 }
326
327                 public void SetSigmaBellShape (float focus, float scale)
328                 {
329                         if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
330                                 throw new ArgumentException ("Invalid parameter passed.");
331
332                         Status status = GDIPlus.GdipSetPathGradientSigmaBlend (nativeObject, focus, scale);
333                         GDIPlus.CheckStatus (status);
334                 }
335
336                 public void TranslateTransform (float dx, float dy)
337                 {
338                         TranslateTransform (dx, dy, MatrixOrder.Prepend);
339                 }
340
341                 public void TranslateTransform (float dx, float dy, MatrixOrder order)
342                 {
343                         Status status = GDIPlus.GdipTranslatePathGradientTransform (nativeObject, dx, dy, order);
344                         GDIPlus.CheckStatus (status);
345                 }
346
347                 public override object Clone ()
348                 {
349                         IntPtr clonePtr;
350                         Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
351                         GDIPlus.CheckStatus (status);
352
353                         PathGradientBrush clone = new PathGradientBrush (clonePtr);
354                         return clone;
355                 }
356         }
357 }