Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / CommonUI / System / Drawing / Advanced / PathGradientBrush.cs / 1 / PathGradientBrush.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing.Drawing2D { using System.Runtime.InteropServices; using System.Diagnostics; using System.Drawing; using System.ComponentModel; using Microsoft.Win32; using System.Drawing.Internal; using System; /** * Represent a PathGradient brush object */ ////// /// Encapsulates a public sealed class PathGradientBrush : Brush { /** * Create a new rectangle gradient brush object */ ///that fills the interior of a /// with a gradient. /// /// /// public PathGradientBrush(PointF[] points) : this(points, System.Drawing.Drawing2D.WrapMode.Clamp) { } ////// Initializes a new instance of the ///class with the specified points. /// /// /// Initializes a new instance of the public PathGradientBrush(PointF[] points, WrapMode wrapMode) { if (points == null) throw new ArgumentNullException("points"); //validate the WrapMode enum //valid values are 0x0 to 0x4 if (!ClientUtils.IsEnumValid(wrapMode, (int)wrapMode, (int)WrapMode.Tile, (int)WrapMode.Clamp)) { throw new InvalidEnumArgumentException("wrapMode", (int)wrapMode, typeof(WrapMode)); } IntPtr brush = IntPtr.Zero; IntPtr pointsBuf = SafeNativeMethods.Gdip.ConvertPointToMemory(points); int status = SafeNativeMethods.Gdip.GdipCreatePathGradient(new HandleRef(null, pointsBuf), points.Length, (int) wrapMode, out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); } ///class with the specified points and /// wrap mode. /// /// /// public PathGradientBrush(Point[] points) : this(points, System.Drawing.Drawing2D.WrapMode.Clamp) { } ////// Initializes a new instance of the ///class with the /// specified points. /// /// /// public PathGradientBrush(Point[] points, WrapMode wrapMode) { if (points == null) throw new ArgumentNullException("points"); //validate the WrapMode enum if (!ClientUtils.IsEnumValid(wrapMode, (int)wrapMode, (int)WrapMode.Tile, (int)WrapMode.Clamp)) { throw new InvalidEnumArgumentException("wrapMode", (int)wrapMode, typeof(WrapMode)); } IntPtr brush = IntPtr.Zero; IntPtr pointsBuf = SafeNativeMethods.Gdip.ConvertPointToMemory(points); int status = SafeNativeMethods.Gdip.GdipCreatePathGradientI(new HandleRef(null, pointsBuf), points.Length, (int) wrapMode, out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); } ////// Initializes a new instance of the ///class with the /// specified points and wrap mode. /// /// /// public PathGradientBrush(GraphicsPath path) { if (path == null) throw new ArgumentNullException("path"); IntPtr brush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreatePathGradientFromPath(new HandleRef(path, path.nativePath), out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); } ////// Initializes a new instance of the ////// class with the specified path. /// /// Constructor to initialized this object to be owned by GDI+. /// internal PathGradientBrush(IntPtr nativeBrush ) { Debug.Assert( nativeBrush != IntPtr.Zero, "Initializing native brush with null." ); SetNativeBrush( nativeBrush ); } ////// /// Creates an exact copy of this public override object Clone() { IntPtr cloneBrush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCloneBrush(new HandleRef(this, this.NativeBrush), out cloneBrush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return new PathGradientBrush(cloneBrush ); } /** * Set/get center color attributes */ ///. /// /// /// Gets or sets the color at the center of the /// path gradient. /// public Color CenterColor { get { int argb; int status = SafeNativeMethods.Gdip.GdipGetPathGradientCenterColor(new HandleRef(this, this.NativeBrush), out argb); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return Color.FromArgb(argb); } set { int status = SafeNativeMethods.Gdip.GdipSetPathGradientCenterColor(new HandleRef(this, this.NativeBrush), value.ToArgb()); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } } /** * Get/set colors * !! NOTE: We do not have methods for GetSurroundColor or SetSurroundColor, * May need to add usage of Collection class */ private void _SetSurroundColors(Color[] colors) { int count; int status = SafeNativeMethods.Gdip.GdipGetPathGradientSurroundColorCount(new HandleRef(this, this.NativeBrush), out count); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); if ((colors.Length > count) || (count <= 0)) throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.InvalidParameter); count = colors.Length; int[] argbs = new int[count]; for (int i=0; i/// /// public Color[] SurroundColors { get { return _GetSurroundColors();} set { _SetSurroundColors(value);} } /** * Set/get center point */ ////// Gets or sets an array of colors that /// correspond to the points in the path this ///fills. /// /// /// public PointF CenterPoint { get { GPPOINTF point = new GPPOINTF(); int status = SafeNativeMethods.Gdip.GdipGetPathGradientCenterPoint(new HandleRef(this, this.NativeBrush), point); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return point.ToPoint(); } set { int status = SafeNativeMethods.Gdip.GdipSetPathGradientCenterPoint(new HandleRef(this, this.NativeBrush), new GPPOINTF(value)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } } /** * Get source rectangle */ private RectangleF _GetRectangle() { GPRECTF rect = new GPRECTF(); int status = SafeNativeMethods.Gdip.GdipGetPathGradientRect(new HandleRef(this, this.NativeBrush), ref rect); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return rect.ToRectangleF(); } ////// Gets or sets the center point of the path /// gradient. /// ////// /// public RectangleF Rectangle { get { return _GetRectangle();} } /** * Set/get blend factors */ private Blend _GetBlend() { Blend blend; // Figure out the size of blend factor array int retval = 0; int status = SafeNativeMethods.Gdip.GdipGetPathGradientBlendCount(new HandleRef(this, this.NativeBrush), out retval); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // Allocate temporary native memory buffer int count = retval; IntPtr factors = IntPtr.Zero; IntPtr positions = IntPtr.Zero; try { factors = Marshal.AllocHGlobal(4*count); positions = Marshal.AllocHGlobal(4*count); // Retrieve horizontal blend factors status = SafeNativeMethods.Gdip.GdipGetPathGradientBlend(new HandleRef(this, this.NativeBrush), factors, positions, count); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // Return the result in a managed array blend = new Blend(count); Marshal.Copy(factors, blend.Factors, 0, count); Marshal.Copy(positions, blend.Positions, 0, count); } finally { if( factors != IntPtr.Zero ) { Marshal.FreeHGlobal(factors); } if( positions != IntPtr.Zero ) { Marshal.FreeHGlobal(positions); } } return blend; } private void _SetBlend(Blend blend) { // Allocate temporary native memory buffer // and copy input blend factors into it. int count = blend.Factors.Length; IntPtr factors = IntPtr.Zero; IntPtr positions = IntPtr.Zero; try { factors = Marshal.AllocHGlobal(4*count); positions = Marshal.AllocHGlobal(4*count); Marshal.Copy(blend.Factors, 0, factors, count); Marshal.Copy(blend.Positions, 0, positions, count); // Set blend factors int status = SafeNativeMethods.Gdip.GdipSetPathGradientBlend(new HandleRef(this, this.NativeBrush), new HandleRef(null, factors), new HandleRef(null, positions), count); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } } finally { if( factors != IntPtr.Zero ) { Marshal.FreeHGlobal(factors); } if( positions != IntPtr.Zero ) { Marshal.FreeHGlobal(positions); } } } ////// Gets a bounding rectangle for this ///. /// /// /// public Blend Blend { get { return _GetBlend();} set { _SetBlend(value);} } /* * SigmaBlend & LinearBlend */ ////// Gets or sets a ///that specifies positions and factors /// that define a custom falloff for the gradient. /// /// /// public void SetSigmaBellShape(float focus) { SetSigmaBellShape(focus, (float)1.0); } ////// Creates a gradient falloff based on a bell-shaped curve. /// ////// /// public void SetSigmaBellShape(float focus, float scale) { int status = SafeNativeMethods.Gdip.GdipSetPathGradientSigmaBlend(new HandleRef(this, this.NativeBrush), focus, scale); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Creates a gradient falloff based on a bell-shaped curve. /// ////// /// public void SetBlendTriangularShape(float focus) { SetBlendTriangularShape(focus, (float)1.0); } ////// Creates a triangular gradient. /// ////// /// public void SetBlendTriangularShape(float focus, float scale) { int status = SafeNativeMethods.Gdip.GdipSetPathGradientLinearBlend(new HandleRef(this, this.NativeBrush), focus, scale); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } /* * Preset Color Blend */ private ColorBlend _GetInterpolationColors() { ColorBlend blend; // Figure out the size of blend factor array int retval = 0; int status = SafeNativeMethods.Gdip.GdipGetPathGradientPresetBlendCount(new HandleRef(this, this.NativeBrush), out retval); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // If retVal is 0, then there is nothing to marshal. // In this case, we'll return an empty ColorBlend... // if (retval == 0) { return new ColorBlend(); } // Allocate temporary native memory buffer int count = retval; IntPtr colors = IntPtr.Zero; IntPtr positions = IntPtr.Zero; try { colors = Marshal.AllocHGlobal(4*count); positions = Marshal.AllocHGlobal(4*count); // Retrieve horizontal blend factors status = SafeNativeMethods.Gdip.GdipGetPathGradientPresetBlend(new HandleRef(this, this.NativeBrush), colors, positions, count); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // Return the result in a managed array blend = new ColorBlend(count); int[] argb = new int[count]; Marshal.Copy(colors, argb, 0, count); Marshal.Copy(positions, blend.Positions, 0, count); // copy ARGB values into Color array of ColorBlend blend.Colors = new Color[argb.Length]; for (int i=0; i/// Creates a triangular gradient. /// ////// /// public ColorBlend InterpolationColors { get { return _GetInterpolationColors(); } set { _SetInterpolationColors(value); } } /** * Set/get brush transform */ private void _SetTransform(Matrix matrix) { if (matrix == null) throw new ArgumentNullException("matrix"); int status = SafeNativeMethods.Gdip.GdipSetPathGradientTransform(new HandleRef(this, this.NativeBrush), new HandleRef(matrix, matrix.nativeMatrix)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } private Matrix _GetTransform() { Matrix matrix = new Matrix(); int status = SafeNativeMethods.Gdip.GdipGetPathGradientTransform(new HandleRef(this, this.NativeBrush), new HandleRef(matrix, matrix.nativeMatrix)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return matrix; } ////// Gets or sets a ///that defines a multi-color linear /// gradient. /// /// /// public Matrix Transform { get { return _GetTransform();} set { _SetTransform(value);} } ////// Gets or sets a ///that defines a local geometrical /// transform for this . /// /// /// public void ResetTransform() { int status = SafeNativeMethods.Gdip.GdipResetPathGradientTransform(new HandleRef(this, this.NativeBrush)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Resets the ///property to /// identity. /// /// /// public void MultiplyTransform(Matrix matrix) { MultiplyTransform(matrix, MatrixOrder.Prepend); } ////// Multiplies the ///that represents the local geometrical /// transform of this by the specified by prepending the specified . /// /// /// public void MultiplyTransform(Matrix matrix, MatrixOrder order) { if (matrix == null) throw new ArgumentNullException("matrix"); int status = SafeNativeMethods.Gdip.GdipMultiplyPathGradientTransform(new HandleRef(this, this.NativeBrush), new HandleRef(matrix, matrix.nativeMatrix), order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Multiplies the ///that represents the local geometrical /// transform of this by the specified in the specified order. /// /// /// public void TranslateTransform(float dx, float dy) { TranslateTransform(dx, dy, MatrixOrder.Prepend); } ////// Translates the local geometrical transform by the specified dimmensions. This /// method prepends the translation to the transform. /// ////// /// public void TranslateTransform(float dx, float dy, MatrixOrder order) { int status = SafeNativeMethods.Gdip.GdipTranslatePathGradientTransform(new HandleRef(this, this.NativeBrush), dx, dy, order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Translates the local geometrical transform by the specified dimmensions in /// the specified order. /// ////// /// public void ScaleTransform(float sx, float sy) { ScaleTransform(sx, sy, MatrixOrder.Prepend); } ////// Scales the local geometric transform by the specified amounts. This method /// prepends the scaling matrix to the transform. /// ////// /// public void ScaleTransform(float sx, float sy, MatrixOrder order) { int status = SafeNativeMethods.Gdip.GdipScalePathGradientTransform(new HandleRef(this, this.NativeBrush), sx, sy, order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Scales the local geometric transform by the specified amounts in the /// specified order. /// ////// /// public void RotateTransform(float angle) { RotateTransform(angle, MatrixOrder.Prepend); } ////// Rotates the local geometric transform by the specified amount. This method /// prepends the rotation to the transform. /// ////// /// public void RotateTransform(float angle, MatrixOrder order) { int status = SafeNativeMethods.Gdip.GdipRotatePathGradientTransform(new HandleRef(this, this.NativeBrush), angle, order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } /** * Set/get brush focus scales */ ////// Rotates the local geometric transform by the specified amount in the /// specified order. /// ////// /// Gets or sets the focus point for the /// gradient falloff. /// public PointF FocusScales { get { float[] scaleX = new float[] { 0.0f }; float[] scaleY = new float[] { 0.0f }; int status = SafeNativeMethods.Gdip.GdipGetPathGradientFocusScales(new HandleRef(this, this.NativeBrush), scaleX, scaleY); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return new PointF(scaleX[0], scaleY[0]); } set { int status = SafeNativeMethods.Gdip.GdipSetPathGradientFocusScales(new HandleRef(this, this.NativeBrush), value.X, value.Y); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } } /** * Set/get brush wrapping mode */ private void _SetWrapMode(WrapMode wrapMode) { int status = SafeNativeMethods.Gdip.GdipSetPathGradientWrapMode(new HandleRef(this, this.NativeBrush), (int) wrapMode); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } private WrapMode _GetWrapMode() { int mode = 0; int status = SafeNativeMethods.Gdip.GdipGetPathGradientWrapMode(new HandleRef(this, this.NativeBrush), out mode); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return (WrapMode) mode; } ////// /// public WrapMode WrapMode { get { return _GetWrapMode(); } set { //validate the WrapMode enum if (!ClientUtils.IsEnumValid(value, (int)value, (int)WrapMode.Tile, (int)WrapMode.Clamp)) { throw new InvalidEnumArgumentException("value", (int)value, typeof(WrapMode)); } _SetWrapMode(value); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ ///// Gets or sets a ///that indicates the wrap mode for this /// . /// // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing.Drawing2D { using System.Runtime.InteropServices; using System.Diagnostics; using System.Drawing; using System.ComponentModel; using Microsoft.Win32; using System.Drawing.Internal; using System; /** * Represent a PathGradient brush object */ ////// /// Encapsulates a public sealed class PathGradientBrush : Brush { /** * Create a new rectangle gradient brush object */ ///that fills the interior of a /// with a gradient. /// /// /// public PathGradientBrush(PointF[] points) : this(points, System.Drawing.Drawing2D.WrapMode.Clamp) { } ////// Initializes a new instance of the ///class with the specified points. /// /// /// Initializes a new instance of the public PathGradientBrush(PointF[] points, WrapMode wrapMode) { if (points == null) throw new ArgumentNullException("points"); //validate the WrapMode enum //valid values are 0x0 to 0x4 if (!ClientUtils.IsEnumValid(wrapMode, (int)wrapMode, (int)WrapMode.Tile, (int)WrapMode.Clamp)) { throw new InvalidEnumArgumentException("wrapMode", (int)wrapMode, typeof(WrapMode)); } IntPtr brush = IntPtr.Zero; IntPtr pointsBuf = SafeNativeMethods.Gdip.ConvertPointToMemory(points); int status = SafeNativeMethods.Gdip.GdipCreatePathGradient(new HandleRef(null, pointsBuf), points.Length, (int) wrapMode, out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); } ///class with the specified points and /// wrap mode. /// /// /// public PathGradientBrush(Point[] points) : this(points, System.Drawing.Drawing2D.WrapMode.Clamp) { } ////// Initializes a new instance of the ///class with the /// specified points. /// /// /// public PathGradientBrush(Point[] points, WrapMode wrapMode) { if (points == null) throw new ArgumentNullException("points"); //validate the WrapMode enum if (!ClientUtils.IsEnumValid(wrapMode, (int)wrapMode, (int)WrapMode.Tile, (int)WrapMode.Clamp)) { throw new InvalidEnumArgumentException("wrapMode", (int)wrapMode, typeof(WrapMode)); } IntPtr brush = IntPtr.Zero; IntPtr pointsBuf = SafeNativeMethods.Gdip.ConvertPointToMemory(points); int status = SafeNativeMethods.Gdip.GdipCreatePathGradientI(new HandleRef(null, pointsBuf), points.Length, (int) wrapMode, out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); } ////// Initializes a new instance of the ///class with the /// specified points and wrap mode. /// /// /// public PathGradientBrush(GraphicsPath path) { if (path == null) throw new ArgumentNullException("path"); IntPtr brush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreatePathGradientFromPath(new HandleRef(path, path.nativePath), out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); } ////// Initializes a new instance of the ////// class with the specified path. /// /// Constructor to initialized this object to be owned by GDI+. /// internal PathGradientBrush(IntPtr nativeBrush ) { Debug.Assert( nativeBrush != IntPtr.Zero, "Initializing native brush with null." ); SetNativeBrush( nativeBrush ); } ////// /// Creates an exact copy of this public override object Clone() { IntPtr cloneBrush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCloneBrush(new HandleRef(this, this.NativeBrush), out cloneBrush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return new PathGradientBrush(cloneBrush ); } /** * Set/get center color attributes */ ///. /// /// /// Gets or sets the color at the center of the /// path gradient. /// public Color CenterColor { get { int argb; int status = SafeNativeMethods.Gdip.GdipGetPathGradientCenterColor(new HandleRef(this, this.NativeBrush), out argb); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return Color.FromArgb(argb); } set { int status = SafeNativeMethods.Gdip.GdipSetPathGradientCenterColor(new HandleRef(this, this.NativeBrush), value.ToArgb()); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } } /** * Get/set colors * !! NOTE: We do not have methods for GetSurroundColor or SetSurroundColor, * May need to add usage of Collection class */ private void _SetSurroundColors(Color[] colors) { int count; int status = SafeNativeMethods.Gdip.GdipGetPathGradientSurroundColorCount(new HandleRef(this, this.NativeBrush), out count); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); if ((colors.Length > count) || (count <= 0)) throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.InvalidParameter); count = colors.Length; int[] argbs = new int[count]; for (int i=0; i/// /// public Color[] SurroundColors { get { return _GetSurroundColors();} set { _SetSurroundColors(value);} } /** * Set/get center point */ ////// Gets or sets an array of colors that /// correspond to the points in the path this ///fills. /// /// /// public PointF CenterPoint { get { GPPOINTF point = new GPPOINTF(); int status = SafeNativeMethods.Gdip.GdipGetPathGradientCenterPoint(new HandleRef(this, this.NativeBrush), point); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return point.ToPoint(); } set { int status = SafeNativeMethods.Gdip.GdipSetPathGradientCenterPoint(new HandleRef(this, this.NativeBrush), new GPPOINTF(value)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } } /** * Get source rectangle */ private RectangleF _GetRectangle() { GPRECTF rect = new GPRECTF(); int status = SafeNativeMethods.Gdip.GdipGetPathGradientRect(new HandleRef(this, this.NativeBrush), ref rect); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return rect.ToRectangleF(); } ////// Gets or sets the center point of the path /// gradient. /// ////// /// public RectangleF Rectangle { get { return _GetRectangle();} } /** * Set/get blend factors */ private Blend _GetBlend() { Blend blend; // Figure out the size of blend factor array int retval = 0; int status = SafeNativeMethods.Gdip.GdipGetPathGradientBlendCount(new HandleRef(this, this.NativeBrush), out retval); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // Allocate temporary native memory buffer int count = retval; IntPtr factors = IntPtr.Zero; IntPtr positions = IntPtr.Zero; try { factors = Marshal.AllocHGlobal(4*count); positions = Marshal.AllocHGlobal(4*count); // Retrieve horizontal blend factors status = SafeNativeMethods.Gdip.GdipGetPathGradientBlend(new HandleRef(this, this.NativeBrush), factors, positions, count); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // Return the result in a managed array blend = new Blend(count); Marshal.Copy(factors, blend.Factors, 0, count); Marshal.Copy(positions, blend.Positions, 0, count); } finally { if( factors != IntPtr.Zero ) { Marshal.FreeHGlobal(factors); } if( positions != IntPtr.Zero ) { Marshal.FreeHGlobal(positions); } } return blend; } private void _SetBlend(Blend blend) { // Allocate temporary native memory buffer // and copy input blend factors into it. int count = blend.Factors.Length; IntPtr factors = IntPtr.Zero; IntPtr positions = IntPtr.Zero; try { factors = Marshal.AllocHGlobal(4*count); positions = Marshal.AllocHGlobal(4*count); Marshal.Copy(blend.Factors, 0, factors, count); Marshal.Copy(blend.Positions, 0, positions, count); // Set blend factors int status = SafeNativeMethods.Gdip.GdipSetPathGradientBlend(new HandleRef(this, this.NativeBrush), new HandleRef(null, factors), new HandleRef(null, positions), count); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } } finally { if( factors != IntPtr.Zero ) { Marshal.FreeHGlobal(factors); } if( positions != IntPtr.Zero ) { Marshal.FreeHGlobal(positions); } } } ////// Gets a bounding rectangle for this ///. /// /// /// public Blend Blend { get { return _GetBlend();} set { _SetBlend(value);} } /* * SigmaBlend & LinearBlend */ ////// Gets or sets a ///that specifies positions and factors /// that define a custom falloff for the gradient. /// /// /// public void SetSigmaBellShape(float focus) { SetSigmaBellShape(focus, (float)1.0); } ////// Creates a gradient falloff based on a bell-shaped curve. /// ////// /// public void SetSigmaBellShape(float focus, float scale) { int status = SafeNativeMethods.Gdip.GdipSetPathGradientSigmaBlend(new HandleRef(this, this.NativeBrush), focus, scale); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Creates a gradient falloff based on a bell-shaped curve. /// ////// /// public void SetBlendTriangularShape(float focus) { SetBlendTriangularShape(focus, (float)1.0); } ////// Creates a triangular gradient. /// ////// /// public void SetBlendTriangularShape(float focus, float scale) { int status = SafeNativeMethods.Gdip.GdipSetPathGradientLinearBlend(new HandleRef(this, this.NativeBrush), focus, scale); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } /* * Preset Color Blend */ private ColorBlend _GetInterpolationColors() { ColorBlend blend; // Figure out the size of blend factor array int retval = 0; int status = SafeNativeMethods.Gdip.GdipGetPathGradientPresetBlendCount(new HandleRef(this, this.NativeBrush), out retval); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // If retVal is 0, then there is nothing to marshal. // In this case, we'll return an empty ColorBlend... // if (retval == 0) { return new ColorBlend(); } // Allocate temporary native memory buffer int count = retval; IntPtr colors = IntPtr.Zero; IntPtr positions = IntPtr.Zero; try { colors = Marshal.AllocHGlobal(4*count); positions = Marshal.AllocHGlobal(4*count); // Retrieve horizontal blend factors status = SafeNativeMethods.Gdip.GdipGetPathGradientPresetBlend(new HandleRef(this, this.NativeBrush), colors, positions, count); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } // Return the result in a managed array blend = new ColorBlend(count); int[] argb = new int[count]; Marshal.Copy(colors, argb, 0, count); Marshal.Copy(positions, blend.Positions, 0, count); // copy ARGB values into Color array of ColorBlend blend.Colors = new Color[argb.Length]; for (int i=0; i/// Creates a triangular gradient. /// ////// /// public ColorBlend InterpolationColors { get { return _GetInterpolationColors(); } set { _SetInterpolationColors(value); } } /** * Set/get brush transform */ private void _SetTransform(Matrix matrix) { if (matrix == null) throw new ArgumentNullException("matrix"); int status = SafeNativeMethods.Gdip.GdipSetPathGradientTransform(new HandleRef(this, this.NativeBrush), new HandleRef(matrix, matrix.nativeMatrix)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } private Matrix _GetTransform() { Matrix matrix = new Matrix(); int status = SafeNativeMethods.Gdip.GdipGetPathGradientTransform(new HandleRef(this, this.NativeBrush), new HandleRef(matrix, matrix.nativeMatrix)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return matrix; } ////// Gets or sets a ///that defines a multi-color linear /// gradient. /// /// /// public Matrix Transform { get { return _GetTransform();} set { _SetTransform(value);} } ////// Gets or sets a ///that defines a local geometrical /// transform for this . /// /// /// public void ResetTransform() { int status = SafeNativeMethods.Gdip.GdipResetPathGradientTransform(new HandleRef(this, this.NativeBrush)); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Resets the ///property to /// identity. /// /// /// public void MultiplyTransform(Matrix matrix) { MultiplyTransform(matrix, MatrixOrder.Prepend); } ////// Multiplies the ///that represents the local geometrical /// transform of this by the specified by prepending the specified . /// /// /// public void MultiplyTransform(Matrix matrix, MatrixOrder order) { if (matrix == null) throw new ArgumentNullException("matrix"); int status = SafeNativeMethods.Gdip.GdipMultiplyPathGradientTransform(new HandleRef(this, this.NativeBrush), new HandleRef(matrix, matrix.nativeMatrix), order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Multiplies the ///that represents the local geometrical /// transform of this by the specified in the specified order. /// /// /// public void TranslateTransform(float dx, float dy) { TranslateTransform(dx, dy, MatrixOrder.Prepend); } ////// Translates the local geometrical transform by the specified dimmensions. This /// method prepends the translation to the transform. /// ////// /// public void TranslateTransform(float dx, float dy, MatrixOrder order) { int status = SafeNativeMethods.Gdip.GdipTranslatePathGradientTransform(new HandleRef(this, this.NativeBrush), dx, dy, order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Translates the local geometrical transform by the specified dimmensions in /// the specified order. /// ////// /// public void ScaleTransform(float sx, float sy) { ScaleTransform(sx, sy, MatrixOrder.Prepend); } ////// Scales the local geometric transform by the specified amounts. This method /// prepends the scaling matrix to the transform. /// ////// /// public void ScaleTransform(float sx, float sy, MatrixOrder order) { int status = SafeNativeMethods.Gdip.GdipScalePathGradientTransform(new HandleRef(this, this.NativeBrush), sx, sy, order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } ////// Scales the local geometric transform by the specified amounts in the /// specified order. /// ////// /// public void RotateTransform(float angle) { RotateTransform(angle, MatrixOrder.Prepend); } ////// Rotates the local geometric transform by the specified amount. This method /// prepends the rotation to the transform. /// ////// /// public void RotateTransform(float angle, MatrixOrder order) { int status = SafeNativeMethods.Gdip.GdipRotatePathGradientTransform(new HandleRef(this, this.NativeBrush), angle, order); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } /** * Set/get brush focus scales */ ////// Rotates the local geometric transform by the specified amount in the /// specified order. /// ////// /// Gets or sets the focus point for the /// gradient falloff. /// public PointF FocusScales { get { float[] scaleX = new float[] { 0.0f }; float[] scaleY = new float[] { 0.0f }; int status = SafeNativeMethods.Gdip.GdipGetPathGradientFocusScales(new HandleRef(this, this.NativeBrush), scaleX, scaleY); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return new PointF(scaleX[0], scaleY[0]); } set { int status = SafeNativeMethods.Gdip.GdipSetPathGradientFocusScales(new HandleRef(this, this.NativeBrush), value.X, value.Y); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } } /** * Set/get brush wrapping mode */ private void _SetWrapMode(WrapMode wrapMode) { int status = SafeNativeMethods.Gdip.GdipSetPathGradientWrapMode(new HandleRef(this, this.NativeBrush), (int) wrapMode); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); } private WrapMode _GetWrapMode() { int mode = 0; int status = SafeNativeMethods.Gdip.GdipGetPathGradientWrapMode(new HandleRef(this, this.NativeBrush), out mode); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); return (WrapMode) mode; } ////// /// public WrapMode WrapMode { get { return _GetWrapMode(); } set { //validate the WrapMode enum if (!ClientUtils.IsEnumValid(value, (int)value, (int)WrapMode.Tile, (int)WrapMode.Clamp)) { throw new InvalidEnumArgumentException("value", (int)value, typeof(WrapMode)); } _SetWrapMode(value); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007./// Gets or sets a ///that indicates the wrap mode for this /// . ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TdsEnums.cs
- DataSourceDesigner.cs
- CallInfo.cs
- Item.cs
- ExtenderControl.cs
- DataSourceView.cs
- Rect3D.cs
- CommonRemoteMemoryBlock.cs
- XmlRootAttribute.cs
- Parameter.cs
- KeyValueSerializer.cs
- NameValueSectionHandler.cs
- embossbitmapeffect.cs
- ImageMetadata.cs
- UIElement.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- TaskSchedulerException.cs
- HttpApplication.cs
- CachedBitmap.cs
- DataGridPageChangedEventArgs.cs
- ResourceDefaultValueAttribute.cs
- DataServiceRequestOfT.cs
- Vector3DAnimationUsingKeyFrames.cs
- SafeArrayRankMismatchException.cs
- SessionStateContainer.cs
- HttpTransportBindingElement.cs
- DataTransferEventArgs.cs
- DSACryptoServiceProvider.cs
- CompositeScriptReferenceEventArgs.cs
- TextEncodedRawTextWriter.cs
- SqlCacheDependencySection.cs
- StagingAreaInputItem.cs
- ToggleButton.cs
- WSHttpBindingCollectionElement.cs
- ExtensionSimplifierMarkupObject.cs
- TemplateNodeContextMenu.cs
- DCSafeHandle.cs
- IssuanceLicense.cs
- StringStorage.cs
- DataGrid.cs
- EventEntry.cs
- ElementAtQueryOperator.cs
- MethodExpr.cs
- NamespaceList.cs
- Attributes.cs
- ClonableStack.cs
- Vector3DKeyFrameCollection.cs
- UnauthorizedWebPart.cs
- VarRemapper.cs
- Propagator.ExtentPlaceholderCreator.cs
- DesignerDataView.cs
- CalendarDay.cs
- ModuleConfigurationInfo.cs
- Attachment.cs
- ActiveXContainer.cs
- DataGridAddNewRow.cs
- SerialReceived.cs
- EndpointBehaviorElementCollection.cs
- BitmapDecoder.cs
- ToolStripProgressBar.cs
- DataDocumentXPathNavigator.cs
- Module.cs
- DecimalFormatter.cs
- StyleSelector.cs
- TypeDelegator.cs
- CompositeDataBoundControl.cs
- DataGridColumn.cs
- ClientApiGenerator.cs
- Scripts.cs
- EntityContainerEntitySetDefiningQuery.cs
- COM2ColorConverter.cs
- OwnerDrawPropertyBag.cs
- Geometry.cs
- UrlPath.cs
- XpsFilter.cs
- EntityViewContainer.cs
- WpfWebRequestHelper.cs
- SqlPersonalizationProvider.cs
- WebDescriptionAttribute.cs
- ObjectSet.cs
- PathNode.cs
- DataBindingCollection.cs
- IsolatedStorageSecurityState.cs
- EnterpriseServicesHelper.cs
- TimelineClockCollection.cs
- CodeArgumentReferenceExpression.cs
- DataMemberFieldConverter.cs
- StackSpiller.cs
- QuaternionConverter.cs
- MenuItemBindingCollection.cs
- Model3D.cs
- IndexedGlyphRun.cs
- ComAdminInterfaces.cs
- ClientBuildManager.cs
- StylusEventArgs.cs
- DataGridViewElement.cs
- ListViewGroup.cs
- ExeConfigurationFileMap.cs
- RepeatButtonAutomationPeer.cs
- PEFileReader.cs