Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectTypes/CText.cpp
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | for (const CGUIText::SSpriteCall& spritecall : guitext.GetSpriteCalls()) | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void CText::RegisterScriptFunctions() | |||||
void CText::CreateJSObject() | |||||
{ | { | ||||
ScriptRequest rq(m_pGUI.GetScriptInterface()); | ScriptRequest rq(m_pGUI.GetScriptInterface()); | ||||
JS_DefineFunctions(rq.cx, m_JSObject, CText::JSI_methods); | |||||
// TODO SM60: actually use this when we can use GetProxyPrivate | |||||
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<CText>::singleton, priv, nullptr, options)); | |||||
// TODO: remove this when we can use GetProxyPrivate | |||||
JS_SetPrivate(m_JSObject.get(), this); | |||||
} | } | ||||
JSFunctionSpec CText::JSI_methods[] = | bool CText::toString(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JS_FN("getTextSize", CText::GetTextSize, 0, 0), | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
JS_FS_END | IGUIObject* e = static_cast<CText*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | ||||
}; | if (!e) | ||||
return false; | |||||
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface); | |||||
ScriptInterface::ToJSVal(rq, args.rval(), "[GUIObject: " + e->GetName() + "]"); | |||||
return true; | |||||
} | |||||
bool CText::focus(JSContext*, uint argc, JS::Value* vp) | |||||
{ | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
IGUIObject* e = static_cast<CText*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | |||||
if (!e) | |||||
return false; | |||||
e->GetGUI().SetFocusedObject(e); | |||||
args.rval().setUndefined(); | |||||
return true; | |||||
} | |||||
bool CText::blur(JSContext*, uint argc, JS::Value* vp) | |||||
{ | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
IGUIObject* e = static_cast<CText*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | |||||
if (!e) | |||||
return false; | |||||
e->GetGUI().SetFocusedObject(nullptr); | |||||
args.rval().setUndefined(); | |||||
return true; | |||||
} | |||||
bool CText::getComputedSize(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
CText* e = static_cast<CText*>(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 CText::GetTextSize(JSContext* cx, uint argc, JS::Value* vp) | bool CText::getTextSize(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
CText* thisObj = static_cast<CText*>(JS_GetPrivate(args.thisv().toObjectOrNull())); | |||||
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface); | ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface); | ||||
CText* thisObj = ScriptInterface::GetPrivate<CText>(rq, args, &JSI_IGUIObject::JSI_class); | |||||
if (!thisObj) | if (!thisObj) | ||||
{ | { | ||||
ScriptException::Raise(rq, "This is not a CText object!"); | ScriptException::Raise(rq, "This is not a CText object!"); | ||||
return false; | return false; | ||||
} | } | ||||
thisObj->UpdateText(); | thisObj->UpdateText(); | ||||
ScriptInterface::ToJSVal(rq, args.rval(), thisObj->m_GeneratedTexts[0].GetSize()); | ScriptInterface::ToJSVal(rq, args.rval(), thisObj->m_GeneratedTexts[0].GetSize()); | ||||
return true; | return true; | ||||
} | } |
Wildfire Games · Phabricator