i6engine  1.0
GUIManager.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_MODULES_GUIMANAGER_H__
26 #define __I6ENGINE_MODULES_GUIMANAGER_H__
27 
28 #include <array>
29 #include <list>
30 #include <map>
31 #include <sstream>
32 #include <vector>
33 
35 
36 #include "i6engine/api/KeyCodes.h"
38 
40 
41 #include "boost/function.hpp"
42 #include "boost/thread/mutex.hpp"
43 
44 namespace CEGUI {
45  class EventArgs;
46  class OgreRenderer;
47  class Window;
48 } /* namespace CEGUI */
49 
50 namespace Ogre {
51  class Root;
52 } /* namespace Ogre */
53 
54 namespace i6e {
55 namespace core {
56  struct MessageStruct;
57 } /* namespace core */
58 namespace api {
59  class GUIWidget;
60 
61 namespace gui {
63 } /* namespace gui */
64 } /* namespace api */
65 namespace modules {
66 
67  const std::string GUIMAN = "GUIManager"; // i.e. GUI Manager Name
68 
69  enum class KeyState;
70  class GUICanvas;
71  class GUIController;
72 
77  class GUIManager {
78  friend class GUICanvas;
79  friend class GUIController;
80  friend class GUIMailbox;
81 
82  public:
83  typedef std::map<std::string, boost::function<void(void)>> GUIFunctions;
84 
85  typedef std::map<std::pair<api::KeyCode, std::string>, boost::function<void(void)>> GUIKeyFunctions;
86 
90  GUIManager(GUIController * ctrl);
91 
95  ~GUIManager();
96 
102  void initializeGUI(Ogre::Root * root);
103 
108  inline CEGUI::Window * getRootWindow() const { return _objRoot; }
109 
119  void setFunction(const std::string & name, const boost::function<void(void)> & ptrEventMethod);
120 
129  bool allowedEvent(const std::string & name);
130 
134  inline void changeEvent(const std::string & name, const bool b) { _enabledFunctions[name] = b; }
135 
144  bool getVisibility(const std::string & windowname);
145 
151  void processCreateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct * data);
152 
159  void processUpdateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct * data);
160 
166  void processDeleteMessage(uint16_t type, api::gui::GUIUpdateMessageStruct * data);
167 
171  void processInputUpdateMessage(uint16_t type, core::MessageStruct * data);
172 
176  void addTicker(api::GUIWidget * widget);
177 
181  void removeTicker(api::GUIWidget * widget);
182 
186  void tickWidgets();
187 
194  void registerGUIWidgetTemplate(const std::string & name, GUIWidget_factory createFunc);
195 
196  protected:
208  void createGUI(const std::string & strScheme, const std::string & strFont, const std::string & strDefaultFont, const std::string & strDefaultMouseImageSet, const std::string & strDefaultMouseImageName);
209 
220  void MouseMove(const double fltDeltaX, const double fltDeltaY, const double fltDeltaZ) const;
221 
230  void MousePos(const double fltPosX, const double fltPosY) const;
231 
240  void MouseDown(const api::KeyCode enuButton) const;
241 
250  void MouseUp(const api::KeyCode enuButton) const;
251 
260  void KeyDown(const api::KeyCode intKeyCode, uint32_t text);
261 
265  void KeyHold(const api::KeyCode intKeyCode);
266 
275  void KeyUp(const api::KeyCode intKeyCode);
276 
280  void MouseLeaves() const;
281 
288  void addChildWindow(const std::string & parent_widget, const std::string & child_widget);
289 
297  void addToRootWindow(CEGUI::Window * child);
298 
306  void setMouseVisibility(const bool visibility);
307 
313  void cleanUpAllWindows();
314 
323  void subscribeEvent(const std::string & name, const std::string & type);
324 
334  void triggerFunction(const std::string & name);
335 
344  void triggerKeyFunction(const uint32_t keyCode, const std::string & type);
345 
349  void handleCreateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct * data);
350 
354  void handleUpdateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct * data);
355 
359  void handleDeleteMessage(uint16_t type, api::gui::GUIUpdateMessageStruct * data);
360 
365  inline CEGUI::OgreRenderer * getRenderer() const { return _objRenderer; }
366 
370  void Tick();
371 
372  private:
382  bool ClickedEventHandler(const CEGUI::EventArgs & e);
383 
392  bool PressedEventHandler(const CEGUI::EventArgs & e);
393 
402  bool ReleasedEventHandler(const CEGUI::EventArgs & e);
403 
410  api::GUIWidget * getWidgetByName(const std::string & name);
411 
415  std::vector<api::GUIWidget *> getMouseoverWidgets() const {
417  return _mouseOverWidgets;
418  }
419 
420  CEGUI::OgreRenderer * _objRenderer;
421  GUIFunctions _objGUIFunctions;
422  GUIKeyFunctions _objGUIKeyFunctions;
423  CEGUI::Window * _objRoot;
424 
428  std::map<std::string, api::GUIWidget *> _widgets;
429  std::map<std::string, bool> _enabledFunctions;
430  uint64_t _listIDs;
431 
435  std::list<api::GUIWidget *> _toTick;
436 
437  std::array<api::KeyState, 238> _keyStates;
438 
439  GUIFactory _factory;
440 
444  mutable boost::mutex _tickerLock;
445 
446  GUIController * _ctrl;
447 
448  std::string _lastOnWindow;
449 
450  std::vector<api::GUIWidget *> _mouseOverWidgets;
451 
455  GUIManager(const GUIManager &) = delete;
456 
460  const GUIManager & operator=(const GUIManager &) = delete;
461 
463  };
464 
465 } /* namespace modules */
466 } /* namespace i6e */
467 
468 #endif /* __I6ENGINE_MODULES_GUIMANAGER_H__ */
469 
void KeyUp(const api::KeyCode intKeyCode)
Injects the release of a keyboard key into the gui subsystem.
bool getVisibility(const std::string &windowname)
return visibility of the window
void addTicker(api::GUIWidget *widget)
registers a widget to be ticked
void handleUpdateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct *data)
Handles all update messages, which are for the GUIManager.
Extracts the contents of incoming messages on the "Gui" channel and calls the corresponding methods o...
Definition: GUIMailbox.h:45
#define ASSERT_THREAD_SAFETY_FUNCTION
void triggerFunction(const std::string &name)
Triggers the previously subscribed event by clicking the window, with the name "name". Only clicking so far available.
Responsible for initializing and updating the gui.
Definition: GUIController.h:44
void subscribeEvent(const std::string &name, const std::string &type)
Calls the CEGUI method subscribeEvent for mouse actions or keystrokes (see CEGUI documentation) ...
void changeEvent(const std::string &name, const bool b)
changes the status of the event
Definition: GUIManager.h:134
const std::string GUIMAN
Definition: GUIManager.h:67
void handleDeleteMessage(uint16_t type, api::gui::GUIUpdateMessageStruct *data)
Handles all delete messages, which are for the GUIManager.
void MouseDown(const api::KeyCode enuButton) const
Injects the press of a mouse button into the gui subsytem.
boost::function< api::GUIWidget *(const std::string &name, const std::string &style)> GUIWidget_factory
Definition: GUIFactory.h:40
void handleCreateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct *data)
Handles all create messages, which are for the GUIManager.
This class provides method to load a canvas file.
Definition: GUICanvas.h:48
void setFunction(const std::string &name, const boost::function< void(void)> &ptrEventMethod)
Adds the given function associated with the window to the GUIFunctions map.
Used to partially unwrap GUI messages.
Definition: GUIConfig.h:108
std::map< std::pair< api::KeyCode, std::string >, boost::function< void(void)> > GUIKeyFunctions
Definition: GUIManager.h:85
CEGUI::OgreRenderer * getRenderer() const
Returns a pointer to the renderer of the gui subsystem.
Definition: GUIManager.h:365
CEGUI::Window * getRootWindow() const
Returns a pointer to gui root window.
Definition: GUIManager.h:108
void removeTicker(api::GUIWidget *widget)
removes a widget from the tick list
#define ASSERT_THREAD_SAFETY_HEADER
i6e::api::gui::GUIUpdateMessageStruct GUIUpdateMessageStruct
void triggerKeyFunction(const uint32_t keyCode, const std::string &type)
Triggers the previously subscribed event for a key "Pressed" or "Released" event. ...
void processDeleteMessage(uint16_t type, api::gui::GUIUpdateMessageStruct *data)
Handles an incoming message to delete a GUI widget.
void addToRootWindow(CEGUI::Window *child)
Calls the CEGUI method addChildWindow with the root window (see CEGUI documentation) ...
~GUIManager()
destructor, cleans up GUI
void registerGUIWidgetTemplate(const std::string &name, GUIWidget_factory createFunc)
registers a widget-template to create new widgets via messages.
GUIManager(GUIController *ctrl)
constructor, registers basic GUI stuff
void addChildWindow(const std::string &parent_widget, const std::string &child_widget)
Calls the CEGUI method addChildWindow (see CEGUI documentation)
void cleanUpAllWindows()
Calls clear on _objGUIWindows.
void setMouseVisibility(const bool visibility)
Calls the CEGUI method setVisible on the mouse cursor (see CEGUI documentation)
void MouseLeaves() const
Notifies the gui subsystem that the cursor has left the game window.
void MouseMove(const double fltDeltaX, const double fltDeltaY, const double fltDeltaZ) const
Injects a mouse movement into the gui subsystem.
void processCreateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct *data)
Handles an incoming message to create a GUI widget.
void createGUI(const std::string &strScheme, const std::string &strFont, const std::string &strDefaultFont, const std::string &strDefaultMouseImageSet, const std::string &strDefaultMouseImageName)
Creates the GUI.
void Tick()
Tick method of the GUI Subsystem.
friend class GUIController
Definition: GUIManager.h:79
Superclass for all GUI widgets.
Definition: GUIWidget.h:65
void KeyHold(const api::KeyCode intKeyCode)
Injects a hold key.
void MouseUp(const api::KeyCode enuButton) const
Injects the release of a mouse button into the gui subsytem.
This class interacts with CEGUI. It's methods are executed in the OGRE / CEGUI thread.
Definition: GUIManager.h:77
void initializeGUI(Ogre::Root *root)
Automatically sets up all necessary dat structures of the underlying gui library. ...
struct ISIXE_CORE_API i6e::core::MessageStruct MessageStruct
bool allowedEvent(const std::string &name)
returns true, if the event is allowed to be called
void KeyDown(const api::KeyCode intKeyCode, uint32_t text)
Injects the press of a keyboard key into the gui subsystem.
void tickWidgets()
ticks all registered GUIWidgets
void processUpdateMessage(uint16_t type, api::gui::GUIUpdateMessageStruct *data)
Handles an incoming message to update a GUI widget This method forwards the message to the right widg...
void processInputUpdateMessage(uint16_t type, core::MessageStruct *data)
Handles incoming input messages.
void MousePos(const double fltPosX, const double fltPosY) const
Injects a new absolute cursor position into the gui subsystem.
std::map< std::string, boost::function< void(void)> > GUIFunctions
Definition: GUIManager.h:83