diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index 87b6dcc1c8..b36202cb04 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -162,12 +162,7 @@ QScriptValue BillboardOverlay::getProperty(const QString& property) { return _url; } if (property == "subImage") { - QScriptValue subImage = _scriptEngine->newObject(); - subImage.setProperty("x", _fromImage.x()); - subImage.setProperty("y", _fromImage.y()); - subImage.setProperty("width", _fromImage.width()); - subImage.setProperty("height", _fromImage.height()); - return subImage; + return qRectToScriptValue(_scriptEngine, _fromImage); } if (property == "scale") { return _scale; diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index f2e93c2e0e..615872e6ef 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -153,12 +153,7 @@ void ImageOverlay::setProperties(const QScriptValue& properties) { QScriptValue ImageOverlay::getProperty(const QString& property) { if (property == "subImage") { - QScriptValue subImage = _scriptEngine->newObject(); - subImage.setProperty("x", _fromImage.x()); - subImage.setProperty("y", _fromImage.y()); - subImage.setProperty("width", _fromImage.width()); - subImage.setProperty("height", _fromImage.height()); - return subImage; + return qRectToScriptValue(_scriptEngine, _fromImage); } if (property == "imageURL") { return _imageURL.toString(); diff --git a/interface/src/ui/overlays/Overlay2D.cpp b/interface/src/ui/overlays/Overlay2D.cpp index d71f8cac05..b7c0a3a3e4 100644 --- a/interface/src/ui/overlays/Overlay2D.cpp +++ b/interface/src/ui/overlays/Overlay2D.cpp @@ -67,12 +67,7 @@ void Overlay2D::setProperties(const QScriptValue& properties) { QScriptValue Overlay2D::getProperty(const QString& property) { if (property == "bounds") { - QScriptValue bounds = _scriptEngine->newObject(); - bounds.setProperty("x", _bounds.x()); - bounds.setProperty("y", _bounds.y()); - bounds.setProperty("width", _bounds.width()); - bounds.setProperty("height", _bounds.height()); - return bounds; + return qRectToScriptValue(_scriptEngine, _bounds); } if (property == "x") { return _bounds.x(); diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 5867e2ef43..02b9d5c927 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -30,6 +31,7 @@ void registerMetaTypes(QScriptEngine* engine) { qScriptRegisterMetaType(engine, vec3toScriptValue, vec3FromScriptValue); qScriptRegisterMetaType(engine, vec2toScriptValue, vec2FromScriptValue); qScriptRegisterMetaType(engine, quatToScriptValue, quatFromScriptValue); + qScriptRegisterMetaType(engine, qRectToScriptValue, qRectFromScriptValue); qScriptRegisterMetaType(engine, xColorToScriptValue, xColorFromScriptValue); qScriptRegisterMetaType(engine, qColorToScriptValue, qColorFromScriptValue); qScriptRegisterMetaType(engine, qURLToScriptValue, qURLFromScriptValue); @@ -96,6 +98,22 @@ void quatFromScriptValue(const QScriptValue &object, glm::quat& quat) { quat.w = object.property("w").toVariant().toFloat(); } +QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect) { + QScriptValue obj = engine->newObject(); + obj.setProperty("x", rect.x()); + obj.setProperty("y", rect.y()); + obj.setProperty("width", rect.width()); + obj.setProperty("height", rect.height()); + return obj; +} + +void qRectFromScriptValue(const QScriptValue &object, QRect& rect) { + rect.setX(object.property("x").toVariant().toInt()); + rect.setY(object.property("y").toVariant().toInt()); + rect.setWidth(object.property("width").toVariant().toInt()); + rect.setHeight(object.property("height").toVariant().toInt()); +} + QScriptValue xColorToScriptValue(QScriptEngine *engine, const xColor& color) { QScriptValue obj = engine->newObject(); obj.setProperty("red", color.red); diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index b8884be845..0fd3138b06 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -42,6 +42,9 @@ void vec2FromScriptValue(const QScriptValue &object, glm::vec2 &vec2); QScriptValue quatToScriptValue(QScriptEngine* engine, const glm::quat& quat); void quatFromScriptValue(const QScriptValue &object, glm::quat& quat); +QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect); +void qRectFromScriptValue(const QScriptValue& object, QRect& rect); + QScriptValue xColorToScriptValue(QScriptEngine* engine, const xColor& color); void xColorFromScriptValue(const QScriptValue &object, xColor& color);