(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Drawing / System.Drawing.Drawing2D / LinearGradientBrush.cs
blob88bfcc8744f47725b982db92bedef229adf8b52a
1 //
2 // System.Drawing.Drawing2D.LinearGradientBrush.cs
3 //
4 // Authors:
5 // Dennis Hayes (dennish@Raytek.com)
6 // Ravindra (rkumar@novell.com)
7 //
8 // Copyright (C) 2002/3 Ximian, Inc. http://www.ximian.com
9 //
10 // Copyright (C) 2004 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.Drawing;
34 namespace System.Drawing.Drawing2D
36 /// <summary>
37 /// Summary description for LinearGradientBrush.
38 /// </summary>
39 public sealed class LinearGradientBrush : Brush
41 RectangleF rectangle;
43 internal LinearGradientBrush (IntPtr native) : base (native)
47 public LinearGradientBrush (Point point1, Point point2, Color color1, Color color2)
49 Status status = GDIPlus.GdipCreateLineBrushI (ref point1, ref point2, color1.ToArgb (), color2.ToArgb (), WrapMode.Tile, out nativeObject);
50 GDIPlus.CheckStatus (status);
52 Rectangle rect;
53 status = GDIPlus.GdipGetLineRectI (nativeObject, out rect);
54 GDIPlus.CheckStatus (status);
55 rectangle = (RectangleF) rect;
58 public LinearGradientBrush (PointF point1, PointF point2, Color color1, Color color2)
60 Status status = GDIPlus.GdipCreateLineBrush (ref point1, ref point2, color1.ToArgb (), color2.ToArgb (), WrapMode.Tile, out nativeObject);
61 GDIPlus.CheckStatus (status);
63 status = GDIPlus.GdipGetLineRect (nativeObject, out rectangle);
64 GDIPlus.CheckStatus (status);
67 public LinearGradientBrush (Rectangle rect, Color color1, Color color2, LinearGradientMode linearGradientMode)
69 Status status = GDIPlus.GdipCreateLineBrushFromRectI (ref rect, color1.ToArgb (), color2.ToArgb (), linearGradientMode, WrapMode.Tile, out nativeObject);
70 GDIPlus.CheckStatus (status);
72 rectangle = (RectangleF) rect;
75 public LinearGradientBrush (Rectangle rect, Color color1, Color color2, float angle) : this (rect, color1, color2, angle, false)
79 public LinearGradientBrush (RectangleF rect, Color color1, Color color2, LinearGradientMode linearGradientMode)
81 Status status = GDIPlus.GdipCreateLineBrushFromRect (ref rect, color1.ToArgb (), color2.ToArgb (), linearGradientMode, WrapMode.Tile, out nativeObject);
82 GDIPlus.CheckStatus (status);
84 rectangle = rect;
87 public LinearGradientBrush (RectangleF rect, Color color1, Color color2, float angle) : this (rect, color1, color2, angle, false)
91 public LinearGradientBrush (Rectangle rect, Color color1, Color color2, float angle, bool isAngleScaleable)
93 Status status = GDIPlus.GdipCreateLineBrushFromRectWithAngleI (ref rect, color1.ToArgb (), color2.ToArgb (), angle, isAngleScaleable, WrapMode.Tile, out nativeObject);
94 GDIPlus.CheckStatus (status);
96 rectangle = (RectangleF) rect;
99 public LinearGradientBrush (RectangleF rect, Color color1, Color color2, float angle, bool isAngleScaleable)
101 Status status = GDIPlus.GdipCreateLineBrushFromRectWithAngle (ref rect, color1.ToArgb (), color2.ToArgb (), angle, isAngleScaleable, WrapMode.Tile, out nativeObject);
102 GDIPlus.CheckStatus (status);
104 rectangle = rect;
107 // Public Properties
109 public Blend Blend {
110 get {
111 int count;
112 Status status = GDIPlus.GdipGetLineBlendCount (nativeObject, out count);
113 GDIPlus.CheckStatus (status);
114 float [] factors = new float [count];
115 float [] positions = new float [count];
116 status = GDIPlus.GdipGetLineBlend (nativeObject, factors, positions, count);
117 GDIPlus.CheckStatus (status);
119 Blend blend = new Blend ();
120 blend.Factors = factors;
121 blend.Positions = positions;
123 return blend;
125 set {
126 int count;
127 float [] factors = value.Factors;
128 float [] positions = value.Positions;
129 count = factors.Length;
131 if (count == 0 || positions.Length == 0)
132 throw new ArgumentException ("Invalid Blend object. It should have at least 2 elements in each of the factors and positions arrays.");
134 if (count != positions.Length)
135 throw new ArgumentException ("Invalid Blend object. It should contain the same number of factors and positions values.");
137 if (positions [0] != 0.0F)
138 throw new ArgumentException ("Invalid Blend object. The positions array must have 0.0 as its first element.");
140 if (positions [count - 1] != 1.0F)
141 throw new ArgumentException ("Invalid Blend object. The positions array must have 1.0 as its last element.");
143 Status status = GDIPlus.GdipSetLineBlend (nativeObject, factors, positions, count);
144 GDIPlus.CheckStatus (status);
148 public bool GammaCorrection {
149 get {
150 bool gammaCorrection;
151 Status status = GDIPlus.GdipGetLineGammaCorrection (nativeObject, out gammaCorrection);
152 GDIPlus.CheckStatus (status);
153 return gammaCorrection;
155 set {
156 Status status = GDIPlus.GdipSetLineGammaCorrection (nativeObject, value);
157 GDIPlus.CheckStatus (status);
161 public ColorBlend InterpolationColors {
162 get {
163 int count;
164 Status status = GDIPlus.GdipGetLinePresetBlendCount (nativeObject, out count);
165 GDIPlus.CheckStatus (status);
166 int [] intcolors = new int [count];
167 float [] positions = new float [count];
168 status = GDIPlus.GdipGetLinePresetBlend (nativeObject, intcolors, positions, count);
169 GDIPlus.CheckStatus (status);
171 ColorBlend interpolationColors = new ColorBlend ();
172 Color [] colors = new Color [count];
173 for (int i = 0; i < count; i++)
174 colors [i] = Color.FromArgb (intcolors [i]);
175 interpolationColors.Colors = colors;
176 interpolationColors.Positions = positions;
178 return interpolationColors;
180 set {
181 int count;
182 Color [] colors = value.Colors;
183 float [] positions = value.Positions;
184 count = colors.Length;
186 if (count == 0 || positions.Length == 0)
187 throw new ArgumentException ("Invalid ColorBlend object. It should have at least 2 elements in each of the colors and positions arrays.");
189 if (count != positions.Length)
190 throw new ArgumentException ("Invalid ColorBlend object. It should contain the same number of positions and color values.");
192 if (positions [0] != 0.0F)
193 throw new ArgumentException ("Invalid ColorBlend object. The positions array must have 0.0 as its first element.");
195 if (positions [count - 1] != 1.0F)
196 throw new ArgumentException ("Invalid ColorBlend object. The positions array must have 1.0 as its last element.");
198 int [] blend = new int [colors.Length];
199 for (int i = 0; i < colors.Length; i++)
200 blend [i] = colors [i].ToArgb ();
202 Status status = GDIPlus.GdipSetLinePresetBlend (nativeObject, blend, positions, count);
203 GDIPlus.CheckStatus (status);
207 public Color [] LinearColors {
208 get {
209 int [] colors = new int [2];
210 Status status = GDIPlus.GdipGetLineColors (nativeObject, colors);
211 GDIPlus.CheckStatus (status);
212 Color [] linearColors = new Color [2];
213 linearColors [0] = Color.FromArgb (colors [0]);
214 linearColors [1] = Color.FromArgb (colors [1]);
216 return linearColors;
218 set {
219 Status status = GDIPlus.GdipSetLineColors (nativeObject, value [0].ToArgb (), value [1].ToArgb ());
220 GDIPlus.CheckStatus (status);
224 public RectangleF Rectangle {
225 get {
226 return rectangle;
230 public Matrix Transform {
231 get {
232 Matrix matrix = new Matrix ();
233 Status status = GDIPlus.GdipGetLineTransform (nativeObject, matrix.nativeMatrix);
234 GDIPlus.CheckStatus (status);
236 return matrix;
238 set {
239 Status status = GDIPlus.GdipSetLineTransform (nativeObject, value.nativeMatrix);
240 GDIPlus.CheckStatus (status);
244 public WrapMode WrapMode {
245 get {
246 WrapMode wrapMode;
247 Status status = GDIPlus.GdipGetLineWrapMode (nativeObject, out wrapMode);
248 GDIPlus.CheckStatus (status);
250 return wrapMode;
252 set {
253 Status status = GDIPlus.GdipSetLineWrapMode (nativeObject, value);
254 GDIPlus.CheckStatus (status);
258 // Public Methods
260 public void MultiplyTransform (Matrix matrix)
262 MultiplyTransform (matrix, MatrixOrder.Prepend);
265 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
267 Status status = GDIPlus.GdipMultiplyLineTransform (nativeObject, matrix.nativeMatrix, order);
268 GDIPlus.CheckStatus (status);
271 public void ResetTransform ()
273 Status status = GDIPlus.GdipResetLineTransform (nativeObject);
274 GDIPlus.CheckStatus (status);
277 public void RotateTransform (float angle)
279 RotateTransform (angle, MatrixOrder.Prepend);
282 public void RotateTransform (float angle, MatrixOrder order)
284 Status status = GDIPlus.GdipRotateLineTransform (nativeObject, angle, order);
285 GDIPlus.CheckStatus (status);
288 public void ScaleTransform (float sx, float sy)
290 ScaleTransform (sx, sy, MatrixOrder.Prepend);
293 public void ScaleTransform (float sx, float sy, MatrixOrder order)
295 Status status = GDIPlus.GdipScaleLineTransform (nativeObject, sx, sy, order);
296 GDIPlus.CheckStatus (status);
299 public void SetBlendTriangularShape (float focus)
301 SetBlendTriangularShape (focus, 1.0F);
304 public void SetBlendTriangularShape (float focus, float scale)
306 if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
307 throw new ArgumentException ("Invalid parameter passed.");
309 Status status = GDIPlus.GdipSetLineLinearBlend (nativeObject, focus, scale);
310 GDIPlus.CheckStatus (status);
313 public void SetSigmaBellShape (float focus)
315 SetSigmaBellShape (focus, 1.0F);
318 public void SetSigmaBellShape (float focus, float scale)
320 if (focus < 0 || focus > 1 || scale < 0 || scale > 1)
321 throw new ArgumentException ("Invalid parameter passed.");
323 Status status = GDIPlus.GdipSetLineSigmaBlend (nativeObject, focus, scale);
324 GDIPlus.CheckStatus (status);
327 public void TranslateTransform (float dx, float dy)
329 TranslateTransform (dx, dy, MatrixOrder.Prepend);
332 public void TranslateTransform (float dx, float dy, MatrixOrder order)
334 Status status = GDIPlus.GdipTranslateLineTransform (nativeObject, dx, dy, order);
335 GDIPlus.CheckStatus (status);
338 public override object Clone ()
340 IntPtr clonePtr;
341 Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
342 GDIPlus.CheckStatus (status);
344 LinearGradientBrush clone = new LinearGradientBrush (clonePtr);
345 return clone;