forked from badvectors/ATISPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggleButton.cs
177 lines (156 loc) · 5.41 KB
/
ToggleButton.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
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Windows.Forms;
using vatsys;
using System;
namespace ATISPlugin
{
internal class ToggleButton : CheckBox
{
private Color _DisabledForeColor = Colours.GetColour(Colours.Identities.NonInteractiveText);
private Color _BackColor = Colours.GetColour(Colours.Identities.WindowBackground);
private Color _ForeColor = Colours.GetColour(Colours.Identities.InteractiveText);
private string _SubText = "";
private Font _SubFont = SystemFonts.DefaultFont;
private IContainer components;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Color DisabledForeColor
{
get
{
return _DisabledForeColor;
}
set
{
_DisabledForeColor = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Color BackColor
{
get
{
return _BackColor;
}
set
{
_BackColor = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Color ForeColor
{
get
{
return _ForeColor;
}
set
{
_ForeColor = value;
}
}
public string SubText
{
get
{
return _SubText;
}
set
{
_SubText = value;
Invalidate();
}
}
public Font SubFont
{
get
{
return _SubFont;
}
set
{
_SubFont = value;
Invalidate();
}
}
public ToggleButton()
{
InitializeComponent();
if (!Colours.Loaded)
{
//Colours.LoadColours();
}
Font = MMI.eurofont_sml;
TextAlign = ContentAlignment.MiddleCenter;
}
protected override void OnPaint(PaintEventArgs pe)
{
using (SolidBrush solidBrush = new SolidBrush(BackColor))
{
if (!base.Checked)
{
pe.Graphics.FillRectangle(solidBrush, base.ClientRectangle);
DrawText(pe.Graphics);
ControlPaint.DrawBorder3D(pe.Graphics, base.ClientRectangle, Border3DStyle.Raised);
}
else
{
solidBrush.Color = Colours.GetColour(Colours.Identities.WindowButtonDepressed);
pe.Graphics.FillRectangle(solidBrush, base.ClientRectangle);
DrawText(pe.Graphics);
ControlPaint.DrawBorder3D(pe.Graphics, base.ClientRectangle, Border3DStyle.Sunken);
}
}
}
private void DrawText(Graphics g)
{
Brush brush = null;
using ((!base.Enabled) ? (brush = new HatchBrush(HatchStyle.Percent50, DisabledForeColor, BackColor)) : (brush = new SolidBrush(ForeColor)))
{
using (StringFormat stringFormat = new StringFormat())
using (StringFormat stringFormat2 = new StringFormat())
using (StringFormat stringFormat3 = new StringFormat())
{
if (_SubText == "")
{
stringFormat.LineAlignment = StringAlignment.Center;
stringFormat.Alignment = StringAlignment.Center;
g.DrawString(Text, Font, brush, base.ClientRectangle, stringFormat);
return;
}
stringFormat2.LineAlignment = StringAlignment.Far;
stringFormat2.Alignment = StringAlignment.Center;
stringFormat3.LineAlignment = StringAlignment.Near;
stringFormat3.Alignment = StringAlignment.Center;
Rectangle rectangle = new Rectangle(base.ClientRectangle.Left, base.ClientRectangle.Top, base.ClientRectangle.Width, (int)((double)base.ClientRectangle.Height * 0.55));
g.DrawString(Text, Font, brush, rectangle, stringFormat2);
Rectangle rectangle2 = new Rectangle(base.ClientRectangle.Left, rectangle.Bottom, base.ClientRectangle.Width, base.ClientRectangle.Height - rectangle.Height);
g.DrawString(_SubText, _SubFont, brush, rectangle2, stringFormat3);
}
}
}
protected override void OnMouseDown(MouseEventArgs mevent)
{
Refresh();
base.OnMouseDown(mevent);
}
protected override void OnMouseUp(MouseEventArgs mevent)
{
Refresh();
base.OnMouseUp(mevent);
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
}
}
}