mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 15:30:11 +02:00
Refactor QRect conversion to QScriptValue
This commit is contained in:
parent
9e19641a1d
commit
fac6b6b426
5 changed files with 24 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QColor>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <QRect>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue