Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectBases/IGUIObject.cpp
Show First 20 Lines • Show All 431 Lines • ▼ Show 20 Lines | bool IGUIObject::ScriptEventWithReturn(const CStr& eventName, const JS::HandleValueArray& paramData) | ||||
} | } | ||||
return JS::ToBoolean(result); | return JS::ToBoolean(result); | ||||
} | } | ||||
void IGUIObject::CreateJSObject() | void IGUIObject::CreateJSObject() | ||||
{ | { | ||||
ScriptRequest rq(m_pGUI.GetScriptInterface()); | ScriptRequest rq(m_pGUI.GetScriptInterface()); | ||||
m_JSObject.init(rq.cx, m_pGUI.GetScriptInterface()->CreateCustomObject("GUIObject")); | // TODO SM60: actually use this when we can use GetProxyPrivate | ||||
JS_SetPrivate(m_JSObject.get(), this); | JS::RootedValue priv(rq.cx); | ||||
//priv.get().setPrivate(this); -> need to use a virtual func. | |||||
js::ProxyOptions options; | |||||
options.setClass(&JSI_GUIProxy::ClassDefinition); | |||||
m_JSObject.init(rq.cx, js::NewProxyObject(rq.cx, &JSI_GUIProxy::GUIProxy<IGUIObject>::singleton, priv, nullptr, options)); | |||||
RegisterScriptFunctions(); | // TODO: remove this when we can use GetProxyPrivate | ||||
JS_SetPrivate(m_JSObject.get(), this); | |||||
} | } | ||||
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.initialized()) | ||||
CreateJSObject(); | CreateJSObject(); | ||||
return m_JSObject.get(); | return m_JSObject.get(); | ||||
} | } | ||||
bool IGUIObject::toString(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
// No JSAutoRequest needed for these calls | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
IGUIObject* e = static_cast<IGUIObject*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | |||||
Stan: How can one know? Does it warrant for a test? | |||||
Done Inline ActionsNeeds to dig deeper into C++ and what happens with pointers. It's either necessary or it's useless. wraitii: Needs to dig deeper into C++ and what happens with pointers. It's either necessary or it's… | |||||
if (!e) | |||||
return false; | |||||
Not Done Inline ActionsWhat is this? Itms: What is this? | |||||
Done Inline ActionsThis is a function to set the private value for a proxy. Upstream, it becomes SetProxyPrivate. The private slot fo the proxy must hold a pointer to the C++ GUI object (it already did, it still does). wraitii: This is a function to set the private value for a proxy. Upstream, it becomes SetProxyPrivate. | |||||
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface); | |||||
ScriptInterface::ToJSVal(rq, args.rval(), "[GUIObject: " + e->GetName() + "]"); | |||||
return true; | |||||
} | |||||
Not Done Inline ActionsCan we return something more meaningfull? Stan: Can we return something more meaningfull? | |||||
Done Inline ActionsMh, should probably return void at the moment, you're right. wraitii: Mh, should probably return void at the moment, you're right. | |||||
bool IGUIObject::focus(JSContext*, uint argc, JS::Value* vp) | |||||
{ | |||||
// No JSAutoRequest needed for these calls | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
IGUIObject* e = static_cast<IGUIObject*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | |||||
if (!e) | |||||
return false; | |||||
e->GetGUI().SetFocusedObject(e); | |||||
args.rval().setUndefined(); | |||||
return true; | |||||
} | |||||
bool IGUIObject::blur(JSContext*, uint argc, JS::Value* vp) | |||||
{ | |||||
// No JSAutoRequest needed for these calls | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
IGUIObject* e = static_cast<IGUIObject*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | |||||
if (!e) | |||||
return false; | |||||
e->GetGUI().SetFocusedObject(nullptr); | |||||
args.rval().setUndefined(); | |||||
return true; | |||||
} | |||||
bool IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
IGUIObject* e = static_cast<IGUIObject*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | |||||
if (!e) | |||||
return false; | |||||
e->UpdateCachedSize(); | |||||
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface); | |||||
ScriptInterface::ToJSVal(rq, args.rval(), e->m_CachedActualSize); | |||||
return true; | |||||
} | |||||
bool IGUIObject::IsEnabled() const | bool IGUIObject::IsEnabled() const | ||||
{ | { | ||||
return m_Enabled; | return m_Enabled; | ||||
} | } | ||||
bool IGUIObject::IsHidden() const | bool IGUIObject::IsHidden() const | ||||
{ | { | ||||
return m_Hidden; | return m_Hidden; | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
How can one know? Does it warrant for a test?