Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/IGUIObject.cpp
Show All 37 Lines | IGUIObject::IGUIObject(CGUI& pGUI) | ||||
AddSetting<float>("z"); | AddSetting<float>("z"); | ||||
AddSetting<bool>("absolute"); | AddSetting<bool>("absolute"); | ||||
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 | // Setup important defaults | ||||
GUI<bool>::SetSetting(this, "hidden", false); | SetSetting<bool>("hidden", false, true); | ||||
GUI<bool>::SetSetting(this, "ghost", false); | SetSetting<bool>("ghost", false, true); | ||||
GUI<bool>::SetSetting(this, "enabled", true); | SetSetting<bool>("enabled", true, true); | ||||
GUI<bool>::SetSetting(this, "absolute", 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 82 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
template <typename T> | template <typename T> | ||||
const T& IGUIObject::GetSetting(const CStr& Setting) const | const T& IGUIObject::GetSetting(const CStr& Setting) const | ||||
{ | { | ||||
return static_cast<CGUISetting<T>* >(m_Settings.at(Setting))->m_pSetting; | return static_cast<CGUISetting<T>* >(m_Settings.at(Setting))->m_pSetting; | ||||
} | } | ||||
bool IGUIObject::SetSettingFromString(const CStr& Setting, const CStrW& Value, const bool SendMessage) | |||||
{ | |||||
return m_Settings[Setting]->FromString(Value, SendMessage); | |||||
} | |||||
template <typename T> | |||||
void IGUIObject::SetSetting(const CStr& Setting, T& Value, const bool SendMessage) | |||||
{ | |||||
static_cast<CGUISetting<T>* >(m_Settings[Setting])->m_pSetting = std::move(Value); | |||||
SettingChanged(Setting, SendMessage); | |||||
} | |||||
template <typename T> | |||||
void IGUIObject::SetSetting(const CStr& Setting, const T& Value, const bool SendMessage) | |||||
{ | |||||
static_cast<CGUISetting<T>* >(m_Settings[Setting])->m_pSetting = Value; | |||||
SettingChanged(Setting, SendMessage); | |||||
} | |||||
void IGUIObject::SettingChanged(const CStr& Setting, const bool SendMessage) | |||||
{ | |||||
if (Setting == "size") | |||||
{ | |||||
// If setting was "size", we need to re-cache itself and all children | |||||
RecurseObject(nullptr, &IGUIObject::UpdateCachedSize); | |||||
} | |||||
else if (Setting == "hidden") | |||||
{ | |||||
// Hiding an object requires us to reset it and all children | |||||
if (GetSetting<bool>(Setting)) | |||||
RecurseObject(nullptr, &IGUIObject::ResetStates); | |||||
} | |||||
if (SendMessage) | |||||
{ | |||||
SGUIMessage msg(GUIM_SETTINGS_UPDATED, Setting); | |||||
HandleMessage(msg); | |||||
} | |||||
} | |||||
bool IGUIObject::IsMouseOver() const | bool IGUIObject::IsMouseOver() const | ||||
{ | { | ||||
return m_CachedActualSize.PointInside(m_pGUI.GetMousePos()); | return m_CachedActualSize.PointInside(m_pGUI.GetMousePos()); | ||||
} | } | ||||
bool IGUIObject::MouseOverIcon() | bool IGUIObject::MouseOverIcon() | ||||
{ | { | ||||
return false; | return false; | ||||
Show All 15 Lines | else | ||||
if (m_MouseHovering) | if (m_MouseHovering) | ||||
{ | { | ||||
m_MouseHovering = false; | m_MouseHovering = false; | ||||
SendEvent(GUIM_MOUSE_LEAVE, "mouseleave"); | SendEvent(GUIM_MOUSE_LEAVE, "mouseleave"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage) | |||||
{ | |||||
if (!SettingExists(Setting)) | |||||
return PSRETURN_GUI_InvalidSetting; | |||||
if (!m_Settings[Setting]->FromString(Value, SkipMessage)) | |||||
return PSRETURN_GUI_UnableToParse; | |||||
return PSRETURN_OK; | |||||
} | |||||
void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject) | void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject) | ||||
{ | { | ||||
if (!IsMouseOver()) | if (!IsMouseOver()) | ||||
return; | return; | ||||
// Check if we've got competition at all | // Check if we've got competition at all | ||||
if (pObject == NULL) | if (pObject == NULL) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | void IGUIObject::LoadStyle(const CStr& StyleName) | ||||
// The default style may specify settings for any GUI object. | // The default style may specify settings for any GUI object. | ||||
// Other styles are reported if they specify a Setting that does not exist, | // Other styles are reported if they specify a Setting that does not exist, | ||||
// so that the XML author is informed and can correct the style. | // so that the XML author is informed and can correct the style. | ||||
for (const std::pair<CStr, CStrW>& p : m_pGUI.GetStyle(StyleName).m_SettingsDefaults) | for (const std::pair<CStr, CStrW>& p : m_pGUI.GetStyle(StyleName).m_SettingsDefaults) | ||||
{ | { | ||||
if (SettingExists(p.first)) | if (SettingExists(p.first)) | ||||
SetSetting(p.first, p.second); | SetSettingFromString(p.first, p.second, true); | ||||
else if (StyleName != "default") | else if (StyleName != "default") | ||||
LOGWARNING("GUI object has no setting \"%s\", but the style \"%s\" defines it", p.first, StyleName.c_str()); | LOGWARNING("GUI object has no setting \"%s\", but the style \"%s\" defines it", p.first, StyleName.c_str()); | ||||
} | } | ||||
} | } | ||||
float IGUIObject::GetBufferedZ() const | float IGUIObject::GetBufferedZ() const | ||||
{ | { | ||||
const float Z = GetSetting<float>("z"); | const float Z = GetSetting<float>("z"); | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
// Please ensure to adapt the Tracer enabling and disabling in accordance with the GC things traced! | // Please ensure to adapt the Tracer enabling and disabling in accordance with the GC things traced! | ||||
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. | |||||
#define TYPE(T) \ | #define TYPE(T) \ | ||||
template void IGUIObject::AddSetting<T>(const CStr& Name); \ | template void IGUIObject::AddSetting<T>(const CStr& Name); \ | ||||
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); \ | |||||
#include "gui/GUItypes.h" | #include "gui/GUItypes.h" | ||||
#undef TYPE | |||||
// Copying functions - discouraged except for primitives. | |||||
#define TYPE(T) \ | |||||
template void IGUIObject::SetSetting<T>(const CStr& Setting, const T& Value, const bool SendMessage); \ | |||||
#define GUITYPE_IGNORE_NONCOPYABLE | |||||
#include "gui/GUItypes.h" | |||||
#undef GUITYPE_IGNORE_NONCOPYABLE | |||||
#undef TYPE | #undef TYPE |
Wildfire Games · Phabricator