Pyrogenesis trunk
|
The main object that represents a whole GUI page. More...
#include <CGUI.h>
Public Member Functions | |
CGUI (ScriptContext &context) | |
~CGUI () | |
void | AddObjectTypes () |
Informs the GUI page which GUI object types may be constructed from XML. More... | |
void | TickObjects () |
Performs processing that should happen every frame (including sending the "Tick" event to scripts) More... | |
void | SendEventToAll (const CStr &eventName) |
Sends a specified script event to every object. More... | |
void | SendEventToAll (const CStr &eventName, const JS::HandleValueArray ¶mData) |
Sends a specified script event to every object. More... | |
void | Draw (CCanvas2D &canvas) |
Displays the whole GUI. More... | |
void | DrawSprite (const CGUISpriteInstance &Sprite, CCanvas2D &canvas, const CRect &Rect, const CRect &Clipping=CRect()) |
Draw GUI Sprite. More... | |
InReaction | HandleEvent (const SDL_Event_ *ev) |
The replacement of Process(), handles an SDL_Event_. More... | |
void | LoadXmlFile (const VfsPath &Filename, std::unordered_set< VfsPath > &Paths) |
Load a GUI XML file into the GUI. More... | |
void | LoadedXmlFiles () |
Called after all XML files linked in the page file were loaded. More... | |
void | SetObjectHotkey (IGUIObject *pObject, const CStr &hotkeyTag) |
Allows the JS side to modify the hotkey setting assigned to a GUI object. More... | |
void | UnsetObjectHotkey (IGUIObject *pObject, const CStr &hotkeyTag) |
void | SetObjectStyle (IGUIObject *pObject, const CStr &styleName) |
Allows the JS side to modify the style setting assigned to a GUI object. More... | |
void | UnsetObjectStyle (IGUIObject *pObject) |
void | SetGlobalHotkey (const CStr &hotkeyTag, const CStr &eventName, JS::HandleValue function) |
Allows the JS side to add or remove global hotkeys. More... | |
void | UnsetGlobalHotkey (const CStr &hotkeyTag, const CStr &eventName) |
IGUIObject * | GetBaseObject () |
Return the object which is an ancestor of every other GUI object. More... | |
bool | ObjectExists (const CStr &Name) const |
Checks if object exists and return true or false accordingly. More... | |
IGUIObject * | FindObjectByName (const CStr &Name) const |
Returns the GUI object with the desired name, or nullptr if no match is found,. More... | |
IGUIObject * | FindObjectUnderMouse () |
Returns the GUI object under the mouse, or nullptr if none. More... | |
const CVector2D & | GetMousePos () const |
Returns the current screen coordinates of the cursor. More... | |
const unsigned int & | GetMouseButtons () |
Returns the currently pressed mouse buttons. More... | |
const SGUIScrollBarStyle * | GetScrollBarStyle (const CStr &style) const |
CSize2D | GetWindowSize () const |
Returns the current GUI window size. More... | |
void | AddObjectType (const CStr &str, ConstructObjectFunction pFunc) |
The GUI needs to have all object types inputted and their constructors. More... | |
void | UpdateResolution () |
Update Resolution, should be called every time the resolution of the OpenGL screen has been changed, this is because it needs to re-cache all its actual sizes. More... | |
bool | HasIcon (const CStr &name) const |
Check if an icon exists. More... | |
const SGUIIcon & | GetIcon (const CStr &name) const |
Get Icon (a const reference, can never be changed) More... | |
bool | HasStyle (const CStr &name) const |
Check if a style exists. More... | |
const SGUIStyle & | GetStyle (const CStr &name) const |
Get Style if it exists, otherwise throws an exception. More... | |
bool | HasPreDefinedColor (const CStr &name) const |
Check if a predefined color of that name exists. More... | |
const CGUIColor & | GetPreDefinedColor (const CStr &name) const |
Resolve the predefined color if it exists, otherwise throws an exception. More... | |
GUIProxyProps * | GetProxyData (const js::BaseProxyHandler *ptr) |
std::shared_ptr< ScriptInterface > | GetScriptInterface () |
IGUIObject * | GetFocusedObject () |
Get Focused Object. More... | |
void | SetFocusedObject (IGUIObject *pObject) |
Change focus to new object. More... | |
void | SendFocusMessage (EGUIMessageType msg) |
Alert the focussed object of this GUIPage that the focus of the page has changed. More... | |
Static Public Member Functions | |
template<typename T > | |
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. More... | |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, bool &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, int &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, u32 &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, float &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CRect &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CGUISize &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CGUIColor &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CSize2D &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CVector2D &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, EAlign &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, EVAlign &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CGUIString &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CStr &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CStrW &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CGUISpriteInstance &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CGUISeries &Output) |
template<> | |
bool | ParseString (const CGUI *pGUI, const CStrW &Value, CGUIList &Output) |
Private Types | |
using | ConstructObjectFunction = IGUIObject *(*)(CGUI &) |
Private Member Functions | |
NONCOPYABLE (CGUI) | |
bool | AddObject (IGUIObject &parent, IGUIObject &child) |
The CGUI takes ownership of the child object and links the parent with the child. More... | |
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 CGUIObjet* as a CButton. More... | |
XML Reading Xeromyces specific subroutines | |
These does not throw! Because when reading in XML files, it won't be fatal if an error occurs, perhaps one particular object fails, but it'll still continue reading in the next. All Error are reported with ReportParseError | |
void | Xeromyces_ReadRootObjects (const XMBData &xmb, XMBElement element, std::unordered_set< VfsPath > &Paths) |
Reads in the root element <objects> (the DOMElement). More... | |
void | Xeromyces_ReadRootSprites (const XMBData &xmb, XMBElement element) |
Reads in the root element <sprites> (the DOMElement). More... | |
void | Xeromyces_ReadRootStyles (const XMBData &xmb, XMBElement element) |
Reads in the root element <styles> (the DOMElement). More... | |
void | Xeromyces_ReadRootSetup (const XMBData &xmb, XMBElement element) |
Reads in the root element <setup> (the DOMElement). More... | |
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! More... | |
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 'count' times, replacing the string "[n]" (or the value of the attribute 'var' enclosed in square brackets) in its descendants' names with "[0]", "[1]", etc. More... | |
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. More... | |
void | Xeromyces_ReadSprite (const XMBData &xmb, XMBElement element) |
Reads in the element <sprite> (the XMBElement) and stores the result in a new CGUISprite. More... | |
void | Xeromyces_ReadImage (const XMBData &xmb, XMBElement element, CGUISprite &parent) |
Reads in the element <image> (the XMBElement) and stores the result within the CGUISprite. More... | |
void | Xeromyces_ReadEffects (const XMBData &xmb, XMBElement element, SGUIImageEffects &effects) |
Reads in the element <effect> (the XMBElement) and stores the result within the SGUIImageEffects. More... | |
void | Xeromyces_ReadStyle (const XMBData &xmb, XMBElement element) |
Reads in the element <style> (the XMBElement) and stores the result in m_Styles. More... | |
void | Xeromyces_ReadScrollBarStyle (const XMBData &xmb, XMBElement element) |
Reads in the element <scrollbar> (the XMBElement) and stores the result in m_ScrollBarStyles. More... | |
void | Xeromyces_ReadIcon (const XMBData &xmb, XMBElement element) |
Reads in the element <icon> (the XMBElement) and stores the result in m_Icons. More... | |
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 __tooltip_#. More... | |
void | Xeromyces_ReadColor (const XMBData &xmb, XMBElement element) |
Reads in the element <color> (the XMBElement) and stores the result in m_PreDefinedColors. More... | |
Private Attributes | |
Miscellaneous | |
std::shared_ptr< ScriptInterface > | m_ScriptInterface |
CVector2D | m_MousePos |
don't want to pass this around with the ChooseMouseOverAndClosest broadcast - we'd need to pack this and pNearest in a struct More... | |
unsigned int | m_MouseButtons |
Indicates which buttons are pressed (bit 0 = LMB, bit 1 = RMB, bit 2 = MMB) More... | |
GUITooltip | m_Tooltip |
Objects | |
std::unique_ptr< IGUIObject > | m_BaseObject |
Base Object, all its children are considered parentless because this is not a real object per se. More... | |
IGUIObject * | m_FocusedObject |
Focused object! Say an input box that is selected. More... | |
map_pObjects | m_pAllObjects |
Just pointers for fast name access, each object is really constructed within its parent for easy recursive management. More... | |
int | m_InternalNameNumber |
Number of object that has been given name automatically. More... | |
std::map< CStr, ConstructObjectFunction > | m_ObjectTypes |
Function pointers to functions that constructs IGUIObjects by name... For instance m_ObjectTypes["button"] is filled with a function that will "return new CButton();". More... | |
std::unordered_map< const js::BaseProxyHandler *, std::unique_ptr< GUIProxyProps > > | m_ProxyData |
This is intended to store the JSFunction when accessing certain properties. More... | |
std::map< CStr, std::vector< IGUIObject * > > | m_HotkeyObjects |
Map from hotkey names to objects that listen to the hotkey. More... | |
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 through the event. More... | |
std::map< CStr, const CGUIColor > | m_PreDefinedColors |
std::map< CStr, std::unique_ptr< const CGUISprite > > | m_Sprites |
std::map< CStr, const SGUIStyle > | m_Styles |
std::map< CStr, const SGUIScrollBarStyle > | m_ScrollBarStyles |
std::map< CStr, const SGUIIcon > | m_Icons |
static const CStr | EventNameLoad = "Load" |
XML and JS can subscribe handlers to events identified by these names. More... | |
static const CStr | EventNameTick = "Tick" |
static const CStr | EventNamePress = "Press" |
static const CStr | EventNameKeyDown = "KeyDown" |
static const CStr | EventNameRelease = "Release" |
static const CStr | EventNameMouseRightPress = "MouseRightPress" |
static const CStr | EventNameMouseLeftPress = "MouseLeftPress" |
static const CStr | EventNameMouseWheelDown = "MouseWheelDown" |
static const CStr | EventNameMouseWheelUp = "MouseWheelUp" |
static const CStr | EventNameMouseLeftDoubleClick = "MouseLeftDoubleClick" |
static const CStr | EventNameMouseLeftRelease = "MouseLeftRelease" |
static const CStr | EventNameMouseRightDoubleClick = "MouseRightDoubleClick" |
static const CStr | EventNameMouseRightRelease = "MouseRightRelease" |
std::unordered_map< CStr, std::vector< IGUIObject * > > | m_EventObjects |
Map from event names to object which listen to a given event. More... | |
The main object that represents a whole GUI page.
|
private |
CGUI::CGUI | ( | ScriptContext & | context | ) |
CGUI::~CGUI | ( | ) |
|
private |
The CGUI takes ownership of the child object and links the parent with the child.
Returns false on failure to take over ownership of the child object.
|
inline |
The GUI needs to have all object types inputted and their constructors.
Also it needs to associate a type by a string name of the type.
To add a type:
str | Reference name of object type |
pFunc | Pointer of function ConstuctObject() in the object |
void CGUI::AddObjectTypes | ( | ) |
Informs the GUI page which GUI object types may be constructed from XML.
|
private |
You input the name of the object type, and let's say you input "button", then it will construct a CGUIObjet* as a CButton.
str | Name of object type |
void CGUI::Draw | ( | CCanvas2D & | canvas | ) |
Displays the whole GUI.
void CGUI::DrawSprite | ( | const CGUISpriteInstance & | Sprite, |
CCanvas2D & | canvas, | ||
const CRect & | Rect, | ||
const CRect & | Clipping = CRect() |
||
) |
Draw GUI Sprite.
Sprite | Object referring to the sprite (which also caches calculations for faster rendering) |
Canvas | Canvas to draw on |
Rect | Position and Size |
Clipping | The sprite shouldn't be drawn outside this rectangle |
IGUIObject * CGUI::FindObjectByName | ( | const CStr & | Name | ) | const |
Returns the GUI object with the desired name, or nullptr if no match is found,.
Name | String name of object |
IGUIObject * CGUI::FindObjectUnderMouse | ( | ) |
Returns the GUI object under the mouse, or nullptr if none.
IGUIObject * CGUI::GetBaseObject | ( | ) |
Return the object which is an ancestor of every other GUI object.
|
inline |
Get Focused Object.
|
inline |
Get Icon (a const reference, can never be changed)
|
inline |
Returns the currently pressed mouse buttons.
|
inline |
Returns the current screen coordinates of the cursor.
|
inline |
Resolve the predefined color if it exists, otherwise throws an exception.
|
inline |
|
inline |
const SGUIScrollBarStyle * CGUI::GetScrollBarStyle | ( | const CStr & | style | ) | const |
|
inline |
Get Style if it exists, otherwise throws an exception.
CSize2D CGUI::GetWindowSize | ( | ) | const |
Returns the current GUI window size.
InReaction CGUI::HandleEvent | ( | const SDL_Event_ * | ev | ) |
The replacement of Process(), handles an SDL_Event_.
ev | SDL Event, like mouse/keyboard input |
|
inline |
Check if an icon exists.
|
inline |
Check if a predefined color of that name exists.
|
inline |
Check if a style exists.
void CGUI::LoadedXmlFiles | ( | ) |
Called after all XML files linked in the page file were loaded.
|
private |
bool CGUI::ObjectExists | ( | const CStr & | Name | ) | const |
Checks if object exists and return true or false accordingly.
Name | String name of object |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Reads a string value and modifies the given value of type T if successful.
Does not change the value upon conversion failure.
pGUI | The GUI page which may contain data relevant to the parsing (for example predefined colors). |
Value | The value in string form, like "0 0 100% 100%" |
tOutput | Parsed value of type T |
void CGUI::SendEventToAll | ( | const CStr & | eventName | ) |
Sends a specified script event to every object.
eventName | String representation of event name |
void CGUI::SendEventToAll | ( | const CStr & | eventName, |
const JS::HandleValueArray & | paramData | ||
) |
Sends a specified script event to every object.
eventName | String representation of event name |
paramData | JS::HandleValueArray storing the arguments passed to the event handler. |
void CGUI::SendFocusMessage | ( | EGUIMessageType | msg | ) |
Alert the focussed object of this GUIPage that the focus of the page has changed.
void CGUI::SetFocusedObject | ( | IGUIObject * | pObject | ) |
Change focus to new object.
Will send LOST_FOCUS/GOT_FOCUS messages as appropriate. pObject can be nullptr to remove all focus.
void CGUI::SetGlobalHotkey | ( | const CStr & | hotkeyTag, |
const CStr & | eventName, | ||
JS::HandleValue | function | ||
) |
Allows the JS side to add or remove global hotkeys.
void CGUI::SetObjectHotkey | ( | IGUIObject * | pObject, |
const CStr & | hotkeyTag | ||
) |
Allows the JS side to modify the hotkey setting assigned to a GUI object.
void CGUI::SetObjectStyle | ( | IGUIObject * | pObject, |
const CStr & | styleName | ||
) |
Allows the JS side to modify the style setting assigned to a GUI object.
void CGUI::TickObjects | ( | ) |
Performs processing that should happen every frame (including sending the "Tick" event to scripts)
void CGUI::UnsetGlobalHotkey | ( | const CStr & | hotkeyTag, |
const CStr & | eventName | ||
) |
void CGUI::UnsetObjectHotkey | ( | IGUIObject * | pObject, |
const CStr & | hotkeyTag | ||
) |
void CGUI::UnsetObjectStyle | ( | IGUIObject * | pObject | ) |
void CGUI::UpdateResolution | ( | ) |
Update Resolution, should be called every time the resolution of the OpenGL screen has been changed, this is because it needs to re-cache all its actual sizes.
Needs no input since screen resolution is global.
|
private |
Reads in the element <color> (the XMBElement) and stores the result in m_PreDefinedColors.
Element | The Xeromyces object that represents the scrollbar-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the element <effect> (the XMBElement) and stores the result within the SGUIImageEffects.
Element | The Xeromyces object that represents the image-tag. |
pFile | The Xeromyces object for the file being read |
effects | Effects object to add this effect to. |
|
private |
Reads in the element <icon> (the XMBElement) and stores the result in m_Icons.
Element | The Xeromyces object that represents the scrollbar-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the element <image> (the XMBElement) and stores the result within the CGUISprite.
Element | The Xeromyces object that represents the image-tag. |
pFile | The Xeromyces object for the file being read |
parent | Parent sprite. |
|
private |
Notice! Recursive function!
Read in an <object> (the XMBElement) and stores it as a child in the pParent.
It will also check the object's children and call this function on them too. Also it will call all other functions that reads in other stuff that can be found within an object. Check the tree in the beginning of this class' Xeromyces_* section.
Element | The Xeromyces object that represents the object-tag. |
pFile | The Xeromyces object for the file being read |
pParent | Parent to add this object as child in. |
NameSubst | A set of substitution strings that will be applied to all object names within this object. |
Paths | Output set of file paths that this GUI object relies on. |
|
private |
Reads in the element <repeat>, which repeats its child <object>s 'count' times, replacing the string "[n]" (or the value of the attribute 'var' enclosed in square brackets) in its descendants' names with "[0]", "[1]", etc.
|
private |
Reads in the root element <objects> (the DOMElement).
Element | The Xeromyces object that represents the objects-tag. |
pFile | The Xeromyces object for the file being read |
Paths | Collects the set of all XML/JS files that are loaded |
|
private |
Reads in the root element <setup> (the DOMElement).
Element | The Xeromyces object that represents the setup-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the root element <sprites> (the DOMElement).
Element | The Xeromyces object that represents the sprites-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the root element <styles> (the DOMElement).
Element | The Xeromyces object that represents the styles-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the element <script> (the XMBElement) and executes the script's code.
Element | The Xeromyces object that represents the script-tag. |
pFile | The Xeromyces object for the file being read |
Paths | Output set of file paths that this script is loaded from. |
|
private |
Reads in the element <scrollbar> (the XMBElement) and stores the result in m_ScrollBarStyles.
Element | The Xeromyces object that represents the scrollbar-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the element <sprite> (the XMBElement) and stores the result in a new CGUISprite.
Element | The Xeromyces object that represents the sprite-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the element <style> (the XMBElement) and stores the result in m_Styles.
Element | The Xeromyces object that represents the style-tag. |
pFile | The Xeromyces object for the file being read |
|
private |
Reads in the element <tooltip> (the XMBElement) and stores the result as an object with the name __tooltip_#.
Element | The Xeromyces object that represents the scrollbar-tag. |
pFile | The Xeromyces object for the file being read |
|
staticprivate |
|
staticprivate |
XML and JS can subscribe handlers to events identified by these names.
Store in static const members to avoid string copies, gain compile errors when misspelling and to allow reuse in other classes.
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
Base Object, all its children are considered parentless because this is not a real object per se.
std::unordered_map<CStr, std::vector<IGUIObject*> > CGUI::m_EventObjects |
Map from event names to object which listen to a given event.
|
private |
Focused object! Say an input box that is selected.
That one is focused. There can only be one focused object.
|
private |
Map from hotkey names to maps of eventNames to functions that are triggered when the hotkey goes through the event.
Contrary to object hotkeys, this allows for only one global function per hotkey name per event type.
|
private |
Map from hotkey names to objects that listen to the hotkey.
(This is an optimisation to avoid recursing over the whole GUI tree every time a hotkey is pressed).
|
private |
|
private |
Number of object that has been given name automatically.
the name given will be '__internal(#)', the number (#) being this variable. When an object's name has been set as followed, the value will increment.
|
private |
Indicates which buttons are pressed (bit 0 = LMB, bit 1 = RMB, bit 2 = MMB)
|
private |
don't want to pass this around with the ChooseMouseOverAndClosest broadcast - we'd need to pack this and pNearest in a struct
|
private |
Function pointers to functions that constructs IGUIObjects by name... For instance m_ObjectTypes["button"] is filled with a function that will "return new CButton();".
|
private |
Just pointers for fast name access, each object is really constructed within its parent for easy recursive management.
Notice m_BaseObject won't belong here since it's not considered a real object.
|
private |
|
private |
This is intended to store the JSFunction when accessing certain properties.
The problem is that these functions are per-scriptInterface, and proxy handlers aren't. So we know what we want to store, but we don't really have anywhere to store it. It would be simpler to recreate the functions on every JS call, but that is slower (this may or may not matter now and in the future). It's not a great solution, but I can't find a better one at the moment. An alternative would be to store these on the proxy's prototype, but that embarks a lot of un-necessary code.
|
private |
|
private |
|
private |
|
private |
|
private |