From f6e7a477681109aea040456e3f4ebd0f65645ecc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Mar 2009 09:55:44 -0600 Subject: Moved the responsibility for skin alpha adjustment to the Skin class. This fixes a break that occured where skins wouldn't update in real time in the client, due to being passed a reference, rather than getting the skin itself. Signed-off-by: Ira Rice --- src/gui/skin.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/gui/skin.cpp') diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index d44c54a8..ac258175 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -19,8 +19,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "skin.h" +#include "../configuration.h" +#include "../configlistener.h" #include "../log.h" #include "../resources/image.h" @@ -30,6 +34,16 @@ #include "../utils/xml.h" SkinLoader* skinLoader = NULL; +ConfigListener *SkinLoader::skinConfigListener = NULL; + +class SkinConfigListener : public ConfigListener +{ + void optionChanged(const std::string &) + { + if (skinLoader) + skinLoader->updateAlpha(); + } +}; Skin::Skin(ImageRect skin, Image* close, std::string name): instances(0), @@ -51,6 +65,15 @@ Skin::~Skin() closeImage->decRef(); } +void Skin::updateAlpha() +{ + const float alpha = config.getValue("guialpha", 0.8); + + for_each(border.grid, border.grid + 9, + std::bind2nd(std::mem_fun(&Image::setAlpha), alpha)); + closeImage->setAlpha(alpha); +} + unsigned int Skin::getMinWidth() { return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + @@ -177,15 +200,34 @@ Skin* SkinLoader::load(const std::string &filename) Skin* skin = new Skin(border, closeImage); mSkins[filename] = skin; + + updateAlpha(); + return skin; } -SkinLoader::SkinLoader() +SkinLoader::SkinLoader() : + mSkins() { + skinConfigListener = new SkinConfigListener(); + // Send GUI alpha changed for initialization + skinConfigListener->optionChanged("guialpha"); + config.addListener("guialpha", skinConfigListener); } SkinLoader::~SkinLoader() { delete_all(mSkins); + config.removeListener("guialpha", skinConfigListener); + delete skinConfigListener; + skinConfigListener = NULL; +} + +void SkinLoader::updateAlpha() +{ + for (SkinIterator iter = mSkins.begin(); iter != mSkins.end(); ++iter) + { + iter->second->updateAlpha(); + } } -- cgit v1.2.3-70-g09d2