summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-09 15:32:05 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-11 02:39:48 +0200
commitd956102647a5b53dab359290568c6caabd5f75e0 (patch)
treec209d64690a0caac962a7caf6dffbcc0a45a0fb9 /src
parent6a2d8e712aefbec19e870ad8799936cbe5786783 (diff)
downloadmana-d956102647a5b53dab359290568c6caabd5f75e0.tar.gz
mana-d956102647a5b53dab359290568c6caabd5f75e0.tar.bz2
mana-d956102647a5b53dab359290568c6caabd5f75e0.tar.xz
mana-d956102647a5b53dab359290568c6caabd5f75e0.zip
Made the button icon only shown when the icon file is valid.
And falls back to the text based caption otherwise.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/button.cpp13
-rw-r--r--src/gui/widgets/button.h2
-rw-r--r--src/gui/windowmenu.cpp3
3 files changed, 9 insertions, 9 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 6770c180..61ec28a2 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -83,7 +83,7 @@ Button::Button(const std::string &caption, const std::string &actionEventId,
adjustSize();
}
-void Button::setButtonIcon(const std::string& iconFile)
+bool Button::setButtonIcon(const std::string& iconFile)
{
// We clean up possible older references.
if (mButtonIcon)
@@ -91,18 +91,18 @@ void Button::setButtonIcon(const std::string& iconFile)
// If nothing relevant was set, we can quit now.
if (iconFile.empty())
- return;
+ return false;
// Load the icon frames.
Image *btnIcons = Theme::getImageFromTheme(iconFile);
if (!btnIcons)
- return;
+ return false;
// Compute the sub images size.
- int frameWidth = btnIcons->getWidth() / 4;
- int frameHeight = btnIcons->getHeight();
+ const int frameWidth = btnIcons->getWidth() / 4;
+ const int frameHeight = btnIcons->getHeight();
- if (btnIcons->getWidth() > 0 && btnIcons->getHeight() > 0)
+ if (frameWidth > 0 && frameHeight > 0)
{
mButtonIcon = new Image*[BUTTON_COUNT];
for (int mode = 0; mode < BUTTON_COUNT; ++mode)
@@ -115,6 +115,7 @@ void Button::setButtonIcon(const std::string& iconFile)
}
btnIcons->decRef();
+ return (mButtonIcon);
}
void Button::removeButtonIcon()
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index 39b3eb75..7463d2ad 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -72,7 +72,7 @@ class Button : public gcn::Button
* Standard, Highlighted, Pressed, and Disabled.
* If the image is too short, the missing states won't be loaded.
*/
- void setButtonIcon(const std::string& iconFile = std::string());
+ bool setButtonIcon(const std::string& iconFile = std::string());
/**
* Set the button popup text when hovering it for a few seconds.
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index a200427f..2595c819 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -160,10 +160,9 @@ void WindowMenu::addButton(const std::string& text, int &x, int &h,
const std::string& iconPath)
{
Button *btn = new Button("", text, this);
- if (!iconPath.empty())
+ if (!iconPath.empty() && btn->setButtonIcon(iconPath))
{
btn->setButtonPopupText(gettext(text.c_str()));
- btn->setButtonIcon(iconPath);
}
else
{