diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-03-27 13:25:04 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-03-27 13:25:24 +0100 |
commit | dd05447445dc1766e532130318af2cb6bb72a994 (patch) | |
tree | c8b2cbac64ccf9545a39c143088b57fe2cb8e678 /src/gui/popup.cpp | |
parent | 05e753294c1a603252d2eed4b1731c3f50543a7e (diff) | |
parent | 2aab736bc5d77ffda789d7de56cef100fac207e1 (diff) | |
download | mana-dd05447445dc1766e532130318af2cb6bb72a994.tar.gz mana-dd05447445dc1766e532130318af2cb6bb72a994.tar.bz2 mana-dd05447445dc1766e532130318af2cb6bb72a994.tar.xz mana-dd05447445dc1766e532130318af2cb6bb72a994.zip |
Merge branch 'aethyra/master'
Conflicts:
src/beingmanager.cpp
src/gui/confirm_dialog.cpp
src/gui/inventorywindow.cpp
src/gui/inventorywindow.h
src/gui/label.cpp
src/gui/label.h
src/gui/popup.cpp
src/gui/popup.h
src/gui/scrollarea.cpp
src/gui/skin.cpp
src/gui/skin.h
src/gui/speechbubble.cpp
src/gui/window.cpp
src/gui/window.h
src/localplayer.h
src/main.cpp
src/net/ea/playerhandler.cpp
src/resources/ambientoverlay.h
src/resources/dye.cpp
src/resources/imagewriter.cpp
src/resources/itemdb.cpp
src/shopitem.cpp
Diffstat (limited to 'src/gui/popup.cpp')
-rw-r--r-- | src/gui/popup.cpp | 98 |
1 files changed, 35 insertions, 63 deletions
diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 47c3c43c..648a9d6a 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -20,66 +20,35 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <algorithm> -#include <cassert> -#include <climits> - #include <guichan/exception.hpp> -#include "gui.h" #include "skin.h" #include "popup.h" -#include "window.h" #include "windowcontainer.h" -#include "../configlistener.h" #include "../configuration.h" +#include "../graphics.h" #include "../log.h" #include "../resources/image.h" -ConfigListener *Popup::popupConfigListener = 0; -int Popup::instances = 0; -bool Popup::mAlphaChanged = false; - -class PopupConfigListener : public ConfigListener -{ - void optionChanged(const std::string &) - { - Popup::mAlphaChanged = true; - } -}; - -Popup::Popup(const std::string &name, Window *parent, - const std::string &skin): - mParent(parent), +Popup::Popup(const std::string &name, const std::string &skin): mPopupName(name), + mDefaultSkinPath(skin), mMinWidth(100), mMinHeight(40), - mMaxWidth(INT_MAX), - mMaxHeight(INT_MAX) + mMaxWidth(graphics->getWidth()), + mMaxHeight(graphics->getHeight()) { logger->log("Popup::Popup(\"%s\")", name.c_str()); if (!windowContainer) throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); - if (instances == 0) - { - popupConfigListener = new PopupConfigListener(); - // Send GUI alpha changed for initialization - popupConfigListener->optionChanged("guialpha"); - config.addListener("guialpha", popupConfigListener); - } - setPadding(3); - instances++; - // Loads the skin - mSkin = skinLoader->load(skin); - - setGuiAlpha(); + mSkin = skinLoader->load(skin, mDefaultSkinPath); // Add this window to the window container windowContainer->add(this); @@ -92,6 +61,8 @@ Popup::~Popup() { logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str()); + savePopupConfiguration(); + while (!mWidgets.empty()) { gcn::Widget *w = mWidgets.front(); @@ -99,21 +70,40 @@ Popup::~Popup() delete(w); } - instances--; - mSkin->instances--; +} - if (instances == 0) +void Popup::setWindowContainer(WindowContainer *wc) +{ + windowContainer = wc; +} + +void Popup::loadPopupConfiguration() +{ + if (mPopupName.empty()) + return; + + const std::string &name = mPopupName; + const std::string &skinName = config.getValue(name + "Skin", + mSkin->getFilePath()); + + if (skinName.compare(mSkin->getFilePath()) != 0) { - config.removeListener("guialpha", popupConfigListener); - delete popupConfigListener; - popupConfigListener = NULL; + mSkin->instances--; + mSkin = skinLoader->load(skinName, mDefaultSkinPath); } } -void Popup::setWindowContainer(WindowContainer *wc) +void Popup::savePopupConfiguration() { - windowContainer = wc; + if (mPopupName.empty()) + return; + + const std::string &name = mPopupName; + + // Saves the skin path in a config file (which allows for skins to be + // changed from the default path) + config.setValue(name + "Skin", mSkin->getFilePath()); } void Popup::draw(gcn::Graphics *graphics) @@ -125,13 +115,6 @@ void Popup::draw(gcn::Graphics *graphics) g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); - // Update Popup alpha values - if (mAlphaChanged) - { - for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, - std::bind2nd(std::mem_fun(&Image::setAlpha), - config.getValue("guialpha", 0.8))); - } drawChildren(graphics); } @@ -195,14 +178,3 @@ void Popup::scheduleDelete() windowContainer->scheduleDelete(this); } -void Popup::setGuiAlpha() -{ - //logger->log("Popup::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8)); - for (int i = 0; i < 9; i++) - { - //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); - mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); - } - - mAlphaChanged = false; -} |