summaryrefslogtreecommitdiff
path: root/src/gui/button.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-18 01:53:10 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-18 01:53:10 +0000
commit8fb163024e321e00e55ff324ccdac34b9adfb773 (patch)
tree5b461cee991aaff633a6ae11f1d16a280952ebbb /src/gui/button.cpp
parent73e815469fd2332d424852afe6153243b5d12043 (diff)
downloadmana-client-8fb163024e321e00e55ff324ccdac34b9adfb773.tar.gz
mana-client-8fb163024e321e00e55ff324ccdac34b9adfb773.tar.bz2
mana-client-8fb163024e321e00e55ff324ccdac34b9adfb773.tar.xz
mana-client-8fb163024e321e00e55ff324ccdac34b9adfb773.zip
Added colon to the fixed font and removed some alfont usage.
Diffstat (limited to 'src/gui/button.cpp')
-rw-r--r--src/gui/button.cpp70
1 files changed, 25 insertions, 45 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index 030dd9de..fd82b9b1 100644
--- a/src/gui/button.cpp
+++ b/src/gui/button.cpp
@@ -24,26 +24,17 @@
Button::Button(const std::string& caption):
gcn::Button(caption)
{
- mouseDown = false;
- keyDown = false;
setBorderSize(0);
}
void Button::draw(gcn::Graphics* graphics) {
- int x, y;
int mode;
- int offset = 0;
-
- getAbsolutePosition(x, y);
-
- //printf("draw - %d,%d\n", x, y);
if (false /*disabled*/) {
mode = 3;
}
- else if (hasMouse() && mouseDown || keyDown) {
+ else if (isPressed()) {
mode = 2;
- offset = 1;
}
else if (hasMouse()) {
mode = 1;
@@ -52,48 +43,37 @@ void Button::draw(gcn::Graphics* graphics) {
mode = 0;
}
+ int x, y;
+ getAbsolutePosition(x, y);
+
draw_skinned_rect(gui_bitmap, &gui_skin.button.background[mode],
x, y, getWidth(), getHeight());
- int rtm = alfont_text_mode(-1);
- gui_text(gui_bitmap, getCaption().c_str(),
- x + 2 + offset, y + 4 + offset,
- gui_skin.button.textcolor[mode], FALSE);
- alfont_text_mode(rtm);
-}
+ graphics->setColor(getForegroundColor());
-void Button::lostFocus() {
- mouseDown = false;
- keyDown = false;
-}
+ int textX;
+ int textY = getHeight() / 2 - getFont()->getHeight() / 2;
-void Button::mousePress(int x, int y, int button) {
- if (button == gcn::MouseInput::LEFT && hasMouse()) {
- mouseDown = true;
+ switch (getAlignment()) {
+ case gcn::Graphics::LEFT:
+ textX = 4;
+ break;
+ case gcn::Graphics::CENTER:
+ textX = getWidth() / 2;
+ break;
+ case gcn::Graphics::RIGHT:
+ textX = getWidth() - 4;
+ break;
+ default:
+ throw GCN_EXCEPTION("Button::draw. Uknown alignment.");
}
-}
-
-void Button::mouseRelease(int x, int y, int button) {
- if (button == gcn::MouseInput::LEFT) {
- mouseDown = false;
- }
-}
-void Button::keyPress(const gcn::Key& key) {
- if (key.getValue() == gcn::Key::ENTER ||
- key.getValue() == gcn::Key::SPACE)
- {
- keyDown = true;
- }
- mouseDown = false;
-}
+ graphics->setFont(getFont());
-void Button::keyRelease(const gcn::Key& key) {
- if ((key.getValue() == gcn::Key::ENTER ||
- key.getValue() == gcn::Key::SPACE) && keyDown)
- {
- keyDown = false;
- generateAction();
+ if (isPressed()) {
+ graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
}
+ else {
+ graphics->drawText(getCaption(), textX, textY, getAlignment());
+ }
}
-