Moved resources to better filenames;

Updated HoverButton, now an actual custom control, added focused and down states;
Added Help->Website

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@196 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-02-06 21:48:49 +00:00
parent c6cefaec27
commit 504269e903
36 changed files with 203 additions and 88 deletions
+80 -13
View File
@@ -14,12 +14,12 @@
// ----------------------------------------------------------------------------- : About window
AboutWindow::AboutWindow(Window* parent)
: wxDialog(parent, wxID_ANY, _TITLE_("about"), wxDefaultPosition, wxSize(510,340), wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE)
: wxDialog(parent, wxID_ANY, _TITLE_("about"), wxDefaultPosition, wxSize(510,340), wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL)
, logo (load_resource_image(_("about")))
, logo2(load_resource_image(_("two")))
{
// init controls
wxButton* ok_button = new HoverButton(this, wxID_OK, _("btn_ok"));
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
}
@@ -65,22 +65,81 @@ END_EVENT_TABLE ()
HoverButton::HoverButton(Window* parent, int id, const String& name)
: normal(load_resource_image(name + _("_NORMAL")))
, hover (load_resource_image(name + _("_HOVER")))
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxNO_BORDER)
, bg_normal(load_resource_image(name + _("_normal")))
, bg_hover (load_resource_image(name + _("_hover")))
, bg_focus (load_resource_image(name + _("_focus")))
, bg_down (load_resource_image(name + _("_down")))
, hover(false), focus(false), mouse_down(false), key_down(false)
, last_drawn(nullptr)
{
Create(parent, id, normal, wxDefaultPosition, wxSize(normal.GetWidth(), normal.GetHeight()), 0);
SetSize(DoGetBestSize());
}
void HoverButton::onMouseEnter(wxMouseEvent&) {
SetBitmapLabel(hover);
Refresh(false);
hover = true;
refreshIfNeeded();
}
void HoverButton::onMouseLeave(wxMouseEvent&) {
SetBitmapLabel(normal);
Refresh(false);
hover = false;
refreshIfNeeded();
}
void HoverButton::onFocus(wxFocusEvent&) {
focus = true;
refreshIfNeeded();
}
void HoverButton::onKillFocus(wxFocusEvent&) {
focus = false;
refreshIfNeeded();
}
void HoverButton::onLeftDown(wxMouseEvent&) {
mouse_down = true;
SetFocus();
CaptureMouse();
refreshIfNeeded();
}
void HoverButton::onLeftUp(wxMouseEvent&) {
if (HasCapture()) ReleaseMouse();
if (mouse_down && hover) {
mouse_down = false;
refreshIfNeeded();
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
ProcessEvent(evt);
}
mouse_down = false;
}
void HoverButton::onKeyDown(wxKeyEvent& ev) {
int code = ev.GetKeyCode();
if (code == WXK_RETURN || code == WXK_SPACE) {
key_down = true;
refreshIfNeeded();
} else {
ev.Skip();
}
}
void HoverButton::onKeyUp(wxKeyEvent& ev) {
int code = ev.GetKeyCode();
if (code == WXK_RETURN || code == WXK_SPACE) {
key_down = false;
refreshIfNeeded();
wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
ProcessEvent(evt);
}
}
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::onFocus(wxFocusEvent&) {}
void HoverButton::onKillFocus(wxFocusEvent&) {}
void HoverButton::onPaint(wxPaintEvent&) {
wxPaintDC dc(this);
@@ -95,13 +154,21 @@ void HoverButton::draw(DC& dc) {
dc.SetBrush(Color(240,247,255));
dc.DrawRectangle(0, 0, ws.GetWidth(), ws.GetHeight());
// draw button
dc.DrawBitmap(GetBitmapLabel(), 0, 0);
dc.DrawBitmap(*toDraw(), 0, 0);
last_drawn = toDraw();
}
int HoverButton::drawDelta() const {
return (mouse_down && hover) || key_down ? 2 : 0;
}
BEGIN_EVENT_TABLE(HoverButton, wxBitmapButton)
BEGIN_EVENT_TABLE(HoverButton, wxControl)
EVT_ENTER_WINDOW (HoverButton::onMouseEnter)
EVT_LEAVE_WINDOW (HoverButton::onMouseLeave)
EVT_PAINT (HoverButton::onPaint)
EVT_SET_FOCUS (HoverButton::onFocus)
EVT_KILL_FOCUS (HoverButton::onKillFocus)
EVT_LEFT_DOWN (HoverButton::onLeftDown)
EVT_LEFT_UP (HoverButton::onLeftUp)
EVT_KEY_DOWN (HoverButton::onKeyDown)
EVT_KEY_UP (HoverButton::onKeyUp)
END_EVENT_TABLE ()