22 #include "precompiled.h"
46 m_MouseHovering(false),
66 for (
int i=0; i<6; i++)
73 std::map<CStr, SGUISetting>::iterator it;
76 switch (it->second.m_Type)
79 #define TYPE(t) case GUIST_##t: delete (t*)it->second.m_pSetting; break;
89 std::map<CStr, JSObject**>::iterator it;
151 if (ObjectMap.count(
m_Name) > 0)
169 m_Settings[Name].m_pSetting = new type(); \
187 debug_warn(L
"IGUIObject::AddSetting failed, type not recognized!");
215 if (pMouseOver ==
this)
251 if (set.m_Type == GUIST_##type) \
254 if (!GUI<type>::ParseString(Value, _Value)) \
255 return PSRETURN_GUI_UnableToParse; \
257 GUI<type>::SetSetting(this, Setting, _Value, SkipMessage); \
297 Type =
m_Settings.find(Setting)->second.m_Type;
341 float aspectratio = 0.f;
378 if (GUIinstance.
m_Styles.count(StyleName)==1)
391 std::map<CStr, CStrW>::const_iterator cit;
432 const int paramCount = 1;
433 const char* paramNames[paramCount] = {
"mouse" };
436 CStr CodeName =
GetName()+
" "+Action;
444 buf, paramCount, paramNames, Code.c_str(), Code.length(), CodeName.c_str(), 0);
454 JSObject** obj =
new JSObject*;
493 jsval paramData[] = { mouse.
get() };
512 jsval arg = Argument.
get();
515 JSBool ok = JS_CallFunctionValue(
g_ScriptingHost.getContext(), object, OBJECT_TO_JSVAL(*it->second), 1, &arg, &result);
518 JS_ReportError(
g_ScriptingHost.getContext(),
"Errors executing script action \"%s\"", Action.c_str());
540 if (
m_Name.length() <= 12)
543 if (
m_Name.substr(0, 10) ==
"__internal")
544 return CStr(
"[unnamed object]");
566 LOGWARNING(L
"IGUIObject: setting %hs was not found on an object",
#define PROFILE2_EVENT(name)
Record the named event at the current time.
std::map< CStr, CStrW > m_SettingsDefaults
void RegisterScriptHandler(const CStr &Action, const CStr &Code, CGUI *pGUI)
Set the script handler for a particular object-specific action.
void SetScriptHandler(const CStr &Action, JSObject *Function)
IGUIObject * m_FocusedObject
Focused object! Say an input box that is selected.
const PSRETURN PSRETURN_OK
void ScriptEvent(const CStr &Action)
Execute the script for a particular action.
JSObject * m_ScriptObject
An JSObject* under which all GUI JavaScript things will be created, so that they can be garbage-colle...
float left
Returning CPos representing each corner.
static PSRETURN GetSetting(const IGUIObject *pObject, const CStr &Setting, T &Value)
Retrieves a setting by name from object pointer.
const jsval & get() const
Returns the current value.
A trivial wrapper around a jsval.
const CStr & GetName() const
Get object name, name is unique.
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
CStr GetPresentableName() const
int sprintf_s(char *buf, size_t max_chars, const char *fmt,...) PRINTF_ARGS(3)
The main object that represents a whole GUI page.
virtual float GetBufferedZ() const
Returns not the Z value, but the actual buffered Z value, i.e.
unsigned int m_MouseButtons
Indicates which buttons are pressed (bit 0 = LMB, bit 1 = RMB, bit 2 = MMB)
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.
JSObject * GetJSObject()
Retrieves the JSObject representing this GUI object.
CPos m_MousePos
don't want to pass this around with the ChooseMouseOverAndClosest broadcast - we'd need to pack this ...
bool IsRootObject() const
IGUIObject * GetParent() const
NOTE! This will not just return m_pParent, when that is need use it! There is one exception to it...
vector_pObjects m_Children
void UpdateObjects()
Updates the object pointers, needs to be called each time an object has been added or removed...
void SetParent(IGUIObject *pParent)
Set parent of this object.
std::map< CStr, SGUISetting > m_Settings
Settings pool, all an object's settings are located here If a derived object has got more settings th...
EGUIMessageType
Message types.
std::map< CStr, SGUIStyle > m_Styles
void AddSetting(const EGUISettingType &Type, const CStr &Name)
Add a setting to m_Settings.
virtual bool MouseOver()
Checks if mouse is hovering this object.
void AddChild(IGUIObject *pChild)
Notice nothing will be returned or thrown if the child hasn't been inputted into the GUI yet...
bool IsFocused() const
Check if object is focused.
CRect GetClientArea(const CRect &parent) const
Get client area rectangle when the parent is given.
void ChooseMouseOverAndClosest(IGUIObject *&pObject)
Inputs a reference pointer, checks if the new inputted object if hovered, if so, then check if this's...
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
Made to represent screen positions and delta values.
InReaction SendEvent(EGUIMessageType type, const CStr &EventName)
Send event to this GUI object (HandleMessage and ScriptEvent)
double m_LastClickTime[6]
std::map< CStr, IGUIObject * > map_pObjects
#define PROFILE2_ATTR
Associates a string (with printf-style formatting) with the current region or event.
PSRETURN LogInvalidSettings(const CStr8 &Setting) const
Logs an invalid setting search and returns the correct return result.
PSRETURN GetSettingType(const CStr &Setting, EGUISettingType &Type) const
Retrieves the type of a named setting.
CPos GetMousePos() const
Get Mouse from CGUI.
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.
const PSRETURN PSRETURN_GUI_InvalidSetting
A GUI Setting is anything that can be inputted from XML as <object>-attributes (with exceptions)...
void UpdateMouseOver(IGUIObject *const &pMouseOver)
Inputes the object that is currently hovered, this function updates this object accordingly (i...
PSRETURN SetSetting(const CStr &Setting, const CStrW &Value, const bool &SkipMessage=false)
Set a setting by string, regardless of what type it is.
static PSRETURN SetSetting(IGUIObject *pObject, const CStr &Setting, const T &Value, const bool &SkipMessage=false)
Sets a value by name using a real datatype as input.
jsval get() const
Returns the current value (or JSVAL_VOID if uninitialised).
std::map< CStr, JSObject ** > m_ScriptHandlers
#define debug_warn(expr)
display the error dialog with the given text.
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...
bool m_MouseHovering
This is an array of true or false, each element is associated with a string representing a setting...
virtual void Destroy()
Calls Destroy on all children, and deallocates all memory.
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
virtual void HandleMessage(SGUIMessage &Message)
This function is called with different messages for instance when the mouse enters the object...
void LoadStyle(CGUI &GUIinstance, const CStr &StyleName)
Loads a style.
Contains a list of values for new defaults to objects.
bool PointInside(const CPos &point) const
Evalutates if point is within the rectangle.
virtual bool MouseOverIcon()
Test if mouse position is over an icon.
void SetFocus()
Take focus!
Rectangle class used for screen rectangles.
Client Area is a rectangle relative to a parent rectangle.