Changeset View
Changeset View
Standalone View
Standalone View
source/gui/scripting/JSInterface_GUITypes.cpp
Show All 27 Lines | JSClass JSI_GUISize::JSI_class = { | ||||
nullptr, nullptr, | nullptr, nullptr, | ||||
nullptr, nullptr, | nullptr, nullptr, | ||||
nullptr, nullptr, nullptr, nullptr, | nullptr, nullptr, nullptr, nullptr, | ||||
nullptr, nullptr, JSI_GUISize::construct, nullptr | nullptr, nullptr, JSI_GUISize::construct, nullptr | ||||
}; | }; | ||||
JSFunctionSpec JSI_GUISize::JSI_methods[] = | JSFunctionSpec JSI_GUISize::JSI_methods[] = | ||||
{ | { | ||||
JS_FS("toString", JSI_GUISize::toString, 0, 0), | JS_FS("toString", JSI_GUISize::toString, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), | ||||
JS_FS_END | JS_FS_END | ||||
}; | }; | ||||
JSPropertySpec JSI_GUISize::JSI_props[] = | |||||
{ | |||||
JS_PS_END | |||||
}; | |||||
void JSI_GUISize::RegisterScriptClass(ScriptInterface& scriptInterface) | |||||
{ | |||||
scriptInterface.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 1, nullptr, JSI_GUISize::JSI_methods, nullptr, nullptr); | |||||
} | |||||
bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp) | bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize")); | JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize")); | ||||
if (args.length() == 8) | if (args.length() == 8) | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | #undef SIDE | ||||
rec.rval().setString(JS_NewStringCopyZ(cx, buffer.c_str())); | rec.rval().setString(JS_NewStringCopyZ(cx, buffer.c_str())); | ||||
return true; | return true; | ||||
} | } | ||||
/**** GUIColor ****/ | /**** GUIColor ****/ | ||||
JSClass JSI_GUIColor::JSI_class = { | JSClass JSI_GUIColor::JSI_class = { | ||||
"GUIColor", 0, | "GUIColor", 0, | ||||
nullptr, nullptr, | nullptr, nullptr, | ||||
nullptr, nullptr, | nullptr, nullptr, | ||||
nullptr, nullptr, nullptr, nullptr, | nullptr, nullptr, nullptr, nullptr, | ||||
nullptr, nullptr, JSI_GUIColor::construct, nullptr | nullptr, nullptr, JSI_GUIColor::construct, nullptr | ||||
}; | }; | ||||
JSFunctionSpec JSI_GUIColor::JSI_methods[] = | JSFunctionSpec JSI_GUIColor::JSI_methods[] = | ||||
{ | { | ||||
JS_FS("toString", JSI_GUIColor::toString, 0, 0), | JS_FS("toString", JSI_GUIColor::toString, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), | ||||
JS_FS_END | JS_FS_END | ||||
}; | }; | ||||
JSPropertySpec JSI_GUIColor::JSI_props[] = | |||||
{ | |||||
JS_PS_END | |||||
}; | |||||
void JSI_GUIColor::RegisterScriptClass(ScriptInterface& scriptInterface) | |||||
{ | |||||
scriptInterface.DefineCustomObjectType(&JSI_GUIColor::JSI_class, JSI_GUIColor::construct, 1, nullptr, JSI_GUIColor::JSI_methods, nullptr, nullptr); | |||||
} | |||||
bool JSI_GUIColor::construct(JSContext* cx, uint argc, JS::Value* vp) | bool JSI_GUIColor::construct(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor")); | JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor")); | ||||
Show All 35 Lines | bool JSI_GUIColor::toString(JSContext* cx, uint argc, JS::Value* vp) | ||||
snprintf(buffer, 256, "%d %d %d %d", | snprintf(buffer, 256, "%d %d %d %d", | ||||
(int)(255.0 * r), | (int)(255.0 * r), | ||||
(int)(255.0 * g), | (int)(255.0 * g), | ||||
(int)(255.0 * b), | (int)(255.0 * b), | ||||
(int)(255.0 * a)); | (int)(255.0 * a)); | ||||
rec.rval().setString(JS_NewStringCopyZ(cx, buffer)); | rec.rval().setString(JS_NewStringCopyZ(cx, buffer)); | ||||
return true; | return true; | ||||
} | } | ||||
/**** GUIMouse ****/ | |||||
JSClass JSI_GUIMouse::JSI_class = { | |||||
"GUIMouse", 0, | |||||
nullptr, nullptr, | |||||
nullptr, nullptr, | |||||
nullptr, nullptr, nullptr, nullptr, | |||||
nullptr, nullptr, JSI_GUIMouse::construct, nullptr | |||||
}; | |||||
JSFunctionSpec JSI_GUIMouse::JSI_methods[] = | |||||
{ | |||||
JS_FS("toString", JSI_GUIMouse::toString, 0, 0), | |||||
JS_FS_END | |||||
}; | |||||
bool JSI_GUIMouse::construct(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JSAutoRequest rq(cx); | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | |||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIMouse")); | |||||
if (args.length() == 3) | |||||
{ | |||||
JS_SetProperty(cx, obj, "x", args[0]); | |||||
JS_SetProperty(cx, obj, "y", args[1]); | |||||
JS_SetProperty(cx, obj, "buttons", args[2]); | |||||
} | |||||
else | |||||
{ | |||||
JS::RootedValue zero (cx, JS::NumberValue(0)); | |||||
JS_SetProperty(cx, obj, "x", zero); | |||||
JS_SetProperty(cx, obj, "y", zero); | |||||
JS_SetProperty(cx, obj, "buttons", zero); | |||||
} | |||||
args.rval().setObject(*obj); | |||||
return true; | |||||
} | |||||
bool JSI_GUIMouse::toString(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
UNUSED2(argc); | |||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | |||||
i32 x, y, buttons; | |||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | |||||
pScriptInterface->GetProperty(rec.thisv(), "x", x); | |||||
pScriptInterface->GetProperty(rec.thisv(), "y", y); | |||||
pScriptInterface->GetProperty(rec.thisv(), "buttons", buttons); | |||||
char buffer[256]; | |||||
snprintf(buffer, 256, "%d %d %d", x, y, buttons); | |||||
rec.rval().setString(JS_NewStringCopyZ(cx, buffer)); | |||||
return true; | |||||
} | |||||
// Initialise all the types at once: | |||||
void JSI_GUITypes::init(ScriptInterface& scriptInterface) | |||||
{ | |||||
scriptInterface.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 1, nullptr, JSI_GUISize::JSI_methods, NULL, NULL); | |||||
scriptInterface.DefineCustomObjectType(&JSI_GUIColor::JSI_class, JSI_GUIColor::construct, 1, nullptr, JSI_GUIColor::JSI_methods, NULL, NULL); | |||||
scriptInterface.DefineCustomObjectType(&JSI_GUIMouse::JSI_class, JSI_GUIMouse::construct, 1, nullptr, JSI_GUIMouse::JSI_methods, NULL, NULL); | |||||
} |
Wildfire Games · Phabricator