Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Utils/Styling/GradientPaintStyle.cs @ 2768

Last change on this file since 2768 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 6.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Drawing;
5using System.Drawing.Drawing2D;
6
7namespace Netron.Diagramming.Core
8{
9    // ----------------------------------------------------------------------
10    /// <summary>
11    /// The gradient paint style
12    /// </summary>
13    // ----------------------------------------------------------------------
14    public partial class GradientPaintStyle :
15        IPaintStyle,
16        IVersion
17    {
18        // ------------------------------------------------------------------
19        /// <summary>
20        /// Event raised when this paint style is changed.
21        /// </summary>
22        // ------------------------------------------------------------------
23        public event PaintStyleChangedEventHandler PaintStyleChanged;
24
25        #region Fields
26       
27        // ------------------------------------------------------------------
28        /// <summary>
29        /// Implementation of IVersion - the current version of
30        /// GradientPaintStyle.
31        /// </summary>
32        // ------------------------------------------------------------------
33        protected const double gradientPaintStyleVersion = 1.0;
34
35        // ------------------------------------------------------------------
36        /// <summary>
37        /// the Angle field.
38        /// </summary>
39        // ------------------------------------------------------------------
40        private float mAngle;
41
42        // ------------------------------------------------------------------
43        /// <summary>
44        /// the EndColor field
45        /// </summary>
46        // ------------------------------------------------------------------
47        private Color mEndColor;
48
49        // ------------------------------------------------------------------
50        /// <summary>
51        /// the StartColor field
52        /// </summary>
53        // ------------------------------------------------------------------
54        private Color mStartColor;
55
56        #endregion
57
58        #region Properties
59
60        // ------------------------------------------------------------------
61        /// <summary>
62        /// Gets the current version.
63        /// </summary>
64        // ------------------------------------------------------------------
65        public virtual double Version
66        {
67            get
68            {
69                return gradientPaintStyleVersion;
70            }
71        }
72
73        // ------------------------------------------------------------------
74        /// <summary>
75        /// Gets or sets the StartColor
76        /// </summary>
77        // ------------------------------------------------------------------
78        public Color StartColor
79        {
80            get
81            {
82                return mStartColor;
83            }
84            set
85            {
86                mStartColor = value;
87                RaisePaintStyleChanged();
88            }
89        }
90
91        // ------------------------------------------------------------------
92        /// <summary>
93        /// Gets or sets the EndColor
94        /// </summary>
95        // ------------------------------------------------------------------
96        public Color EndColor
97        {
98            get
99            {
100                return mEndColor;
101            }
102            set
103            {
104                mEndColor = value;
105                RaisePaintStyleChanged();
106            }
107        }
108
109        // ------------------------------------------------------------------
110        /// <summary>
111        /// Gets or sets the Angle
112        /// </summary>
113        // ------------------------------------------------------------------
114        public float Angle
115        {
116            get
117            {
118                return mAngle;
119            }
120            set
121            {
122                mAngle = value;
123                RaisePaintStyleChanged();
124            }
125        }
126        #endregion
127
128        #region Constructor
129
130        // ------------------------------------------------------------------
131        ///<summary>
132        ///Default constructor
133        ///</summary>
134        // ------------------------------------------------------------------
135        public GradientPaintStyle(
136            Color startColor,
137            Color endColor,
138            float angle)
139        {
140            mStartColor = startColor;
141            mEndColor = endColor;
142            mAngle = angle;
143        }
144
145        // ------------------------------------------------------------------
146        /// <summary>
147        /// Initializes a new instance of the
148        /// <see cref="T:GradientPaintStyle"/> class.
149        /// </summary>
150        // ------------------------------------------------------------------
151        public GradientPaintStyle()
152        {
153            mStartColor = ArtPalette.RandomLowSaturationColor;
154            mEndColor = Color.White;
155            mAngle = -135;
156        }
157        #endregion
158
159        // ------------------------------------------------------------------
160        /// <summary>
161        /// Gets the brush.
162        /// </summary>
163        /// <param name="rectangle">The rectangle.</param>
164        /// <returns>Brush</returns>
165        // ------------------------------------------------------------------
166        public Brush GetBrush(Rectangle rectangle)
167        {
168            if (rectangle.Equals(Rectangle.Empty))
169            {
170                return new SolidBrush(mStartColor);
171            }
172            else
173            {
174                if (rectangle.Width == 0)
175                {
176                    rectangle.Width = 1;
177                }
178
179                if (rectangle.Height == 0)
180                {
181                    rectangle.Height = 1;
182                }
183                return new LinearGradientBrush(
184                    rectangle,
185                    mStartColor,
186                    mEndColor,
187                    mAngle,
188                    true);
189            }
190        }
191
192        // ------------------------------------------------------------------
193        /// <summary>
194        /// Raises the PaintStyleChanged event.
195        /// </summary>
196        // ------------------------------------------------------------------
197        protected virtual void RaisePaintStyleChanged()
198        {
199            if (this.PaintStyleChanged != null)
200            {
201                // Raise the event
202                this.PaintStyleChanged(
203                    this,
204                    new PaintStyleChangedEventArgs(
205                    this,
206                    FillType.LinearGradient));
207            }
208        }
209    }
210}
Note: See TracBrowser for help on using the repository browser.