Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/GUIutil.cpp
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
template<typename T> | template<typename T> | ||||
void CGUISetting<T>::ToJSVal(JSContext* cx, JS::MutableHandleValue Value) | void CGUISetting<T>::ToJSVal(JSContext* cx, JS::MutableHandleValue Value) | ||||
{ | { | ||||
ScriptInterface::ToJSVal<T>(cx, Value, m_pSetting); | ScriptInterface::ToJSVal<T>(cx, Value, m_pSetting); | ||||
}; | }; | ||||
template <typename T> | template <typename T> | ||||
T& GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting) | |||||
{ | |||||
return static_cast<CGUISetting<T>* >(pObject->m_Settings.at(Setting))->m_pSetting; | |||||
} | |||||
template <typename T> | |||||
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage) | PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage) | ||||
{ | { | ||||
return SetSettingWrap(pObject, Setting, SkipMessage, | return SetSettingWrap(pObject, Setting, SkipMessage, | ||||
[&pObject, &Setting, &Value]() { | [&pObject, &Setting, &Value]() { | ||||
static_cast<CGUISetting<T>* >(pObject->m_Settings[Setting])->m_pSetting = std::move(Value); | static_cast<CGUISetting<T>* >(pObject->m_Settings[Setting])->m_pSetting = std::move(Value); | ||||
}); | }); | ||||
} | } | ||||
Show All 26 Lines | PSRETURN GUI<T>::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const bool& SkipMessage, const std::function<void()>& valueSet) | ||||
// If setting was "size", we need to re-cache itself and all children | // If setting was "size", we need to re-cache itself and all children | ||||
if (Setting == "size") | if (Setting == "size") | ||||
{ | { | ||||
pObject->RecurseObject(nullptr, &IGUIObject::UpdateCachedSize); | pObject->RecurseObject(nullptr, &IGUIObject::UpdateCachedSize); | ||||
} | } | ||||
else if (Setting == "hidden") | else if (Setting == "hidden") | ||||
{ | { | ||||
// Hiding an object requires us to reset it and all children | // Hiding an object requires us to reset it and all children | ||||
if (GUI<bool>::GetSetting(pObject, Setting)) | if (pObject->GetSetting<bool>(Setting)) | ||||
pObject->RecurseObject(nullptr, &IGUIObject::ResetStates); | pObject->RecurseObject(nullptr, &IGUIObject::ResetStates); | ||||
} | } | ||||
if (!SkipMessage) | if (!SkipMessage) | ||||
{ | { | ||||
SGUIMessage msg(GUIM_SETTINGS_UPDATED, Setting); | SGUIMessage msg(GUIM_SETTINGS_UPDATED, Setting); | ||||
pObject->HandleMessage(msg); | pObject->HandleMessage(msg); | ||||
} | } | ||||
return PSRETURN_OK; | return PSRETURN_OK; | ||||
} | } | ||||
// 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 T& GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting); \ | |||||
template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage); \ | template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage); \ | ||||
template class CGUISetting<T>; \ | template class CGUISetting<T>; \ | ||||
#include "GUItypes.h" | #include "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 PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage); \ | template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage); \ | ||||
#define GUITYPE_IGNORE_NONCOPYABLE | #define GUITYPE_IGNORE_NONCOPYABLE | ||||
#include "GUItypes.h" | #include "GUItypes.h" | ||||
#undef GUITYPE_IGNORE_NONCOPYABLE | #undef GUITYPE_IGNORE_NONCOPYABLE | ||||
#undef TYPE | #undef TYPE |
Wildfire Games · Phabricator