Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/ObjectBases/IGUIObject.cpp
Show First 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | if (m_AspectRatio) | ||||
{ | { | ||||
float delta = m_CachedActualSize.GetHeight() - m_CachedActualSize.GetWidth() / m_AspectRatio; | float delta = m_CachedActualSize.GetHeight() - m_CachedActualSize.GetWidth() / m_AspectRatio; | ||||
m_CachedActualSize.bottom -= delta/2.f; | m_CachedActualSize.bottom -= delta/2.f; | ||||
m_CachedActualSize.top += delta/2.f; | m_CachedActualSize.top += delta/2.f; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
CRect IGUIObject::GetComputedSize() | |||||
{ | |||||
UpdateCachedSize(); | |||||
return m_CachedActualSize; | |||||
} | |||||
bool IGUIObject::ApplyStyle(const CStr& StyleName) | bool IGUIObject::ApplyStyle(const CStr& StyleName) | ||||
{ | { | ||||
if (!m_pGUI.HasStyle(StyleName)) | if (!m_pGUI.HasStyle(StyleName)) | ||||
{ | { | ||||
LOGERROR("IGUIObject: Trying to use style '%s' that doesn't exist.", StyleName.c_str()); | LOGERROR("IGUIObject: Trying to use style '%s' that doesn't exist.", StyleName.c_str()); | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | bool IGUIObject::ScriptEventWithReturn(const CStr& eventName, const JS::HandleValueArray& paramData) | ||||
{ | { | ||||
LOGERROR("Errors executing script event \"%s\"", eventName.c_str()); | LOGERROR("Errors executing script event \"%s\"", eventName.c_str()); | ||||
ScriptException::CatchPending(rq); | ScriptException::CatchPending(rq); | ||||
return false; | return false; | ||||
} | } | ||||
return JS::ToBoolean(result); | return JS::ToBoolean(result); | ||||
} | } | ||||
void IGUIObject::CreateJSObject() | |||||
{ | |||||
ScriptRequest rq(m_pGUI.GetScriptInterface()); | |||||
using ProxyHandler = JSI_GUIProxy<std::remove_pointer_t<decltype(this)>>; | |||||
ProxyHandler::CreateJSObject(rq, this, GetGUI().GetProxyData(&ProxyHandler::Singleton()), m_JSObject); | |||||
} | |||||
JSObject* IGUIObject::GetJSObject() | JSObject* IGUIObject::GetJSObject() | ||||
{ | { | ||||
// Cache the object when somebody first asks for it, because otherwise | // Cache the object when somebody first asks for it, because otherwise | ||||
// we end up doing far too much object allocation. | // we end up doing far too much object allocation. | ||||
if (!m_JSObject.initialized()) | if (!m_JSObject) | ||||
CreateJSObject(); | CreateJSObject(); | ||||
return m_JSObject.get(); | return m_JSObject->Get(); | ||||
} | |||||
void IGUIObject::toString(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | |||||
{ | |||||
ScriptRequest rq(scriptInterface); | |||||
ScriptInterface::ToJSVal(rq, ret, "[GUIObject: " + GetName() + "]"); | |||||
} | |||||
void IGUIObject::focus(ScriptInterface& UNUSED(scriptInterface), JS::MutableHandleValue ret) | |||||
{ | |||||
GetGUI().SetFocusedObject(this); | |||||
ret.setUndefined(); | |||||
} | |||||
void IGUIObject::blur(ScriptInterface& UNUSED(scriptInterface), JS::MutableHandleValue ret) | |||||
{ | |||||
GetGUI().SetFocusedObject(nullptr); | |||||
ret.setUndefined(); | |||||
} | |||||
void IGUIObject::getComputedSize(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | |||||
{ | |||||
UpdateCachedSize(); | |||||
ScriptRequest rq(scriptInterface); | |||||
ScriptInterface::ToJSVal(rq, ret, m_CachedActualSize); | |||||
} | } | ||||
bool IGUIObject::IsEnabled() const | bool IGUIObject::IsEnabled() const | ||||
{ | { | ||||
return m_Enabled; | return m_Enabled; | ||||
} | } | ||||
bool IGUIObject::IsHidden() const | bool IGUIObject::IsHidden() const | ||||
Show All 25 Lines | else | ||||
return m_Name; | return m_Name; | ||||
} | } | ||||
void IGUIObject::SetFocus() | void IGUIObject::SetFocus() | ||||
{ | { | ||||
m_pGUI.SetFocusedObject(this); | m_pGUI.SetFocusedObject(this); | ||||
} | } | ||||
void IGUIObject::ReleaseFocus() | |||||
{ | |||||
m_pGUI.SetFocusedObject(nullptr); | |||||
} | |||||
bool IGUIObject::IsFocused() const | bool IGUIObject::IsFocused() const | ||||
{ | { | ||||
return m_pGUI.GetFocusedObject() == this; | return m_pGUI.GetFocusedObject() == this; | ||||
} | } | ||||
bool IGUIObject::IsBaseObject() const | bool IGUIObject::IsBaseObject() const | ||||
{ | { | ||||
return this == m_pGUI.GetBaseObject(); | return this == m_pGUI.GetBaseObject(); | ||||
Show All 34 Lines |
Wildfire Games · Phabricator