diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-03-08 23:53:39 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-03-09 00:19:37 +0300 |
commit | 0424b1383e3c07192b4493d5210b4384b5a69a75 (patch) | |
tree | 531f5b541bde1f0a02cb1f35b0a95f4061a59b6b /src/gui | |
parent | 2061d47d50cafad5fd5d412b25c1dae110cd85ab (diff) | |
download | mv-0424b1383e3c07192b4493d5210b4384b5a69a75.tar.gz mv-0424b1383e3c07192b4493d5210b4384b5a69a75.tar.bz2 mv-0424b1383e3c07192b4493d5210b4384b5a69a75.tar.xz mv-0424b1383e3c07192b4493d5210b4384b5a69a75.zip |
Use own skin for each button.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/widgets/button.cpp | 60 | ||||
-rw-r--r-- | src/gui/widgets/button.h | 8 | ||||
-rw-r--r-- | src/gui/widgets/sliderlist.cpp | 3 |
3 files changed, 37 insertions, 34 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index c2bc423d3..7a0fdef7d 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -85,27 +85,26 @@ #include "debug.h" -int Button::mInstances = 0; float Button::mAlpha = 1.0; static std::string const data[Button::BUTTON_COUNT] = { - "button.xml", - "button_highlighted.xml", - "button_pressed.xml", - "button_disabled.xml" + ".xml", + "_highlighted.xml", + "_pressed.xml", + "_disabled.xml" }; -Skin *Button::button[BUTTON_COUNT]; - Button::Button(const Widget2 *const widget) : Widget(widget), MouseListener(), KeyListener(), FocusListener(), WidgetListener(), + mSkin(), mCaption(), mDescription(), + mSkinName(BUTTON_SKIN), mTextChunk(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)), @@ -149,8 +148,10 @@ Button::Button(const Widget2 *const widget, KeyListener(), FocusListener(), WidgetListener(), + mSkin(), mCaption(caption), mDescription(), + mSkinName(BUTTON_SKIN), mTextChunk(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)), @@ -200,8 +201,10 @@ Button::Button(const Widget2 *const widget, KeyListener(), FocusListener(), WidgetListener(), + mSkin(), mCaption(caption), mDescription(), + mSkinName(BUTTON_SKIN), mTextChunk(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)), @@ -251,8 +254,10 @@ Button::Button(const Widget2 *const widget, KeyListener(), FocusListener(), WidgetListener(), + mSkin(), mCaption(), mDescription(), + mSkinName(BUTTON_SKIN), mTextChunk(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)), @@ -302,8 +307,10 @@ Button::Button(const Widget2 *const widget, KeyListener(), FocusListener(), WidgetListener(), + mSkin(), mCaption(caption), mDescription(), + mSkinName(BUTTON_SKIN), mTextChunk(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)), @@ -354,28 +361,23 @@ void Button::init() setFocusable(true); setFrameSize(0); - if (mInstances == 0) + if (theme != nullptr) { - if (theme != nullptr) + for (int mode = 0; mode < BUTTON_COUNT; mode ++) { - for (int mode = 0; mode < BUTTON_COUNT; mode ++) + Skin *const skin = theme->load(mSkinName + data[mode], + "button.xml", + true, + Theme::getThemePath()); + if (skin != nullptr) { - Skin *const skin = theme->load(data[mode], - "button.xml", - true, - Theme::getThemePath()); - if (skin != nullptr) - { - button[mode] = skin; - mSpacing[mode] = skin->getOption("spacing"); - } + mSkin[mode] = skin; + mSpacing[mode] = skin->getOption("spacing"); } } - - updateAlpha(); } - mInstances++; + updateAlpha(); } Button::~Button() @@ -386,12 +388,10 @@ Button::~Button() if (gui != nullptr) gui->removeDragged(this); - mInstances--; - - if (mInstances == 0 && (theme != nullptr)) + if (theme != nullptr) { for (int mode = 0; mode < BUTTON_COUNT; mode ++) - theme->unload(button[mode]); + theme->unload(mSkin[mode]); } delete2(mVertexes2); if (mImageSet != nullptr) @@ -457,7 +457,7 @@ void Button::updateAlpha() { for (int a = 0; a < 9; a ++) { - Skin *const skin = button[mode]; + Skin *const skin = mSkin[mode]; if (skin != nullptr) { const ImageRect &rect = skin->getBorder(); @@ -484,7 +484,7 @@ void Button::draw(Graphics *const graphics) else mode = BUTTON_STANDARD; - const Skin *const skin = button[mode]; + const Skin *const skin = mSkin[mode]; if (skin == nullptr) { BLOCK_END("Button::draw") @@ -663,7 +663,7 @@ void Button::safeDraw(Graphics *const graphics) else mode = BUTTON_STANDARD; - const Skin *const skin = button[mode]; + const Skin *const skin = mSkin[mode]; if (skin == nullptr) { BLOCK_END("Button::safeDraw") @@ -829,7 +829,7 @@ void Button::widgetHidden(const Event &event A_UNUSED) void Button::adjustSize() { const Font *const font = getFont(); - const Skin *const skin = button[BUTTON_STANDARD]; + const Skin *const skin = mSkin[BUTTON_STANDARD]; if (skin == nullptr) return; const int padding = skin->getPadding(); diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index 2721406ce..bd0766323 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -85,6 +85,7 @@ class ImageSet; class Skin; const std::string BUTTON_PLAY = "buttonplay.png"; +const std::string BUTTON_SKIN = "button"; /** * Button widget. Same as the Guichan button but with custom look. @@ -160,7 +161,7 @@ class Button final : public Widget, /** * Update the alpha value to the button components. */ - static void updateAlpha(); + void updateAlpha(); void mouseReleased(MouseEvent& event) override final; @@ -281,10 +282,9 @@ class Button final : public Widget, void init(); - static Skin *button[BUTTON_COUNT]; /**< Button state graphics */ - static int mInstances; /**< Number of button instances */ static float mAlpha; + Skin *mSkin[BUTTON_COUNT]; /**< Button state graphics */ /** * Holds the caption of the button. */ @@ -292,6 +292,8 @@ class Button final : public Widget, std::string mDescription; + std::string mSkinName; + TextChunk mTextChunk; ImageCollection *mVertexes2 A_NONNULLPOINTER; diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp index 87204eb4b..cbe65684b 100644 --- a/src/gui/widgets/sliderlist.cpp +++ b/src/gui/widgets/sliderlist.cpp @@ -81,7 +81,8 @@ SliderList::~SliderList() void SliderList::updateAlpha() { - Button::updateAlpha(); + mButtons[0]->updateAlpha(); + mButtons[1]->updateAlpha(); } void SliderList::mouseWheelMovedUp(MouseEvent& event) |