Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 18 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_FN("toString", JSI_GUISize::toString, 0, 0), | ||||
JS_FS_END | JS_FS_END | ||||
}; | }; | ||||
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) | ||||
{ | { | ||||
JS_SetProperty(cx, obj, "left", args[0]); | JS_SetProperty(cx, obj, "left", args[0]); | ||||
JS_SetProperty(cx, obj, "top", args[1]); | JS_SetProperty(cx, obj, "top", args[1]); | ||||
JS_SetProperty(cx, obj, "right", args[2]); | JS_SetProperty(cx, obj, "right", args[2]); | ||||
JS_SetProperty(cx, obj, "bottom", args[3]); | JS_SetProperty(cx, obj, "bottom", args[3]); | ||||
JS_SetProperty(cx, obj, "rleft", args[4]); | JS_SetProperty(cx, obj, "rleft", args[4]); | ||||
JS_SetProperty(cx, obj, "rtop", args[5]); | JS_SetProperty(cx, obj, "rtop", args[5]); | ||||
JS_SetProperty(cx, obj, "rright", args[6]); | JS_SetProperty(cx, obj, "rright", args[6]); | ||||
JS_SetProperty(cx, obj, "rbottom", args[7]); | JS_SetProperty(cx, obj, "rbottom", args[7]); | ||||
} | } | ||||
else if (args.length() == 4) | else if (args.length() == 4) | ||||
{ | { | ||||
JS::RootedValue zero(cx, JSVAL_ZERO); | JS::RootedValue zero(cx, JS::NumberValue(0)); | ||||
JS_SetProperty(cx, obj, "left", args[0]); | JS_SetProperty(cx, obj, "left", args[0]); | ||||
JS_SetProperty(cx, obj, "top", args[1]); | JS_SetProperty(cx, obj, "top", args[1]); | ||||
JS_SetProperty(cx, obj, "right", args[2]); | JS_SetProperty(cx, obj, "right", args[2]); | ||||
JS_SetProperty(cx, obj, "bottom", args[3]); | JS_SetProperty(cx, obj, "bottom", args[3]); | ||||
JS_SetProperty(cx, obj, "rleft", zero); | JS_SetProperty(cx, obj, "rleft", zero); | ||||
JS_SetProperty(cx, obj, "rtop", zero); | JS_SetProperty(cx, obj, "rtop", zero); | ||||
JS_SetProperty(cx, obj, "rright", zero); | JS_SetProperty(cx, obj, "rright", zero); | ||||
JS_SetProperty(cx, obj, "rbottom", zero); | JS_SetProperty(cx, obj, "rbottom", zero); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
JS::RootedValue zero(cx, JSVAL_ZERO); | JS::RootedValue zero(cx, JS::NumberValue(0)); | ||||
JS_SetProperty(cx, obj, "left", zero); | JS_SetProperty(cx, obj, "left", zero); | ||||
JS_SetProperty(cx, obj, "top", zero); | JS_SetProperty(cx, obj, "top", zero); | ||||
JS_SetProperty(cx, obj, "right", zero); | JS_SetProperty(cx, obj, "right", zero); | ||||
JS_SetProperty(cx, obj, "bottom", zero); | JS_SetProperty(cx, obj, "bottom", zero); | ||||
JS_SetProperty(cx, obj, "rleft", zero); | JS_SetProperty(cx, obj, "rleft", zero); | ||||
JS_SetProperty(cx, obj, "rtop", zero); | JS_SetProperty(cx, obj, "rtop", zero); | ||||
JS_SetProperty(cx, obj, "rright", zero); | JS_SetProperty(cx, obj, "rright", zero); | ||||
JS_SetProperty(cx, obj, "rbottom", zero); | JS_SetProperty(cx, obj, "rbottom", zero); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | JSClass JSI_GUIColor::JSI_class = { | ||||
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_FN("toString", JSI_GUIColor::toString, 0, 0), | ||||
JS_FS_END | JS_FS_END | ||||
}; | }; | ||||
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); | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | JSClass JSI_GUIMouse::JSI_class = { | ||||
nullptr, nullptr, | nullptr, nullptr, | ||||
nullptr, nullptr, | nullptr, nullptr, | ||||
nullptr, nullptr, nullptr, nullptr, | nullptr, nullptr, nullptr, nullptr, | ||||
nullptr, nullptr, JSI_GUIMouse::construct, nullptr | nullptr, nullptr, JSI_GUIMouse::construct, nullptr | ||||
}; | }; | ||||
JSFunctionSpec JSI_GUIMouse::JSI_methods[] = | JSFunctionSpec JSI_GUIMouse::JSI_methods[] = | ||||
{ | { | ||||
JS_FS("toString", JSI_GUIMouse::toString, 0, 0), | JS_FN("toString", JSI_GUIMouse::toString, 0, 0), | ||||
JS_FS_END | JS_FS_END | ||||
}; | }; | ||||
bool JSI_GUIMouse::construct(JSContext* cx, uint argc, JS::Value* vp) | bool JSI_GUIMouse::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); | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator