Pyrogenesis  trunk
Public Member Functions | Friends | List of all members
IGUIObject Class Referenceabstract

Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found in the documentations. More...

#include <IGUIObject.h>

Inheritance diagram for IGUIObject:
Inheritance graph
[legend]
Collaboration diagram for IGUIObject:
Collaboration graph
[legend]

Public Member Functions

 IGUIObject ()
 
virtual ~IGUIObject ()
 
virtual bool MouseOver ()
 Checks if mouse is hovering this object. More...
 
virtual bool MouseOverIcon ()
 Test if mouse position is over an icon. More...
 
Leaf Functions
const CStr & GetName () const
 Get object name, name is unique. More...
 
void SetName (const CStr &Name)
 Get object name. More...
 
CStr GetPresentableName () const
 
void AddToPointersMap (map_pObjects &ObjectMap)
 Adds object and its children to the map, it's name being the first part, and the second being itself. More...
 
void AddChild (IGUIObject *pChild)
 Notice nothing will be returned or thrown if the child hasn't been inputted into the GUI yet. More...
 
Iterate

Used to iterate over all children of this object.

vector_pObjects::iterator begin ()
 
vector_pObjects::iterator end ()
 
Settings Management
bool SettingExists (const CStr &Setting) const
 Checks if settings exists, only available for derived classes that has this set up, that's why the base class just returns false. More...
 
virtual void UpdateCachedSize ()
 All sizes are relative to resolution, and the calculation is not wanted in real time, therefore it is cached, update the cached size with this function. More...
 
PSRETURN SetSetting (const CStr &Setting, const CStrW &Value, const bool &SkipMessage=false)
 Set a setting by string, regardless of what type it is. More...
 
PSRETURN GetSettingType (const CStr &Setting, EGUISettingType &Type) const
 Retrieves the type of a named setting. More...
 
void RegisterScriptHandler (const CStr &Action, const CStr &Code, CGUI *pGUI)
 Set the script handler for a particular object-specific action. More...
 
JSObject * GetJSObject ()
 Retrieves the JSObject representing this GUI object. More...
 

Friends

class CGUI
 
class CInternalCGUIAccessorBase
 
class IGUIScrollBar
 
class GUITooltip
 
