diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-07-28 01:55:56 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-07-28 01:55:56 +0300 |
commit | f60d54307c20d4150e630620dbe0be62b2a1b8a5 (patch) | |
tree | dc5661a9f75cf495bbea050b6566b1fa0240781e /src/gui/widgets | |
parent | 3574afc2818a5401d825fe649d49a0b9fbccdf00 (diff) | |
download | manaplus-f60d54307c20d4150e630620dbe0be62b2a1b8a5.tar.gz manaplus-f60d54307c20d4150e630620dbe0be62b2a1b8a5.tar.bz2 manaplus-f60d54307c20d4150e630620dbe0be62b2a1b8a5.tar.xz manaplus-f60d54307c20d4150e630620dbe0be62b2a1b8a5.zip |
Extend playerbox theming.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/playerbox.cpp | 55 | ||||
-rw-r--r-- | src/gui/widgets/playerbox.h | 13 |
2 files changed, 41 insertions, 27 deletions
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index bf17793f5..f0a6a5e89 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -36,36 +36,45 @@ #include "debug.h" -int PlayerBox::instances = 0; -float PlayerBox::mAlpha = 1.0; -ImageRect PlayerBox::background; - -PlayerBox::PlayerBox(Being *being): - mBeing(being) +PlayerBox::PlayerBox(Being *being, std::string skin): + mBeing(being), + mAlpha(1.0) { - setFrameSize(2); - - if (instances == 0) - { - if (Theme::instance()) - { - Theme::instance()->loadRect(background, - "playerbox_background.xml"); - } - } + init(skin); +} - instances++; +PlayerBox::PlayerBox(std::string skin): + mBeing(nullptr), + mAlpha(1.0) +{ + init(skin); } PlayerBox::~PlayerBox() { - instances--; - if (instances == 0 && Theme::instance()) - Theme::instance()->unloadRect(background); + if (Theme::instance()) + Theme::instance()->unloadRect(mBackground); mBeing = nullptr; } +void PlayerBox::init(std::string skin) +{ + setFrameSize(2); + + if (Theme::instance()) + { + if (skin.empty()) + skin = "playerbox_background.xml"; + Theme::instance()->loadRect(mBackground, skin); + } + else + { + for (int f = 0; f < 9; f ++) + mBackground.grid[f] = nullptr; + } +} + void PlayerBox::draw(gcn::Graphics *graphics) { if (mBeing) @@ -81,8 +90,8 @@ void PlayerBox::draw(gcn::Graphics *graphics) { for (int a = 0; a < 9; a++) { - if (background.grid[a]) - background.grid[a]->setAlpha(Client::getGuiAlpha()); + if (mBackground.grid[a]) + mBackground.grid[a]->setAlpha(Client::getGuiAlpha()); } } } @@ -94,5 +103,5 @@ void PlayerBox::drawFrame(gcn::Graphics *graphics) w = getWidth() + bs * 2; h = getHeight() + bs * 2; - static_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h, background); + static_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h, mBackground); } diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h index 9e5a761b4..6498e69ec 100644 --- a/src/gui/widgets/playerbox.h +++ b/src/gui/widgets/playerbox.h @@ -25,6 +25,8 @@ #include <guichan/widgets/scrollarea.hpp> +#include "graphics.h" + #include "localconsts.h" class Being; @@ -42,13 +44,17 @@ class PlayerBox : public gcn::ScrollArea * Constructor. Takes the initial player character that this box should * display, which defaults to <code>NULL</code>. */ - PlayerBox(Being *being = nullptr); + PlayerBox(Being *being, std::string skin = ""); + + PlayerBox(std::string skin = ""); /** * Destructor. */ ~PlayerBox(); + void init(std::string skin); + /** * Sets a new player character to be displayed by this box. Setting the * player to <code>NULL</code> causes the box not to draw any @@ -73,9 +79,8 @@ class PlayerBox : public gcn::ScrollArea private: Being *mBeing; /**< The character used for display */ - static float mAlpha; - static int instances; - static ImageRect background; + float mAlpha; + ImageRect mBackground; }; #endif |