Cafu Engine
GuiManImpl.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GUISYS_GUIMAN_HPP_INCLUDED
8 #define CAFU_GUISYS_GUIMAN_HPP_INCLUDED
9 
10 #include "Templates/Array.hpp"
11 #include "Templates/Pointer.hpp"
12 #include <string>
13 
14 
15 struct CaKeyboardEventT;
16 struct CaMouseEventT;
17 
18 
19 namespace cf
20 {
21  namespace GuiSys
22  {
23  class GuiImplT;
24  class GuiResourcesT;
25 
26 
27  /// This class implements a GUI manager.
29  {
30  public:
31 
32  /// The constructor.
33  /// The MatSys *must* be initialized *before* this constructor is called (i.e. a GuiManImplT is instantiated)!
34  GuiManImplT(GuiResourcesT& GuiRes);
35 
36  /// Creates a GUI from the script with name GuiScriptName and registers it with the GUI manager.
37  IntrusivePtrT<GuiImplT> Register(const std::string& GuiScriptName);
38 
39  /// Registers a programmatically instantiated GUI with the GUI manager.
41 
42  /// Removes the Gui from the GUI manager.
43  void Free(IntrusivePtrT<GuiImplT> Gui);
44 
45  /// Searches the GUI manager for a GUI whose script name is GuiScriptName.
46  /// If the GUI was found, the pointer to the GuiImplT instance is returned.
47  /// Otherwise (GUI not found), Register() is called and its result returned if AutoRegister was true,
48  /// NULL is returned if AutoRegister was false.
49  /// @param GuiScriptName The filename of the GUI script to search for.
50  /// @param AutoRegister Whether the script should be registered with this GUI manager if it is not found.
51  IntrusivePtrT<GuiImplT> Find(const std::string& GuiScriptName, bool AutoRegister=false);
52 
53  /// Makes sure that if multiple GUIs are active, Gui is the topmost one.
55 
56  /// Returns the top-most GUI that is both active and interactive.
57  /// NULL is returned if no such GUI exists.
59 
60  /// Reloads all registered GUIs.
61  void ReloadAllGuis();
62 
63  /// Renders all the GUIs.
64  void RenderAll();
65 
66  /// Processes a keyboard event from the device that this GuiMan is running under,
67  /// sending it to the top-most GUI that is both active and interactive.
68  /// @param KE Keyboard event to process.
69  void ProcessDeviceEvent(const CaKeyboardEventT& KE);
70 
71  /// Processes a mouse event from the device that this GuiMan is running under,
72  /// sending it to the top-most GUI that is both active and interactive.
73  /// @param ME Mouse event to process.
74  void ProcessDeviceEvent(const CaMouseEventT& ME);
75 
76  /// "Creates" a time tick event for each window of each active GUI by calling its OnTimeTickEvent() methods.
77  /// Note that inactive GUIs do not get the time tick event, but active GUIs who get them usually pass them
78  /// to all their (sub-)windows, even if that part of the window(-hierarchy) is currently invisible.
79  /// @param t The time in seconds since the last clock-tick.
80  void DistributeClockTickEvents(float t);
81 
82 
83  private:
84 
85  GuiManImplT(const GuiManImplT&); ///< Use of the Copy Constructor is not allowed.
86  void operator = (const GuiManImplT&); ///< Use of the Assignment Operator is not allowed.
87 
88  GuiResourcesT& m_GuiResources; ///< The provider for resources (fonts and models) that are used in the GUIs created by this GuiMan.
90  bool SuppressNextChar; ///< Whether the next character (CaKeyboardEventT::CKE_CHAR) event should be suppressed. This is true whenever the preceeding CaKeyboardEventT::CKE_KEYDOWN event was positively processed.
91  };
92 
93 
94  /// A global pointer to an implementation of the GuiManI interface.
95  ///
96  /// Each module (exe or dll) that uses this pointer must somewhere provide exactly one definition for it (none is provided by the GuiSys library).
97  /// That is, typically the main.cpp or similar file of each exe and dll must contain a line like
98  /// cf::GuiSys::GuiManI* cf::GuiSys::GuiMan=NULL;
99  /// or else the module will not link successfully due to an undefined symbol.
100  ///
101  /// Exe files will then want to reset this pointer to an instance of a GuiManImplT during their initialization
102  /// e.g. by code like: cf::GuiSys::GuiMan=new cf::GuiSys::GuiManImplT;
103  /// Note that the GuiManImplT ctor may require that other interfaces (e.g. the MatSys) have been inited first.
104  ///
105  /// Dlls typically get one of their init functions called immediately after they have been loaded.
106  /// By doing so, the exe passes a pointer to its above instance to the dll, which in turn copies it to its GuiMan variable.
107  extern GuiManImplT* GuiMan;
108  }
109 }
110 
111 #endif
void ReloadAllGuis()
Reloads all registered GUIs.
Definition: GuiManImpl.cpp:105
IntrusivePtrT< GuiImplT > Register(const std::string &GuiScriptName)
Creates a GUI from the script with name GuiScriptName and registers it with the GUI manager...
Definition: GuiManImpl.cpp:29
This class implements smart (reference-counted) pointers.
Definition: Pointer.hpp:43
This class implements a GUI manager.
Definition: GuiManImpl.hpp:28
IntrusivePtrT< GuiImplT > GetTopmostActiveAndInteractive()
Returns the top-most GUI that is both active and interactive.
Definition: GuiManImpl.cpp:91
IntrusivePtrT< GuiImplT > Find(const std::string &GuiScriptName, bool AutoRegister=false)
Searches the GUI manager for a GUI whose script name is GuiScriptName.
Definition: GuiManImpl.cpp:69
This struct describes a mouse event.
Definition: OpenGLWindow.hpp:185
void RenderAll()
Renders all the GUIs.
Definition: GuiManImpl.cpp:127
void DistributeClockTickEvents(float t)
"Creates" a time tick event for each window of each active GUI by calling its OnTimeTickEvent() metho...
Definition: GuiManImpl.cpp:202
void Free(IntrusivePtrT< GuiImplT > Gui)
Removes the Gui from the GUI manager.
Definition: GuiManImpl.cpp:58
This struct describes a keyboard event.
Definition: OpenGLWindow.hpp:20
void ProcessDeviceEvent(const CaKeyboardEventT &KE)
Processes a keyboard event from the device that this GuiMan is running under, sending it to the top-m...
Definition: GuiManImpl.cpp:156
GuiManImplT(GuiResourcesT &GuiRes)
The constructor.
Definition: GuiManImpl.cpp:21
Definition: Renderer.hpp:16
void BringToFront(IntrusivePtrT< GuiImplT > Gui)
Makes sure that if multiple GUIs are active, Gui is the topmost one.
Definition: GuiManImpl.cpp:79
This class manages and provides resources (fonts and models) for GuiImplT instances.
Definition: GuiResources.hpp:26