Repository navigation
Expand file tree
/
Copy pathabout_window.cpp
More file actions
209 lines (186 loc) · 6.91 KB
/
Copy pathabout_window.cpp
File metadata and controls
209 lines (186 loc) · 6.91 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2012 Twan van Laarhoven and Sean Hunt |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/about_window.hpp>
#include <gui/util.hpp>
#include <util/version.hpp>
#include <wx/dcbuffer.h>
// ----------------------------------------------------------------------------- : About window
AboutWindow::AboutWindow(Window* parent)
: wxDialog(parent, wxID_ANY, _TITLE_("about"), wxDefaultPosition, wxSize(510,340), wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL)
, logo (load_resource_image(_("about")))
#if USE_BETA_LOGO
, logo2(load_resource_image(_("two_beta")))
#endif
{
// init controls
wxControl* ok_button = new HoverButton(this, wxID_OK, _("btn_ok"));
wxSize bs = ok_button->GetSize(), ws = GetClientSize();
ok_button->Move(ws.GetWidth() - bs.GetWidth(), ws.GetHeight() - bs.GetHeight()); // align bottom right
}
void AboutWindow::onPaint(wxPaintEvent& ev) {
wxBufferedPaintDC dc(this);
draw(dc);
}
void AboutWindow::draw(DC& dc) {
wxSize ws = GetClientSize();
// draw background
dc.SetPen (*wxTRANSPARENT_PEN);
dc.SetBrush(Color(240,247,255));
dc.DrawRectangle(0, 0, ws.GetWidth(), ws.GetHeight());
// draw logo
dc.DrawBitmap(logo, (ws.GetWidth() - logo.GetWidth()) / 2, 5);
#if USE_BETA_LOGO
dc.DrawBitmap(logo2, ws.GetWidth() - logo2.GetWidth(), ws.GetHeight() - logo2.GetHeight());
#endif
// draw version box
dc.SetPen (wxPen(Color(184,29,19), 2));
dc.SetBrush(Color(114,197,224));
dc.DrawRectangle(28, 104, 245, 133);
dc.SetTextBackground(Color(114,197,224));
dc.SetTextForeground(Color(0,0,0));
// draw version info
dc.SetFont(wxFont(9, wxSWISS, wxNORMAL, wxNORMAL, false, _("Arial")));
dc.DrawText(_("Version: ") + app_version.toString() + version_suffix, 34, 110);
dc.DrawText(_("Copyright \xA9 2001-2011"), 34, 130);
dc.DrawText(_(" Twan van Laarhoven,"), 34, 147);
dc.DrawText(_(" Sean Hunt,"), 34, 164);
dc.DrawText(_(" and the other MSE developers"), 34, 181);
}
BEGIN_EVENT_TABLE(AboutWindow, wxDialog)
EVT_PAINT (AboutWindow::onPaint)
END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : Button hover effect
HoverButtonBase::HoverButtonBase(Window* parent, int id, bool accepts_focus)
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxNO_BORDER )
, accepts_focus(accepts_focus)
, hover(false), focus(false), mouse_down(false), key_down(false)
{}
void HoverButtonBase::onMouseEnter(wxMouseEvent&) {
hover = true;
refreshIfNeeded();
if (!help_text.empty()) set_status_text(this,help_text);
}
void HoverButtonBase::onMouseLeave(wxMouseEvent&) {
hover = false;
refreshIfNeeded();
if (!help_text.empty()) set_status_text(this,wxEmptyString);
}
void HoverButtonBase::onFocus(wxFocusEvent&) {
focus = true;
refreshIfNeeded();
}
void HoverButtonBase::onKillFocus(wxFocusEvent&) {
focus = false;
refreshIfNeeded();
}
void HoverButtonBase::onLeftDown(wxMouseEvent&) {
mouse_down = true;
SetFocus();
CaptureMouse();
refreshIfNeeded();
}
void HoverButtonBase::onLeftUp(wxMouseEvent&) {
if (HasCapture()) ReleaseMouse();
mouse_down = false;
refreshIfNeeded();
if (hover) {
onClick();
}
}
void HoverButtonBase::onLoseCapture(wxMouseCaptureLostEvent&) {
// We already test for wrong release with HasCapture()
// but stupid wxWidget people decided to throw assertion failures
}
void HoverButtonBase::onKeyDown(wxKeyEvent& ev) {
int code = ev.GetKeyCode();
if (code == WXK_RETURN || code == WXK_SPACE) {
key_down = true;
refreshIfNeeded();
} else {
ev.Skip();
}
}
void HoverButtonBase::onKeyUp(wxKeyEvent& ev) {
int code = ev.GetKeyCode();
if (code == WXK_RETURN || code == WXK_SPACE) {
key_down = false;
refreshIfNeeded();
onClick();
}
}
void HoverButtonBase::onClick() {
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
evt.SetEventObject(this);
ProcessEvent(evt);
}
bool HoverButtonBase::AcceptsFocus() const {
return wxControl::AcceptsFocus() && accepts_focus;
}
void HoverButtonBase::refreshIfNeeded() {
Refresh(false);
}
void HoverButtonBase::onPaint(wxPaintEvent&) {
wxPaintDC dc(this);
draw(dc);
}
BEGIN_EVENT_TABLE(HoverButtonBase, wxControl)
EVT_ENTER_WINDOW (HoverButtonBase::onMouseEnter)
EVT_LEAVE_WINDOW (HoverButtonBase::onMouseLeave)
EVT_PAINT (HoverButtonBase::onPaint)
EVT_SET_FOCUS (HoverButtonBase::onFocus)
EVT_KILL_FOCUS (HoverButtonBase::onKillFocus)
EVT_LEFT_DOWN (HoverButtonBase::onLeftDown)
EVT_LEFT_UP (HoverButtonBase::onLeftUp)
EVT_KEY_DOWN (HoverButtonBase::onKeyDown)
EVT_KEY_UP (HoverButtonBase::onKeyUp)
EVT_MOUSE_CAPTURE_LOST(HoverButtonBase::onLoseCapture)
EVT_ERASE_BACKGROUND(HoverButtonBase::onEraseBackground)
END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : Button with image and hover effect
HoverButton::HoverButton(Window* parent, int id, const String& name, const Color& background, bool accepts_focus)
: HoverButtonBase(parent, id, accepts_focus)
, background(background)
, last_drawn(nullptr)
{
loadBitmaps(name);
SetSize(DoGetBestSize());
}
void HoverButton::loadBitmaps(const String& name) {
if (bitmaps == name) return;
bitmaps = name;
bg_normal = Bitmap(load_resource_image(name + _("_normal")));
bg_hover = Bitmap(load_resource_image(name + _("_hover")));
bg_focus = Bitmap(load_resource_image(name + _("_focus")));
bg_down = Bitmap(load_resource_image(name + _("_down")));
Refresh(false);
}
wxSize HoverButton::DoGetBestSize() const {
return wxSize(bg_normal.GetWidth(), bg_normal.GetHeight());
}
const Bitmap* HoverButton::toDraw() const {
return (mouse_down && hover) || key_down ? &bg_down
: hover ? &bg_hover
: focus ? &bg_focus
: &bg_normal;
}
void HoverButton::refreshIfNeeded() {
if (last_drawn != toDraw()) Refresh(false);
}
void HoverButton::draw(DC& dc) {
// clear background (for transparent button images)
wxSize ws = GetClientSize();
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(background != wxNullColour ? background : wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
dc.DrawRectangle(0, 0, ws.GetWidth(), ws.GetHeight());
// draw button
dc.DrawBitmap(*toDraw(), 0, 0, true);
last_drawn = toDraw();
}
int HoverButton::drawDelta() const {
return (mouse_down && hover) || key_down ? 2 : 0;
}