Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp
Show All 38 Lines | |||||
}; | }; | ||||
JSFunctionSpec JSI_IGUIObject::JSI_methods[] = | JSFunctionSpec JSI_IGUIObject::JSI_methods[] = | ||||
{ | { | ||||
JS_FN("toString", JSI_IGUIObject::toString, 0, 0), | JS_FN("toString", JSI_IGUIObject::toString, 0, 0), | ||||
JS_FN("focus", JSI_IGUIObject::focus, 0, 0), | JS_FN("focus", JSI_IGUIObject::focus, 0, 0), | ||||
JS_FN("blur", JSI_IGUIObject::blur, 0, 0), | JS_FN("blur", JSI_IGUIObject::blur, 0, 0), | ||||
JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), | JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), | ||||
JS_FN("getTextSize", JSI_IGUIObject::getTextSize, 0, 0), | |||||
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 = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); | ||||
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; | ||||
if (!ScriptInterface::FromJSVal(cx, idval, propName)) | if (!ScriptInterface::FromJSVal(cx, idval, propName)) | ||||
return false; | return false; | ||||
// Skip registered functions and inherited properties | // Skip registered functions and inherited properties | ||||
// including JSInterfaces of derived classes | |||||
if (propName == "constructor" || | if (propName == "constructor" || | ||||
propName == "prototype" || | propName == "prototype" || | ||||
propName == "toString" || | propName == "toString" || | ||||
propName == "toJSON" || | propName == "toJSON" || | ||||
propName == "focus" || | propName == "focus" || | ||||
propName == "blur" || | propName == "blur" || | ||||
propName == "getTextSize" || | propName == "getTextSize" || | ||||
propName == "getComputedSize" | propName == "getComputedSize" | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | if (!e) | ||||
return false; | return false; | ||||
e->GetGUI()->SetFocusedObject(NULL); | e->GetGUI()->SetFocusedObject(NULL); | ||||
rec.rval().setUndefined(); | rec.rval().setUndefined(); | ||||
return true; | return true; | ||||
} | } | ||||
bool JSI_IGUIObject::getTextSize(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JSAutoRequest rq(cx); | |||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
JS::RootedObject thisObj(cx, &args.thisv().toObject()); | |||||
IGUIObject* obj = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); | |||||
if (!obj || !obj->SettingExists("caption")) | |||||
return false; | |||||
CStrW font; | |||||
if (GUI<CStrW>::GetSetting(obj, "font", font) != PSRETURN_OK || font.empty()) | |||||
font = L"default"; | |||||
CGUIString caption; | |||||
EGUISettingType Type; | |||||
obj->GetSettingType("caption", Type); | |||||
if (Type == GUIST_CGUIString) | |||||
// CText, CButton, CCheckBox, CRadioButton | |||||
GUI<CGUIString>::GetSetting(obj, "caption", caption); | |||||
else if (Type == GUIST_CStrW) | |||||
{ | |||||
// CInput | |||||
CStrW captionStr; | |||||
GUI<CStrW>::GetSetting(obj, "caption", captionStr); | |||||
caption.SetValue(captionStr); | |||||
} | |||||
else | |||||
return false; | |||||
obj->UpdateCachedSize(); | |||||
float width = obj->m_CachedActualSize.GetWidth(); | |||||
if (obj->SettingExists("scrollbar")) | |||||
{ | |||||
bool scrollbar; | |||||
GUI<bool>::GetSetting(obj, "scrollbar", scrollbar); | |||||
if (scrollbar) | |||||
{ | |||||
CStr scrollbar_style; | |||||
GUI<CStr>::GetSetting(obj, "scrollbar_style", scrollbar_style); | |||||
const SGUIScrollBarStyle* scrollbar_style_object = obj->GetGUI()->GetScrollBarStyle(scrollbar_style); | |||||
if (scrollbar_style_object) | |||||
width -= scrollbar_style_object->m_Width; | |||||
} | |||||
} | |||||
float buffer_zone = 0.f; | |||||
GUI<float>::GetSetting(obj, "buffer_zone", buffer_zone); | |||||
SGUIText text = obj->GetGUI()->GenerateText(caption, font, width, buffer_zone, obj); | |||||
JS::RootedValue objVal(cx); | |||||
try | |||||
{ | |||||
ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject( | |||||
&objVal, | |||||
"width", text.m_Size.cx, | |||||
"height", text.m_Size.cy); | |||||
} | |||||
catch (PSERROR_Scripting_ConversionFailed&) | |||||
{ | |||||
debug_warn(L"Error creating size object!"); | |||||
return false; | |||||
} | |||||
rec.rval().set(objVal); | |||||
return true; | |||||
} | |||||
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | ||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | ||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); | IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); | ||||
Show All 25 Lines |
Wildfire Games · Phabricator