bool JSI_IGUIObject::getProperty (JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
 
bool JSI_IGUIObject::setProperty (JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp)
 
bool JSI_IGUIObject::getComputedSize (JSContext *cx, uint argc, jsval *vp)
 

Called by CGUI and friends

Methods that the CGUI will call using its friendship, these should not be called by user.

These functions' security are a lot what constitutes the GUI's

CRect m_CachedActualSize
 Cached size, real size m_Size is actually dependent on resolution and can have different real outcomes, this is the real outcome cached to avoid slow calculations in real time. More...
 
virtual void HandleMessage (SGUIMessage &Message)
 This function is called with different messages for instance when the mouse enters the object. More...
 
CGUIGetGUI ()
 
const CGUIGetGUI () const
 
void SetFocus ()
 Take focus! More...
 
void AddSetting (const EGUISettingType &Type, const CStr &Name)
 Add a setting to m_Settings. More...
 
virtual void Destroy ()
 Calls Destroy on all children, and deallocates all memory. More...
 
virtual void Draw ()=0
 Draws the object. More...
 
virtual InReaction ManuallyHandleEvent (const SDL_Event_ *ev)
 Some objects need to handle the SDL_Event_ manually. More...
 
void LoadStyle (CGUI &GUIinstance, const CStr &StyleName)
 Loads a style. More...
 
void LoadStyle (const SGUIStyle &Style)
 Loads a style. More...
 
virtual float GetBufferedZ () const
 Returns not the Z value, but the actual buffered Z value, i.e. More...
 
void SetGUI (CGUI *const &pGUI)
 
void SetParent (IGUIObject *pParent)
 Set parent of this object. More...
 
virtual void ResetStates ()
 Reset internal state of this object. More...
 
bool IsFocused () const
 Check if object is focused. More...
 
IGUIObjectGetParent () const
 NOTE! This will not just return m_pParent, when that is need use it! There is one exception to it, when the parent is the top-node (the object that isn't a real object), this will return NULL, so that the top-node's children are seemingly parentless. More...
 
CPos GetMousePos () const
 Get Mouse from CGUI. More...
 
virtual bool HandleAdditionalChildren (const XMBElement &child, CXeromyces *pFile)
 Handle additional children to the <object>-tag. More...
 
InReaction SendEvent (EGUIMessageType type, const CStr &EventName)
 Send event to this GUI object (HandleMessage and ScriptEvent) More...
 
void ScriptEvent (const CStr &Action)
 Execute the script for a particular action. More...
 
void ScriptEvent (const CStr &Action, JS::HandleValue Argument)
 Execute the script for a particular action. More...
 
void SetScriptHandler (const CStr &Action, JS::HandleObject Function)
 
void UpdateMouseOver (IGUIObject *const &pMouseOver)
 Inputes the object that is currently hovered, this function updates this object accordingly (i.e. More...
 

Internal functions

CStr m_Name
 
vector_pObjects m_Children
 
IGUIObjectm_pParent
 
double m_LastClickTime [6]
 
bool m_MouseHovering
 This is an array of true or false, each element is associated with a string representing a setting. More...
 
std::map< CStr, SGUISettingm_Settings
 Settings pool, all an object's settings are located here If a derived object has got more settings that the base settings, it's because they have a new version of the function SetupSettings(). More...
 
CGUIm_pGUI
 
std::map< CStr, JS::Heap< JSObject * > > m_ScriptHandlers
 
JS::PersistentRootedObject m_JSObject
 
void ChooseMouseOverAndClosest (IGUIObject *&pObject)
 Inputs a reference pointer, checks if the new inputted object if hovered, if so, then check if this's Z value is greater than the inputted object... More...
 
bool IsRootObject () const
 
PSRETURN LogInvalidSettings (const CStr8 &Setting) const
 Logs an invalid setting search and returns the correct return result. More...
 
void TraceMember (JSTracer *trc)
 
static void Trace (JSTracer *trc, void *data)
 

Detailed Description

Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found in the documentations.

GUI object such as a button or an input-box. Abstract data type !

Constructor & Destructor Documentation

IGUIObject::IGUIObject ( )
IGUIObject::~IGUIObject ( )
virtual

Member Function Documentation

void IGUIObject::AddChild ( IGUIObject pChild)

Notice nothing will be returned or thrown if the child hasn't been inputted into the GUI yet.

This is because that's were all is checked. Now we're just linking two objects, but it's when we're inputting them into the GUI we'll check validity! Notice also when adding it to the GUI this function will inevitably have been called by CGUI::AddObject which will catch the throw and return the error code. i.e. The user will never put in the situation wherein a throw must be caught, the GUI's internal error handling will be completely transparent to the interfacially sequential model.

Parameters
pChildChild to add
Exceptions
PSERROR_GUIfrom CGUI::UpdateObjects().
void IGUIObject::AddSetting ( const EGUISettingType Type,
const CStr &  Name 
)
protected

Add a setting to m_Settings.

Parameters
TypeSetting type
NameSetting reference name
void IGUIObject::AddToPointersMap ( map_pObjects ObjectMap)

Adds object and its children to the map, it's name being the first part, and the second being itself.

Parameters
ObjectMapAdds this to the map_pObjects.
Exceptions
PSERROR_GUI_ObjectNeedsNameName is missing
PSERROR_GUI_NameAmbiguityName is already taken
vector_pObjects::iterator IGUIObject::begin ( )
inline
void IGUIObject::ChooseMouseOverAndClosest ( IGUIObject *&  pObject)
private

Inputs a reference pointer, checks if the new inputted object if hovered, if so, then check if this's Z value is greater than the inputted object...

If so then the object is closer and we'll replace the pointer with this. Also Notice input can be NULL, which means the Z value demand is out. NOTICE you can't input NULL as const so you'll have to set an object to NULL.

Parameters
pObjectObject pointer, can be either the old one, or the new one.
void IGUIObject::Destroy ( )
protectedvirtual

Calls Destroy on all children, and deallocates all memory.

MEGA TODO Should it destroy it's children?

Reimplemented in CMiniMap.

virtual void IGUIObject::Draw ( )
protectedpure virtual

Draws the object.

Exceptions
PSERRORif any. But this will mostlikely be very rare since if an object is drawn unsuccessfully it'll probably only output in the Error log, and not disrupt the whole GUI drawing.

Implemented in CGUIDummyObject, CInput, CDropDown, CList, CText, CChart, CCheckBox, CButton, CImage, CTooltip, IGUIScrollBarOwner, CProgressBar, and CMiniMap.

vector_pObjects::iterator IGUIObject::end ( )
inline
float IGUIObject::GetBufferedZ ( ) const
protectedvirtual

Returns not the Z value, but the actual buffered Z value, i.e.

if it's defined relative, then it will check its parent's Z value and add the relativity.

Returns
Actual Z value on the screen.

Reimplemented in CDropDown.

CGUI* IGUIObject::GetGUI ( )
inline
const CGUI* IGUIObject::GetGUI ( ) const
inline
JSObject * IGUIObject::GetJSObject ( )

Retrieves the JSObject representing this GUI object.

CPos IGUIObject::GetMousePos ( ) const
protected

Get Mouse from CGUI.

const CStr& IGUIObject::GetName ( ) const
inline

Get object name, name is unique.

IGUIObject * IGUIObject::GetParent ( ) const
protected

NOTE! This will not just return m_pParent, when that is need use it! There is one exception to it, when the parent is the top-node (the object that isn't a real object), this will return NULL, so that the top-node's children are seemingly parentless.

Returns
Pointer to parent
CStr IGUIObject::GetPresentableName ( ) const
PSRETURN IGUIObject::GetSettingType ( const CStr &  Setting,
EGUISettingType Type 
) const

Retrieves the type of a named setting.

Parameters
SettingSetting by name
TypeStores an EGUISettingType
Returns
PSRETURN (PSRETURN_OK if successful)
virtual bool IGUIObject::HandleAdditionalChildren ( const XMBElement child,
CXeromyces pFile 
)
inlineprotectedvirtual

Handle additional children to the <object>-tag.

In IGUIObject, this function does nothing. In CList and CDropDown, it handles the <item>, used to build the data.

Returning false means the object doesn't recognize the child. Should be reported. Notice 'false' is default, because an object not using this function, should not have any additional children (and this function should never be called).

Reimplemented in CList, and COList.

virtual void IGUIObject::HandleMessage ( SGUIMessage Message)
inlinevirtual

This function is called with different messages for instance when the mouse enters the object.

Parameters
MessageGUI Message

Reimplemented in CDropDown, CInput, CList, IGUITextOwner, IGUIButtonBehavior, CText, COList, CChart, CCheckBox, CProgressBar, IGUIScrollBarOwner, CButton, CTooltip, CMiniMap, and CRadioButton.

bool IGUIObject::IsFocused ( ) const
protected

Check if object is focused.

bool IGUIObject::IsRootObject ( ) const
private
void IGUIObject::LoadStyle ( CGUI GUIinstance,
const CStr &  StyleName 
)
protected

Loads a style.

Parameters
GUIinstanceReference to the GUI
StyleNameStyle by name
void IGUIObject::LoadStyle ( const SGUIStyle Style)
protected

Loads a style.

Parameters
StyleThe style object.
PSRETURN IGUIObject::LogInvalidSettings ( const CStr8 &  Setting) const
private

Logs an invalid setting search and returns the correct return result.

Returns
the error result
virtual InReaction IGUIObject::ManuallyHandleEvent ( const SDL_Event_ ev)
inlineprotectedvirtual

Some objects need to handle the SDL_Event_ manually.

For instance the input box.

Only the object with focus will have this function called.

Returns either IN_PASS or IN_HANDLED. If IN_HANDLED, then the key won't be passed on and processed by other handlers. This is used for keys that the GUI uses.

Reimplemented in CDropDown, CInput, and CList.

bool IGUIObject::MouseOver ( )
virtual

Checks if mouse is hovering this object.

The mouse position is cached in CGUI.

This function checks if the mouse is hovering the rectangle that the base setting "size" makes. Although it is virtual, so one could derive an object from CButton, which changes only this to checking the circle that "size" makes.

Returns
true if mouse is hovering

Reimplemented in CGUIDummyObject, CDropDown, and CMiniMap.

bool IGUIObject::MouseOverIcon ( )
virtual

Test if mouse position is over an icon.

Reimplemented in IGUITextOwner, and CText.

void IGUIObject::RegisterScriptHandler ( const CStr &  Action,
const CStr &  Code,
CGUI pGUI 
)

Set the script handler for a particular object-specific action.

Parameters
ActionName of action
CodeJavascript code to execute when the action occurs
pGUIGUI instance to associate the script with
virtual void IGUIObject::ResetStates ( )
inlineprotectedvirtual

Reset internal state of this object.

Reimplemented in IGUIButtonBehavior, IGUIScrollBarOwner, CInput, CList, CCheckBox, CButton, and CText.

void IGUIObject::ScriptEvent ( const CStr &  Action)
protected

Execute the script for a particular action.

Does nothing if no script has been registered for that action. The mouse coordinates will be passed as the first argument.

Parameters
ActionName of action
void IGUIObject::ScriptEvent ( const CStr &  Action,
JS::HandleValue  Argument 
)
protected

Execute the script for a particular action.

Does nothing if no script has been registered for that action.

Parameters
ActionName of action
ArgumentArgument to pass to action
InReaction IGUIObject::SendEvent ( EGUIMessageType  type,
const CStr &  EventName 
)
protected

Send event to this GUI object (HandleMessage and ScriptEvent)

Parameters
typeType of GUI message to be handled
EventNameString representation of event name
Returns
IN_HANDLED if event was handled, or IN_PASS if skipped
void IGUIObject::SetFocus ( )

Take focus!

void IGUIObject::SetGUI ( CGUI *const &  pGUI)
protected
void IGUIObject::SetName ( const CStr &  Name)
inline

Get object name.

void IGUIObject::SetParent ( IGUIObject pParent)
inlineprotected

Set parent of this object.

void IGUIObject::SetScriptHandler ( const CStr &  Action,
JS::HandleObject  Function 
)
protected
PSRETURN IGUIObject::SetSetting ( const CStr &  Setting,
const CStrW &  Value,
const bool &  SkipMessage = false 
)

Set a setting by string, regardless of what type it is.

example a CRect(10,10,20,20) would be "10 10 20 20"

Parameters
SettingSetting by name
ValueValue to set to
SkipMessageDoes not send a GUIM_SETTINGS_UPDATED if true
Returns
PSRETURN (PSRETURN_OK if successful)
bool IGUIObject::SettingExists ( const CStr &  Setting) const

Checks if settings exists, only available for derived classes that has this set up, that's why the base class just returns false.

Parameters
Settingsetting name
Returns
True if settings exist.
static void IGUIObject::Trace ( JSTracer *  trc,
void *  data 
)
inlinestaticprivate
void IGUIObject::TraceMember ( JSTracer *  trc)
private
void IGUIObject::UpdateCachedSize ( )
virtual

All sizes are relative to resolution, and the calculation is not wanted in real time, therefore it is cached, update the cached size with this function.

Reimplemented in CInput, and IGUITextOwner.

void IGUIObject::UpdateMouseOver ( IGUIObject *const &  pMouseOver)
protected

Inputes the object that is currently hovered, this function updates this object accordingly (i.e.

if it's the object being inputted one thing happens, and not, another).

Parameters
pMouseOverObject that is currently hovered, can OF COURSE be NULL too!

Friends And Related Function Documentation

friend class CGUI
friend
friend class CInternalCGUIAccessorBase
friend
friend class GUITooltip
friend
friend class IGUIScrollBar
friend
bool JSI_IGUIObject::getComputedSize ( JSContext *  cx,
uint  argc,
jsval *  vp 
)
friend
bool JSI_IGUIObject::getProperty ( JSContext *  cx,
JS::HandleObject  obj,
JS::HandleId  id,
JS::MutableHandleValue  vp 
)
friend
bool JSI_IGUIObject::setProperty ( JSContext *  cx,
JS::HandleObject  obj,
JS::HandleId  id,
bool  strict,
JS::MutableHandleValue  vp 
)
friend

Member Data Documentation

CRect IGUIObject::m_CachedActualSize
protected

Cached size, real size m_Size is actually dependent on resolution and can have different real outcomes, this is the real outcome cached to avoid slow calculations in real time.

vector_pObjects IGUIObject::m_Children
protected
JS::PersistentRootedObject IGUIObject::m_JSObject
private
double IGUIObject::m_LastClickTime[6]
protected
bool IGUIObject::m_MouseHovering
protected

This is an array of true or false, each element is associated with a string representing a setting.

Number of elements is equal to number of settings.

A true means the setting has been manually set in the file when read. This is important to know because I don't want to force the user to include its <styles>-XML-files first, so somehow the GUI needs to know which settings were set, and which is meant to.

CStr IGUIObject::m_Name
protected
CGUI* IGUIObject::m_pGUI
private
IGUIObject* IGUIObject::m_pParent
protected
std::map<CStr, JS::Heap<JSObject*> > IGUIObject::m_ScriptHandlers
private
std::map<CStr, SGUISetting> IGUIObject::m_Settings

Settings pool, all an object's settings are located here If a derived object has got more settings that the base settings, it's because they have a new version of the function SetupSettings().

See also
SetupSettings()

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