Changeset View
Changeset View
Standalone View
Standalone View
source/gui/Scripting/JSInterface_CText.cpp
- This file was added.
/* Copyright (C) 2020 Wildfire Games. | |||||
* This file is part of 0 A.D. | |||||
* | |||||
* 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 | |||||
* the Free Software Foundation, either version 2 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* 0 A.D. is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "precompiled.h" | |||||
#include "JSInterface_GUIProxy.h" | |||||
#include "gui/CGUI.h" | |||||
#include "gui/CGUISetting.h" | |||||
#include "gui/ObjectBases/IGUIObject.h" | |||||
#include "gui/ObjectTypes/CText.h" | |||||
#include "ps/CLogger.h" | |||||
#include "scriptinterface/ScriptExtraHeaders.h" | |||||
#include "scriptinterface/ScriptInterface.h" | |||||
// Include the definition of the generic templates. | |||||
#include "JSInterface_GUIProxy_impl.h" | |||||
template <> | |||||
JSI_GUIProxy::GUIProxy<CText> JSI_GUIProxy::GUIProxy<CText>::singleton = JSI_GUIProxy::GUIProxy<CText>(); | |||||
template <> | |||||
bool JSI_GUIProxy::GUIProxy<CText>::funcGetter(ScriptInterface& scriptInterface, const std::string& propName, JS::MutableHandleValue vp) const | |||||
{ | |||||
if (propName == "toString" || | |||||
propName == "focus" || | |||||
propName == "blur" || | |||||
propName == "getComputedSize" || | |||||
propName == "getTextSize") | |||||
{ | |||||
ScriptRequest rq(scriptInterface); | |||||
JS::RootedFunction func(rq.cx); | |||||
std::string temp = "ctext_" + propName; | |||||
scriptInterface.GetFunctionFromStorage(temp, &func); | |||||
vp.setObjectOrNull(JS_GetFunctionObject(func)); | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
template <> | |||||
void JSI_GUIProxy::GUIProxy<CText>::RegisterFunctions(ScriptInterface& scriptInterface) | |||||
{ | |||||
ScriptRequest rq(scriptInterface); | |||||
#define REGISTERFUNC(func) \ | |||||
{\ | |||||
JS::RootedFunction obj(rq.cx, JS_NewFunction(rq.cx, &CText::func, 0, 0, #func));\ | |||||
scriptInterface.AddFunctionToStorage("ctext_"#func, obj);\ | |||||
} | |||||
REGISTERFUNC(toString); | |||||
REGISTERFUNC(focus); | |||||
REGISTERFUNC(blur); | |||||
REGISTERFUNC(getComputedSize); | |||||
REGISTERFUNC(getTextSize); | |||||
#undef REGISTERFUNC | |||||
} |
Wildfire Games · Phabricator