Changeset View
Standalone View
source/gui/scripting/JSInterface_IGUIObject.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) | ||||
// partly for efficiency, and also to allow correct reporting of attempts to | // partly for efficiency, and also to allow correct reporting of attempts to | ||||
// access nonexistent properties.) | // access nonexistent properties.) | ||||
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 == "addItem" || | |||||
propName == "getTextSize" || | propName == "getTextSize" || | ||||
elexis: The mess with adding new entries here is that these properties are available to every GUIObject… | |||||
Done Inline ActionsI know. When I started I thought of different strategies but for the meanwhile this is the cleanest of all without doing a massive changes on how GUI code works. :/ nani: I know. When I started I thought of different strategies but for the meanwhile this is the… | |||||
Done Inline ActionsAlso having random macro definitions spread all over the place doesn't help knowing what can be changed. nani: Also having random macro definitions spread all over the place doesn't help knowing what can… | |||||
propName == "getComputedSize" | propName == "getComputedSize" | ||||
Not Done Inline Actions(This idea of #5442 is that this file becomes agnostic of specific GUIObject properties, so ideally this reference (and getTextSize) would become removed here as well.) elexis: (This idea of #5442 is that this file becomes agnostic of specific GUIObject properties, so… | |||||
Done Inline ActionsThat's unfortunately impossible/annoying to do while we still override the "get" property. That needs to be changed since SM5X+ won't support it anymore, but until then the easiest is a line there. wraitii: That's unfortunately impossible/annoying to do while we still override the "get" property. That… | |||||
) | ) | ||||
return true; | return true; | ||||
// Use onWhatever to access event handlers | // Use onWhatever to access event handlers | ||||
if (propName.substr(0, 2) == "on") | if (propName.substr(0, 2) == "on") | ||||
{ | { | ||||
CStr eventName(CStr(propName.substr(2)).LowerCase()); | CStr eventName(CStr(propName.substr(2)).LowerCase()); | ||||
std::map<CStr, JS::Heap<JSObject*>>::iterator it = e->m_ScriptHandlers.find(eventName); | std::map<CStr, JS::Heap<JSObject*>>::iterator it = e->m_ScriptHandlers.find(eventName); | ||||
▲ Show 20 Lines • Show All 629 Lines • ▼ Show 20 Lines | if (scrollbar) | ||||
CStr scrollbar_style; | CStr scrollbar_style; | ||||
GUI<CStr>::GetSetting(obj, "scrollbar_style", scrollbar_style); | GUI<CStr>::GetSetting(obj, "scrollbar_style", scrollbar_style); | ||||
const SGUIScrollBarStyle* scrollbar_style_object = obj->GetGUI()->GetScrollBarStyle(scrollbar_style); | const SGUIScrollBarStyle* scrollbar_style_object = obj->GetGUI()->GetScrollBarStyle(scrollbar_style); | ||||
if (scrollbar_style_object) | if (scrollbar_style_object) | ||||
width -= scrollbar_style_object->m_Width; | width -= scrollbar_style_object->m_Width; | ||||
} | } | ||||
} | } | ||||
float buffer_zone = 0.f; | float buffer_zone = 0.f; | ||||
Not Done Inline Actions(IIRC JS_THIS_OBJECT is replaced in some future SM version) elexis: (IIRC JS_THIS_OBJECT is replaced in some future SM version) | |||||
Not Done Inline Actionselexis: https://code.wildfiregames.com/D844?id=6608#inline-32631 | |||||
GUI<float>::GetSetting(obj, "buffer_zone", buffer_zone); | GUI<float>::GetSetting(obj, "buffer_zone", buffer_zone); | ||||
SGUIText text = obj->GetGUI()->GenerateText(caption, font, width, buffer_zone, obj); | SGUIText text = obj->GetGUI()->GenerateText(caption, font, width, buffer_zone, obj); | ||||
JS::RootedValue objVal(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); | JS::RootedValue objVal(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); | ||||
try | try | ||||
{ | { | ||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ||||
pScriptInterface->SetProperty(objVal, "width", text.m_Size.cx, false, true); | pScriptInterface->SetProperty(objVal, "width", text.m_Size.cx, false, true); | ||||
Show All 11 Lines | |||||
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); | ||||
Not Done Inline ActionsAdd one ;) If you are using vscode, you can configure it to do it for you :) Stan: Add one ;) If you are using vscode, you can configure it to do it for you :) | |||||
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::ObjectValue(*JS_NewPlainObject(cx))); | JS::RootedValue objVal(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); | ||||
try | try | ||||
Show All 16 Lines |
The mess with adding new entries here is that these properties are available to every GUIObject type, not only the one type that it was implemented with so far. So there ought to be GUIObject-type specific JSInterfaces (while possibly keeping the properties that share the same code in a shared JSInterface file)
So if one adds such a property here, then only knowingly that it's increasing the mess.
(The alternative was adding a "Setting" in the CFoo.cpp, but that is even worse because functions aren't settings and we don't want a setter for that)