diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/gui/gui.cpp | 30 | ||||
-rw-r--r-- | src/gui/gui.h | 5 |
3 files changed, 25 insertions, 11 deletions
@@ -1,5 +1,6 @@ 2005-08-27 Björn Steinbrink <B.Steinbrink@gmx.de> + * src/gui/gui.cpp, src/gui/gui.h: Create a GuiConfigListener class. * src/gui/window.h: Small cleanup. * src/gui/window.cpp, src/gui/window.h: Create a static ConfigListener for the Window class. (Fixes each Window listening to config changes, diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 612ca7a1..97bc8153 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -38,6 +38,7 @@ #include "windowcontainer.h" #include "../being.h" +#include "../configlistener.h" #include "../configuration.h" #include "../engine.h" #include "../game.h" @@ -64,6 +65,21 @@ gcn::ImageFont *hitYellowFont; // Font used to display speech and player names gcn::ImageFont *speechFont; +class GuiConfigListener : public ConfigListener +{ + public: + GuiConfigListener(Gui *gui):mGui(gui) {} + + void optionChanged(const std::string &name) + { + if (name == "customcursor") { + mGui->setUseCustomCursor(config.getValue("customcursor", 1) == 1); + } + } + private: + Gui *mGui; +}; + Gui::Gui(Graphics *graphics): mHostImageLoader(NULL), mMouseCursor(NULL), @@ -152,11 +168,15 @@ Gui::Gui(Graphics *graphics): // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getValue("customcursor", 1) == 1); - config.addListener("customcursor", this); + mConfigListener = new GuiConfigListener(this); + config.addListener("customcursor", mConfigListener); } Gui::~Gui() { + config.removeListener("customcursor", mConfigListener); + delete mConfigListener; + // Fonts used in showing hits delete hitRedFont; delete hitBlueFont; @@ -261,11 +281,3 @@ Gui::setUseCustomCursor(bool customCursor) } } } - -void -Gui::optionChanged(const std::string &name) -{ - if (name == "customcursor") { - setUseCustomCursor(config.getValue("customcursor", 1) == 1); - } -} diff --git a/src/gui/gui.h b/src/gui/gui.h index 80a4ee7d..959fa2ed 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -26,9 +26,9 @@ #include <guichan/gui.hpp> -#include "../configlistener.h" #include "../guichanfwd.h" +class GuiConfigListener; class Graphics; class Image; class WindowContainer; @@ -46,7 +46,7 @@ class WindowContainer; * * \ingroup GUI */ -class Gui : public gcn::Gui, public gcn::MouseListener, ConfigListener +class Gui : public gcn::Gui, public gcn::MouseListener { public: /** @@ -97,6 +97,7 @@ class Gui : public gcn::Gui, public gcn::MouseListener, ConfigListener optionChanged(const std::string &name); private: + GuiConfigListener *mConfigListener; gcn::ImageLoader *mHostImageLoader; /**< For loading images in GL */ gcn::ImageLoader *mImageLoader; /**< For loading images */ gcn::ImageFont *mGuiFont; /**< The global GUI font */ |