summaryrefslogtreecommitdiff
path: root/src/gui/widgets/button.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-03-08 23:53:39 +0300
committerAndrei Karas <akaras@inbox.ru>2018-03-09 00:19:37 +0300
commit0424b1383e3c07192b4493d5210b4384b5a69a75 (patch)
tree531f5b541bde1f0a02cb1f35b0a95f4061a59b6b /src/gui/widgets/button.cpp
parent2061d47d50cafad5fd5d412b25c1dae110cd85ab (diff)
downloadplus-0424b1383e3c07192b4493d5210b4384b5a69a75.tar.gz
plus-0424b1383e3c07192b4493d5210b4384b5a69a75.tar.bz2
plus-0424b1383e3c07192b4493d5210b4384b5a69a75.tar.xz
plus-0424b1383e3c07192b4493d5210b4384b5a69a75.zip
Use own skin for each button.
Diffstat (limited to 'src/gui/widgets/button.cpp')
-rw-r--r--src/gui/widgets/button.cpp60
1 files changed, 30 insertions, 30 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();