Pyrogenesis  trunk
CGUI.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * This is the top class of the whole GUI, all objects
20  * and settings are stored within this class.
21  */
22 
23 #ifndef INCLUDED_CGUI
24 #define INCLUDED_CGUI
25 
26 #include "gui/GUITooltip.h"
28 #include "gui/SGUIIcon.h"
29 #include "gui/SGUIMessage.h"
30 #include "gui/SGUIStyle.h"
31 #include "lib/input.h"
32 #include "maths/Rect.h"
33 #include "maths/Size2D.h"
34 #include "maths/Vector2D.h"
35 #include "ps/XML/Xeromyces.h"
37 
38 #include <map>
39 #include <memory>
40 #include <unordered_map>
41 #include <unordered_set>
42 #include <vector>
43 
44 extern const double SELECT_DBLCLICK_RATE;
45 
46 class CCanvas2D;
47 class CGUISpriteInstance;
48 class CGUISprite;
49 class IGUIObject;
50 struct SGUIImageEffects;
51 struct SGUIScrollBarStyle;
52 
53 class GUIProxyProps;
54 
55 using map_pObjects = std::map<CStr, IGUIObject*>;
56 
57 /**
58  * The main object that represents a whole GUI page.
59  */
60 class CGUI
61 {
63 
64 private:
65  // Private typedefs
67 
68 public:
69  CGUI(const std::shared_ptr<ScriptContext>& context);
70  ~CGUI();
71 
72  /**
73  * Informs the GUI page which GUI object types may be constructed from XML.
74  */
75  void AddObjectTypes();
76 
77  /**
78  * Performs processing that should happen every frame
79  * (including sending the "Tick" event to scripts)
80  */
81  void TickObjects();
82 
83  /**
84  * Sends a specified script event to every object
85  *
86  * @param eventName String representation of event name
87  */
88  void SendEventToAll(const CStr& eventName);
89 
90  /**
91  * Sends a specified script event to every object
92  *
93  * @param eventName String representation of event name
94  * @param paramData JS::HandleValueArray storing the arguments passed to the event handler.
95  */
96  void SendEventToAll(const CStr& eventName, const JS::HandleValueArray& paramData);
97 
98  /**
99  * Displays the whole GUI
100  */
101  void Draw(CCanvas2D& canvas);
102 
103  /**
104  * Draw GUI Sprite
105  *
106  * @param Sprite Object referring to the sprite (which also caches
107  * calculations for faster rendering)
108  * @param Canvas Canvas to draw on
109  * @param Rect Position and Size
110  * @param Clipping The sprite shouldn't be drawn outside this rectangle
111  */
112  void DrawSprite(const CGUISpriteInstance& Sprite, CCanvas2D& canvas, const CRect& Rect, const CRect& Clipping = CRect());
113 
114  /**
115  * The replacement of Process(), handles an SDL_Event_
116  *
117  * @param ev SDL Event, like mouse/keyboard input
118  */
119  InReaction HandleEvent(const SDL_Event_* ev);
120 
121  /**
122  * Load a GUI XML file into the GUI.
123  *
124  * <b>VERY IMPORTANT!</b> All <styles>-files must be read before
125  * everything else!
126  *
127  * @param Filename Name of file
128  * @param Paths Set of paths; all XML and JS files loaded will be added to this
129  */
130  void LoadXmlFile(const VfsPath& Filename, std::unordered_set<VfsPath>& Paths);
131 
132  /**
133  * Called after all XML files linked in the page file were loaded.
134  */
135  void LoadedXmlFiles();
136 
137  /**
138  * Allows the JS side to modify the hotkey setting assigned to a GUI object.
139  */
140  void SetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag);
141  void UnsetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag);
142 
143  /**
144  * Allows the JS side to modify the style setting assigned to a GUI object.
145  */
146  void SetObjectStyle(IGUIObject* pObject, const CStr& styleName);
147  void UnsetObjectStyle(IGUIObject* pObject);
148 
149  /**
150  * Allows the JS side to add or remove global hotkeys.
151  */
152  void SetGlobalHotkey(const CStr& hotkeyTag, const CStr& eventName, JS::HandleValue function);
153  void UnsetGlobalHotkey(const CStr& hotkeyTag, const CStr& eventName);
154 
155  /**
156  * Return the object which is an ancestor of every other GUI object.
157  */
159 
160  /**
161  * Checks if object exists and return true or false accordingly
162  *
163  * @param Name String name of object
164  * @return true if object exists
165  */
166  bool ObjectExists(const CStr& Name) const;
167 
168  /**
169  * Returns the GUI object with the desired name, or nullptr
170  * if no match is found,
171  *
172  * @param Name String name of object
173  * @return Matching object, or nullptr
174  */
175  IGUIObject* FindObjectByName(const CStr& Name) const;
176 
177  /**
178  * Returns the GUI object under the mouse, or nullptr if none.
179  */
181 
182  /**
183  * Returns the current screen coordinates of the cursor.
184  */
185  const CVector2D& GetMousePos() const { return m_MousePos; }
186 
187  /**
188  * Returns the currently pressed mouse buttons.
189  */
190  const unsigned int& GetMouseButtons() { return m_MouseButtons; }
191 
192  const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const;
193 
194  /**
195  * Returns the current GUI window size.
196  */
197  CSize2D GetWindowSize() const;
198 
199  /**
200  * The GUI needs to have all object types inputted and
201  * their constructors. Also it needs to associate a type
202  * by a string name of the type.
203  *
204  * To add a type:
205  * @code
206  * AddObjectType("button", &CButton::ConstructObject);
207  * @endcode
208  *
209  * @param str Reference name of object type
210  * @param pFunc Pointer of function ConstuctObject() in the object
211  *
212  * @see CGUI#ConstructObject()
213  */
214  void AddObjectType(const CStr& str, ConstructObjectFunction pFunc) { m_ObjectTypes[str] = pFunc; }
215 
216  /**
217  * Update Resolution, should be called every time the resolution
218  * of the OpenGL screen has been changed, this is because it needs
219  * to re-cache all its actual sizes
220  *
221  * Needs no input since screen resolution is global.
222  *
223  * @see IGUIObject#UpdateCachedSize()
224  */
225  void UpdateResolution();
226 
227  /**
228  * Check if an icon exists
229  */
230  bool HasIcon(const CStr& name) const { return (m_Icons.find(name) != m_Icons.end()); }
231 
232  /**
233  * Get Icon (a const reference, can never be changed)
234  */
235  const SGUIIcon& GetIcon(const CStr& name) const { return m_Icons.at(name); }
236 
237  /**
238  * Check if a style exists
239  */
240  bool HasStyle(const CStr& name) const { return (m_Styles.find(name) != m_Styles.end()); }
241 
242  /**
243  * Get Style if it exists, otherwise throws an exception.
244  */
245  const SGUIStyle& GetStyle(const CStr& name) const { return m_Styles.at(name); }
246 
247  /**
248  * Check if a predefined color of that name exists.
249  */
250  bool HasPreDefinedColor(const CStr& name) const { return (m_PreDefinedColors.find(name) != m_PreDefinedColors.end()); }
251 
252  /**
253  * Resolve the predefined color if it exists, otherwise throws an exception.
254  */
255  const CGUIColor& GetPreDefinedColor(const CStr& name) const { return m_PreDefinedColors.at(name); }
256 
257  GUIProxyProps* GetProxyData(const js::BaseProxyHandler* ptr) { return m_ProxyData.at(ptr).get(); }
258 
259  std::shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; };
260 
261 private:
262  /**
263  * The CGUI takes ownership of the child object and links the parent with the child.
264  * Returns false on failure to take over ownership of the child object.
265  */
266  bool AddObject(IGUIObject& parent, IGUIObject& child);
267 
268  /**
269  * You input the name of the object type, and let's
270  * say you input "button", then it will construct a
271  * CGUIObjet* as a CButton.
272  *
273  * @param str Name of object type
274  * @return Newly constructed IGUIObject (but constructed as a subclass)
275  */
276  IGUIObject* ConstructObject(const CStr& str);
277 
278 public:
279  /**
280  * Get Focused Object.
281  */
283 
284  /**
285  * Change focus to new object.
286  * Will send LOST_FOCUS/GOT_FOCUS messages as appropriate.
287  * pObject can be nullptr to remove all focus.
288  */
289  void SetFocusedObject(IGUIObject* pObject);
290 
291  /**
292  * Alert the focussed object of this GUIPage that the focus of the page has changed.
293  */
295 
296  /**
297  * Reads a string value and modifies the given value of type T if successful.
298  * Does not change the value upon conversion failure.
299  *
300  * @param pGUI The GUI page which may contain data relevant to the parsing
301  * (for example predefined colors).
302  * @param Value The value in string form, like "0 0 100% 100%"
303  * @param tOutput Parsed value of type T
304  * @return True at success.
305  */
306  template <typename T>
307  static bool ParseString(const CGUI* pGUI, const CStrW& Value, T& tOutput);
308 
309 private:
310 
311  //--------------------------------------------------------
312  /** @name XML Reading Xeromyces specific subroutines
313  *
314  * These does not throw!
315  * Because when reading in XML files, it won't be fatal
316  * if an error occurs, perhaps one particular object
317  * fails, but it'll still continue reading in the next.
318  * All Error are reported with ReportParseError
319  */
320  //--------------------------------------------------------
321 
322  /*
323  Xeromyces_* functions tree
324  <objects> (ReadRootObjects)
325  |
326  +-<script> (ReadScript)
327  |
328  +-<object> (ReadObject)
329  |
330  +-<action>
331  |
332  +-Optional Type Extensions (IGUIObject::ReadExtendedElement) TODO
333  |
334  +-<<object>> *recursive*
335 
336 
337  <styles> (ReadRootStyles)
338  |
339  +-<style> (ReadStyle)
340 
341 
342  <sprites> (ReadRootSprites)
343  |
344  +-<sprite> (ReadSprite)
345  |
346  +-<image> (ReadImage)
347 
348 
349  <setup> (ReadRootSetup)
350  |
351  +-<tooltip> (ReadToolTip)
352  |
353  +-<scrollbar> (ReadScrollBar)
354  |
355  +-<icon> (ReadIcon)
356  |
357  +-<color> (ReadColor)
358  */
359  //@{
360 
361  // Read Roots
362 
363  /**
364  * Reads in the root element <objects> (the DOMElement).
365  *
366  * @param Element The Xeromyces object that represents
367  * the objects-tag.
368  * @param pFile The Xeromyces object for the file being read
369  * @param Paths Collects the set of all XML/JS files that are loaded
370  *
371  * @see LoadXmlFile()
372  */
373  void Xeromyces_ReadRootObjects(const XMBData& xmb, XMBElement element, std::unordered_set<VfsPath>& Paths);
374 
375  /**
376  * Reads in the root element <sprites> (the DOMElement).
377  *
378  * @param Element The Xeromyces object that represents
379  * the sprites-tag.
380  * @param pFile The Xeromyces object for the file being read
381  *
382  * @see LoadXmlFile()
383  */
384  void Xeromyces_ReadRootSprites(const XMBData& xmb, XMBElement element);
385 
386  /**
387  * Reads in the root element <styles> (the DOMElement).
388  *
389  * @param Element The Xeromyces object that represents
390  * the styles-tag.
391  * @param pFile The Xeromyces object for the file being read
392  *
393  * @see LoadXmlFile()
394  */
395  void Xeromyces_ReadRootStyles(const XMBData& xmb, XMBElement element);
396 
397  /**
398  * Reads in the root element <setup> (the DOMElement).
399  *
400  * @param Element The Xeromyces object that represents
401  * the setup-tag.
402  * @param pFile The Xeromyces object for the file being read
403  *
404  * @see LoadXmlFile()
405  */
406  void Xeromyces_ReadRootSetup(const XMBData& xmb, XMBElement element);
407 
408  // Read Subs
409 
410  /**
411  * Notice! Recursive function!
412  *
413  * Read in an <object> (the XMBElement) and stores it
414  * as a child in the pParent.
415  *
416  * It will also check the object's children and call this function
417  * on them too. Also it will call all other functions that reads
418  * in other stuff that can be found within an object. Check the
419  * tree in the beginning of this class' Xeromyces_* section.
420  *
421  * @param Element The Xeromyces object that represents
422  * the object-tag.
423  * @param pFile The Xeromyces object for the file being read
424  * @param pParent Parent to add this object as child in.
425  * @param NameSubst A set of substitution strings that will be
426  * applied to all object names within this object.
427  * @param Paths Output set of file paths that this GUI object
428  * relies on.
429  *
430  * @see LoadXmlFile()
431  */
432  IGUIObject* Xeromyces_ReadObject(const XMBData& xmb, XMBElement element, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth);
433 
434  /**
435  * Reads in the element <repeat>, which repeats its child <object>s
436  * 'count' times, replacing the string "[n]" (or the value of the attribute
437  * 'var' enclosed in square brackets) in its descendants' names with "[0]",
438  * "[1]", etc.
439  */
440  void Xeromyces_ReadRepeat(const XMBData& xmb, XMBElement element, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth);
441 
442  /**
443  * Reads in the element <script> (the XMBElement) and executes
444  * the script's code.
445  *
446  * @param Element The Xeromyces object that represents
447  * the script-tag.
448  * @param pFile The Xeromyces object for the file being read
449  * @param Paths Output set of file paths that this script is loaded from.
450  *
451  * @see LoadXmlFile()
452  */
453  void Xeromyces_ReadScript(const XMBData& xmb, XMBElement element, std::unordered_set<VfsPath>& Paths);
454 
455  /**
456  * Reads in the element <sprite> (the XMBElement) and stores the
457  * result in a new CGUISprite.
458  *
459  * @param Element The Xeromyces object that represents
460  * the sprite-tag.
461  * @param pFile The Xeromyces object for the file being read
462  *
463  * @see LoadXmlFile()
464  */
465  void Xeromyces_ReadSprite(const XMBData& xmb, XMBElement element);
466 
467  /**
468  * Reads in the element <image> (the XMBElement) and stores the
469  * result within the CGUISprite.
470  *
471  * @param Element The Xeromyces object that represents
472  * the image-tag.
473  * @param pFile The Xeromyces object for the file being read
474  * @param parent Parent sprite.
475  *
476  * @see LoadXmlFile()
477  */
478  void Xeromyces_ReadImage(const XMBData& xmb, XMBElement element, CGUISprite& parent);
479 
480  /**
481  * Reads in the element <effect> (the XMBElement) and stores the
482  * result within the SGUIImageEffects.
483  *
484  * @param Element The Xeromyces object that represents
485  * the image-tag.
486  * @param pFile The Xeromyces object for the file being read
487  * @param effects Effects object to add this effect to.
488  *
489  * @see LoadXmlFile()
490  */
491  void Xeromyces_ReadEffects(const XMBData& xmb, XMBElement element, SGUIImageEffects& effects);
492 
493  /**
494  * Reads in the element <style> (the XMBElement) and stores the
495  * result in m_Styles.
496  *
497  * @param Element The Xeromyces object that represents
498  * the style-tag.
499  * @param pFile The Xeromyces object for the file being read
500  *
501  * @see LoadXmlFile()
502  */
503  void Xeromyces_ReadStyle(const XMBData& xmb, XMBElement element);
504 
505  /**
506  * Reads in the element <scrollbar> (the XMBElement) and stores the
507  * result in m_ScrollBarStyles.
508  *
509  * @param Element The Xeromyces object that represents
510  * the scrollbar-tag.
511  * @param pFile The Xeromyces object for the file being read
512  *
513  * @see LoadXmlFile()
514  */
515  void Xeromyces_ReadScrollBarStyle(const XMBData& xmb, XMBElement element);
516 
517  /**
518  * Reads in the element <icon> (the XMBElement) and stores the
519  * result in m_Icons.
520  *
521  * @param Element The Xeromyces object that represents
522  * the scrollbar-tag.
523  * @param pFile The Xeromyces object for the file being read
524  *
525  * @see LoadXmlFile()
526  */
527  void Xeromyces_ReadIcon(const XMBData& xmb, XMBElement element);
528 
529  /**
530  * Reads in the element <tooltip> (the XMBElement) and stores the
531  * result as an object with the name __tooltip_#.
532  *
533  * @param Element The Xeromyces object that represents
534  * the scrollbar-tag.
535  * @param pFile The Xeromyces object for the file being read
536  *
537  * @see LoadXmlFile()
538  */
539  void Xeromyces_ReadTooltip(const XMBData& xmb, XMBElement element);
540 
541  /**
542  * Reads in the element <color> (the XMBElement) and stores the
543  * result in m_PreDefinedColors
544  *
545  * @param Element The Xeromyces object that represents
546  * the scrollbar-tag.
547  * @param pFile The Xeromyces object for the file being read
548  *
549  * @see LoadXmlFile()
550  */
551  void Xeromyces_ReadColor(const XMBData& xmb, XMBElement element);
552 
553  //@}
554 
555 private:
556 
557  // Variables
558 
559  //--------------------------------------------------------
560  /** @name Miscellaneous */
561  //--------------------------------------------------------
562  //@{
563 
564  std::shared_ptr<ScriptInterface> m_ScriptInterface;
565 
566  /**
567  * don't want to pass this around with the
568  * ChooseMouseOverAndClosest broadcast -
569  * we'd need to pack this and pNearest in a struct
570  */
572 
573  /**
574  * Indicates which buttons are pressed (bit 0 = LMB,
575  * bit 1 = RMB, bit 2 = MMB)
576  */
577  unsigned int m_MouseButtons;
578 
579  // Tooltip
581 
582  //@}
583  //--------------------------------------------------------
584  /** @name Objects */
585  //--------------------------------------------------------
586  //@{
587 
588  /**
589  * Base Object, all its children are considered parentless
590  * because this is not a real object per se.
591  */
592  std::unique_ptr<IGUIObject> m_BaseObject;
593 
594  /**
595  * Focused object!
596  * Say an input box that is selected. That one is focused.
597  * There can only be one focused object.
598  */
600 
601  /**
602  * Just pointers for fast name access, each object
603  * is really constructed within its parent for easy
604  * recursive management.
605  * Notice m_BaseObject won't belong here since it's
606  * not considered a real object.
607  */
609 
610  /**
611  * Number of object that has been given name automatically.
612  * the name given will be '__internal(#)', the number (#)
613  * being this variable. When an object's name has been set
614  * as followed, the value will increment.
615  */
617 
618  /**
619  * Function pointers to functions that constructs
620  * IGUIObjects by name... For instance m_ObjectTypes["button"]
621  * is filled with a function that will "return new CButton();"
622  */
623  std::map<CStr, ConstructObjectFunction> m_ObjectTypes;
624 
625  /**
626  * This is intended to store the JSFunction when accessing certain properties.
627  * The problem is that these functions are per-scriptInterface, and proxy handlers aren't.
628  * So we know what we want to store, but we don't really have anywhere to store it.
629  * It would be simpler to recreate the functions on every JS call, but that is slower
630  * (this may or may not matter now and in the future).
631  * It's not a great solution, but I can't find a better one at the moment.
632  * An alternative would be to store these on the proxy's prototype,
633  * but that embarks a lot of un-necessary code.
634  */
635  std::unordered_map<const js::BaseProxyHandler*, std::unique_ptr<GUIProxyProps>> m_ProxyData;
636 
637  /**
638  * Map from hotkey names to objects that listen to the hotkey.
639  * (This is an optimisation to avoid recursing over the whole GUI
640  * tree every time a hotkey is pressed).
641  */
642  std::map<CStr, std::vector<IGUIObject*> > m_HotkeyObjects;
643 
644  /**
645  * Map from hotkey names to maps of eventNames to functions that are triggered
646  * when the hotkey goes through the event. Contrary to object hotkeys, this
647  * allows for only one global function per hotkey name per event type.
648  */
649  std::map<CStr, std::map<CStr, JS::PersistentRootedValue>> m_GlobalHotkeys;
650 
651  /**
652  * XML and JS can subscribe handlers to events identified by these names.
653  * Store in static const members to avoid string copies, gain compile errors when misspelling and
654  * to allow reuse in other classes.
655  */
656  static const CStr EventNameLoad;
657  static const CStr EventNameTick;
658  static const CStr EventNamePress;
659  static const CStr EventNameKeyDown;
660  static const CStr EventNameRelease;
661  static const CStr EventNameMouseRightPress;
662  static const CStr EventNameMouseLeftPress;
663  static const CStr EventNameMouseWheelDown;
664  static const CStr EventNameMouseWheelUp;
665  static const CStr EventNameMouseLeftDoubleClick;
666  static const CStr EventNameMouseLeftRelease;
668  static const CStr EventNameMouseRightRelease;
669 
670  //--------------------------------------------------------
671  // Databases
672  // These are loaded from XML files and marked as noncopyable and const to
673  // rule out unintentional modification and copy, especially during Draw calls.
674  //--------------------------------------------------------
675 
676  // Colors
677  std::map<CStr, const CGUIColor> m_PreDefinedColors;
678 
679  // Sprites
680  std::map<CStr, std::unique_ptr<const CGUISprite>> m_Sprites;
681 
682  // Styles
683  std::map<CStr, const SGUIStyle> m_Styles;
684 
685  // Scroll-bar styles
686  std::map<CStr, const SGUIScrollBarStyle> m_ScrollBarStyles;
687 
688  // Icons
689  std::map<CStr, const SGUIIcon> m_Icons;
690 
691 public:
692  /**
693  * Map from event names to object which listen to a given event.
694  */
695  std::unordered_map<CStr, std::vector<IGUIObject*>> m_EventObjects;
696 };
697 
698 #endif // INCLUDED_CGUI
std::unordered_map< CStr, std::vector< IGUIObject * > > m_EventObjects
Map from event names to object which listen to a given event.
Definition: CGUI.h:695
void SendEventToAll(const CStr &eventName)
Sends a specified script event to every object.
Definition: CGUI.cpp:306
static const CStr EventNameMouseLeftPress
Definition: CGUI.h:662
IGUIObject * FindObjectByName(const CStr &Name) const
Returns the GUI object with the desired name, or nullptr if no match is found,.
Definition: CGUI.cpp:404
std::map< CStr, const SGUIIcon > m_Icons
Definition: CGUI.h:689
Definition: CGUISprite.h:39
void Xeromyces_ReadRootStyles(const XMBData &xmb, XMBElement element)
Reads in the root element <styles> (the DOMElement).
Definition: CGUI.cpp:603
static const CStr EventNameRelease
Definition: CGUI.h:660
bool AddObject(IGUIObject &parent, IGUIObject &child)
The CGUI takes ownership of the child object and links the parent with the child. ...
Definition: CGUI.cpp:375
static const CStr EventNameMouseRightRelease
Definition: CGUI.h:668
const SGUIIcon & GetIcon(const CStr &name) const
Get Icon (a const reference, can never be changed)
Definition: CGUI.h:235
static const CStr EventNameMouseRightPress
Definition: CGUI.h:661
IGUIObject * m_FocusedObject
Focused object! Say an input box that is selected.
Definition: CGUI.h:599
~CGUI()
Definition: CGUI.cpp:111
void Xeromyces_ReadRootObjects(const XMBData &xmb, XMBElement element, std::unordered_set< VfsPath > &Paths)
Reads in the root element <objects> (the DOMElement).
Definition: CGUI.cpp:578
void UnsetGlobalHotkey(const CStr &hotkeyTag, const CStr &eventName)
Definition: CGUI.cpp:516
GUITooltip m_Tooltip
Definition: CGUI.h:580
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:29
The GUI Scroll-bar style.
Definition: IGUIScrollBar.h:44
IGUIObject * Xeromyces_ReadObject(const XMBData &xmb, XMBElement element, IGUIObject *pParent, std::vector< std::pair< CStr, CStr > > &NameSubst, std::unordered_set< VfsPath > &Paths, u32 nesting_depth)
Notice! Recursive function!
Definition: CGUI.cpp:627
bool ObjectExists(const CStr &Name) const
Checks if object exists and return true or false accordingly.
Definition: CGUI.cpp:399
Definition: XMBData.h:135
const unsigned int & GetMouseButtons()
Returns the currently pressed mouse buttons.
Definition: CGUI.h:190
static const CStr EventNameMouseLeftDoubleClick
Definition: CGUI.h:665
const CGUIColor & GetPreDefinedColor(const CStr &name) const
Resolve the predefined color if it exists, otherwise throws an exception.
Definition: CGUI.h:255
std::shared_ptr< ScriptInterface > GetScriptInterface()
Definition: CGUI.h:259
GUI object such as a button or an input-box.
Definition: IGUIObject.h:59
static const CStr EventNameTick
Definition: CGUI.h:657
std::map< CStr, std::unique_ptr< const CGUISprite > > m_Sprites
Definition: CGUI.h:680
static const CStr EventNameLoad
XML and JS can subscribe handlers to events identified by these names.
Definition: CGUI.h:656
Definition: libsdl.h:52
const SGUIStyle & GetStyle(const CStr &name) const
Get Style if it exists, otherwise throws an exception.
Definition: CGUI.h:245
EGUIMessageType
Message types.
Definition: SGUIMessage.h:27
std::map< CStr, std::vector< IGUIObject * > > m_HotkeyObjects
Map from hotkey names to objects that listen to the hotkey.
Definition: CGUI.h:642
The main object that represents a whole GUI page.
Definition: CGUI.h:60
std::unique_ptr< IGUIObject > m_BaseObject
Base Object, all its children are considered parentless because this is not a real object per se...
Definition: CGUI.h:592
Definition: Size2D.h:24
void TickObjects()
Performs processing that should happen every frame (including sending the "Tick" event to scripts) ...
Definition: CGUI.cpp:299
void SetObjectHotkey(IGUIObject *pObject, const CStr &hotkeyTag)
Allows the JS side to modify the hotkey setting assigned to a GUI object.
Definition: CGUI.cpp:467
std::map< CStr, const SGUIStyle > m_Styles
Definition: CGUI.h:683
Proxies need to store some data whose lifetime is tied to an interface.
Definition: JSInterface_GUIProxy.h:85
static const CStr EventNameMouseWheelDown
Definition: CGUI.h:663
unsigned int m_MouseButtons
Indicates which buttons are pressed (bit 0 = LMB, bit 1 = RMB, bit 2 = MMB)
Definition: CGUI.h:577
void UnsetObjectStyle(IGUIObject *pObject)
Definition: CGUI.cpp:462
void Xeromyces_ReadTooltip(const XMBData &xmb, XMBElement element)
Reads in the element <tooltip> (the XMBElement) and stores the result as an object with the name __to...
Definition: CGUI.cpp:1285
void SetGlobalHotkey(const CStr &hotkeyTag, const CStr &eventName, JS::HandleValue function)
Allows the JS side to add or remove global hotkeys.
Definition: CGUI.cpp:489
void Xeromyces_ReadImage(const XMBData &xmb, XMBElement element, CGUISprite &parent)
Reads in the element <image> (the XMBElement) and stores the result within the CGUISprite.
Definition: CGUI.cpp:1044
uint32_t u32
Definition: types.h:39
void Xeromyces_ReadScript(const XMBData &xmb, XMBElement element, std::unordered_set< VfsPath > &Paths)
Reads in the element <script> (the XMBElement) and executes the script&#39;s code.
Definition: CGUI.cpp:958
Config::Value_type Value
Definition: json_spirit_value.h:182
IGUIObject * GetFocusedObject()
Get Focused Object.
Definition: CGUI.h:282
CGUI(const std::shared_ptr< ScriptContext > &context)
Definition: CGUI.cpp:98
Definition: path.h:79
std::map< CStr, std::map< CStr, JS::PersistentRootedValue > > m_GlobalHotkeys
Map from hotkey names to maps of eventNames to functions that are triggered when the hotkey goes thro...
Definition: CGUI.h:649
Definition: XMBData.h:95
IGUIObject * GetBaseObject()
Return the object which is an ancestor of every other GUI object.
Definition: CGUI.cpp:394
InReaction
Definition: input.h:34
bool HasStyle(const CStr &name) const
Check if a style exists.
Definition: CGUI.h:240
void Xeromyces_ReadRepeat(const XMBData &xmb, XMBElement element, IGUIObject *pParent, std::vector< std::pair< CStr, CStr > > &NameSubst, std::unordered_set< VfsPath > &Paths, u32 nesting_depth)
Reads in the element <repeat>, which repeats its child <object>s &#39;count&#39; times, replacing the string ...
Definition: CGUI.cpp:930
void Xeromyces_ReadIcon(const XMBData &xmb, XMBElement element)
Reads in the element <icon> (the XMBElement) and stores the result in m_Icons.
Definition: CGUI.cpp:1252
static const CStr EventNameMouseLeftRelease
Definition: CGUI.h:666
Definition: Canvas2D.h:35
void LoadXmlFile(const VfsPath &Filename, std::unordered_set< VfsPath > &Paths)
Load a GUI XML file into the GUI.
Definition: CGUI.cpp:540
NONCOPYABLE(CGUI)
IGUIObject * ConstructObject(const CStr &str)
You input the name of the object type, and let&#39;s say you input "button", then it will construct a CGU...
Definition: CGUI.cpp:365
std::unordered_map< const js::BaseProxyHandler *, std::unique_ptr< GUIProxyProps > > m_ProxyData
This is intended to store the JSFunction when accessing certain properties.
Definition: CGUI.h:635
IGUIObject *(*)(CGUI &) ConstructObjectFunction
Definition: CGUI.h:66
void AddObjectTypes()
Informs the GUI page which GUI object types may be constructed from XML.
Definition: GUIObjectTypes.cpp:38
void Xeromyces_ReadColor(const XMBData &xmb, XMBElement element)
Reads in the element <color> (the XMBElement) and stores the result in m_PreDefinedColors.
Definition: CGUI.cpp:1304
void AddObjectType(const CStr &str, ConstructObjectFunction pFunc)
The GUI needs to have all object types inputted and their constructors.
Definition: CGUI.h:214
#define T(string_literal)
Definition: secure_crt.cpp:77
int m_InternalNameNumber
Number of object that has been given name automatically.
Definition: CGUI.h:616
bool HasIcon(const CStr &name) const
Check if an icon exists.
Definition: CGUI.h:230
The GUI sprite, is actually several real sprites (images) like a collage.
Definition: CGUISprite.h:112
const CVector2D & GetMousePos() const
Returns the current screen coordinates of the cursor.
Definition: CGUI.h:185
std::shared_ptr< ScriptInterface > m_ScriptInterface
Definition: CGUI.h:564
Definition: Vector2D.h:31
void Xeromyces_ReadStyle(const XMBData &xmb, XMBElement element)
Reads in the element <style> (the XMBElement) and stores the result in m_Styles.
Definition: CGUI.cpp:1149
static const CStr EventNamePress
Definition: CGUI.h:658
static const CStr EventNameMouseWheelUp
Definition: CGUI.h:664
void Xeromyces_ReadRootSetup(const XMBData &xmb, XMBElement element)
Reads in the root element <setup> (the DOMElement).
Definition: CGUI.cpp:609
static const CStr EventNameKeyDown
Definition: CGUI.h:659
map_pObjects m_pAllObjects
Just pointers for fast name access, each object is really constructed within its parent for easy recu...
Definition: CGUI.h:608
Icon, you create them in the XML file with root element <setup>.
Definition: SGUIIcon.h:28
Wrapper class for OS paths used by the game.
Definition: Paths.h:27
void LoadedXmlFiles()
Called after all XML files linked in the page file were loaded.
Definition: CGUI.cpp:564
const SGUIScrollBarStyle * GetScrollBarStyle(const CStr &style) const
Definition: CGUI.cpp:528
static bool ParseString(const CGUI *pGUI, const CStrW &Value, T &tOutput)
Reads a string value and modifies the given value of type T if successful.
void UpdateResolution()
Update Resolution, should be called every time the resolution of the OpenGL screen has been changed...
Definition: CGUI.cpp:360
const double SELECT_DBLCLICK_RATE
Definition: CGUI.cpp:54
void UnsetObjectHotkey(IGUIObject *pObject, const CStr &hotkeyTag)
Definition: CGUI.cpp:473
void Xeromyces_ReadScrollBarStyle(const XMBData &xmb, XMBElement element)
Reads in the element <scrollbar> (the XMBElement) and stores the result in m_ScrollBarStyles.
Definition: CGUI.cpp:1169
std::map< CStr, IGUIObject * > map_pObjects
Definition: CGUI.h:55
static const CStr EventNameMouseRightDoubleClick
Definition: CGUI.h:667
Definition: CGUISprite.h:133
bool HasPreDefinedColor(const CStr &name) const
Check if a predefined color of that name exists.
Definition: CGUI.h:250
void SendFocusMessage(EGUIMessageType msg)
Alert the focussed object of this GUIPage that the focus of the page has changed. ...
Definition: CGUI.cpp:426
void DrawSprite(const CGUISpriteInstance &Sprite, CCanvas2D &canvas, const CRect &Rect, const CRect &Clipping=CRect())
Draw GUI Sprite.
Definition: CGUI.cpp:349
CVector2D m_MousePos
don&#39;t want to pass this around with the ChooseMouseOverAndClosest broadcast - we&#39;d need to pack this ...
Definition: CGUI.h:571
std::map< CStr, ConstructObjectFunction > m_ObjectTypes
Function pointers to functions that constructs IGUIObjects by name...
Definition: CGUI.h:623
GUIProxyProps * GetProxyData(const js::BaseProxyHandler *ptr)
Definition: CGUI.h:257
IGUIObject * FindObjectUnderMouse()
Returns the GUI object under the mouse, or nullptr if none.
Definition: CGUI.cpp:414
Contains a list of values for new defaults to objects.
Definition: SGUIStyle.h:28
void Xeromyces_ReadRootSprites(const XMBData &xmb, XMBElement element)
Reads in the root element <sprites> (the DOMElement).
Definition: CGUI.cpp:597
Definition: GUITooltip.h:27
CSize2D GetWindowSize() const
Returns the current GUI window size.
Definition: CGUI.cpp:421
std::map< CStr, const SGUIScrollBarStyle > m_ScrollBarStyles
Definition: CGUI.h:686
void Xeromyces_ReadEffects(const XMBData &xmb, XMBElement element, SGUIImageEffects &effects)
Reads in the element <effect> (the XMBElement) and stores the result within the SGUIImageEffects.
Definition: CGUI.cpp:1132
void Draw(CCanvas2D &canvas)
Displays the whole GUI.
Definition: CGUI.cpp:328
InReaction HandleEvent(const SDL_Event_ *ev)
The replacement of Process(), handles an SDL_Event_.
Definition: CGUI.cpp:117
void SetFocusedObject(IGUIObject *pObject)
Change focus to new object.
Definition: CGUI.cpp:435
std::map< CStr, const CGUIColor > m_PreDefinedColors
Definition: CGUI.h:677
Rectangle class used for screen rectangles.
Definition: Rect.h:30
void SetObjectStyle(IGUIObject *pObject, const CStr &styleName)
Allows the JS side to modify the style setting assigned to a GUI object.
Definition: CGUI.cpp:455
void Xeromyces_ReadSprite(const XMBData &xmb, XMBElement element)
Reads in the element <sprite> (the XMBElement) and stores the result in a new CGUISprite.
Definition: CGUI.cpp:999