comparison 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
comparison
equal deleted inserted replaced
696:e201abd8c807 697:ecaa4d98f05f
17 * License along with this library; if not, write to the * 17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., * 18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22 #ifndef FIFE_VIDEO_GUI_GUIMANAGER_H 22 #ifndef FIFE_GUI_GUIMANAGER_H
23 #define FIFE_VIDEO_GUI_GUIMANAGER_H 23 #define FIFE_GUI_GUIMANAGER_H
24 24
25 // Standard C++ library includes 25 // Standard C++ library includes
26 #include <set>
27 26
28 // 3rd party library includes 27 // 3rd party library includes
29 #include <guichan.hpp>
30 28
31 // FIFE includes 29 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line 30 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory 31 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder 32 // Second block: files included from the same folder
35 #include "util/base/singleton.h" 33 #include "util/base/singleton.h"
36 #include "eventchannel/sdl/ec_isdleventlistener.h" 34 #include "eventchannel/sdl/ec_isdleventlistener.h"
37 // #include "eventchannel/mouse/ec_imouselistener.h"
38 // #include "eventchannel/key/ec_ikeylistener.h"
39
40 namespace gcn {
41
42 class Gui;
43 class Container;
44 class Widget;
45 class SDLInput;
46 class FocusHandler;
47
48 }
49
50 35
51 namespace FIFE { 36 namespace FIFE {
52
53 class ImagePool; 37 class ImagePool;
38 class RenderBackend;
54 class GuiImageLoader; 39 class GuiImageLoader;
55 class Console; 40 class Console;
56 class KeyEvent;
57 class MouseEvent;
58 class AbstractFont;
59 class GuiFont; 41 class GuiFont;
60 42
61 /* GUI Manager. 43 class GuiManager:
62 * 44 public ISdlEventListener {
63 * This class controls the GUI system in FIFE. 45 public:
64 */ 46 /** Constructor.
65 class GUIManager : 47 */
66 public DynamicSingleton<GUIManager>, 48 GuiManager(ImagePool& pool);
67 public ISdlEventListener
68 {
69 public:
70 /** Constructor.
71 */
72 GUIManager(ImagePool& pool);
73 /** Destructor.
74 */
75 virtual ~GUIManager();
76 49
77 /** Gets the member pointer to the Guichan GUI. 50 /** Destructor.
78 * 51 */
79 * @return The member pointer to the Guichan GUI. 52 virtual ~GuiManager();
80 */
81 gcn::Gui* getGuichanGUI() const;
82 53
83 /** Performs the GUI logic and draws the GUI accordingly. 54 /** Performs the GUI logic and draws the GUI accordingly.
84 * 55 *
85 * This will be called each frame. 56 * This will be called each frame.
86 */ 57 */
87 void turn(); 58 virtual void turn() = 0;
88 59
89 /** Inits the GUI Manager. 60 /** Inits the GUI Manager.
90 * @param graphics backend specific grapchics object to use 61 * @param graphics backend specific graphics object to use
91 * @param screenWidth width for the gui top container 62 * @param screenWidth width for the gui top container
92 * @param screenHeight height for the gui top container 63 * @param screenHeight height for the gui top container
93 */ 64 */
94 void init(gcn::Graphics* graphics, int screenWidth, int screenHeight); 65 virtual void init(RenderBackend* render_backend, int screenWidth,
66 int screenHeight);
95 67
96 /** Resizes the top container. 68 /** Resizes the top container.
97 * 69 *
98 * @param x The new starting X coordinate. 70 * @param x The new starting X coordinate.
99 * @param y The new starting Y coordinate. 71 * @param y The new starting Y coordinate.
100 * @param width The new width. 72 * @param width The new width.
101 * @param height The new height. 73 * @param height The new height.
102 */ 74 */
103 void resizeTopContainer(unsigned int x, unsigned int y, unsigned int width, unsigned int height); 75 virtual void resize(unsigned int x, unsigned int y, unsigned int width,
76 unsigned int height) = 0;
104 77
105 /** Adds a new widget. 78 /** Gets the console.
106 * 79 *
107 * @param A pointer to the widget to add. 80 * @return The console.
108 */ 81 */
109 void add(gcn::Widget* widget); 82 Console* getConsole() const {
110 /** Removes a widget. 83 return m_console;
111 * 84 }
112 * @param A pointer to the widget to remove.
113 */
114 void remove(gcn::Widget* widget);
115 /** Gets the top container.
116 *
117 * @return The top container.
118 */
119 gcn::Container* getTopContainer() const { return m_gcn_topcontainer; }
120 85
121 /** Gets the console. 86 /** Display the in-game FIFE console. */
122 * 87 virtual void showConsole() = 0;
123 * @return The console.
124 */
125 Console* getConsole() const { return m_console; };
126 88
127 /** Set the global font properties. 89 /** Hide the in-game FIFE console. */
128 */ 90 virtual void hideConsole() = 0;
129 GuiFont* setDefaultFont(const std::string& path, unsigned int size, const std::string& glyphs);
130 91
131 /** Gets font with given properties. Note that font will be owned by guimanager 92 /** Toggle the visibility of the in-game FIFE console. */
132 */ 93 virtual void toggleConsole();
133 GuiFont* createFont(const std::string& path = "", unsigned int size = 0, const std::string& glyphs = "");
134 94
135 /** Releases given font. 95 /** Gets the shared ImagePool instance.
136 */ 96 *
137 void releaseFont(GuiFont* font); 97 * @return The ImagePool instance.
98 */
99 ImagePool& getImagePool() const {
100 return m_image_pool;
101 }
138 102
139 void invalidateFonts(); 103 virtual bool onSdlEvent(SDL_Event& evt) = 0;
140 104
141 bool onSdlEvent(SDL_Event& evt); 105 /** Set the global font properties.
106 */
107 virtual GuiFont* setDefaultFont(const std::string& path,
108 unsigned int size, const std::string& glyphs);
142 109
143 KeyEvent translateKeyEvent(const gcn::KeyEvent& evt); 110 /** Gets font with given properties. Note that font will be owned by
144 MouseEvent translateMouseEvent(const gcn::MouseEvent& evt); 111 * guimanager
112 */
113 virtual GuiFont* createFont(const std::string& path = "",
114 unsigned int size = 0, const std::string& glyphs = "");
145 115
146 protected: 116 /** Releases given font.
147 static int convertGuichanKeyToFifeKey(int value); 117 */
118 virtual void releaseFont(GuiFont* font);
148 119
149 private: 120 virtual void invalidateFonts();
150 // The Guichan GUI.
151 gcn::Gui* m_gcn_gui;
152 // Focus handler for input management
153 gcn::FocusHandler* m_focushandler;
154 // The top container of the GUI.
155 gcn::Container* m_gcn_topcontainer;
156 // The imageloader.
157 GuiImageLoader* m_imgloader;
158 // The input controller.
159 gcn::SDLInput *m_input;
160 // The console.
161 Console *m_console;
162 // The fonts used
163 std::vector<GuiFont*> m_fonts;
164 // Added widgets
165 std::set<gcn::Widget*> m_widgets;
166 121
167 // Used to accept mouse motion events that leave widget space 122 protected:
168 bool m_had_mouse; 123 // Whether the console is visible.
124 bool m_console_visible;
169 125
170 // pool used for images 126 private:
171 ImagePool& m_pool; 127 // pool used for images
128 ImagePool& m_image_pool;
172 129
173 // default font settings 130 // The console.
174 std::string m_fontpath; 131 Console* m_console;
175 std::string m_fontglyphs;
176 int m_fontsize;
177 132
178 // true, if guichan logic has already been executed for this round 133 // The fonts used
179 bool m_logic_executed; 134 std::vector<GuiFont*> m_fonts;
135 // default font settings
136 std::string m_fontpath;
137 std::string m_fontglyphs;
138 int m_fontsize;
180 }; 139 };
181
182 } 140 }
183 141
184 #endif 142 #endif