41#include <js/RootingAPI.h>
42#include <js/TypeDecls.h>
43#include <js/ValueArray.h>
49#include <unordered_map>
50#include <unordered_set>
63namespace JS {
class HandleValueArray; }
64namespace JS {
class Value; }
65namespace js {
class BaseProxyHandler; }
66namespace Script {
class Context; }
67namespace Script {
class Interface; }
68namespace Script {
class Request; }
99 JS::HandleValue hotloadDataVal,
const std::string_view scriptName);
106 const std::string_view scriptName);
115 const JS::HandleValueArray paramData = JS::HandleValueArray::empty());
171 void SetGlobalHotkey(
const CStr& hotkeyTag,
const CStr& eventName, JS::HandleValue function);
344 template <
typename T>
412 std::unordered_set<VfsPath>&
Paths);
472 std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>&
Paths,
473 std::uint32_t nesting_depth);
482 std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>&
Paths,
483 std::uint32_t nesting_depth);
678 std::unordered_map<const js::BaseProxyHandler*, std::unique_ptr<GUIProxyProps>>
m_ProxyData;
725 std::map<CStr, std::unique_ptr<const CGUISprite>>
m_Sprites;
std::map< CStr, std::unique_ptr< IGUIObject > > map_pObjects
Definition: CGUI.h:74
const double SELECT_DBLCLICK_RATE
Definition: CGUI.cpp:73
EGUIMessageType
Message types.
Definition: SGUIMessage.h:29
Definition: Canvas2D.h:36
Definition: CGUISprite.h:137
The GUI sprite, is actually several real sprites (images) like a collage.
Definition: CGUISprite.h:116
The main object that represents a whole GUI page.
Definition: CGUI.h:80
void ReportMissingIcon(const CStr &name) const
Log a warning when text markup refers to an icon that doesn't exist.
Definition: CGUI.cpp:1379
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:678
bool ObjectExists(const CStr &Name) const
Checks if object exists and return true or false accordingly.
Definition: CGUI.cpp:432
const SGUIStyle & GetStyle(const CStr &name) const
Get Style if it exists, otherwise throws an exception.
Definition: CGUI.h:283
static const CStr EventNamePress
Definition: CGUI.h:701
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:692
const unsigned int & GetMouseButtons()
Returns the currently pressed mouse buttons.
Definition: CGUI.h:219
void AddObjectType(const CStr &str, ConstructObjectFunction pFunc)
The GUI needs to have all object types inputted and their constructors.
Definition: CGUI.h:243
std::map< CStr, const SGUIIcon > m_Icons
Definition: CGUI.h:734
Input::Reaction HandleEvent(const SDL_Event &ev)
The replacement of Process(), handles an SDL_Event.
Definition: CGUI.cpp:114
std::map< CStr, ConstructObjectFunction > m_ObjectTypes
Function pointers to functions that constructs IGUIObjects by name... For instance m_ObjectTypes["but...
Definition: CGUI.h:666
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:1218
std::map< CStr, std::vector< IGUIObject * > > m_HotkeyObjects
Map from hotkey names to objects that listen to the hotkey.
Definition: CGUI.h:685
CVector2D m_MousePos
don't want to pass this around with the ChooseMouseOverAndClosest broadcast - we'd need to pack this ...
Definition: CGUI.h:614
std::shared_ptr< Script::Interface > m_ScriptInterface
Definition: CGUI.h:607
const SGUIScrollBarStyle * GetScrollBarStyle(const CStr &style) const
Definition: CGUI.cpp:568
JSObject * TickObjects(const Script::Request &rq, Script::StructuredClone initData, const std::string_view scriptName)
Performs processing that should happen every frame (including sending the "Tick" event to scripts)
Definition: CGUI.cpp:339
bool HasIcon(const CStr &name) const
Check if an icon exists.
Definition: CGUI.h:259
GUITooltip m_Tooltip
Definition: CGUI.h:623
static const CStr EventNameMouseWheelRight
Definition: CGUI.h:709
static const CStr EventNameRelease
Definition: CGUI.h:703
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:1235
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:1115
std::map< CStr, const CGUIColor > m_PreDefinedColors
Definition: CGUI.h:722
std::unique_ptr< IGUIObject >(*)(CGUI &) ConstructObjectFunction
Definition: CGUI.h:85
CSize2D GetWindowSize() const
Returns the current GUI window size.
Definition: CGUI.cpp:467
void SendEventToAll(const CStr &eventName, const JS::HandleValueArray paramData=JS::HandleValueArray::empty())
Sends a specified script event to every object.
Definition: CGUI.cpp:364
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:1388
IGUIObject * TryFindObjectByName(const CStr &Name) const
Returns the GUI object with the desired name, or nullptr if no match is found.
Definition: CGUI.cpp:437
CGUI(Script::Context &context)
Definition: CGUI.cpp:92
bool HasPreDefinedColor(const CStr &name) const
Check if a predefined color of that name exists.
Definition: CGUI.h:288
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:635
void Xeromyces_ReadScript(const XMBData &xmb, XMBElement element, std::unordered_set< VfsPath > &Paths)
Reads in the element <script> (the XMBElement) and executes the script's code.
Definition: CGUI.cpp:1016
std::unordered_set< CStr > m_MissingIconsReported
Definition: CGUI.h:738
IGUIObject * GetBaseObject()
Return the object which is an ancestor of every other GUI object.
Definition: CGUI.cpp:427
void UnsetGlobalHotkey(const CStr &hotkeyTag, const CStr &eventName)
Definition: CGUI.cpp:556
static const CStr EventNameMouseRightRelease
Definition: CGUI.h:713
map_pObjects m_pAllObjects
Just pointers for fast name access, each object is really constructed within its parent for easy recu...
Definition: CGUI.h:651
void SetObjectHotkey(IGUIObject &object, const CStr &hotkeyTag)
Allows the JS side to modify the hotkey setting assigned to a GUI object.
Definition: CGUI.cpp:513
void SendFocusMessage(EGUIMessageType msg)
Alert the focussed object of this GUIPage that the focus of the page has changed.
Definition: CGUI.cpp:472
static const CStr EventNameTick
Definition: CGUI.h:700
void Xeromyces_ReadObject(const XMBData &xmb, XMBElement element, IGUIObject &parent, std::vector< std::pair< CStr, CStr > > &NameSubst, std::unordered_set< VfsPath > &Paths, std::uint32_t nesting_depth)
Notice! Recursive function!
Definition: CGUI.cpp:667
void Xeromyces_ReadRootObjects(const XMBData &xmb, XMBElement element, std::unordered_set< VfsPath > &Paths)
Reads in the root element <objects> (the DOMElement).
Definition: CGUI.cpp:618
static const CStr EventNameLoad
XML and JS can subscribe handlers to events identified by these names.
Definition: CGUI.h:699
const CGUIColor & GetPreDefinedColor(const CStr &name) const
Resolve the predefined color if it exists, otherwise throws an exception.
Definition: CGUI.h:293
static const CStr EventNameKeyDown
Definition: CGUI.h:702
static const CStr EventNameMouseWheelDown
Definition: CGUI.h:706
void Xeromyces_ReadRootSprites(const XMBData &xmb, XMBElement element)
Reads in the root element <sprites> (the DOMElement).
Definition: CGUI.cpp:637
void SetFocusedObject(IGUIObject *pObject)
Change focus to new object.
Definition: CGUI.cpp:481
static const CStr EventNameMouseWheelLeft
Definition: CGUI.h:708
static const CStr EventNameMouseLeftPress
Definition: CGUI.h:705
static const CStr EventNameMouseLeftDoubleClick
Definition: CGUI.h:710
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:1406
JS::Value GetHotloadData(const Script::Request &rq)
Definition: CGUI.cpp:301
JSObject * CallPageInit(const Script::Request &rq, Script::StructuredClone initDataVal, JS::HandleValue hotloadDataVal, const std::string_view scriptName)
Definition: CGUI.cpp:310
void LoadXmlFile(const VfsPath &Filename, std::unordered_set< VfsPath > &Paths)
Load a GUI XML file into the GUI.
Definition: CGUI.cpp:580
void UpdateResolution()
Update Resolution, should be called every time the resolution of the OpenGL screen has been changed,...
Definition: CGUI.cpp:394
static const CStr EventNameMouseRightDoubleClick
Definition: CGUI.h:712
void UnsetObjectHotkey(IGUIObject &object, const CStr &hotkeyTag)
Definition: CGUI.cpp:519
IGUIObject * m_FocusedObject
Focused object! Say an input box that is selected.
Definition: CGUI.h:642
void DrawSprite(const CGUISpriteInstance &Sprite, CCanvas2D &canvas, const CRect &Rect, const CRect &Clipping=CRect())
Draw GUI Sprite.
Definition: CGUI.cpp:381
void Xeromyces_ReadRepeat(const XMBData &xmb, XMBElement element, IGUIObject &parent, std::vector< std::pair< CStr, CStr > > &NameSubst, std::unordered_set< VfsPath > &Paths, std::uint32_t nesting_depth)
Reads in the element <repeat>, which repeats its child <object>s 'count' times, replacing the string ...
Definition: CGUI.cpp:986
unsigned int m_MouseButtons
Indicates which buttons are pressed (bit 0 = LMB, bit 1 = RMB, bit 2 = MMB)
Definition: CGUI.h:620
std::unique_ptr< IGUIObject > ConstructObject(const CStr &str)
You input the name of the object type, and let's say you input "button", then it will construct a CGU...
Definition: CGUI.cpp:399
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.
const CVector2D & GetMousePos() const
Returns the current screen coordinates of the cursor.
Definition: CGUI.h:214
void Draw(CCanvas2D &canvas)
Displays the whole GUI.
Definition: CGUI.cpp:376
static const CStr EventNameMouseRightPress
Definition: CGUI.h:704
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:1255
void AddObjectTypes()
Informs the GUI page which GUI object types may be constructed from XML.
Definition: GUIObjectTypes.cpp:47
IGUIObject * FindObjectByName(const CStr &Name) const
Returns the GUI object with the desired name, or nullptr and logs an error if no match is found.
Definition: CGUI.cpp:447
static const CStr EventNameMouseWheelUp
Definition: CGUI.h:707
void LoadedXmlFiles()
Called after all XML files linked in the page file were loaded.
Definition: CGUI.cpp:604
GUIProxyProps * GetProxyData(const js::BaseProxyHandler *ptr)
Definition: CGUI.h:295
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:1346
std::optional< ModuleArtifact > m_LoadModuleResult
Definition: CGUI.h:749
std::map< CStr, std::unique_ptr< const CGUISprite > > m_Sprites
Definition: CGUI.h:725
void Xeromyces_ReadRootSetup(const XMBData &xmb, XMBElement element)
Reads in the root element <setup> (the DOMElement).
Definition: CGUI.cpp:649
static const CStr EventNameMouseLeftRelease
Definition: CGUI.h:711
std::shared_ptr< Script::Interface > GetScriptInterface()
Definition: CGUI.h:297
void SetGlobalHotkey(const CStr &hotkeyTag, const CStr &eventName, JS::HandleValue function)
Allows the JS side to add or remove global hotkeys.
Definition: CGUI.cpp:535
void AddObject(IGUIObject &parent, std::unique_ptr< IGUIObject > child)
The CGUI takes ownership of the child object and links the parent with the child.
Definition: CGUI.cpp:409
void Xeromyces_ReadRootStyles(const XMBData &xmb, XMBElement element)
Reads in the root element <styles> (the DOMElement).
Definition: CGUI.cpp:643
IGUIObject * FindObjectUnderMouse()
Returns the GUI object under the mouse, or nullptr if none.
Definition: CGUI.cpp:460
bool HasStyle(const CStr &name) const
Check if a style exists.
Definition: CGUI.h:278
~CGUI()
Definition: CGUI.cpp:108
IGUIObject * GetFocusedObject()
Get Focused Object.
Definition: CGUI.h:320
std::unordered_map< CStr, std::vector< IGUIObject * > > m_EventObjects
Map from event names to object which listen to a given event.
Definition: CGUI.h:754
void UnsetObjectStyle(IGUIObject &object)
Definition: CGUI.cpp:508
std::map< CStr, const SGUIStyle > m_Styles
Definition: CGUI.h:728
void SetObjectStyle(IGUIObject &object, const CStr &styleName)
Allows the JS side to modify the style setting assigned to a GUI object.
Definition: CGUI.cpp:501
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:1067
std::map< CStr, const SGUIScrollBarStyle > m_ScrollBarStyles
Definition: CGUI.h:731
const SGUIIcon & GetIcon(const CStr &name) const
Get Icon (a const reference, can never be changed)
Definition: CGUI.h:264
int m_InternalNameNumber
Number of object that has been given name automatically.
Definition: CGUI.h:659
Rectangle class used for screen rectangles.
Definition: Rect.h:31
Definition: Vector2D.h:32
Proxies need to store some data whose lifetime is tied to an interface.
Definition: JSInterface_GUIProxy.h:96
GUI object such as a button or an input-box.
Definition: IGUIObject.h:63
Wrapper class for OS paths used by the game.
Definition: Paths.h:29
Definition: ModuleLoader.h:185
Definition: ModuleLoader.h:162
iterator begin() noexcept
Definition: ModuleLoader.cpp:471
Definition: XMBData.h:135
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32
std::shared_ptr< JSStructuredCloneData > StructuredClone
Structured clones are a way to serialize 'simple' JS::Values into a buffer that can safely be passed ...
Definition: StructuredClone.h:39
#define T(string_literal)
Definition: secure_crt.cpp:81
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:31
Script::ModuleLoader::Result result
Definition: CGUI.h:745
JS::PersistentRootedObject moduleNamespace
Definition: CGUI.h:747
Script::ModuleLoader::Result::iterator iterator
Definition: CGUI.h:746
ModuleArtifact(const Script::Request &rq, VfsPath filename)
Definition: CGUI.cpp:1429
Icon, you create them in the XML file with root element <setup>.
Definition: SGUIIcon.h:30
Definition: CGUISprite.h:43
Contains a list of values for new defaults to objects.
Definition: SGUIStyle.h:30