Pyrogenesis  trunk
Public Member Functions | Private Types | Private Member Functions | Friends | List of all members
CGUI Class Reference

The main object that represents a whole GUI page. More...

#include <CGUI.h>

Collaboration diagram for CGUI:
Collaboration graph
[legend]

Public Member Functions

 CGUI (const shared_ptr< ScriptRuntime > &runtime)
 
 ~CGUI ()
 
void Initialize ()
 Initializes the GUI, needs to be called before the GUI is used. 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 Draw ()
 Displays the whole GUI. More...
 
void DrawSprite (const CGUISpriteInstance &Sprite, int CellID, const float &Z, const CRect &Rect, const CRect &Clipping=CRect())
 Draw GUI Sprite. More...
 
void DrawText (SGUIText &Text, const CColor &DefaultColor, const CPos &pos, const float &z, const CRect &clipping)
 Draw a SGUIText object. More...
 
void Destroy ()
 Clean up, call this to clean up all memory allocated within the GUI. More...
 
InReaction HandleEvent (const SDL_Event_ *ev)
 The replacement of Process(), handles an SDL_Event_. More...
 
void LoadXmlFile (const VfsPath &Filename, boost::unordered_set< VfsPath > &Paths)
 Load a GUI XML file into the GUI. More...
 
bool ObjectExists (const CStr &Name) const
 Checks if object exists and return true or false accordingly. More...
 
IGUIObjectFindObjectByName (const CStr &Name) const
 Returns the GUI object with the desired name, or NULL if no match is found,. More...
 
IGUIObjectFindObjectUnderMouse () const
 Returns the GUI object under the mouse, or NULL if none. 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...
 
SGUIText GenerateText (const CGUIString &Text, const CStrW &Font, const float &Width, const float &BufferZone, const IGUIObject *pObject=NULL)
 Generate a SGUIText object from the inputted string. More...
 
bool IconExists (const CStr &str) const
 Check if an icon exists. More...
 
SGUIIcon GetIcon (const CStr &str) const
 Get Icon (a copy, can never be changed) More...
 
bool GetPreDefinedColor (const CStr &name, CColor &Output) const
 Get pre-defined color (if it exists) Returns false if it fails. More...
 
shared_ptr< ScriptInterfaceGetScriptInterface ()
 
jsval GetGlobalObject ()
 
void SetFocusedObject (IGUIObject *pObject)
 Change focus to new object. More...
 

Private Types

typedef IGUIObject *(* ConstructObjectFunction) ()
 

Private Member Functions

 NONCOPYABLE (CGUI)
 
void UpdateObjects ()
 Updates the object pointers, needs to be called each time an object has been added or removed. More...
 
void AddObject (IGUIObject *pObject)
 Adds an object to the GUI's object database Private, since you can only add objects through XML files. More...
 
