-
Notifications
You must be signed in to change notification settings - Fork 2
/
DashSlider.cs
197 lines (174 loc) · 6.86 KB
/
DashSlider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// ********************************************************************************************************
// Product Name: DotSpatial.Symbology.Forms.dll
// Description: The Windows Forms user interface layer for the DotSpatial.Symbology library.
// ********************************************************************************************************
// The contents of this file are subject to the MIT License (MIT)
// you may not use this file except in compliance with the License. You may obtain a copy of the License at
// http://dotspatial.codeplex.com/license
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
// ANY KIND, either expressed or implied. See the License for the specific language governing rights and
// limitations under the License.
//
// The Original Code is from MapWindow.dll version 6.0
//
// The Initial Developer of this Original Code is Ted Dunsford. Created 5/1/2009 12:24:43 PM
//
// Contributor(s): (Open source contributors should list themselves and their modifications here).
//
// ********************************************************************************************************
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DotSpatial.Symbology.Forms
{
/// <summary>
/// DashSlider
/// </summary>
[TypeConverter(typeof(ExpandableObjectConverter))]
public class DashSlider
{
#region Private Variables
private readonly Orientation _orientation;
private Color _color;
private Image _image;
private bool _isDragging;
private PointF _position;
private SizeF _size;
private bool _visible;
#endregion
#region Constructors
/// <summary>
/// Creates a new instance of DashSlider
/// </summary>
public DashSlider(Orientation sliderOrientation)
{
_orientation = sliderOrientation;
_visible = true;
_size = new SizeF(20F, 20F);
}
#endregion
#region Methods
/// <summary>
/// Draws the current control
/// </summary>
/// <param name="g"></param>
/// <param name="clipRectangle"></param>
public virtual void Draw(Graphics g, Rectangle clipRectangle)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
if (_visible == false) return;
if (_image != null)
{
g.DrawImage(_image, Position);
}
else
{
LinearGradientBrush br = CreateGradientBrush(Color, Bounds.Location, new PointF(Bounds.Right, Bounds.Bottom));
g.FillRectangle(br, Bounds);
br.Dispose();
g.DrawRectangle(Pens.Black, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);
}
}
#endregion
#region Properties
/// <summary>
/// Gets or sets an image that can be used instead of the default triangular drawing
/// </summary>
[Description("Gets or sets an image that can be used instead of the default drawing")]
public Image Image
{
get { return _image; }
set { _image = value; }
}
#endregion
#region Private Methods
/// <summary>
/// Gets or sets whether this control is vertical or horizontal
/// </summary>
[Description("Gets or sets whether this control is vertical or horizontal")]
public Orientation Orientation
{
get { return _orientation; }
}
/// <summary>
/// Gets the bounds of this slider.
/// </summary>
[Browsable(false)]
public virtual RectangleF Bounds
{
get
{
return new RectangleF(_position, _size);
}
}
/// <summary>
/// Gets or sets the color for this control if it is not using a custom image.
/// </summary>
[Description("Gets or sets the color for this control if it is not using a custom image.")]
public Color Color
{
get { return _color; }
set { _color = value; }
}
/// <summary>
/// Gets or sets whether or not this slider is in the process of being adjusted
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsDragging
{
get { return _isDragging; }
set { _isDragging = value; }
}
/// <summary>
/// Gets or sets the position. Whether the X or Y coordinate is used depends on the orientation.
/// </summary>
[Description("Gets or sets the position. Whether the X or Y coordinate is used depends on the orientation."),
TypeConverter(typeof(PointFConverter))]
public PointF Position
{
get { return _position; }
set { _position = value; }
}
/// <summary>
/// Gets or sets the size of this slider. This is only used when the slider is not based on an image.
/// </summary>
[Description("Gets or sets the size of this slider. This is only used when the slider is not based on an image."),
TypeConverter(typeof(ExpandableObjectConverter))]
public SizeF Size
{
get { return _size; }
set { _size = value; }
}
/// <summary>
/// Gets or sets a boolean indicating whether this slider will draw itself.
/// </summary>
[Description("Gets or sets a boolean indicating whether this slider will draw itself.")]
public bool Visible
{
get { return _visible; }
set { _visible = value; }
}
/// <summary>
/// Creates a Gradient Brush
/// </summary>
/// <param name="color"></param>
/// <param name="topLeft"></param>
/// <param name="bottomRight"></param>
/// <returns></returns>
protected static LinearGradientBrush CreateGradientBrush(Color color, PointF topLeft, PointF bottomRight)
{
float b = color.GetBrightness();
b += .3F;
if (b > 1F) b = 1F;
Color light = SymbologyGlobal.ColorFromHsl(color.GetHue(), color.GetSaturation(), b);
float d = color.GetBrightness();
d -= .3F;
if (d < 0F) d = 0F;
Color dark = SymbologyGlobal.ColorFromHsl(color.GetHue(), color.GetSaturation(), d);
return new LinearGradientBrush(topLeft, bottomRight, light, dark);
}
#endregion
}
}