diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-14 01:36:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-14 13:30:24 +0300 |
commit | c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a (patch) | |
tree | f9929a081b3479bcc1f515aac0a11bbc3cbc111a /src/gui | |
parent | ccf90e41053bf1a327939cad1082be05c15a8cde (diff) | |
download | ManaVerse-c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a.tar.gz ManaVerse-c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a.tar.bz2 ManaVerse-c23959e3c40e97f9c1aeb9eabc52131b6fa68f2a.tar.xz ManaVerse-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')
-rw-r--r-- | src/gui/theme.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/button.cpp | 74 | ||||
-rw-r--r-- | src/gui/widgets/button.h | 5 |
3 files changed, 52 insertions, 31 deletions
diff --git a/src/gui/theme.h b/src/gui/theme.h index cbda2ee4d..4d99649da 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -68,7 +68,7 @@ class Skin final /** * Returns the background skin. */ - const ImageRect &getBorder() const + ImageRect &getBorder() const { return *mBorder; } /** @@ -104,7 +104,7 @@ class Skin final int getTitlePadding() const { return mTitlePadding; } - int getOption(std::string name) + int getOption(const std::string &name) const { if (mOptions->find(name) != mOptions->end()) return (*mOptions)[name]; 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); } } diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index d7e7ebf89..84aedb078 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -31,6 +31,7 @@ class GraphicsVertexes; class Image; class ImageSet; class ImageRect; +class Skin; const std::string BUTTON_PLAY = "buttonplay.png"; @@ -131,8 +132,8 @@ class Button final : public gcn::Button, public gcn::WidgetListener private: void init(); - static ImageRect button[4]; /**< Button state graphics */ - static int mInstances; /**< Number of button instances */ + static Skin *button[4]; /**< Button state graphics */ + static int mInstances; /**< Number of button instances */ static float mAlpha; std::string mDescription; |