using System.Drawing; using System.Drawing.Drawing2D; namespace Netron.Diagramming.Core { // ---------------------------------------------------------------------- /// /// The gradient paint style /// // ---------------------------------------------------------------------- public partial class GradientPaintStyle : IPaintStyle, IVersion { // ------------------------------------------------------------------ /// /// Event raised when this paint style is changed. /// // ------------------------------------------------------------------ public event PaintStyleChangedEventHandler PaintStyleChanged; #region Fields // ------------------------------------------------------------------ /// /// Implementation of IVersion - the current version of /// GradientPaintStyle. /// // ------------------------------------------------------------------ protected const double gradientPaintStyleVersion = 1.0; // ------------------------------------------------------------------ /// /// the Angle field. /// // ------------------------------------------------------------------ private float mAngle; // ------------------------------------------------------------------ /// /// the EndColor field /// // ------------------------------------------------------------------ private Color mEndColor; // ------------------------------------------------------------------ /// /// the StartColor field /// // ------------------------------------------------------------------ private Color mStartColor; #endregion #region Properties // ------------------------------------------------------------------ /// /// Gets the current version. /// // ------------------------------------------------------------------ public virtual double Version { get { return gradientPaintStyleVersion; } } // ------------------------------------------------------------------ /// /// Gets or sets the StartColor /// // ------------------------------------------------------------------ public Color StartColor { get { return mStartColor; } set { mStartColor = value; RaisePaintStyleChanged(); } } // ------------------------------------------------------------------ /// /// Gets or sets the EndColor /// // ------------------------------------------------------------------ public Color EndColor { get { return mEndColor; } set { mEndColor = value; RaisePaintStyleChanged(); } } // ------------------------------------------------------------------ /// /// Gets or sets the Angle /// // ------------------------------------------------------------------ public float Angle { get { return mAngle; } set { mAngle = value; RaisePaintStyleChanged(); } } #endregion #region Constructor // ------------------------------------------------------------------ /// ///Default constructor /// // ------------------------------------------------------------------ public GradientPaintStyle( Color startColor, Color endColor, float angle) { mStartColor = startColor; mEndColor = endColor; mAngle = angle; } // ------------------------------------------------------------------ /// /// Initializes a new instance of the /// class. /// // ------------------------------------------------------------------ public GradientPaintStyle() { mStartColor = ArtPalette.RandomLowSaturationColor; mEndColor = Color.White; mAngle = -135; } #endregion // ------------------------------------------------------------------ /// /// Gets the brush. /// /// The rectangle. /// Brush // ------------------------------------------------------------------ public Brush GetBrush(Rectangle rectangle) { if (rectangle.Equals(Rectangle.Empty)) { return new SolidBrush(mStartColor); } else { if (rectangle.Width == 0) { rectangle.Width = 1; } if (rectangle.Height == 0) { rectangle.Height = 1; } return new LinearGradientBrush( rectangle, mStartColor, mEndColor, mAngle, true); } } // ------------------------------------------------------------------ /// /// Raises the PaintStyleChanged event. /// // ------------------------------------------------------------------ protected virtual void RaisePaintStyleChanged() { if (this.PaintStyleChanged != null) { // Raise the event this.PaintStyleChanged( this, new PaintStyleChangedEventArgs( this, FillType.LinearGradient)); } } } }