2020-01-15 08:00:37 -08:00
|
|
|
/* Copyright (C) 2020 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
#include "JSInterface_GUIProxy.h"
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2004-12-21 05:37:24 -08:00
|
|
|
#include "gui/CGUI.h"
|
2019-08-29 02:07:29 -07:00
|
|
|
#include "gui/CGUISetting.h"
|
2019-10-02 02:44:00 -07:00
|
|
|
#include "gui/ObjectBases/IGUIObject.h"
|
2020-11-21 09:49:06 -08:00
|
|
|
#include "gui/ObjectTypes/CText.h"
|
2020-06-14 13:51:21 -07:00
|
|
|
#include "ps/CLogger.h"
|
2016-09-02 09:23:44 -07:00
|
|
|
#include "scriptinterface/ScriptExtraHeaders.h"
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2004-09-06 04:28:30 -07:00
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
#include <string>
|
2020-11-18 06:39:04 -08:00
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
// Include the definition of the generic templates.
|
|
|
|
|
#include "JSInterface_GUIProxy_impl.h"
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
namespace {
|
|
|
|
|
struct SData
|
2019-10-28 04:35:04 -07:00
|
|
|
{
|
2020-11-21 09:49:06 -08:00
|
|
|
JS::PersistentRootedObject m_ToString;
|
|
|
|
|
JS::PersistentRootedObject m_Focus;
|
|
|
|
|
JS::PersistentRootedObject m_Blur;
|
|
|
|
|
JS::PersistentRootedObject m_GetComputedSize;
|
|
|
|
|
};
|
2019-10-28 04:35:04 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
template <>
|
2020-11-24 07:47:03 -08:00
|
|
|
bool JSI_GUIProxy<IGUIObject>::funcGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2020-11-24 07:47:03 -08:00
|
|
|
const SData& data = *static_cast<const SData*>(js::GetProxyReservedSlot(proxy, 0).toPrivate());
|
2020-11-21 09:49:06 -08:00
|
|
|
if (propName == "toString")
|
|
|
|
|
return vp.setObjectOrNull(data.m_ToString), true;
|
|
|
|
|
if (propName == "focus")
|
|
|
|
|
return vp.setObjectOrNull(data.m_Focus), true;
|
|
|
|
|
if (propName == "blur")
|
|
|
|
|
return vp.setObjectOrNull(data.m_Blur), true;
|
|
|
|
|
if (propName == "getComputedSize")
|
|
|
|
|
return vp.setObjectOrNull(data.m_GetComputedSize), true;
|
|
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2010-08-11 14:04:09 -07:00
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
template <>
|
|
|
|
|
std::pair<const js::BaseProxyHandler*, void*> JSI_GUIProxy<IGUIObject>::CreateData(ScriptInterface& scriptInterface)
|
2010-08-11 14:04:09 -07:00
|
|
|
{
|
2020-11-21 09:49:06 -08:00
|
|
|
SData* data = new SData();
|
|
|
|
|
ScriptRequest rq(scriptInterface);
|
|
|
|
|
#define func(class, func) &apply_to<IGUIObject, class, &class::func>
|
|
|
|
|
data->m_ToString.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, toString), 0, 0, "toString")));
|
|
|
|
|
data->m_Focus.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, focus), 0, 0, "focus")));
|
|
|
|
|
data->m_Blur.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, blur), 0, 0, "blur")));
|
|
|
|
|
data->m_GetComputedSize.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, getComputedSize), 0, 0, "getComputedSize")));
|
|
|
|
|
#undef func
|
|
|
|
|
return { &Singleton(), data };
|
2010-08-13 06:50:03 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
template class JSI_GUIProxy<IGUIObject>;
|