-
Notifications
You must be signed in to change notification settings - Fork 2
/
DashSliderHorizontal.cs
125 lines (107 loc) · 4.08 KB
/
DashSliderHorizontal.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
// ********************************************************************************************************
// 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 1:01:02 PM
//
// Contributor(s): (Open source contributors should list themselves and their modifications here).
//
// ********************************************************************************************************
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DotSpatial.Symbology.Forms
{
/// <summary>
/// DashSliderHorizontal
/// </summary>
public class DashSliderHorizontal : DashSlider
{
#region Private Variables
#endregion
#region Constructors
/// <summary>
/// Creates a new instance of DashSliderHorizontal
/// </summary>
public DashSliderHorizontal()
: base(Orientation.Horizontal)
{
}
#endregion
#region Methods
#endregion
#region Properties
/// <summary>
/// Gets the bounding rectangle for this slider.
/// </summary>
public override RectangleF Bounds
{
get
{
RectangleF result = new RectangleF();
if (Image != null)
{
result.X = Position.X - Image.Width / 2;
result.Y = 0;
result.Width = Image.Width;
result.Height = Image.Height;
}
else
{
result.X = Position.X - Size.Width / 2;
result.Y = 0;
result.Width = Size.Width;
result.Height = Size.Height * 3 / 2;
}
return result;
}
}
#endregion
#region Protected Methods
/// <summary>
/// Draws the dash slider
/// </summary>
/// <param name="g"></param>
/// <param name="clipRectangle"></param>
public override void Draw(Graphics g, Rectangle clipRectangle)
{
DrawHorizontal(g, clipRectangle);
}
#endregion
#region Private Functions
private void DrawHorizontal(Graphics g, Rectangle clipRectangle)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
if (Image != null)
{
g.DrawImage(Image, new PointF(Position.X - Image.Width / 2, 0));
}
else
{
float x = Position.X;
float dx = Size.Width / 2;
float dy = Size.Height;
PointF[] trianglePoints = new PointF[4];
trianglePoints[0] = new PointF(x, dy);
trianglePoints[1] = new PointF(x - dx, 0);
trianglePoints[2] = new PointF(x + dx, 0);
trianglePoints[3] = new PointF(x, dy);
LinearGradientBrush br = CreateGradientBrush(Color, new PointF(x - dx, 0), new PointF(x + dx, dy));
g.FillPolygon(br, trianglePoints);
br.Dispose();
g.DrawPolygon(Pens.Black, trianglePoints);
}
}
#endregion
}
}