summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--src/gui/window.cpp54
-rw-r--r--src/gui/window.h17
3 files changed, 47 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index c5e261ed..eba647de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
2005-08-27 Björn Steinbrink <B.Steinbrink@gmx.de>
+
+ * src/gui/window.cpp, src/gui/window.h: Create a static ConfigListener
+ for the Window class. (Fixes each Window listening to config changes,
+ although they only affect a static class member.)
* src/gui/npc.cpp: Fix a memory leak.
* src/game.cpp, src/gui/npc.cpp, src/gui/npc.h: Fix the bug when
sometimes the last entry in npc list windows is missing. The network
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 0fe941bc..acb23cd4 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -26,6 +26,7 @@
#include "window.h"
#include "windowcontainer.h"
+#include "../configlistener.h"
#include "../configuration.h"
#include "../graphics.h"
#include "../log.h"
@@ -35,11 +36,35 @@
#include "../resources/image.h"
#include "../resources/resourcemanager.h"
+ConfigListener *Window::windowConfigListener = NULL;
WindowContainer *Window::windowContainer = NULL;
int Window::instances = 0;
ImageRect Window::border;
Image *Window::resizeGrip;
+class WindowConfigListener : public ConfigListener
+{
+ public:
+ /**
+ * Called when an config option changes.
+ */
+ void optionChanged(const std::string &name)
+ {
+ if (name == "guialpha")
+ {
+ float guiAlpha = config.getValue("guialpha", 0.8);
+
+ for (int i = 0; i < 9; i++)
+ {
+ if (Window::border.grid[i]->getAlpha() != guiAlpha)
+ {
+ Window::border.grid[i]->setAlpha(guiAlpha);
+ }
+ }
+ }
+ }
+};
+
Window::Window(const std::string& caption, bool modal, Window *parent):
gcn::Window(caption),
parent(parent),
@@ -75,6 +100,10 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
border.grid[8] = dBorders->getSubImage(7, 15, 4, 4);
resizeGrip = resman->getImage("graphics/gui/resize.png");
dBorders->decRef();
+ windowConfigListener = new WindowConfigListener();
+ // Send GUI alpha changed for initialization
+ windowConfigListener->optionChanged("guialpha");
+ config.addListener("guialpha", windowConfigListener);
}
instances++;
@@ -91,10 +120,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
// Add this window to the window container
windowContainer->add(this);
- // Send GUI alpha changed for initialization
- optionChanged("guialpha");
- config.addListener("guialpha", this);
-
if (modal)
{
requestModalFocus();
@@ -109,6 +134,10 @@ Window::~Window()
if (instances == 0)
{
+ config.removeListener("guialpha", windowConfigListener);
+ delete windowConfigListener;
+ windowConfigListener = NULL;
+
// Clean up static resources
delete border.grid[0];
delete border.grid[1];
@@ -122,7 +151,6 @@ Window::~Window()
resizeGrip->decRef();
}
- config.removeListener("guialpha", this);
delete chrome;
}
@@ -371,22 +399,6 @@ void Window::mouseRelease(int x, int y, int button)
}
}
-void Window::optionChanged(const std::string &name)
-{
- if (name == "guialpha")
- {
- float guiAlpha = config.getValue("guialpha", 0.8);
-
- for (int i = 0; i < 9; i++)
- {
- if (border.grid[i]->getAlpha() != guiAlpha)
- {
- border.grid[i]->setAlpha(guiAlpha);
- }
- }
- }
-}
-
gcn::Rectangle Window::getGripDimension ()
{
return gcn::Rectangle(getWidth() - resizeGrip->getWidth(), getHeight() - resizeGrip->getHeight(), getWidth(),
diff --git a/src/gui/window.h b/src/gui/window.h
index 18da6cdb..d8717f3c 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -27,11 +27,11 @@
#include <guichan/widgets/window.hpp>
#include <guichan/rectangle.hpp>
-#include "../configlistener.h"
#include "../guichanfwd.h"
#include "../resources/image.h"
+class ConfigListener;
class ImageRect;
class WindowContainer;
@@ -41,9 +41,11 @@ class WindowContainer;
*
* \ingroup GUI
*/
-class Window : public gcn::Window, public ConfigListener
+class Window : public gcn::Window
{
public:
+ friend class WindowConfigListener;
+
/**
* Constructor. Initializes the title to the given text and hooks
* itself into the window container.
@@ -154,11 +156,6 @@ class Window : public gcn::Window, public ConfigListener
void mouseRelease(int x, int y, int button);
/**
- * Called when an config option changes.
- */
- void optionChanged(const std::string &name);
-
- /**
* The position of the resize grip
*/
gcn::Rectangle getGripDimension();
@@ -181,6 +178,12 @@ class Window : public gcn::Window, public ConfigListener
/** The window container windows add themselves to. */
static WindowContainer* windowContainer;
+ /**
+ * The config listener that listens to changes relevant to all
+ * windows
+ */
+ static ConfigListener *windowConfigListener;
+
static int instances; /**< Number of Window instances */
static ImageRect border; /**< The window border and background */
static Image *resizeGrip; /**< The grip to resize window */