1
0
forked from 0ad/0ad

Add missing CPos FromJSVal, ToJSVal following 659a9ea57a.

This was SVN commit r22573.
This commit is contained in:
elexis 2019-07-29 11:56:11 +00:00
parent 0a7d0ecdde
commit d6b93b3be6
5 changed files with 56 additions and 1 deletions

View File

@ -43,6 +43,7 @@ CTooltip::CTooltip()
AddSetting(GUIST_bool, "hide_object");
// Private settings:
// This is set by GUITooltip
AddSetting(GUIST_CPos, "_mousepos");
// Defaults

View File

@ -170,6 +170,34 @@ template<> bool ScriptInterface::FromJSVal<CGUIColor>(JSContext* cx, JS::HandleV
return FromJSVal<CColor>(cx, v, out);
}
template<> void ScriptInterface::ToJSVal<CPos>(JSContext* cx, JS::MutableHandleValue ret, const CPos& val)
{
ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject(ret, "x", val.x, "y", val.y);
}
template<> bool ScriptInterface::FromJSVal<CPos>(JSContext* cx, JS::HandleValue v, CPos& out)
{
if (!v.isObject())
{
JS_ReportError(cx, "CPos value must be an object!");
return false;
}
if (!FromJSProperty(cx, v, "x", out.x))
{
JS_ReportError(cx, "Failed to get CPos.x property");
return false;
}
if (!FromJSProperty(cx, v, "y", out.y))
{
JS_ReportError(cx, "Failed to get CPos.y property");
return false;
}
return true;
}
template<> void ScriptInterface::ToJSVal<CClientArea>(JSContext* cx, JS::MutableHandleValue ret, const CClientArea& val)
{
val.ToJSVal(cx, ret);
@ -301,3 +329,5 @@ template<> bool ScriptInterface::FromJSVal<CGUISpriteInstance>(JSContext* cx, JS
out.SetName(name);
return true;
}
#undef SET

View File

@ -167,6 +167,14 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
break;
}
case GUIST_CPos:
{
CPos value;
GUI<CPos>::GetSetting(e, propName, value);
ScriptInterface::ToJSVal(cx, vp, value);
break;
}
case GUIST_CClientArea:
{
CClientArea value;
@ -421,6 +429,16 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
break;
}
case GUIST_CPos:
{
CPos value;
if (!ScriptInterface::FromJSVal(cx, vp, value))
return false;
GUI<CPos>::SetSetting(e, propName, value);
break;
}
case GUIST_CGUIColor:
{
CGUIColor value;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -345,3 +345,6 @@ template<> bool ScriptInterface::FromJSVal<CVector2D>(JSContext* cx, JS::HandleV
return true;
}
#undef FAIL
#undef WARN_IF_NOT

View File

@ -361,3 +361,6 @@ template<> bool ScriptInterface::FromJSVal<CCinemaPath>(JSContext* cx, JS::Handl
// define vectors
JSVAL_VECTOR(CFixedVector2D)
#undef FAIL
#undef FAIL_VOID