Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/GUIutil.cpp
Show First 20 Lines • Show All 319 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
T* v = NULL; | T* v = NULL; | ||||
PSRETURN ret = GetSettingPointer(pObject, Setting, v); | PSRETURN ret = GetSettingPointer(pObject, Setting, v); | ||||
if (ret == PSRETURN_OK) | if (ret == PSRETURN_OK) | ||||
Value = *v; | Value = *v; | ||||
return ret; | return ret; | ||||
} | } | ||||
template <typename T> | |||||
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage) | |||||
{ | |||||
return SetSettingWrap(pObject, Setting, Value, SkipMessage, | |||||
[&pObject, &Setting, &Value]() { | |||||
*static_cast<T*>(pObject->m_Settings[Setting].m_pSetting) = std::move(Value); | |||||
}); | |||||
} | |||||
template <typename T> | |||||
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage) | |||||
{ | |||||
return SetSettingWrap(pObject, Setting, Value, SkipMessage, | |||||
[&pObject, &Setting, &Value]() { | |||||
*static_cast<T*>(pObject->m_Settings[Setting].m_pSetting) = Value; | |||||
}); | |||||
} | |||||
// Helper function for SetSetting | // Helper function for SetSetting | ||||
template <typename T> | template <typename T> | ||||
bool IsBoolTrue(const T&) | bool IsBoolTrue(const T&) | ||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
template <> | template <> | ||||
bool IsBoolTrue<bool>(const bool& v) | bool IsBoolTrue<bool>(const bool& v) | ||||
{ | { | ||||
return v; | return v; | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage) | PSRETURN GUI<T>::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage, const std::function<void()>& valueSet) | ||||
{ | { | ||||
ENSURE(pObject != NULL); | ENSURE(pObject != NULL); | ||||
if (!pObject->SettingExists(Setting)) | if (!pObject->SettingExists(Setting)) | ||||
{ | { | ||||
LOGWARNING("setting %s was not found on object %s", | LOGWARNING("setting %s was not found on object %s", | ||||
Setting.c_str(), | Setting.c_str(), | ||||
pObject->GetPresentableName().c_str()); | pObject->GetPresentableName().c_str()); | ||||
return PSRETURN_GUI_InvalidSetting; | return PSRETURN_GUI_InvalidSetting; | ||||
} | } | ||||
#ifndef NDEBUG | #ifndef NDEBUG | ||||
CheckType<T>(pObject, Setting); | CheckType<T>(pObject, Setting); | ||||
#endif | #endif | ||||
// Set value | valueSet(); | ||||
*(T*)pObject->m_Settings[Setting].m_pSetting = Value; | |||||
// | |||||
// Some settings needs special attention at change | // Some settings needs special attention at change | ||||
// | |||||
// 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") | ||||
{ | { | ||||
RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize); | RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize); | ||||
} | } | ||||
else if (Setting == "hidden") | else if (Setting == "hidden") | ||||
{ | { | ||||
Show All 10 Lines | #endif | ||||
return PSRETURN_OK; | return PSRETURN_OK; | ||||
} | } | ||||
// Instantiate templated functions: | // Instantiate templated functions: | ||||
#define TYPE(T) \ | #define TYPE(T) \ | ||||
template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \ | template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \ | ||||
template PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \ | template PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \ | ||||
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, 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_CGUISpriteInstance | #define GUITYPE_IGNORE_CGUISpriteInstance | ||||
#include "GUItypes.h" | #include "GUItypes.h" | ||||
#undef GUITYPE_IGNORE_CGUISpriteInstance | #undef GUITYPE_IGNORE_CGUISpriteInstance | ||||
#undef TYPE | #undef TYPE | ||||
// Don't instantiate GetSetting<CGUISpriteInstance> - this will cause linker errors if | // Don't instantiate GetSetting<CGUISpriteInstance> - this will cause linker errors if | ||||
// you attempt to retrieve a sprite using GetSetting, since that copies the sprite | // you attempt to retrieve a sprite using GetSetting, since that copies the sprite | ||||
// and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer | // and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer | ||||
// instead. (This is mainly useful to stop me accidentally using the wrong function.) | // instead. (This is mainly useful to stop me accidentally using the wrong function.) | ||||
template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value); | template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value); | ||||
template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject* pObject, const CStr& Setting, const CGUISpriteInstance& Value, const bool& SkipMessage); | template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance& Value, const bool& SkipMessage); |
Wildfire Games · Phabricator