Debian Codegraph @

engine/core/gui/fifechan/fifechanmanager.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library 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 GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_GUI_FIFECHANMANAGER_H
23 #define FIFE_GUI_FIFECHANMANAGER_H
24
25 // Standard C++ library includes
26 #include <set>
27
28 // 3rd party library includes
29 #include <fifechan.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/fife_stdint.h"
36 #include "util/base/singleton.h"
37 #include "eventchannel/sdl/isdleventlistener.h"
38
39 #include "gui/guimanager.h"
40
41 namespace fcn {
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 GuiImageLoader;
55 class Console;
56 class Cursor;
57 class KeyEvent;
58 class MouseEvent;
59 class IFont;
60 class GuiFont;
61
62
63 /* GUI Fifechan Manager.
64 *
65 * This class controls the Fifechan GUI system in FIFE.
66 */
67 class FifechanManager :
68 public IGUIManager,
69 public DynamicSingleton<FifechanManager>
70 {
71 public:
72 /** Constructor.
73 */
74 FifechanManager();
75 /** Destructor.
76 */
77 virtual ~FifechanManager();
78
79 /** Gets the member pointer to the Fifechan GUI.
80 *
81 * @return The member pointer to the Fifechan GUI.
82 */
83 fcn::Gui* getFifechanGUI() const;
84
85 /** Performs the GUI logic and draws the GUI accordingly.
86 *
87 * This will be called each frame.
88 */
89 virtual void turn();
90
91 /** Inits the Fifechan GUI Manager.
92 * @param backend The GUI backend object to use
93 * @param screenWidth width for the gui top container
94 * @param screenHeight height for the gui top container
95 */
96 void init(const std::string& backend, int32_t screenWidth, int32_t screenHeight);
97
98 /** Resizes the top container.
99 *
100 * @param x The new starting X coordinate.
101 * @param y The new starting Y coordinate.
102 * @param width The new width.
103 * @param height The new height.
104 */
105 void resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
106
107 /** Adds a new widget.
108 *
109 * @param widget A pointer to the widget to add.
110 */
111 void add(fcn::Widget* widget);
112
113 /** Removes a widget.
114 *
115 * @param widget A pointer to the widget to remove.
116 */
117 void remove(fcn::Widget* widget);
118
119 /** Gets the top container.
120 *
121 * @return The top container.
122 */
123 fcn::Container* getTopContainer() const { return m_fcn_topcontainer; }
124
125 /** Gets the console.
126 *
127 * @return The console.
128 */
129 Console* getConsole() const { return m_console; };
130
131 /** Enables the console, or not.
132 *
133 * @param console True if the console should be enabled, false otherwise.
134 * @see isConsoleEnabled, getConsole
135 */
136 void setConsoleEnabled(bool console);
137
138 /** Checks if the console is enabled, or not.
139 *
140 * @return True if the console is enabled, false otherwise.
141 * @see setConsoleEnabled, getConsole
142 */
143 bool isConsoleEnabled() const;
144
145 /** Sets the cursor.
146 *
147 * @param cursor The pointer to the cursor class.
148 */
149 void setCursor(Cursor* cursor) { m_cursor = cursor; }
150
151 /** Gets the cursor.
152 *
153 * @return The pointer to the cursor class.
154 */
155 Cursor* getCursor() const { return m_cursor; }
156
157 /** Set the global font properties.
158 */
159 GuiFont* setDefaultFont(const std::string& path, uint32_t size, const std::string& glyphs);
160
161 /** Gets the default font
162 */
163 GuiFont* getDefaultFont() { return m_defaultfont; };
164
165 /** Gets font with given properties. Note that font will be owned by Fifechan GUI Manager
166 */
167 GuiFont* createFont(const std::string& path = "", uint32_t size = 0, const std::string& glyphs = "");
168
169 /** Releases given font.
170 */
171 void releaseFont(GuiFont* font);
172
173 void invalidateFonts();
174
175 virtual bool onSdlEvent(SDL_Event& evt);
176
177 KeyEvent translateKeyEvent(const fcn::KeyEvent& evt);
178 MouseEvent translateMouseEvent(const fcn::MouseEvent& evt);
179
180 /**
181 * Sets tabbing enabled, or not. Tabbing is the usage of
182 * changing focus by utilising the tab key.
183 *
184 * @param tabbing True if tabbing should be enabled, false otherwise.
185 * @see isTabbingEnabled
186 */
187 void setTabbingEnabled(bool tabbing);
188
189 /**
190 * Checks if tabbing is enabled.
191 *
192 * @return True if tabbing is enabled, false otherwise.
193 * @see setTabbingEnabled
194 */
195 bool isTabbingEnabled() const;
196
197 protected:
198 static int32_t convertFifechanKeyToFifeKey(int32_t value);
199
200 private:
201 // The Fifechan GUI.
202 fcn::Gui* m_fcn_gui;
203 // Fifechan Graphics
204 fcn::Graphics* m_gui_graphics;
205 // Focus handler for input management
206 fcn::FocusHandler* m_focushandler;
207 // The top container of the GUI.
208 fcn::Container* m_fcn_topcontainer;
209 // The imageloader.
210 GuiImageLoader* m_imgloader;
211 // The input controller.
212 fcn::SDLInput *m_input;
213 // The console.
214 Console* m_console;
215 // Acess to the Cursor class.
216 Cursor* m_cursor;
217 //The default font
218 GuiFont* m_defaultfont;
219 // The fonts used
220 std::vector<GuiFont*> m_fonts;
221 // Added widgets
222 std::set<fcn::Widget*> m_widgets;
223
224 // Used to accept mouse motion events that leave widget space
225 bool m_had_mouse;
226 bool m_had_widget;
227 // Track last motion event position
228 int32_t m_lastMotionX;
229 int32_t m_lastMotionY;
230
231 // default font settings
232 std::string m_fontpath;
233 std::string m_fontglyphs;
234 int32_t m_fontsize;
235
236 // true, if fifechan logic has already been executed for this round
237 bool m_logic_executed;
238 // True if the console should be created
239 bool m_enabled_console;
240
241 std::string m_backend;
242 };
243
244 }
245
246 #endif