| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- //
- // System.Drawing.Drawing2D.PathGradientBrush.cs
- //
- // Authors:
- // Dennis Hayes ([email protected])
- // Andreas Nahr ([email protected])
- // Ravindra ([email protected])
- //
- // (C) 2002/3 Ximian, Inc. http://www.ximian.com
- // (C) 2004, Novell, Inc. http://www.novell.com
- //
- using System;
- using System.Drawing;
- using System.Runtime.InteropServices;
- namespace System.Drawing.Drawing2D
- {
- /// <summary>
- /// Summary description for PathGradientBrush.
- /// </summary>
- public sealed class PathGradientBrush : Brush
- {
- Blend blend;
- Color centerColor;
- PointF center;
- PointF focus;
- RectangleF rectangle;
- Color [] surroundColors;
- ColorBlend interpolationColors;
- Matrix transform;
- WrapMode wrapMode;
-
- internal PathGradientBrush (IntPtr native) : base (native)
- {
- }
- public PathGradientBrush (GraphicsPath path)
- {
- Status status = GDIPlus.GdipCreatePathGradientFromPath (path.NativeObject, out nativeObject);
- GDIPlus.CheckStatus (status);
-
- status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
- GDIPlus.CheckStatus (status);
- }
- public PathGradientBrush (Point [] points) : this (points, WrapMode.Clamp)
- {
- }
- public PathGradientBrush (PointF [] points) : this (points, WrapMode.Clamp)
- {
- }
- public PathGradientBrush (Point [] points, WrapMode wrapMode)
- {
- Status status = GDIPlus.GdipCreatePathGradientI (points, points.Length, wrapMode, out nativeObject);
- GDIPlus.CheckStatus (status);
- Rectangle rect;
- status = GDIPlus.GdipGetPathGradientRectI (nativeObject, out rect);
- GDIPlus.CheckStatus (status);
- rectangle = (RectangleF) rect;
- }
- public PathGradientBrush (PointF [] points, WrapMode wrapMode)
- {
- Status status = GDIPlus.GdipCreatePathGradient (points, points.Length, wrapMode, out nativeObject);
- GDIPlus.CheckStatus (status);
- status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
- GDIPlus.CheckStatus (status);
- }
- // Properties
- public Blend Blend {
- get {
- return blend;
- }
- set {
- Status status = GDIPlus.GdipSetPathGradientBlend (nativeObject, value.Factors, value.Positions, value.Factors.Length);
- GDIPlus.CheckStatus (status);
- blend = value;
- }
- }
- public Color CenterColor {
- get {
- return centerColor;
- }
- set {
- Status status = GDIPlus.GdipSetPathGradientCenterColor (nativeObject, value.ToArgb ());
- GDIPlus.CheckStatus (status);
- centerColor = value;
- }
- }
- public PointF CenterPoint {
- get {
- return center;
- }
- set {
- Status status = GDIPlus.GdipSetPathGradientCenterPoint (nativeObject, ref value);
- GDIPlus.CheckStatus (status);
- center = value;
- }
- }
- public PointF FocusScales {
- get {
- return focus;
- }
- set {
- Status status = GDIPlus.GdipSetPathGradientFocusScales (nativeObject, value.X, value.Y);
- GDIPlus.CheckStatus (status);
- focus = value;
- }
- }
- public ColorBlend InterpolationColors {
- get {
- return interpolationColors;
- }
- set {
- Color [] colors = value.Colors;
- int [] blend = new int [colors.Length];
- for (int i = 0; i < colors.Length; i++)
- blend [i] = colors [i].ToArgb ();
- Status status = GDIPlus.GdipSetPathGradientPresetBlend (nativeObject, blend, value.Positions, blend.Length);
- GDIPlus.CheckStatus (status);
- interpolationColors = value;
- }
- }
- public RectangleF Rectangle {
- get {
- return rectangle;
- }
- }
- public Color [] SurroundColors {
- get {
- return surroundColors;
- }
- set {
- int length = value.Length;
- int [] colors = new int [length];
- for (int i = 0; i < length; i++)
- colors [i] = value [i].ToArgb ();
- Status status = GDIPlus.GdipSetPathGradientSurroundColorsWithCount (nativeObject, colors, ref length);
- GDIPlus.CheckStatus (status);
- surroundColors = value;
- }
- }
- public Matrix Transform {
- get {
- return transform;
- }
- set {
- Status status = GDIPlus.GdipSetPathGradientTransform (nativeObject, value.nativeMatrix);
- GDIPlus.CheckStatus (status);
- transform = value;
- }
- }
- public WrapMode WrapMode {
- get {
- return wrapMode;
- }
- set {
- Status status = GDIPlus.GdipSetPathGradientWrapMode (nativeObject, value);
- GDIPlus.CheckStatus (status);
- wrapMode = value;
- }
- }
- // Methods
- public void MultiplyTransform (Matrix matrix)
- {
- MultiplyTransform (matrix, MatrixOrder.Prepend);
- }
- public void MultiplyTransform (Matrix matrix, MatrixOrder order)
- {
- Status status = GDIPlus.GdipMultiplyPathGradientTransform (nativeObject, matrix.nativeMatrix, order);
- GDIPlus.CheckStatus (status);
- }
- public void ResetTransform ()
- {
- Status status = GDIPlus.GdipResetPathGradientTransform (nativeObject);
- GDIPlus.CheckStatus (status);
- }
- public void RotateTransform (float angle)
- {
- RotateTransform (angle, MatrixOrder.Prepend);
- }
- public void RotateTransform (float angle, MatrixOrder order)
- {
- Status status = GDIPlus.GdipRotatePathGradientTransform (nativeObject, angle, order);
- GDIPlus.CheckStatus (status);
- }
- public void ScaleTransform (float sx, float sy)
- {
- ScaleTransform (sx, sy, MatrixOrder.Prepend);
- }
- public void ScaleTransform (float sx, float sy, MatrixOrder order)
- {
- Status status = GDIPlus.GdipScalePathGradientTransform (nativeObject, sx, sy, order);
- GDIPlus.CheckStatus (status);
- }
- public void SetBlendTriangularShape (float focus)
- {
- SetBlendTriangularShape (focus, 1.0F);
- }
- public void SetBlendTriangularShape (float focus, float scale)
- {
- Status status = GDIPlus.GdipSetPathGradientLinearBlend (nativeObject, focus, scale);
- GDIPlus.CheckStatus (status);
- }
- public void SetSigmaBellShape (float focus)
- {
- SetSigmaBellShape (focus, 1.0F);
- }
- public void SetSigmaBellShape (float focus, float scale)
- {
- Status status = GDIPlus.GdipSetPathGradientSigmaBlend (nativeObject, focus, scale);
- GDIPlus.CheckStatus (status);
- }
- public void TranslateTransform (float dx, float dy)
- {
- TranslateTransform (dx, dy, MatrixOrder.Prepend);
- }
- public void TranslateTransform (float dx, float dy, MatrixOrder order)
- {
- Status status = GDIPlus.GdipTranslatePathGradientTransform (nativeObject, dx, dy, order);
- GDIPlus.CheckStatus (status);
- }
- public override object Clone ()
- {
- IntPtr clonePtr;
- Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
- GDIPlus.CheckStatus (status);
- PathGradientBrush clone = new PathGradientBrush (clonePtr);
- return clone;
- }
- }
- }
|