summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/popup.cpp48
-rw-r--r--src/gui/popup.h13
-rw-r--r--src/gui/skin.cpp44
-rw-r--r--src/gui/skin.h18
-rw-r--r--src/gui/window.cpp41
-rw-r--r--src/gui/window.h12
6 files changed, 63 insertions, 113 deletions
diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp
index 17d299a5..d44dbc93 100644
--- a/src/gui/popup.cpp
+++ b/src/gui/popup.cpp
@@ -20,8 +20,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-#include <cassert>
#include <climits>
#include <guichan/exception.hpp>
@@ -38,17 +36,7 @@
#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):
@@ -64,14 +52,6 @@ Popup::Popup(const std::string& name, Window *parent,
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++;
@@ -79,8 +59,6 @@ Popup::Popup(const std::string& name, Window *parent,
// Loads the skin
mSkin = skinLoader->load(skin);
- setGuiAlpha();
-
// Add this window to the window container
windowContainer->add(this);
@@ -102,13 +80,6 @@ Popup::~Popup()
instances--;
mSkin->instances--;
-
- if (instances == 0)
- {
- config.removeListener("guialpha", popupConfigListener);
- delete popupConfigListener;
- popupConfigListener = NULL;
- }
}
void Popup::setWindowContainer(WindowContainer *wc)
@@ -125,13 +96,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,15 +159,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;
-}
-
diff --git a/src/gui/popup.h b/src/gui/popup.h
index bfe8d7e9..3e3ff5ad 100644
--- a/src/gui/popup.h
+++ b/src/gui/popup.h
@@ -28,7 +28,6 @@
#include "../graphics.h"
#include "../guichanfwd.h"
-class ConfigListener;
class Skin;
class SkinLoader;
class Window;
@@ -43,8 +42,6 @@ class WindowContainer;
class Popup : public gcn::Container
{
public:
- friend class PopupConfigListener;
-
/**
* Constructor. Initializes the title to the given text and hooks
* itself into the popup container.
@@ -170,21 +167,13 @@ class Popup : public gcn::Container
virtual gcn::Rectangle getChildrenArea();
private:
- void setGuiAlpha();
-
Window *mParent; /**< The parent Window (if there is one) */
std::string mPopupName; /**< Name of the Popup */
- static bool mAlphaChanged; /**< Whether the alpha percent was changed */
int mMinWidth; /**< Minimum Popup width */
int mMinHeight; /**< Minimum Popup height */
int mMaxWidth; /**< Maximum Popup width */
int mMaxHeight; /**< Maximum Popup height */
- unsigned int mPadding; /**< Holds the padding of the window. */
-
- /**
- * The config listener that listens to changes relevant to all Popups.
- */
- static ConfigListener *popupConfigListener;
+ unsigned int mPadding; /**< Holds the padding of the window. */
static int instances; /**< Number of Popup instances */
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 <algorithm>
+
#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();
+ }
}
diff --git a/src/gui/skin.h b/src/gui/skin.h
index b8a1242e..c90952e3 100644
--- a/src/gui/skin.h
+++ b/src/gui/skin.h
@@ -27,6 +27,7 @@
#include "../graphics.h"
+class ConfigListener;
class Image;
class Skin
@@ -67,6 +68,11 @@ class Skin
*/
unsigned int getMinHeight();
+ /**
+ * Updates the alpha value of the skin
+ */
+ void updateAlpha();
+
int instances;
private:
@@ -84,6 +90,8 @@ typedef Skins::iterator SkinIterator;
class SkinLoader
{
public:
+ friend class SkinConfigListener;
+
SkinLoader();
~SkinLoader();
@@ -92,8 +100,18 @@ class SkinLoader
*/
Skin* load(const std::string &filename);
+ /**
+ * Updates the alpha values of all of the skins
+ */
+ void updateAlpha();
+
private:
Skins mSkins;
+
+ /**
+ * The config listener that listens to changes relevant to all skins.
+ */
+ static ConfigListener *skinConfigListener;
};
extern SkinLoader* skinLoader;
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 13c8f4ce..75820521 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -20,7 +20,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
#include <cassert>
#include <climits>
@@ -35,24 +34,13 @@
#include "widgets/layout.h"
#include "widgets/resizegrip.h"
-#include "../configlistener.h"
#include "../configuration.h"
#include "../log.h"
#include "../resources/image.h"
-ConfigListener *Window::windowConfigListener = 0;
int Window::instances = 0;
int Window::mouseResize = 0;
-bool Window::mAlphaChanged = false;
-
-class WindowConfigListener : public ConfigListener
-{
- void optionChanged(const std::string &)
- {
- Window::mAlphaChanged = true;
- }
-};
Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin):
gcn::Window(caption),
@@ -77,10 +65,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
if (instances == 0)
{
skinLoader = new SkinLoader();
- windowConfigListener = new WindowConfigListener();
- // Send GUI alpha changed for initialization
- windowConfigListener->optionChanged("guialpha");
- config.addListener("guialpha", windowConfigListener);
}
instances++;
@@ -92,8 +76,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
// Loads the skin
mSkin = skinLoader->load(skin);
- setGuiAlpha();
-
// Add this window to the window container
windowContainer->add(this);
@@ -133,9 +115,6 @@ Window::~Window()
if (instances == 0)
{
delete skinLoader;
- config.removeListener("guialpha", windowConfigListener);
- delete windowConfigListener;
- windowConfigListener = NULL;
}
}
@@ -170,14 +149,6 @@ void Window::draw(gcn::Graphics *graphics)
);
}
- // Update window 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)));
- mSkin->getCloseImage()->setAlpha(config.getValue("guialpha", 0.8));
- }
drawChildren(graphics);
}
@@ -665,18 +636,6 @@ int Window::getResizeHandles(gcn::MouseEvent &event)
return resizeHandles;
}
-void Window::setGuiAlpha()
-{
- //logger->log("Window::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8));
- for (int i = 0; i < 9; i++)
- {
- //logger->log("Window::setGuiAlpha: Border Image (%i)", i);
- mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8));
- }
-
- mAlphaChanged = false;
-}
-
int Window::getGuiAlpha()
{
float alpha = config.getValue("guialpha", 0.8);
diff --git a/src/gui/window.h b/src/gui/window.h
index 518e1ec2..b0b67ad8 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -30,7 +30,6 @@
#include "../graphics.h"
#include "../guichanfwd.h"
-class ConfigListener;
class GCContainer;
class ContainerPlacer;
class Layout;
@@ -49,8 +48,6 @@ class WindowContainer;
class Window : public gcn::Window, gcn::WidgetListener
{
public:
- friend class WindowConfigListener;
-
/**
* Constructor. Initializes the title to the given text and hooks
* itself into the window container.
@@ -323,8 +320,6 @@ class Window : public gcn::Window, gcn::WidgetListener
*/
int getResizeHandles(gcn::MouseEvent &event);
- void setGuiAlpha();
-
GCContainer *mChrome; /**< Contained container */
ResizeGrip *mGrip; /**< Resize grip */
Window *mParent; /**< The parent window */
@@ -334,7 +329,7 @@ class Window : public gcn::Window, gcn::WidgetListener
bool mModal; /**< Window is modal */
bool mCloseButton; /**< Window has a close button */
bool mSticky; /**< Window resists minimization */
- static bool mAlphaChanged; /**< Whether the alpha percent was changed */
+ bool mAlphaChanged; /**< Whether the alpha percent was changed */
int mMinWinWidth; /**< Minimum window width */
int mMinWinHeight; /**< Minimum window height */
int mMaxWinWidth; /**< Maximum window width */
@@ -344,11 +339,6 @@ class Window : public gcn::Window, gcn::WidgetListener
int mDefaultWidth; /**< Default window width */
int mDefaultHeight; /**< Default window height */
- /**
- * The config listener that listens to changes relevant to all windows.
- */
- static ConfigListener *windowConfigListener;
-
static int mouseResize; /**< Active resize handles */
static int instances; /**< Number of Window instances */