Mercurial > fife-parpg
diff engine/core/gui/guimanager.h @ 697:ecaa4d98f05f tip
Abstracted the GUI code and refactored the GUIChan-specific code into its own module.
* Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring.
* GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass.
* The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class.
* The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged.
* Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 18 Jun 2011 00:28:40 -1000 |
parents | 5d6b1820b953 |
children |
line wrap: on
line diff
--- a/engine/core/gui/guimanager.h Fri Jun 10 23:37:46 2011 -1000 +++ b/engine/core/gui/guimanager.h Sat Jun 18 00:28:40 2011 -1000 @@ -19,14 +19,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#ifndef FIFE_VIDEO_GUI_GUIMANAGER_H -#define FIFE_VIDEO_GUI_GUIMANAGER_H +#ifndef FIFE_GUI_GUIMANAGER_H +#define FIFE_GUI_GUIMANAGER_H // Standard C++ library includes -#include <set> // 3rd party library includes -#include <guichan.hpp> // FIFE includes // These includes are split up in two parts, separated by one empty line @@ -34,151 +32,111 @@ // Second block: files included from the same folder #include "util/base/singleton.h" #include "eventchannel/sdl/ec_isdleventlistener.h" -// #include "eventchannel/mouse/ec_imouselistener.h" -// #include "eventchannel/key/ec_ikeylistener.h" - -namespace gcn { - - class Gui; - class Container; - class Widget; - class SDLInput; - class FocusHandler; - -} - namespace FIFE { - class ImagePool; + class RenderBackend; class GuiImageLoader; class Console; - class KeyEvent; - class MouseEvent; - class AbstractFont; class GuiFont; - /* GUI Manager. - * - * This class controls the GUI system in FIFE. - */ - class GUIManager : - public DynamicSingleton<GUIManager>, - public ISdlEventListener - { - public: - /** Constructor. - */ - GUIManager(ImagePool& pool); - /** Destructor. - */ - virtual ~GUIManager(); + class GuiManager: + public ISdlEventListener { + public: + /** Constructor. + */ + GuiManager(ImagePool& pool); - /** Gets the member pointer to the Guichan GUI. - * - * @return The member pointer to the Guichan GUI. - */ - gcn::Gui* getGuichanGUI() const; + /** Destructor. + */ + virtual ~GuiManager(); - /** Performs the GUI logic and draws the GUI accordingly. - * - * This will be called each frame. - */ - void turn(); + /** Performs the GUI logic and draws the GUI accordingly. + * + * This will be called each frame. + */ + virtual void turn() = 0; - /** Inits the GUI Manager. - * @param graphics backend specific grapchics object to use - * @param screenWidth width for the gui top container - * @param screenHeight height for the gui top container - */ - void init(gcn::Graphics* graphics, int screenWidth, int screenHeight); - - /** Resizes the top container. - * - * @param x The new starting X coordinate. - * @param y The new starting Y coordinate. - * @param width The new width. - * @param height The new height. - */ - void resizeTopContainer(unsigned int x, unsigned int y, unsigned int width, unsigned int height); + /** Inits the GUI Manager. + * @param graphics backend specific graphics object to use + * @param screenWidth width for the gui top container + * @param screenHeight height for the gui top container + */ + virtual void init(RenderBackend* render_backend, int screenWidth, + int screenHeight); - /** Adds a new widget. - * - * @param A pointer to the widget to add. - */ - void add(gcn::Widget* widget); - /** Removes a widget. - * - * @param A pointer to the widget to remove. - */ - void remove(gcn::Widget* widget); - /** Gets the top container. - * - * @return The top container. - */ - gcn::Container* getTopContainer() const { return m_gcn_topcontainer; } + /** Resizes the top container. + * + * @param x The new starting X coordinate. + * @param y The new starting Y coordinate. + * @param width The new width. + * @param height The new height. + */ + virtual void resize(unsigned int x, unsigned int y, unsigned int width, + unsigned int height) = 0; + + /** Gets the console. + * + * @return The console. + */ + Console* getConsole() const { + return m_console; + } + + /** Display the in-game FIFE console. */ + virtual void showConsole() = 0; + + /** Hide the in-game FIFE console. */ + virtual void hideConsole() = 0; - /** Gets the console. - * - * @return The console. - */ - Console* getConsole() const { return m_console; }; + /** Toggle the visibility of the in-game FIFE console. */ + virtual void toggleConsole(); - /** Set the global font properties. - */ - GuiFont* setDefaultFont(const std::string& path, unsigned int size, const std::string& glyphs); - - /** Gets font with given properties. Note that font will be owned by guimanager - */ - GuiFont* createFont(const std::string& path = "", unsigned int size = 0, const std::string& glyphs = ""); + /** Gets the shared ImagePool instance. + * + * @return The ImagePool instance. + */ + ImagePool& getImagePool() const { + return m_image_pool; + } - /** Releases given font. - */ - void releaseFont(GuiFont* font); - - void invalidateFonts(); + virtual bool onSdlEvent(SDL_Event& evt) = 0; - bool onSdlEvent(SDL_Event& evt); + /** Set the global font properties. + */ + virtual GuiFont* setDefaultFont(const std::string& path, + unsigned int size, const std::string& glyphs); - KeyEvent translateKeyEvent(const gcn::KeyEvent& evt); - MouseEvent translateMouseEvent(const gcn::MouseEvent& evt); - - protected: - static int convertGuichanKeyToFifeKey(int value); + /** Gets font with given properties. Note that font will be owned by + * guimanager + */ + virtual GuiFont* createFont(const std::string& path = "", + unsigned int size = 0, const std::string& glyphs = ""); - private: - // The Guichan GUI. - gcn::Gui* m_gcn_gui; - // Focus handler for input management - gcn::FocusHandler* m_focushandler; - // The top container of the GUI. - gcn::Container* m_gcn_topcontainer; - // The imageloader. - GuiImageLoader* m_imgloader; - // The input controller. - gcn::SDLInput *m_input; - // The console. - Console *m_console; - // The fonts used - std::vector<GuiFont*> m_fonts; - // Added widgets - std::set<gcn::Widget*> m_widgets; + /** Releases given font. + */ + virtual void releaseFont(GuiFont* font); + + virtual void invalidateFonts(); + + protected: + // Whether the console is visible. + bool m_console_visible; - // Used to accept mouse motion events that leave widget space - bool m_had_mouse; + private: + // pool used for images + ImagePool& m_image_pool; - // pool used for images - ImagePool& m_pool; + // The console. + Console* m_console; - // default font settings - std::string m_fontpath; - std::string m_fontglyphs; - int m_fontsize; - - // true, if guichan logic has already been executed for this round - bool m_logic_executed; + // The fonts used + std::vector<GuiFont*> m_fonts; + // default font settings + std::string m_fontpath; + std::string m_fontglyphs; + int m_fontsize; }; - } #endif