Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | JSFunctionSpec JSI_IGUIObject::JSI_methods[] = | ||||
JS_FS_END | JS_FS_END | ||||
}; | }; | ||||
bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) | bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); | IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class); | ||||
if (!e) | if (!e) | ||||
return false; | return false; | ||||
JS::RootedValue idval(cx); | JS::RootedValue idval(cx); | ||||
if (!JS_IdToValue(cx, id, &idval)) | if (!JS_IdToValue(cx, id, &idval)) | ||||
return false; | return false; | ||||
std::string propName; | std::string propName; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) | ||||
} | } | ||||
JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str()); | JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str()); | ||||
return false; | return false; | ||||
} | } | ||||
bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) | bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) | ||||
{ | { | ||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); | IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class); | ||||
if (!e) | if (!e) | ||||
return result.fail(JSMSG_NOT_NONNULL_OBJECT); | return result.fail(JSMSG_NOT_NONNULL_OBJECT); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue idval(cx); | JS::RootedValue idval(cx); | ||||
if (!JS_IdToValue(cx, id, &idval)) | if (!JS_IdToValue(cx, id, &idval)) | ||||
return result.fail(JSMSG_NOT_NONNULL_OBJECT); | return result.fail(JSMSG_NOT_NONNULL_OBJECT); | ||||
Show All 36 Lines | bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) | ||||
return result.fail(JSMSG_UNDEFINED_PROP); | return result.fail(JSMSG_UNDEFINED_PROP); | ||||
} | } | ||||
void JSI_IGUIObject::init(ScriptInterface& scriptInterface) | void JSI_IGUIObject::init(ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 1, nullptr, JSI_methods, nullptr, nullptr); | scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 1, nullptr, JSI_methods, nullptr, nullptr); | ||||
} | } | ||||
bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | bool JSI_IGUIObject::toString(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | // No JSAutoRequest needed for these calls | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class); | |||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | |||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); | |||||
if (!e) | if (!e) | ||||
return false; | return false; | ||||
ScriptInterface::ToJSVal(cx, rec.rval(), "[GUIObject: " + e->GetName() + "]"); | ScriptInterface::ToJSVal(cx, args.rval(), "[GUIObject: " + e->GetName() + "]"); | ||||
return true; | return true; | ||||
} | } | ||||
bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | bool JSI_IGUIObject::focus(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | // No JSAutoRequest needed for these calls | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class); | |||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | |||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); | |||||
if (!e) | if (!e) | ||||
return false; | return false; | ||||
e->GetGUI()->SetFocusedObject(e); | e->GetGUI()->SetFocusedObject(e); | ||||
args.rval().setUndefined(); | |||||
rec.rval().setUndefined(); | |||||
return true; | return true; | ||||
} | } | ||||
bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | bool JSI_IGUIObject::blur(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | // No JSAutoRequest needed for these calls | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class); | |||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | |||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); | |||||
if (!e) | if (!e) | ||||
return false; | return false; | ||||
e->GetGUI()->SetFocusedObject(NULL); | e->GetGUI()->SetFocusedObject(NULL); | ||||
args.rval().setUndefined(); | |||||
rec.rval().setUndefined(); | |||||
return true; | return true; | ||||
} | } | ||||
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | |||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); | IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class); | ||||
if (!e) | if (!e) | ||||
return false; | return false; | ||||
e->UpdateCachedSize(); | e->UpdateCachedSize(); | ||||
CRect size = e->m_CachedActualSize; | CRect size = e->m_CachedActualSize; | ||||
JS::RootedValue objVal(cx); | JS::RootedValue objVal(cx); | ||||
try | try | ||||
{ | { | ||||
ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject( | ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject( | ||||
&objVal, | &objVal, | ||||
"left", size.left, | "left", size.left, | ||||
"right", size.right, | "right", size.right, | ||||
"top", size.top, | "top", size.top, | ||||
"bottom", size.bottom); | "bottom", size.bottom); | ||||
} | } | ||||
catch (PSERROR_Scripting_ConversionFailed&) | catch (PSERROR_Scripting_ConversionFailed&) | ||||
{ | { | ||||
debug_warn(L"Error creating size object!"); | debug_warn(L"Error creating size object!"); | ||||
return false; | return false; | ||||
} | } | ||||
rec.rval().set(objVal); | args.rval().set(objVal); | ||||
return true; | return true; | ||||
} | } |
Wildfire Games · Phabricator