Changeset View
Changeset View
Standalone View
Standalone View
source/gui/IGUIObject.cpp
Show All 25 Lines | |||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "soundmanager/ISoundManager.h" | #include "soundmanager/ISoundManager.h" | ||||
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<bool>("enabled"); | AddSetting<bool>("enabled", true); | ||||
AddSetting<bool>("hidden"); | AddSetting<bool>("hidden"); | ||||
AddSetting<CClientArea>("size"); | AddSetting<CClientArea>("size"); | ||||
AddSetting<CStr>("style"); | AddSetting<CStr>("style"); | ||||
AddSetting<CStr>("hotkey"); | AddSetting<CStr>("hotkey"); | ||||
AddSetting<float>("z"); | AddSetting<float>("z"); | ||||
AddSetting<bool>("absolute"); | AddSetting<bool>("absolute", true); | ||||
AddSetting<bool>("ghost"); | AddSetting<bool>("ghost"); | ||||
AddSetting<float>("aspectratio"); | AddSetting<float>("aspectratio"); | ||||
AddSetting<CStrW>("tooltip"); | AddSetting<CStrW>("tooltip"); | ||||
AddSetting<CStr>("tooltip_style"); | AddSetting<CStr>("tooltip_style"); | ||||
// Setup important defaults | |||||
SetSetting<bool>("hidden", false, true); | |||||
SetSetting<bool>("ghost", false, true); | |||||
SetSetting<bool>("enabled", true, true); | |||||
SetSetting<bool>("absolute", true, true); | |||||
} | } | ||||
IGUIObject::~IGUIObject() | IGUIObject::~IGUIObject() | ||||
{ | { | ||||
for (const std::pair<CStr, IGUISetting*>& p : m_Settings) | for (const std::pair<CStr, IGUISetting*>& p : m_Settings) | ||||
delete p.second; | delete p.second; | ||||
if (!m_ScriptHandlers.empty()) | if (!m_ScriptHandlers.empty()) | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | void IGUIObject::AddToPointersMap(map_pObjects& ObjectMap) | ||||
} | } | ||||
} | } | ||||
void IGUIObject::Destroy() | void IGUIObject::Destroy() | ||||
{ | { | ||||
// Is there anything besides the children to destroy? | // Is there anything besides the children to destroy? | ||||
} | } | ||||
template<typename T> | template<typename T, typename... Args> | ||||
void IGUIObject::AddSetting(const CStr& Name) | void IGUIObject::AddSetting(const CStr& Name, Args&& ...args) | ||||
{ | { | ||||
// This can happen due to inheritance | // This can happen due to inheritance | ||||
if (SettingExists(Name)) | if (SettingExists(Name)) | ||||
return; | return; | ||||
m_Settings[Name] = new CGUISetting<T>(*this, Name); | m_Settings[Name] = new CGUISetting<T>(*this, Name, std::forward<Args>(args)...); | ||||
} | } | ||||
bool IGUIObject::SettingExists(const CStr& Setting) const | bool IGUIObject::SettingExists(const CStr& Setting) const | ||||
{ | { | ||||
return m_Settings.count(Setting) == 1; | return m_Settings.count(Setting) == 1; | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | void IGUIObject::TraceMember(JSTracer* trc) | ||||
for (std::pair<const CStr, JS::Heap<JSObject*>>& handler : m_ScriptHandlers) | for (std::pair<const CStr, JS::Heap<JSObject*>>& handler : m_ScriptHandlers) | ||||
JS_CallObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers"); | JS_CallObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers"); | ||||
} | } | ||||
// Instantiate templated functions: | // Instantiate templated functions: | ||||
// These functions avoid copies by working with a reference and move semantics. | // These functions avoid copies by working with a reference and move semantics. | ||||
#define TYPE(T) \ | #define TYPE(T) \ | ||||
template void IGUIObject::AddSetting<T>(const CStr& Name); \ | template void IGUIObject::AddSetting<T>(const CStr& Name); \ | ||||
template void IGUIObject::AddSetting<T>(const CStr& Name, T&& initialValue); \ | |||||
template T& IGUIObject::GetSetting<T>(const CStr& Setting); \ | template T& IGUIObject::GetSetting<T>(const CStr& Setting); \ | ||||
template const T& IGUIObject::GetSetting<T>(const CStr& Setting) const; \ | template const T& IGUIObject::GetSetting<T>(const CStr& Setting) const; \ | ||||
template void IGUIObject::SetSetting<T>(const CStr& Setting, T& Value, const bool SendMessage); \ | template void IGUIObject::SetSetting<T>(const CStr& Setting, T& Value, const bool SendMessage); \ | ||||
#include "gui/GUItypes.h" | #include "gui/GUItypes.h" | ||||
#undef TYPE | #undef TYPE | ||||
// Copying functions - discouraged except for primitives. | // Copying functions - discouraged except for primitives. | ||||
#define TYPE(T) \ | #define TYPE(T) \ | ||||
template void IGUIObject::SetSetting<T>(const CStr& Setting, const T& Value, const bool SendMessage); \ | template void IGUIObject::SetSetting<T>(const CStr& Setting, const T& Value, const bool SendMessage); \ | ||||
#define GUITYPE_IGNORE_NONCOPYABLE | #define GUITYPE_IGNORE_NONCOPYABLE | ||||
#include "gui/GUItypes.h" | #include "gui/GUItypes.h" | ||||
#undef GUITYPE_IGNORE_NONCOPYABLE | #undef GUITYPE_IGNORE_NONCOPYABLE | ||||
#undef TYPE | #undef TYPE |
Wildfire Games · Phabricator