Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/IGUIObject.cpp
Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
// 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); | ||||
} | } | ||||
bool IGUIObject::SettingExists(const CStr& Setting) const | |||||
{ | |||||
return m_Settings.count(Setting) == 1; | |||||
} | |||||
template <typename T> | |||||
T& IGUIObject::GetSetting(const CStr& Setting) | |||||
{ | |||||
return static_cast<CGUISetting<T>* >(m_Settings.at(Setting))->m_pSetting; | |||||
} | |||||
template <typename T> | |||||
const T& IGUIObject::GetSetting(const CStr& Setting) const | |||||
{ | |||||
return static_cast<CGUISetting<T>* >(m_Settings.at(Setting))->m_pSetting; | |||||
} | |||||
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"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool IGUIObject::SettingExists(const CStr& Setting) const | |||||
{ | |||||
return m_Settings.count(Setting) == 1; | |||||
} | |||||
PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage) | PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage) | ||||
{ | { | ||||
if (!SettingExists(Setting)) | if (!SettingExists(Setting)) | ||||
return PSRETURN_GUI_InvalidSetting; | return PSRETURN_GUI_InvalidSetting; | ||||
if (!m_Settings[Setting]->FromString(Value, SkipMessage)) | if (!m_Settings[Setting]->FromString(Value, SkipMessage)) | ||||
return PSRETURN_GUI_UnableToParse; | return PSRETURN_GUI_UnableToParse; | ||||
Show All 36 Lines | |||||
void IGUIObject::ResetStates() | void IGUIObject::ResetStates() | ||||
{ | { | ||||
// Notify the gui that we aren't hovered anymore | // Notify the gui that we aren't hovered anymore | ||||
UpdateMouseOver(nullptr); | UpdateMouseOver(nullptr); | ||||
} | } | ||||
void IGUIObject::UpdateCachedSize() | void IGUIObject::UpdateCachedSize() | ||||
{ | { | ||||
const CClientArea& ca = GUI<CClientArea>::GetSetting(this, "size"); | const CClientArea& ca = GetSetting<CClientArea>("size"); | ||||
const float aspectratio = GUI<float>::GetSetting(this, "aspectratio"); | const float aspectratio = GetSetting<float>("aspectratio"); | ||||
// If absolute="false" and the object has got a parent, | // If absolute="false" and the object has got a parent, | ||||
// use its cached size instead of the screen. Notice | // use its cached size instead of the screen. Notice | ||||
// it must have just been cached for it to work. | // it must have just been cached for it to work. | ||||
if (!GUI<bool>::GetSetting(this, "absolute") && m_pParent && !IsRootObject()) | if (!GetSetting<bool>("absolute") && m_pParent && !IsRootObject()) | ||||
m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize); | m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize); | ||||
else | else | ||||
m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres / g_GuiScale, g_yres / g_GuiScale)); | m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres / g_GuiScale, g_yres / g_GuiScale)); | ||||
// In a few cases, GUI objects have to resize to fill the screen | // In a few cases, GUI objects have to resize to fill the screen | ||||
// but maintain a constant aspect ratio. | // but maintain a constant aspect ratio. | ||||
// Adjust the size to be the max possible, centered in the original size: | // Adjust the size to be the max possible, centered in the original size: | ||||
if (aspectratio) | if (aspectratio) | ||||
Show All 35 Lines | for (const std::pair<CStr, CStrW>& p : Style.m_SettingsDefaults) | ||||
// The beauty with styles is that it can contain more settings | // The beauty with styles is that it can contain more settings | ||||
// than exists for the objects using it. So if the SetSetting | // than exists for the objects using it. So if the SetSetting | ||||
// fails, don't care. | // fails, don't care. | ||||
} | } | ||||
} | } | ||||
float IGUIObject::GetBufferedZ() const | float IGUIObject::GetBufferedZ() const | ||||
{ | { | ||||
const float Z = GUI<float>::GetSetting(this, "z"); | const float Z = GetSetting<float>("z"); | ||||
if (GUI<bool>::GetSetting(this, "absolute")) | if (GetSetting<bool>("absolute")) | ||||
return Z; | return Z; | ||||
{ | { | ||||
if (GetParent()) | if (GetParent()) | ||||
return GetParent()->GetBufferedZ() + Z; | return GetParent()->GetBufferedZ() + Z; | ||||
else | else | ||||
{ | { | ||||
// In philosophy, a parentless object shouldn't be able to have a relative sizing, | // In philosophy, a parentless object shouldn't be able to have a relative sizing, | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | JSObject* IGUIObject::GetJSObject() | ||||
return m_JSObject.get(); | return m_JSObject.get(); | ||||
} | } | ||||
bool IGUIObject::IsHidden() const | bool IGUIObject::IsHidden() const | ||||
{ | { | ||||
// Statically initialise some strings, so we don't have to do | // Statically initialise some strings, so we don't have to do | ||||
// lots of allocation every time this function is called | // lots of allocation every time this function is called | ||||
static const CStr strHidden("hidden"); | static const CStr strHidden("hidden"); | ||||
return GUI<bool>::GetSetting(this, strHidden); | return GetSetting<bool>(strHidden); | ||||
} | } | ||||
bool IGUIObject::IsHiddenOrGhost() const | bool IGUIObject::IsHiddenOrGhost() const | ||||
{ | { | ||||
static const CStr strGhost("ghost"); | static const CStr strGhost("ghost"); | ||||
return IsHidden() || GUI<bool>::GetSetting(this, strGhost); | return IsHidden() || GetSetting<bool>(strGhost); | ||||
} | } | ||||
void IGUIObject::PlaySound(const CStr& settingName) const | void IGUIObject::PlaySound(const CStr& settingName) const | ||||
{ | { | ||||
if (!g_SoundManager) | if (!g_SoundManager) | ||||
return; | return; | ||||
const CStrW& soundPath = GUI<CStrW>::GetSetting(this, settingName); | const CStrW& soundPath = GetSetting<CStrW>(settingName); | ||||
if (!soundPath.empty()) | if (!soundPath.empty()) | ||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false); | g_SoundManager->PlayAsUI(soundPath.c_str(), false); | ||||
} | } | ||||
CStr IGUIObject::GetPresentableName() const | CStr IGUIObject::GetPresentableName() const | ||||
{ | { | ||||
// __internal(), must be at least 13 letters to be able to be | // __internal(), must be at least 13 letters to be able to be | ||||
Show All 26 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: | ||||
#define TYPE(T) template void IGUIObject::AddSetting<T>(const CStr& Name); | #define TYPE(T) \ | ||||
#include "GUItypes.h" | template void IGUIObject::AddSetting<T>(const CStr& Name); \ | ||||
template T& IGUIObject::GetSetting<T>(const CStr& Setting); \ | |||||
template const T& IGUIObject::GetSetting<T>(const CStr& Setting) const; \ | |||||
#include "gui/GUItypes.h" | |||||
#undef TYPE | #undef TYPE |
Wildfire Games · Phabricator