comparison engine/core/gui/guimanager.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_VIDEO_GUI_GUIMANAGER_H
23 #define FIFE_VIDEO_GUI_GUIMANAGER_H
24
25 // Standard C++ library includes
26 #include <set>
27
28 // 3rd party library includes
29 #include <guichan.hpp>
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/base/singleton.h"
36 #include "eventchannel/sdl/ec_isdleventlistener.h"
37 #include "eventchannel/mouse/ec_imouselistener.h"
38 #include "eventchannel/key/ec_ikeylistener.h"
39 #include "eventchannel/widget/ec_iwidgetlistener.h"
40
41 namespace gcn {
42
43 class Gui;
44 class Container;
45 class Widget;
46 class SDLInput;
47 class FocusHandler;
48
49 }
50
51
52 namespace FIFE {
53
54 class ImagePool;
55 class GuiImageLoader;
56 class Console;
57 class KeyEvent;
58 class MouseEvent;
59 class AbstractFont;
60 class GuiFont;
61
62 /* GUI Manager.
63 *
64 * This class controls the GUI system in FIFE.
65 */
66 class GUIManager :
67 public DynamicSingleton<GUIManager>,
68 public ISdlEventListener,
69 public IKeyListener,
70 public IMouseListener,
71 public gcn::ActionListener
72 {
73 public:
74 /** Constructor.
75 */
76 GUIManager(IWidgetListener* widgetListener, ImagePool& pool);
77 /** Destructor.
78 */
79 virtual ~GUIManager();
80
81 /** Gets the member pointer to the Guichan GUI.
82 *
83 * @return The member pointer to the Guichan GUI.
84 */
85 gcn::Gui* getGuichanGUI() const;
86
87 /** Performs the GUI logic and draws the GUI accordingly.
88 *
89 * This will be called each frame.
90 */
91 void turn();
92
93 /** Inits the GUI Manager.
94 * @param graphics backend specific grapchics object to use
95 * @param screenWidth width for the gui top container
96 * @param screenHeight height for the gui top container
97 */
98 void init(gcn::Graphics* graphics, int screenWidth, int screenHeight);
99
100 /** Resizes the top container.
101 *
102 * @param x The new starting X coordinate.
103 * @param y The new starting Y coordinate.
104 * @param width The new width.
105 * @param height The new height.
106 */
107 void resizeTopContainer(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
108
109 /** Adds a new widget.
110 *
111 * @param A pointer to the widget to add.
112 */
113 void add(gcn::Widget* widget);
114 /** Removes a widget.
115 *
116 * @param A pointer to the widget to remove.
117 */
118 void remove(gcn::Widget* widget);
119 /** Gets the top container.
120 *
121 * @return The top container.
122 */
123 gcn::Container* getTopContainer() { return m_gcn_topcontainer; }
124
125 /** Gets the console.
126 *
127 * @return The console.
128 */
129 Console* getConsole() { return m_console; };
130
131 /** Set the global font properties.
132 */
133 GuiFont* setDefaultFont(const std::string& path, unsigned int size, const std::string& glyphs);
134
135 /** Gets font with given properties. Note that font will be owned by guimanager
136 */
137 GuiFont* createFont(const std::string& path = "", unsigned int size = 0, const std::string& glyphs = "");
138
139 /** Releases given font.
140 */
141 void releaseFont(GuiFont* font);
142
143 /** Callback from guichan
144 */
145 void action(const gcn::ActionEvent & event);
146
147 void onSdlEvent(SDL_Event& evt);
148 void keyPressed(KeyEvent& evt) { evaluateKeyEventConsumption(evt); }
149 void keyReleased(KeyEvent& evt) { evaluateKeyEventConsumption(evt); }
150 void mouseEntered(MouseEvent& evt) { evaluateMouseEventConsumption(evt); }
151 void mouseExited(MouseEvent& evt) { evaluateMouseEventConsumption(evt); }
152 void mousePressed(MouseEvent& evt);
153 void mouseReleased(MouseEvent& evt) { evaluateMouseEventConsumption(evt); }
154 void mouseClicked(MouseEvent& evt) { evaluateMouseEventConsumption(evt); }
155 void mouseWheelMovedUp(MouseEvent& evt) { evaluateMouseEventConsumption(evt); }
156 void mouseWheelMovedDown(MouseEvent& evt) { evaluateMouseEventConsumption(evt); }
157 void mouseMoved(MouseEvent& evt) { evaluateMouseEventConsumption(evt); }
158 void mouseDragged(MouseEvent& evt);
159
160 private:
161 void evaluateKeyEventConsumption(KeyEvent& evt);
162 void evaluateMouseEventConsumption(MouseEvent& evt);
163
164 // The Guichan GUI.
165 gcn::Gui* m_gcn_gui;
166 // Focus handler for input management
167 gcn::FocusHandler* m_focushandler;
168 // The top container of the GUI.
169 gcn::Container* m_gcn_topcontainer;
170 // The imageloader.
171 GuiImageLoader* m_imgloader;
172 // The input controller.
173 gcn::SDLInput *m_input;
174 // The console.
175 Console *m_console;
176 // The fonts used
177 std::vector<GuiFont*> m_fonts;
178 // Added widgets
179 std::set<gcn::Widget*> m_widgets;
180
181 // instance whom to deliver widget events coming from guichan
182 IWidgetListener* m_widgetlistener;
183 // pool used for images
184 ImagePool& m_pool;
185
186 // default font settings
187 std::string m_fontpath;
188 std::string m_fontglyphs;
189 int m_fontsize;
190
191 // true, if guichan logic has already been executed for this round
192 bool m_logic_executed;
193 };
194
195 }
196
197 #endif