IGUIObjectConstructObject (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...
 
IGUIObjectGetFocusedObject ()
 Get Focused Object. 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 (XMBElement Element, CXeromyces *pFile, boost::unordered_set< VfsPath > &Paths)
 Reads in the root element <objects> (the DOMElement). More...
 
void Xeromyces_ReadRootSprites (XMBElement Element, CXeromyces *pFile)
 Reads in the root element <sprites> (the DOMElement). More...
 
void Xeromyces_ReadRootStyles (XMBElement Element, CXeromyces *pFile)
 Reads in the root element <styles> (the DOMElement). More...
 
void Xeromyces_ReadRootSetup (XMBElement Element, CXeromyces *pFile)
 Reads in the root element <setup> (the DOMElement). More...
 
void Xeromyces_ReadObject (XMBElement Element, CXeromyces *pFile, IGUIObject *pParent, std::vector< std::pair< CStr, CStr > > &NameSubst, boost::unordered_set< VfsPath > &Paths, u32 nesting_depth)
 Notice! Recursive function! More...
 
void Xeromyces_ReadRepeat (XMBElement Element, CXeromyces *pFile, IGUIObject *pParent, std::vector< std::pair< CStr, CStr > > &NameSubst, boost::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 (XMBElement Element, CXeromyces *pFile, boost::unordered_set< VfsPath > &Paths)
 Reads in the element <script> (the XMBElement) and executes the script's code. More...
 
void Xeromyces_ReadSprite (XMBElement Element, CXeromyces *pFile)
 Reads in the element <sprite> (the XMBElement) and stores the result in a new CGUISprite. More...
 
void Xeromyces_ReadImage (XMBElement Element, CXeromyces *pFile, CGUISprite &parent)
 Reads in the element <image> (the XMBElement) and stores the result within the CGUISprite. More...
 
void Xeromyces_ReadEffects (XMBElement Element, CXeromyces *pFile, SGUIImageEffects &effects)
 Reads in the element <effect> (the XMBElement) and stores the result within the SGUIImageEffects. More...
 
void Xeromyces_ReadStyle (XMBElement Element, CXeromyces *pFile)
 Reads in the element <style> (the XMBElement) and stores the result in m_Styles. More...
 
void Xeromyces_ReadScrollBarStyle (XMBElement Element, CXeromyces *pFile)
 Reads in the element <scrollbar> (the XMBElement) and stores the result in m_ScrollBarStyles. More...
 
void Xeromyces_ReadIcon (XMBElement Element, CXeromyces *pFile)
 Reads in the element <icon> (the XMBElement) and stores the result in m_Icons. More...
 
void Xeromyces_ReadTooltip (XMBElement Element, CXeromyces *pFile)
 Reads in the element <tooltip> (the XMBElement) and stores the result as an object with the name __tooltip_#. More...
 
void Xeromyces_ReadColor (XMBElement Element, CXeromyces *pFile)
 Reads in the element <color> (the XMBElement) and stores the result in m_PreDefinedColors. More...
 

Private Attributes

Miscellaneous
shared_ptr< ScriptInterfacem_ScriptInterface
 
CPos 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
 
std::map< CStr, CColorm_PreDefinedColors
 This is a bank of custom colors, it is simply a look up table that will return a color object when someone inputs the name of that color. More...
 
Objects
IGUIObjectm_BaseObject
 Base Object, all its children are considered parentless because this is not a real object per se. More...
 
IGUIObjectm_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, ConstructObjectFunctionm_ObjectTypes
 Function pointers to functions that constructs IGUIObjects by name... More...
 
std::map< CStr, std::vector< IGUIObject * > > m_HotkeyObjects
 Map from hotkey names to objects that listen to the hotkey. More...
 
std::map< CStr, CGUISprite * > m_Sprites
 
std::map< CStr, SGUIStylem_Styles
 
std::map< CStr, SGUIScrollBarStylem_ScrollBarStyles
 
std::map< CStr, SGUIIconm_Icons
 

Friends

class IGUIObject
 
class IGUIScrollBarOwner
 
class CInternalCGUIAccessorBase
 

Detailed Description

The main object that represents a whole GUI page.

No interfacial functions throws.

Member Typedef Documentation

typedef IGUIObject*(* CGUI::ConstructObjectFunction) ()
private

Constructor & Destructor Documentation

CGUI::CGUI ( const shared_ptr< ScriptRuntime > &  runtime)
CGUI::~CGUI ( )

Member Function Documentation

void CGUI::AddObject ( IGUIObject pObject)
private

Adds an object to the GUI's object database Private, since you can only add objects through XML files.

Why? Because it enables the GUI to be much more encapsulated and safe.

Exceptions
RethrowsPSERROR_GUI from IGUIObject::AddChild().
void CGUI::AddObjectType ( const CStr &  str,
ConstructObjectFunction  pFunc 
)
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:

AddObjectType("button", &CButton::ConstructObject);
Parameters
strReference name of object type
pFuncPointer of function ConstuctObject() in the object
See also
CGUI::ConstructObject()
IGUIObject * CGUI::ConstructObject ( const CStr &  str)
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.

Parameters
strName of object type
Returns
Newly constructed IGUIObject (but constructed as a subclass)
void CGUI::Destroy ( )

Clean up, call this to clean up all memory allocated within the GUI.

void CGUI::Draw ( )

Displays the whole GUI.

void CGUI::DrawSprite ( const CGUISpriteInstance Sprite,
int  CellID,
const float &  Z,
const CRect Rect,
const CRect Clipping = CRect() 
)

Draw GUI Sprite.

Parameters
SpriteObject referring to the sprite (which also caches calculations for faster rendering)
CellIDNumber of the icon cell to use. (Ignored if this sprite doesn't have any images with "cell-size")
ZDrawing order, depth value
RectPosition and Size
ClippingThe sprite shouldn't be drawn outside this rectangle
void CGUI::DrawText ( SGUIText Text,
const CColor DefaultColor,
const CPos pos,
const float &  z,
const CRect clipping 
)

Draw a SGUIText object.

Parameters
TextText object.
DefaultColorColor used if no tag applied.
posposition
zz value.
clipping
IGUIObject * CGUI::FindObjectByName ( const CStr &  Name) const

Returns the GUI object with the desired name, or NULL if no match is found,.

Parameters
NameString name of object
Returns
Matching object, or NULL
IGUIObject * CGUI::FindObjectUnderMouse ( ) const

Returns the GUI object under the mouse, or NULL if none.

SGUIText CGUI::GenerateText ( const CGUIString Text,
const CStrW &  Font,
const float &  Width,
const float &  BufferZone,
const IGUIObject pObject = NULL 
)

Generate a SGUIText object from the inputted string.

The function will break down the string and its tags to calculate exactly which rendering queries will be sent to the Renderer. Also, horizontal alignment is taken into acount in this method but NOT vertical alignment.

Done through the CGUI since it can communicate with

Parameters
TextText to generate SGUIText object from
FontDefault font, notice both Default color and default font can be changed by tags.
WidthWidth, 0 if no word-wrapping.
BufferZonespace between text and edge, and space between text and images.
pObjectOptional parameter for error output. Used only if error parsing fails, and we need to be able to output which object the error occured in to aid the user.
IGUIObject* CGUI::GetFocusedObject ( )
inlineprivate

Get Focused Object.

jsval CGUI::GetGlobalObject ( )
inline
SGUIIcon CGUI::GetIcon ( const CStr &  str) const
inline

Get Icon (a copy, can never be changed)

bool CGUI::GetPreDefinedColor ( const CStr &  name,
CColor Output 
) const

Get pre-defined color (if it exists) Returns false if it fails.

shared_ptr<ScriptInterface> CGUI::GetScriptInterface ( )
inline
InReaction CGUI::HandleEvent ( const SDL_Event_ ev)

The replacement of Process(), handles an SDL_Event_.

Parameters
evSDL Event, like mouse/keyboard input
bool CGUI::IconExists ( const CStr &  str) const
inline

Check if an icon exists.

void CGUI::Initialize ( )

Initializes the GUI, needs to be called before the GUI is used.

void CGUI::LoadXmlFile ( const VfsPath Filename,
boost::unordered_set< VfsPath > &  Paths 
)

Load a GUI XML file into the GUI.

VERY IMPORTANT! All <styles>-files must be read before everything else!

Parameters
FilenameName of file
PathsSet of paths; all XML and JS files loaded will be added to this

Here is the call graph for this function:

CGUI::NONCOPYABLE ( CGUI  )
private
bool CGUI::ObjectExists ( const CStr &  Name) const

Checks if object exists and return true or false accordingly.

Parameters
NameString name of object
Returns
true if object exists
void CGUI::SendEventToAll ( const CStr &  EventName)

Sends a specified script event to every object.

Parameters
EventNameString representation of event name
void CGUI::SetFocusedObject ( IGUIObject pObject)

Change focus to new object.

Will send LOST_FOCUS/GOT_FOCUS messages as appropriate. pObject can be NULL to remove all focus.

void CGUI::TickObjects ( )

Performs processing that should happen every frame (including sending the "Tick" event to scripts)

void CGUI::UpdateObjects ( )
private

Updates the object pointers, needs to be called each time an object has been added or removed.

This function is atomic, meaning if it throws anything, it will have seen it through that nothing was ultimately changed.

Exceptions
PSERROR_GUIthat is thrown from IGUIObject::AddToPointersMap().
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.

See also
IGUIObject::UpdateCachedSize()
void CGUI::Xeromyces_ReadColor ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the element <color> (the XMBElement) and stores the result in m_PreDefinedColors.

Parameters
ElementThe Xeromyces object that represents the scrollbar-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadEffects ( XMBElement  Element,
CXeromyces pFile,
SGUIImageEffects effects 
)
private

Reads in the element <effect> (the XMBElement) and stores the result within the SGUIImageEffects.

Parameters
ElementThe Xeromyces object that represents the image-tag.
pFileThe Xeromyces object for the file being read
effectsEffects object to add this effect to.
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadIcon ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the element <icon> (the XMBElement) and stores the result in m_Icons.

Parameters
ElementThe Xeromyces object that represents the scrollbar-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadImage ( XMBElement  Element,
CXeromyces pFile,
CGUISprite parent 
)
private

Reads in the element <image> (the XMBElement) and stores the result within the CGUISprite.

Parameters
ElementThe Xeromyces object that represents the image-tag.
pFileThe Xeromyces object for the file being read
parentParent sprite.
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadObject ( XMBElement  Element,
CXeromyces pFile,
IGUIObject pParent,
std::vector< std::pair< CStr, CStr > > &  NameSubst,
boost::unordered_set< VfsPath > &  Paths,
u32  nesting_depth 
)
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.

Parameters
ElementThe Xeromyces object that represents the object-tag.
pFileThe Xeromyces object for the file being read
pParentParent to add this object as child in.
NameSubstA set of substitution strings that will be applied to all object names within this object.
PathsOutput set of file paths that this GUI object relies on.
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadRepeat ( XMBElement  Element,
CXeromyces pFile,
IGUIObject pParent,
std::vector< std::pair< CStr, CStr > > &  NameSubst,
boost::unordered_set< VfsPath > &  Paths,
u32  nesting_depth 
)
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.

void CGUI::Xeromyces_ReadRootObjects ( XMBElement  Element,
CXeromyces pFile,
boost::unordered_set< VfsPath > &  Paths 
)
private

Reads in the root element <objects> (the DOMElement).

Parameters
ElementThe Xeromyces object that represents the objects-tag.
pFileThe Xeromyces object for the file being read
PathsCollects the set of all XML/JS files that are loaded
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadRootSetup ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the root element <setup> (the DOMElement).

Parameters
ElementThe Xeromyces object that represents the setup-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadRootSprites ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the root element <sprites> (the DOMElement).

Parameters
ElementThe Xeromyces object that represents the sprites-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadRootStyles ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the root element <styles> (the DOMElement).

Parameters
ElementThe Xeromyces object that represents the styles-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadScript ( XMBElement  Element,
CXeromyces pFile,
boost::unordered_set< VfsPath > &  Paths 
)
private

Reads in the element <script> (the XMBElement) and executes the script's code.

Parameters
ElementThe Xeromyces object that represents the script-tag.
pFileThe Xeromyces object for the file being read
PathsOutput set of file paths that this script is loaded from.
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadScrollBarStyle ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the element <scrollbar> (the XMBElement) and stores the result in m_ScrollBarStyles.

Parameters
ElementThe Xeromyces object that represents the scrollbar-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadSprite ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the element <sprite> (the XMBElement) and stores the result in a new CGUISprite.

Parameters
ElementThe Xeromyces object that represents the sprite-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadStyle ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the element <style> (the XMBElement) and stores the result in m_Styles.

Parameters
ElementThe Xeromyces object that represents the style-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()
void CGUI::Xeromyces_ReadTooltip ( XMBElement  Element,
CXeromyces pFile 
)
private

Reads in the element <tooltip> (the XMBElement) and stores the result as an object with the name __tooltip_#.

Parameters
ElementThe Xeromyces object that represents the scrollbar-tag.
pFileThe Xeromyces object for the file being read
See also
LoadXmlFile()

Friends And Related Function Documentation

friend class CInternalCGUIAccessorBase
friend
friend class IGUIObject
friend
friend class IGUIScrollBarOwner
friend

Member Data Documentation

IGUIObject* CGUI::m_BaseObject
private

Base Object, all its children are considered parentless because this is not a real object per se.

IGUIObject* CGUI::m_FocusedObject
private

Focused object! Say an input box that is selected.

That one is focused. There can only be one focused object.

std::map<CStr, std::vector<IGUIObject*> > CGUI::m_HotkeyObjects
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). Currently this is only set at load time - dynamic changes to an object's hotkey property will be ignored.

std::map<CStr, SGUIIcon> CGUI::m_Icons
private
int CGUI::m_InternalNameNumber
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.

unsigned int CGUI::m_MouseButtons
private

Indicates which buttons are pressed (bit 0 = LMB, bit 1 = RMB, bit 2 = MMB)

CPos CGUI::m_MousePos
private

don't want to pass this around with the ChooseMouseOverAndClosest broadcast - we'd need to pack this and pNearest in a struct

std::map<CStr, ConstructObjectFunction> CGUI::m_ObjectTypes
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();"

map_pObjects CGUI::m_pAllObjects
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.

std::map<CStr, CColor> CGUI::m_PreDefinedColors
private

This is a bank of custom colors, it is simply a look up table that will return a color object when someone inputs the name of that color.

Of course the colors have to be declared in XML, there are no hard-coded values.

shared_ptr<ScriptInterface> CGUI::m_ScriptInterface
private
std::map<CStr, SGUIScrollBarStyle> CGUI::m_ScrollBarStyles
private
std::map<CStr, CGUISprite*> CGUI::m_Sprites
private
std::map<CStr, SGUIStyle> CGUI::m_Styles
private
GUITooltip CGUI::m_Tooltip
private

The documentation for this class was generated from the following files: