summaryrefslogtreecommitdiff
path: root/src/gui/widgets/button.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-05 00:23:22 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-11 02:39:48 +0200
commit7115ac62eb2069d378d67758a3cd221e6620975d (patch)
tree93391a3b3ce247467bc8b05ef69c65fd0a02646d /src/gui/widgets/button.cpp
parentebc1db2172d3dc1e954647fc21e80f074e6cda4b (diff)
downloadmana-client-7115ac62eb2069d378d67758a3cd221e6620975d.tar.gz
mana-client-7115ac62eb2069d378d67758a3cd221e6620975d.tar.bz2
mana-client-7115ac62eb2069d378d67758a3cd221e6620975d.tar.xz
mana-client-7115ac62eb2069d378d67758a3cd221e6620975d.zip
Added textpopup on mouse hovering support to buttons.
I added a use of it to the menu buttons.
Diffstat (limited to 'src/gui/widgets/button.cpp')
-rw-r--r--src/gui/widgets/button.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index f072ef61..b2fa9e89 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -25,6 +25,7 @@
#include "graphics.h"
#include "gui/palette.h"
+#include "gui/textpopup.h"
#include "resources/image.h"
#include "resources/theme.h"
@@ -36,7 +37,8 @@
int Button::mInstances = 0;
float Button::mAlpha = 1.0;
-ImageRect *Button::mButton;
+ImageRect* Button::mButton;
+TextPopup* Button::mTextPopup = 0;
enum{
BUTTON_STANDARD, // 0
@@ -159,6 +161,10 @@ void Button::init()
btn[mode]->decRef();
}
updateAlpha();
+
+ // Load the popup
+ if (!mTextPopup)
+ mTextPopup = new TextPopup();
}
mInstances++;
}
@@ -175,6 +181,9 @@ Button::~Button()
dtor<Image*>());
}
delete[] mButton;
+
+ // Remove the popup
+ delete mTextPopup;
}
removeButtonIcon();
}
@@ -301,3 +310,50 @@ void Button::setCaption(const std::string& caption)
mCaption = caption;
adjustSize();
}
+
+void Button::logic()
+{
+ gcn::Button::logic();
+ mTextPopup->logic();
+}
+
+void Button::mouseMoved(gcn::MouseEvent &event)
+{
+ gcn::Button::mouseMoved(event);
+ mTextPopup->mouseMoved(event);
+
+ int x = event.getX();
+ int y = event.getY();
+
+ if (event.getSource() == this && !mPopupText.empty())
+ {
+ if (mParent)
+ {
+ x += mParent->getX();
+ y += mParent->getY();
+ }
+
+ mTextPopup->show(x + getX(), y + getY(), mPopupText);
+ }
+ else
+ {
+ mTextPopup->setVisible(false);
+ }
+}
+
+void Button::mouseExited(gcn::MouseEvent &event)
+{
+ gcn::Button::mouseExited(event);
+ mTextPopup->mouseExited(event);
+
+ mTextPopup->setVisible(false);
+}
+
+void Button::setButtonPopupText(const std::string& text)
+{
+ mPopupText = text;
+ if (!mPopupText.empty())
+ mTextPopup->show(getX(), getY(), mPopupText);
+ else
+ mTextPopup->setVisible(false);
+}