summaryrefslogtreecommitdiff
path: root/src/gui/widgets/button.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-14 01:36:25 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-14 13:30:24 +0300
commitc23959e3c40e97f9c1aeb9eabc52131b6fa68f2a (patch)
treef9929a081b3479bcc1f515aac0a11bbc3cbc111a /src/gui/widgets/button.cpp
parentccf90e41053bf1a327939cad1082be05c15a8cde (diff)
downloadmanaplus-c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a.tar.gz
manaplus-c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a.tar.bz2
manaplus-c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a.tar.xz
manaplus-c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a.zip
Add new parameters to buttons theming.
New parameters: padding - padding over button text. spacing - space between text and image.
Diffstat (limited to 'src/gui/widgets/button.cpp')
-rw-r--r--src/gui/widgets/button.cpp74
1 files changed, 47 insertions, 27 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index ce2dfd74a..4cba0b535 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -62,7 +62,7 @@ static std::string const data[BUTTON_COUNT] =
"button_disabled.xml"
};
-ImageRect Button::button[BUTTON_COUNT];
+Skin *Button::button[BUTTON_COUNT];
Button::Button() :
gcn::Button(),
@@ -184,7 +184,7 @@ void Button::init()
{
for (int mode = 0; mode < BUTTON_COUNT; mode ++)
{
- Theme::instance()->loadRect(button[mode],
+ button[mode] = Theme::instance()->load(
data[mode], "button.xml");
}
}
@@ -205,9 +205,9 @@ Button::~Button()
if (mInstances == 0 && Theme::instance())
{
- const Theme *const theme = Theme::instance();
+ Theme *const theme = Theme::instance();
for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- theme->unloadRect(button[mode]);
+ theme->unload(button[mode]);
}
delete mVertexes;
mVertexes = nullptr;
@@ -256,16 +256,19 @@ void Button::updateAlpha()
if (mAlpha != alpha)
{
mAlpha = alpha;
- for (int a = 0; a < 9; a++)
+ for (int mode = 0; mode < BUTTON_COUNT; mode ++)
{
- if (button[BUTTON_DISABLED].grid[a])
- button[BUTTON_DISABLED].grid[a]->setAlpha(mAlpha);
- if (button[BUTTON_PRESSED].grid[a])
- button[BUTTON_PRESSED].grid[a]->setAlpha(mAlpha);
- if (button[BUTTON_HIGHLIGHTED].grid[a])
- button[BUTTON_HIGHLIGHTED].grid[a]->setAlpha(mAlpha);
- if (button[BUTTON_STANDARD].grid[a])
- button[BUTTON_STANDARD].grid[a]->setAlpha(mAlpha);
+ for (int a = 0; a < 9; a ++)
+ {
+ Skin *skin = button[mode];
+ if (skin)
+ {
+ ImageRect &rect = skin->getBorder();
+ Image *image = rect.grid[a];
+ if (image)
+ image->setAlpha(mAlpha);
+ }
+ }
}
}
}
@@ -283,6 +286,10 @@ void Button::draw(gcn::Graphics *graphics)
else
mode = BUTTON_STANDARD;
+ const Skin *const skin = button[mode];
+ if (!skin)
+ return;
+
updateAlpha();
Graphics *const g2 = static_cast<Graphics *const>(graphics);
@@ -318,13 +325,17 @@ void Button::draw(gcn::Graphics *graphics)
{
mRedraw = false;
mMode = mode;
- g2->calcWindow(mVertexes, 0, 0, getWidth(), getHeight(), button[mode]);
+ g2->calcWindow(mVertexes, 0, 0, getWidth(), getHeight(),
+ skin->getBorder());
}
- g2->drawImageRect2(mVertexes, button[mode]);
+ g2->drawImageRect2(mVertexes, skin->getBorder());
// g2->drawImageRect(0, 0, getWidth(), getHeight(), button[mode]);
+ const int padding = skin->getPadding();
+ const int spacing = skin->getOption("spacing");
+
switch (mode)
{
case BUTTON_DISABLED:
@@ -356,21 +367,21 @@ void Button::draw(gcn::Graphics *graphics)
case gcn::Graphics::LEFT:
if (mImages)
{
- imageX = 4;
- textX = 4 + mImageWidth + 2;
+ imageX = padding;
+ textX = padding + mImageWidth + spacing;
}
else
{
- textX = 4;
+ textX = padding;
}
break;
case gcn::Graphics::CENTER:
if (mImages)
{
const int width = getFont()->getWidth(mCaption)
- + mImageWidth + 2;
+ + mImageWidth + spacing;
imageX = getWidth() / 2 - width / 2;
- textX = imageX + mImageWidth + 2;
+ textX = imageX + mImageWidth + spacing;
}
else
{
@@ -378,8 +389,8 @@ void Button::draw(gcn::Graphics *graphics)
}
break;
case gcn::Graphics::RIGHT:
- textX = getWidth() - 4;
- imageX = textX - getFont()->getWidth(mCaption) - 2;
+ textX = getWidth() - padding;
+ imageX = textX - getFont()->getWidth(mCaption) - spacing;
break;
}
@@ -434,19 +445,28 @@ void Button::widgetMoved(const gcn::Event &event A_UNUSED)
void Button::adjustSize()
{
const gcn::Font *const font = getFont();
+ const Skin *const skin = button[BUTTON_STANDARD];
+ if (!skin)
+ return;
+ const int padding = skin->getPadding();
+
if (mImages)
{
- setWidth(font->getWidth(mCaption)
- + mImageWidth + 2 + 2 * mSpacing);
+ const int spacing = skin->getOption("spacing");
+ const int width = font->getWidth(mCaption);
+ if (width)
+ setWidth(width + mImageWidth + spacing + 2 * padding);
+ else
+ setWidth(mImageWidth + 2 * padding);
int height = font->getHeight();
if (height < mImageHeight)
height = mImageHeight;
- setHeight(height + 2 * mSpacing);
+ setHeight(height + 2 * padding);
}
else
{
- setWidth(font->getWidth(mCaption) + 2 * mSpacing);
- setHeight(font->getHeight() + 2 * mSpacing);
+ setWidth(font->getWidth(mCaption) + 2 * padding);
+ setHeight(font->getHeight() + 2 * padding);
}
}