2 // System.Drawing.Drawing2D.PathGradientBrush.cs
5 // Dennis Hayes (dennish@Raytek.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 // Ravindra (rkumar@novell.com)
9 // Copyright (C) 2002/3 Ximian, Inc. http://www.ximian.com
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
35 namespace System.Drawing.Drawing2D
38 /// Summary description for PathGradientBrush.
40 public sealed class PathGradientBrush : Brush
42 internal PathGradientBrush (IntPtr native) : base (native)
46 public PathGradientBrush (GraphicsPath path)
48 Status status = GDIPlus.GdipCreatePathGradientFromPath (path.NativeObject, out nativeObject);
49 GDIPlus.CheckStatus (status);
52 public PathGradientBrush (Point [] points) : this (points, WrapMode.Clamp)
56 public PathGradientBrush (PointF [] points) : this (points, WrapMode.Clamp)
60 public PathGradientBrush (Point [] points, WrapMode wrapMode)
62 Status status = GDIPlus.GdipCreatePathGradientI (points, points.Length, wrapMode, out nativeObject);
63 GDIPlus.CheckStatus (status);
66 public PathGradientBrush (PointF [] points, WrapMode wrapMode)
68 Status status = GDIPlus.GdipCreatePathGradient (points, points.Length, wrapMode, out nativeObject);
69 GDIPlus.CheckStatus (status);
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);
84 Blend blend = new Blend ();
85 blend.Factors = factors;
86 blend.Positions = positions;
92 float [] factors = value.Factors;
93 float [] positions = value.Positions;
94 count = factors.Length;
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.");
99 if (count != positions.Length)
100 throw new ArgumentException ("Invalid Blend object. It should contain the same number of factors and positions values.");
102 if (positions [0] != 0.0F)
103 throw new ArgumentException ("Invalid Blend object. The positions array must have 0.0 as its first element.");
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.");
108 Status status = GDIPlus.GdipSetPathGradientBlend (nativeObject, factors, positions, count);
109 GDIPlus.CheckStatus (status);
113 public Color CenterColor {
116 Status status = GDIPlus.GdipGetPathGradientCenterColor (nativeObject, out centerColor);
117 GDIPlus.CheckStatus (status);
118 return Color.FromArgb (centerColor);
121 Status status = GDIPlus.GdipSetPathGradientCenterColor (nativeObject, value.ToArgb ());
122 GDIPlus.CheckStatus (status);
126 public PointF CenterPoint {
129 Status status = GDIPlus.GdipGetPathGradientCenterPoint (nativeObject, out center);
130 GDIPlus.CheckStatus (status);
135 PointF center = value;
136 Status status = GDIPlus.GdipSetPathGradientCenterPoint (nativeObject, ref center);
137 GDIPlus.CheckStatus (status);
141 public PointF FocusScales {
145 Status status = GDIPlus.GdipGetPathGradientFocusScales (nativeObject, out xScale, out yScale);
146 GDIPlus.CheckStatus (status);
148 return new PointF (xScale, yScale);
151 Status status = GDIPlus.GdipSetPathGradientFocusScales (nativeObject, value.X, value.Y);
152 GDIPlus.CheckStatus (status);
156 public ColorBlend InterpolationColors {
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);
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;
173 return interpolationColors;
177 Color [] colors = value.Colors;
178 float [] positions = value.Positions;
179 count = colors.Length;
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.");
184 if (count != positions.Length)
185 throw new ArgumentException ("Invalid ColorBlend object. It should contain the same number of positions and color values.");
187 if (positions [0] != 0.0F)
188 throw new ArgumentException ("Invalid ColorBlend object. The positions array must have 0.0 as its first element.");
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.");
193 int [] blend = new int [colors.Length];
194 for (int i = 0; i < colors.Length; i++)
195 blend [i] = colors [i].ToArgb ();
197 Status status = GDIPlus.GdipSetPathGradientPresetBlend (nativeObject, blend, positions, count);
198 GDIPlus.CheckStatus (status);
202 public RectangleF Rectangle {
205 Status status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rect);
206 GDIPlus.CheckStatus (status);
212 public Color [] SurroundColors {
215 Status status = GDIPlus.GdipGetPathGradientSurroundColorCount (nativeObject, out count);
216 GDIPlus.CheckStatus (status);
218 int [] intcolors = new int [count];
219 status = GDIPlus.GdipGetPathGradientSurroundColorsWithCount (nativeObject, intcolors, ref count);
220 GDIPlus.CheckStatus (status);
222 Color [] colors = new Color [count];
223 for (int i = 0; i < count; i++)
224 colors [i] = Color.FromArgb (intcolors [i]);
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 ();
234 Status status = GDIPlus.GdipSetPathGradientSurroundColorsWithCount (nativeObject, colors, ref count);
235 GDIPlus.CheckStatus (status);
239 public Matrix Transform {
241 Matrix matrix = new Matrix ();
242 Status status = GDIPlus.GdipGetPathGradientTransform (nativeObject, matrix.nativeMatrix);
243 GDIPlus.CheckStatus (status);
248 Status status = GDIPlus.GdipSetPathGradientTransform (nativeObject, value.nativeMatrix);
249 GDIPlus.CheckStatus (status);
253 public WrapMode WrapMode {
256 Status status = GDIPlus.GdipGetPathGradientWrapMode (nativeObject, out wrapMode);
257 GDIPlus.CheckStatus (status);
262 Status status = GDIPlus.GdipSetPathGradientWrapMode (nativeObject, value);
263 GDIPlus.CheckStatus (status);
269 public void MultiplyTransform (Matrix matrix)
271 MultiplyTransform (matrix, MatrixOrder.Prepend);
274 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
276 Status status = GDIPlus.GdipMultiplyPathGradientTransform (nativeObject, matrix.nativeMatrix, order);
277 GDIPlus.CheckStatus (status);
280 public void ResetTransform ()
282 Status status = GDIPlus.GdipResetPathGradientTransform (nativeObject);
283 GDIPlus.CheckStatus (status);
286 public void RotateTransform (float angle)
288 RotateTransform (angle, MatrixOrder.Prepend);
291 public void RotateTransform (float angle, MatrixOrder order)
293 Status status = GDIPlus.GdipRotatePathGradientTransform (nativeObject, angle, order);
294 GDIPlus.CheckStatus (status);
297 public void ScaleTransform (float sx, float sy)
299 ScaleTransform (sx, sy, MatrixOrder.Prepend);
302 public void ScaleTransform (float sx, float sy, MatrixOrder order)
304 Status status = GDIPlus.GdipScalePathGradientTransform (nativeObject, sx, sy, order);
305 GDIPlus.CheckStatus (status);
308 public void SetBlendTriangularShape (float focus)
310 SetBlendTriangularShape (focus, 1.0F);
313 public void SetBlendTriangularShape (float focus, float scale)
315 if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
316 throw new ArgumentException ("Invalid parameter passed.");
318 Status status = GDIPlus.GdipSetPathGradientLinearBlend (nativeObject, focus, scale);
319 GDIPlus.CheckStatus (status);
322 public void SetSigmaBellShape (float focus)
324 SetSigmaBellShape (focus, 1.0F);
327 public void SetSigmaBellShape (float focus, float scale)
329 if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
330 throw new ArgumentException ("Invalid parameter passed.");
332 Status status = GDIPlus.GdipSetPathGradientSigmaBlend (nativeObject, focus, scale);
333 GDIPlus.CheckStatus (status);
336 public void TranslateTransform (float dx, float dy)
338 TranslateTransform (dx, dy, MatrixOrder.Prepend);
341 public void TranslateTransform (float dx, float dy, MatrixOrder order)
343 Status status = GDIPlus.GdipTranslatePathGradientTransform (nativeObject, dx, dy, order);
344 GDIPlus.CheckStatus (status);
347 public override object Clone ()
350 Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
351 GDIPlus.CheckStatus (status);
353 PathGradientBrush clone = new PathGradientBrush (clonePtr);