forked from Montellese/xbmc-on-imon
-
Notifications
You must be signed in to change notification settings - Fork 5
/
NavigationButton.cs
183 lines (148 loc) · 4.5 KB
/
NavigationButton.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
using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
namespace iMon.XBMC
{
internal class NavigationButton : Button
{
#region Private variables
private int defaultImageIndex;
private int hoverImageIndex;
private int activeImageIndex;
private int currentImageIndex;
#endregion
#region Public variables
[DefaultValue(-1), Browsable(true)]
public int DefaultImageIndex
{
get { return this.defaultImageIndex; }
set
{
if (value < -1)
{
value = -1;
}
this.defaultImageIndex = value;
}
}
[Browsable(false)]
public Image DefaultImage
{
get
{
if (this.ImageList == null || this.defaultImageIndex < 0 || this.defaultImageIndex >= this.ImageList.Images.Count)
{
return null;
}
return this.ImageList.Images[this.defaultImageIndex];
}
}
[DefaultValue(-1), Browsable(true)]
public int HoverImageIndex
{
get { return this.hoverImageIndex; }
set
{
if (value < -1)
{
value = -1;
}
this.hoverImageIndex = value;
}
}
[Browsable(false)]
public Image HoverImage
{
get
{
if (this.ImageList == null || this.hoverImageIndex < 0 || this.hoverImageIndex >= this.ImageList.Images.Count)
{
return null;
}
return this.ImageList.Images[this.hoverImageIndex];
}
}
[DefaultValue(-1), Browsable(true)]
public int ActiveImageIndex
{
get { return this.activeImageIndex; }
set
{
if (value < -1)
{
value = -1;
}
this.activeImageIndex = value;
}
}
[Browsable(false)]
public Image ActiveImage
{
get
{
if (this.ImageList == null || this.activeImageIndex < 0 || this.activeImageIndex >= this.ImageList.Images.Count)
{
return null;
}
return this.ImageList.Images[this.activeImageIndex];
}
}
#endregion
#region Constructors
public NavigationButton()
{
this.defaultImageIndex = -1;
this.hoverImageIndex = -1;
this.activeImageIndex = -1;
this.currentImageIndex = -1;
}
#endregion
#region Public functions
public void Activate()
{
if (this.activeImageIndex < 0 || this.ImageList == null || this.ImageList.Images.Count <= this.activeImageIndex)
{
return;
}
this.ImageIndex = this.activeImageIndex;
this.currentImageIndex = this.activeImageIndex;
}
public void Deactivate()
{
if (this.defaultImageIndex < 0 || this.ImageList == null || this.ImageList.Images.Count <= this.defaultImageIndex)
{
return;
}
this.ImageIndex = this.defaultImageIndex;
}
#endregion
#region Overrides of Button
protected override void OnClick(EventArgs e)
{
this.Activate();
base.OnClick(e);
}
protected override void OnMouseEnter(EventArgs e)
{
if (this.hoverImageIndex < 0 || this.ImageList == null || this.ImageList.Images.Count <= this.hoverImageIndex)
{
base.OnMouseEnter(e);
return;
}
this.currentImageIndex = this.ImageIndex;
this.ImageIndex = this.hoverImageIndex;
}
protected override void OnMouseLeave(EventArgs e)
{
if (this.currentImageIndex < 0 || this.ImageList == null || this.ImageList.Images.Count <= this.currentImageIndex)
{
base.OnMouseLeave(e);
return;
}
this.ImageIndex = this.currentImageIndex;
this.currentImageIndex = -1;
}
#endregion
}
}