Changeset View
Changeset View
Standalone View
Standalone View
source/gui/IGUIObject.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | void SGUISetting::Init(IGUIObject& pObject, const CStr& Name) | ||||
m_ToJSVal = [Name, this](JSContext* cx, JS::MutableHandleValue v) { | m_ToJSVal = [Name, this](JSContext* cx, JS::MutableHandleValue v) { | ||||
ScriptInterface::ToJSVal<T>(cx, v, *static_cast<T*>(m_pSetting)); | ScriptInterface::ToJSVal<T>(cx, v, *static_cast<T*>(m_pSetting)); | ||||
}; | }; | ||||
} | } | ||||
IGUIObject::IGUIObject(CGUI* pGUI) | IGUIObject::IGUIObject(CGUI* pGUI) | ||||
: m_pGUI(pGUI), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime() | : m_pGUI(pGUI), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime() | ||||
{ | { | ||||
AddSetting(GUIST_bool, "enabled"); | // Notice that the base constructor is called prior to the derived constructors. | ||||
AddSetting(GUIST_bool, "hidden"); | // Overridden functions in derived classes will not be called from the constructor. | ||||
AddSetting(GUIST_CClientArea, "size"); | |||||
AddSetting(GUIST_CStr, "style"); | |||||
AddSetting(GUIST_CStr, "hotkey"); | |||||
AddSetting(GUIST_float, "z"); | |||||
AddSetting(GUIST_bool, "absolute"); | |||||
AddSetting(GUIST_bool, "ghost"); | |||||
AddSetting(GUIST_float, "aspectratio"); | |||||
AddSetting(GUIST_CStrW, "tooltip"); | |||||
AddSetting(GUIST_CStr, "tooltip_style"); | |||||
// Setup important defaults | |||||
GUI<bool>::SetSetting(this, "hidden", false); | |||||
GUI<bool>::SetSetting(this, "ghost", false); | |||||
GUI<bool>::SetSetting(this, "enabled", true); | |||||
GUI<bool>::SetSetting(this, "absolute", true); | |||||
} | } | ||||
IGUIObject::~IGUIObject() | IGUIObject::~IGUIObject() | ||||
{ | { | ||||
for (const std::pair<CStr, SGUISetting>& p : m_Settings) | for (const std::pair<CStr, SGUISetting>& p : m_Settings) | ||||
switch (p.second.m_Type) | switch (p.second.m_Type) | ||||
{ | { | ||||
// delete() needs to know the type of the variable - never delete a void* | // delete() needs to know the type of the variable - never delete a void* | ||||
#define TYPE(t) case GUIST_##t: delete (t*)p.second.m_pSetting; break; | #define TYPE(t) case GUIST_##t: delete (t*)p.second.m_pSetting; break; | ||||
#include "GUItypes.h" | #include "GUItypes.h" | ||||
#undef TYPE | #undef TYPE | ||||
default: | default: | ||||
debug_warn(L"Invalid setting type"); | debug_warn(L"Invalid setting type"); | ||||
} | } | ||||
if (!m_ScriptHandlers.empty()) | if (!m_ScriptHandlers.empty()) | ||||
JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this); | JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this); | ||||
} | } | ||||
void IGUIObject::AddSettings() | |||||
{ | |||||
AddSetting(GUIST_bool, "enabled"); | |||||
AddSetting(GUIST_bool, "hidden"); | |||||
AddSetting(GUIST_CClientArea, "size"); | |||||
AddSetting(GUIST_CStr, "style"); | |||||
AddSetting(GUIST_CStr, "hotkey"); | |||||
AddSetting(GUIST_float, "z"); | |||||
AddSetting(GUIST_bool, "absolute"); | |||||
AddSetting(GUIST_bool, "ghost"); | |||||
AddSetting(GUIST_float, "aspectratio"); | |||||
AddSetting(GUIST_CStrW, "tooltip"); | |||||
AddSetting(GUIST_CStr, "tooltip_style"); | |||||
// Setup important defaults | |||||
GUI<bool>::SetSetting(this, "hidden", false); | |||||
GUI<bool>::SetSetting(this, "ghost", false); | |||||
GUI<bool>::SetSetting(this, "enabled", true); | |||||
GUI<bool>::SetSetting(this, "absolute", true); | |||||
} | |||||
//------------------------------------------------------------------- | //------------------------------------------------------------------- | ||||
// Functions | // Functions | ||||
//------------------------------------------------------------------- | //------------------------------------------------------------------- | ||||
void IGUIObject::AddChild(IGUIObject* pChild) | void IGUIObject::AddChild(IGUIObject* pChild) | ||||
{ | { | ||||
// ENSURE(pChild); | // ENSURE(pChild); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (ObjectMap.count(m_Name) > 0) | ||||
throw PSERROR_GUI_NameAmbiguity(m_Name.c_str()); | throw PSERROR_GUI_NameAmbiguity(m_Name.c_str()); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
ObjectMap[m_Name] = this; | ObjectMap[m_Name] = this; | ||||
} | } | ||||
} | } | ||||
void IGUIObject::Destroy() | |||||
{ | |||||
// Is there anything besides the children to destroy? | |||||
} | |||||
elexis: This function is smoke and mirrors.
If an inherited function has to do some destruction, it… | |||||
void IGUIObject::AddSetting(const EGUISettingType& Type, const CStr& Name) | void IGUIObject::AddSetting(const EGUISettingType& Type, const CStr& Name) | ||||
{ | { | ||||
// Is name already taken? | // Is name already taken? | ||||
if (m_Settings.count(Name) >= 1) | if (m_Settings.count(Name) >= 1) | ||||
return; | return; | ||||
// Construct, and set type | // Construct, and set type | ||||
m_Settings[Name].m_Type = Type; | m_Settings[Name].m_Type = Type; | ||||
▲ Show 20 Lines • Show All 417 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This function is smoke and mirrors.
If an inherited function has to do some destruction, it must do so in the destructor.
There is no need for this function to exist exept for the only derived class (MiniMap) which uses it to delete textures, and this has no need to use inheritance. It's private logic. The destructor is necessary and sufficient for this task.