diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-28 19:05:13 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-28 19:05:13 +0000 |
commit | 4b94d5bf99b0ca29f45f3e0688e29e43f4a05f7a (patch) | |
tree | 7cc9d951edfc15c103f856ad7aaa256937ca7ee4 | |
parent | 767aa0301a6b16fb4950e6d1eef21346269aa3d1 (diff) | |
download | mana-4b94d5bf99b0ca29f45f3e0688e29e43f4a05f7a.tar.gz mana-4b94d5bf99b0ca29f45f3e0688e29e43f4a05f7a.tar.bz2 mana-4b94d5bf99b0ca29f45f3e0688e29e43f4a05f7a.tar.xz mana-4b94d5bf99b0ca29f45f3e0688e29e43f4a05f7a.zip |
Create a GuiConfigListener class.
-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 */ |