2019-07-23 18:40:30 -07:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2010-01-09 11:20:14 -08: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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
2019-10-02 02:44:00 -07:00
|
|
|
#include "gui/ObjectBases/IGUIObject.h"
|
|
|
|
|
#include "gui/SettingTypes/CGUIColor.h"
|
|
|
|
|
#include "gui/SettingTypes/CGUIList.h"
|
|
|
|
|
#include "gui/SettingTypes/CGUISeries.h"
|
|
|
|
|
#include "gui/SettingTypes/CGUISize.h"
|
2012-01-12 15:32:27 -08:00
|
|
|
#include "lib/external_libraries/libsdl.h"
|
2017-01-06 03:14:03 -08:00
|
|
|
#include "maths/Vector2D.h"
|
2019-07-26 06:45:14 -07:00
|
|
|
#include "ps/Hotkey.h"
|
|
|
|
|
#include "scriptinterface/ScriptConversions.h"
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2019-09-20 06:11:18 -07:00
|
|
|
#include <string>
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
#define SET(obj, name, value) STMT(JS::RootedValue v_(rq.cx); AssignOrToJSVal(rq, &v_, (value)); JS_SetProperty(rq.cx, obj, (name), v_))
|
2010-01-09 11:20:14 -08:00
|
|
|
// ignore JS_SetProperty return value, because errors should be impossible
|
|
|
|
|
// and we can't do anything useful in the case of errors anyway
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<SDL_Event_>(const Request& rq, JS::MutableHandleValue ret, SDL_Event_ const& val)
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
|
|
|
|
const char* typeName;
|
|
|
|
|
|
|
|
|
|
switch (val.ev.type)
|
|
|
|
|
{
|
2012-02-06 14:47:35 -08:00
|
|
|
case SDL_WINDOWEVENT: typeName = "windowevent"; break;
|
2010-01-09 11:20:14 -08:00
|
|
|
case SDL_KEYDOWN: typeName = "keydown"; break;
|
|
|
|
|
case SDL_KEYUP: typeName = "keyup"; break;
|
|
|
|
|
case SDL_MOUSEMOTION: typeName = "mousemotion"; break;
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN: typeName = "mousebuttondown"; break;
|
|
|
|
|
case SDL_MOUSEBUTTONUP: typeName = "mousebuttonup"; break;
|
2011-11-09 05:09:01 -08:00
|
|
|
case SDL_QUIT: typeName = "quit"; break;
|
2010-01-09 11:20:14 -08:00
|
|
|
case SDL_HOTKEYDOWN: typeName = "hotkeydown"; break;
|
|
|
|
|
case SDL_HOTKEYUP: typeName = "hotkeyup"; break;
|
|
|
|
|
default: typeName = "(unknown)"; break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
|
2014-07-14 12:52:35 -07:00
|
|
|
if (!obj)
|
2014-03-28 13:26:32 -07:00
|
|
|
{
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setUndefined();
|
2014-03-28 13:26:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
SET(obj, "type", typeName);
|
|
|
|
|
|
|
|
|
|
switch (val.ev.type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
|
case SDL_KEYUP:
|
|
|
|
|
{
|
|
|
|
|
// SET(obj, "which", (int)val.ev.key.which); // (not in wsdl.h)
|
|
|
|
|
// SET(obj, "state", (int)val.ev.key.state); // (not in wsdl.h)
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedObject keysym(rq.cx, JS_NewPlainObject(rq.cx));
|
2016-08-02 09:12:11 -07:00
|
|
|
if (!keysym)
|
2014-03-28 13:26:32 -07:00
|
|
|
{
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setUndefined();
|
2014-03-28 13:26:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue keysymVal(rq.cx, JS::ObjectValue(*keysym));
|
|
|
|
|
JS_SetProperty(rq.cx, obj, "keysym", keysymVal);
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
// SET(keysym, "scancode", (int)val.ev.key.keysym.scancode); // (not in wsdl.h)
|
|
|
|
|
SET(keysym, "sym", (int)val.ev.key.keysym.sym);
|
|
|
|
|
// SET(keysym, "mod", (int)val.ev.key.keysym.mod); // (not in wsdl.h)
|
|
|
|
|
{
|
2015-01-24 06:46:52 -08:00
|
|
|
SET(keysym, "unicode", JS::UndefinedHandleValue);
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
|
|
|
|
// TODO: scripts have no idea what all the key/mod enum values are;
|
|
|
|
|
// we should probably expose them as constants if we expect scripts to use them
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
|
{
|
|
|
|
|
// SET(obj, "which", (int)val.ev.motion.which); // (not in wsdl.h)
|
|
|
|
|
// SET(obj, "state", (int)val.ev.motion.state); // (not in wsdl.h)
|
|
|
|
|
SET(obj, "x", (int)val.ev.motion.x);
|
|
|
|
|
SET(obj, "y", (int)val.ev.motion.y);
|
|
|
|
|
// SET(obj, "xrel", (int)val.ev.motion.xrel); // (not in wsdl.h)
|
|
|
|
|
// SET(obj, "yrel", (int)val.ev.motion.yrel); // (not in wsdl.h)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
|
{
|
|
|
|
|
// SET(obj, "which", (int)val.ev.button.which); // (not in wsdl.h)
|
|
|
|
|
SET(obj, "button", (int)val.ev.button.button);
|
|
|
|
|
SET(obj, "state", (int)val.ev.button.state);
|
|
|
|
|
SET(obj, "x", (int)val.ev.button.x);
|
|
|
|
|
SET(obj, "y", (int)val.ev.button.y);
|
2017-04-21 18:24:03 -07:00
|
|
|
SET(obj, "clicks", (int)val.ev.button.clicks);
|
2010-01-09 11:20:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SDL_HOTKEYDOWN:
|
|
|
|
|
case SDL_HOTKEYUP:
|
|
|
|
|
{
|
2010-10-22 19:37:00 -07:00
|
|
|
SET(obj, "hotkey", static_cast<const char*>(val.ev.user.data1));
|
2010-01-09 11:20:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setObject(*obj);
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
2010-08-21 16:58:08 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<IGUIObject*>(const Request& UNUSED(rq), JS::MutableHandleValue ret, IGUIObject* const& val)
|
2010-08-21 16:58:08 -07:00
|
|
|
{
|
2019-09-22 16:28:25 -07:00
|
|
|
if (val == nullptr)
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setNull();
|
2014-03-28 13:26:32 -07:00
|
|
|
else
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setObject(*val->GetJSObject());
|
2010-08-21 16:58:08 -07:00
|
|
|
}
|
2017-01-06 03:14:03 -08:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CGUIString>(const Request& rq, JS::MutableHandleValue ret, const CGUIString& val)
|
2017-01-06 03:14:03 -08:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ScriptInterface::ToJSVal(rq, ret, val.GetOriginalString());
|
2017-01-06 03:14:03 -08:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CGUIString>(const Request& rq, JS::HandleValue v, CGUIString& out)
|
2017-01-06 03:14:03 -08:00
|
|
|
{
|
|
|
|
|
std::wstring val;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSVal(rq, v, val))
|
2017-01-06 03:14:03 -08:00
|
|
|
return false;
|
|
|
|
|
out.SetValue(val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSVAL_VECTOR(CVector2D)
|
|
|
|
|
JSVAL_VECTOR(std::vector<CVector2D>)
|
|
|
|
|
JSVAL_VECTOR(CGUIString)
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CGUIColor>(const Request& rq, JS::MutableHandleValue ret, const CGUIColor& val)
|
2019-07-26 11:57:28 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal<CColor>(rq, ret, val);
|
2019-07-26 11:57:28 -07:00
|
|
|
}
|
|
|
|
|
|
Delete wrongful proxy CGUIManager::GetPreDefinedColor from f0d9806b3f.
It is wrong because the predefined colors should be loaded from the GUI
page that requests to have the color parsed, which may be different from
the topmost page.
Similar to FindObjectByName removed in f9b529f2fb.
Achieve this by implementing the CGUISetting<CGUIColor>::FromJSVal
specialization, moved from ScriptInterface::FromJSVal<CGUIColor>,
instead of adding a CGUI pointer to CGUIColor.
Mark ScriptInterface::FromJSVal<GUIColor> and inherited
CColor::ParseString explicitly as deleted, so that people get a compile
error if they forget to check for predefined colors when parsing a
color.
Refs #5387, D1746 > D1684 > this > f9b529f2fb, 9be8a560a9, 415939b59b,
2c47fbd66a, 85a622b13a.
Differential Revision: https://code.wildfiregames.com/D2108
Tested on: clang 8, VS2015
This was SVN commit r22663.
2019-08-13 11:00:41 -07:00
|
|
|
/**
|
|
|
|
|
* The color depends on the predefined color database stored in the current GUI page.
|
|
|
|
|
*/
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CGUIColor>(const Request& rq, JS::HandleValue v, CGUIColor& out) = delete;
|
2019-07-26 11:57:28 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CSize>(const Request& rq, JS::MutableHandleValue ret, const CSize& val)
|
2019-08-02 09:55:15 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
CreateObject(rq, ret, "width", val.cx, "height", val.cy);
|
2019-08-02 09:55:15 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CSize>(const Request& rq, JS::HandleValue v, CSize& out)
|
2019-08-02 09:55:15 -07:00
|
|
|
{
|
|
|
|
|
if (!v.isObject())
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "CSize value must be an object!");
|
2019-08-02 09:55:15 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSProperty(rq, v, "width", out.cx))
|
2019-08-02 09:55:15 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Failed to get CSize.cx property");
|
2019-08-02 09:55:15 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSProperty(rq, v, "height", out.cy))
|
2019-08-02 09:55:15 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Failed to get CSize.cy property");
|
2019-08-02 09:55:15 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CPos>(const Request& rq, JS::MutableHandleValue ret, const CPos& val)
|
2019-07-29 04:56:11 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
CreateObject(rq, ret, "x", val.x, "y", val.y);
|
2019-07-29 04:56:11 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CPos>(const Request& rq, JS::HandleValue v, CPos& out)
|
2019-07-29 04:56:11 -07:00
|
|
|
{
|
|
|
|
|
if (!v.isObject())
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "CPos value must be an object!");
|
2019-07-29 04:56:11 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSProperty(rq, v, "x", out.x))
|
2019-07-29 04:56:11 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Failed to get CPos.x property");
|
2019-07-29 04:56:11 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSProperty(rq, v, "y", out.y))
|
2019-07-29 04:56:11 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Failed to get CPos.y property");
|
2019-07-29 04:56:11 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CRect>(const Request& rq, JS::MutableHandleValue ret, const CRect& val)
|
2019-09-04 09:15:37 -07:00
|
|
|
{
|
2019-09-12 17:56:51 -07:00
|
|
|
CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-04 09:15:37 -07:00
|
|
|
ret,
|
|
|
|
|
"left", val.left,
|
|
|
|
|
"right", val.right,
|
|
|
|
|
"top", val.top,
|
|
|
|
|
"bottom", val.bottom);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CGUISize>(const Request& rq, JS::MutableHandleValue ret, const CGUISize& val)
|
2019-07-26 07:47:27 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
val.ToJSVal(rq, ret);
|
2019-07-26 07:47:27 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CGUISize>(const Request& rq, JS::HandleValue v, CGUISize& out)
|
2019-07-26 07:47:27 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
return out.FromJSVal(rq, v);
|
2019-07-26 07:47:27 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CGUIList>(const Request& rq, JS::MutableHandleValue ret, const CGUIList& val)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, val.m_Items);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CGUIList>(const Request& rq, JS::HandleValue v, CGUIList& out)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
return FromJSVal(rq, v, out.m_Items);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CGUISeries>(const Request& rq, JS::MutableHandleValue ret, const CGUISeries& val)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, val.m_Series);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CGUISeries>(const Request& rq, JS::HandleValue v, CGUISeries& out)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
return FromJSVal(rq, v, out.m_Series);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
2019-07-26 06:45:14 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<EVAlign>(const Request& rq, JS::MutableHandleValue ret, const EVAlign& val)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
|
|
|
|
case EVAlign_Top:
|
|
|
|
|
word = "top";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EVAlign_Bottom:
|
|
|
|
|
word = "bottom";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EVAlign_Center:
|
|
|
|
|
word = "center";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
word = "error";
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Invalid EVAlign");
|
2019-07-26 06:45:14 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<EVAlign>(const Request& rq, JS::HandleValue v, EVAlign& out)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
2020-11-13 05:18:22 -08:00
|
|
|
FromJSVal(rq, v, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
|
|
|
|
|
if (word == "top")
|
|
|
|
|
out = EVAlign_Top;
|
|
|
|
|
else if (word == "bottom")
|
|
|
|
|
out = EVAlign_Bottom;
|
|
|
|
|
else if (word == "center")
|
|
|
|
|
out = EVAlign_Center;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
out = EVAlign_Top;
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Invalid alignment (should be 'left', 'right' or 'center')");
|
2019-07-26 06:45:14 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<EAlign>(const Request& rq, JS::MutableHandleValue ret, const EAlign& val)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
|
|
|
|
case EAlign_Left:
|
|
|
|
|
word = "left";
|
|
|
|
|
break;
|
|
|
|
|
case EAlign_Right:
|
|
|
|
|
word = "right";
|
|
|
|
|
break;
|
|
|
|
|
case EAlign_Center:
|
|
|
|
|
word = "center";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
word = "error";
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Invalid alignment (should be 'left', 'right' or 'center')");
|
2019-07-26 06:45:14 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<EAlign>(const Request& rq, JS::HandleValue v, EAlign& out)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
2020-11-13 05:18:22 -08:00
|
|
|
FromJSVal(rq, v, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
|
|
|
|
|
if (word == "left")
|
|
|
|
|
out = EAlign_Left;
|
|
|
|
|
else if (word == "right")
|
|
|
|
|
out = EAlign_Right;
|
|
|
|
|
else if (word == "center")
|
|
|
|
|
out = EAlign_Center;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
out = EAlign_Left;
|
2020-11-13 05:18:22 -08:00
|
|
|
JS_ReportError(rq.cx, "Invalid alignment (should be 'left', 'right' or 'center')");
|
2019-07-26 06:45:14 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-07-28 15:40:58 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> void ScriptInterface::ToJSVal<CGUISpriteInstance>(const Request& rq, JS::MutableHandleValue ret, const CGUISpriteInstance& val)
|
2019-07-28 15:40:58 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, val.GetName());
|
2019-07-28 15:40:58 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
template<> bool ScriptInterface::FromJSVal<CGUISpriteInstance>(const Request& rq, JS::HandleValue v, CGUISpriteInstance& out)
|
2019-07-28 15:40:58 -07:00
|
|
|
{
|
|
|
|
|
std::string name;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSVal(rq, v, name))
|
2019-07-28 15:40:58 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
out.SetName(name);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-07-29 04:56:11 -07:00
|
|
|
|
|
|
|
|
#undef SET
|