diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 503acc2ce3..c45f46fffc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3750,6 +3750,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue); qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue); + qScriptRegisterMetaType(scriptEngine, propertyBindingToScriptValue, propertyBindingFromScriptValue); QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get().data()); scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, diff --git a/interface/src/ui/overlays/OverlayPanel.cpp b/interface/src/ui/overlays/OverlayPanel.cpp index e388e981ea..ff7b218a5a 100644 --- a/interface/src/ui/overlays/OverlayPanel.cpp +++ b/interface/src/ui/overlays/OverlayPanel.cpp @@ -21,6 +21,38 @@ #include "Application.h" #include "Base3DOverlay.h" +PropertyBinding::PropertyBinding(QString avatar, QUuid entity) : + avatar(avatar), + entity(entity) +{ +} + +QScriptValue propertyBindingToScriptValue(QScriptEngine* engine, const PropertyBinding& value) { + QScriptValue obj = engine->newObject(); + + if (value.avatar == "MyAvatar") { + obj.setProperty("avatar", "MyAvatar"); + } else if (!value.entity.isNull()) { + obj.setProperty("entity", engine->newVariant(value.entity)); + } + + return obj; +} + +void propertyBindingFromScriptValue(const QScriptValue& object, PropertyBinding& value) { + value.avatar = ""; + value.entity = {}; + QScriptValue avatar = object.property("avatar"); + QScriptValue entity = object.property("entity"); + + if (avatar.isValid() && !avatar.isNull()) { + value.avatar = avatar.toVariant().toString(); + } else if (entity.isValid() && !entity.isNull()) { + value.entity = entity.toVariant().toUuid(); + } +} + + void OverlayPanel::addChild(unsigned int childId) { if (!_children.contains(childId)) { _children.append(childId); @@ -38,29 +70,35 @@ QScriptValue OverlayPanel::getProperty(const QString &property) { return vec3toScriptValue(_scriptEngine, getPosition()); } if (property == "positionBinding") { - QScriptValue obj = _scriptEngine->newObject(); - - if (_positionBindMyAvatar) { - obj.setProperty("avatar", "MyAvatar"); - } else if (!_positionBindEntity.isNull()) { - obj.setProperty("entity", _scriptEngine->newVariant(_positionBindEntity)); - } - - return obj; + return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_positionBindMyAvatar ? + "MyAvatar" : "", + _positionBindEntity)); +// QScriptValue obj = _scriptEngine->newObject(); +// +// if (_positionBindMyAvatar) { +// obj.setProperty("avatar", "MyAvatar"); +// } else if (!_positionBindEntity.isNull()) { +// obj.setProperty("entity", _scriptEngine->newVariant(_positionBindEntity)); +// } +// +// return obj; } if (property == "rotation") { return quatToScriptValue(_scriptEngine, getRotation()); } if (property == "rotationBinding") { - QScriptValue obj = _scriptEngine->newObject(); - - if (_rotationBindMyAvatar) { - obj.setProperty("avatar", "MyAvatar"); - } else if (!_rotationBindEntity.isNull()) { - obj.setProperty("entity", _scriptEngine->newVariant(_rotationBindEntity)); - } - - return obj; + return propertyBindingToScriptValue(_scriptEngine, PropertyBinding(_rotationBindMyAvatar ? + "MyAvatar" : "", + _rotationBindEntity)); +// QScriptValue obj = _scriptEngine->newObject(); +// +// if (_rotationBindMyAvatar) { +// obj.setProperty("avatar", "MyAvatar"); +// } else if (!_rotationBindEntity.isNull()) { +// obj.setProperty("entity", _scriptEngine->newVariant(_rotationBindEntity)); +// } +// +// return obj; } if (property == "visible") { return getVisible(); @@ -80,17 +118,11 @@ void OverlayPanel::setProperties(const QScriptValue &properties) { PanelAttachable::setProperties(properties); QScriptValue position = properties.property("position"); - if (position.isValid()) { - QScriptValue x = position.property("x"); - QScriptValue y = position.property("y"); - QScriptValue z = position.property("z"); - if (x.isValid() && y.isValid() && z.isValid()) { - glm::vec3 newPosition; - newPosition.x = x.toVariant().toFloat(); - newPosition.y = y.toVariant().toFloat(); - newPosition.z = z.toVariant().toFloat(); - setPosition(newPosition); - } + if (position.isValid() && + position.property("x").isValid() && + position.property("y").isValid() && + position.property("z").isValid()) { + vec3FromScriptValue(position, _position); } QScriptValue positionBinding = properties.property("positionBinding"); @@ -109,20 +141,12 @@ void OverlayPanel::setProperties(const QScriptValue &properties) { } QScriptValue rotation = properties.property("rotation"); - if (rotation.isValid()) { - QScriptValue x = rotation.property("x"); - QScriptValue y = rotation.property("y"); - QScriptValue z = rotation.property("z"); - QScriptValue w = rotation.property("w"); - - if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) { - glm::quat newRotation; - newRotation.x = x.toVariant().toFloat(); - newRotation.y = y.toVariant().toFloat(); - newRotation.z = z.toVariant().toFloat(); - newRotation.w = w.toVariant().toFloat(); - setRotation(newRotation); - } + if (rotation.isValid() && + rotation.property("x").isValid() && + rotation.property("y").isValid() && + rotation.property("z").isValid() && + rotation.property("w").isValid()) { + quatFromScriptValue(rotation, _rotation); } QScriptValue rotationBinding = properties.property("rotationBinding"); diff --git a/interface/src/ui/overlays/OverlayPanel.h b/interface/src/ui/overlays/OverlayPanel.h index 7c077e90da..9e790afd9f 100644 --- a/interface/src/ui/overlays/OverlayPanel.h +++ b/interface/src/ui/overlays/OverlayPanel.h @@ -21,6 +21,19 @@ #include "PanelAttachable.h" +class PropertyBinding { +public: + PropertyBinding() {} + PropertyBinding(QString avatar, QUuid entity); + QString avatar; + QUuid entity; +}; + +Q_DECLARE_METATYPE(PropertyBinding); +QScriptValue propertyBindingToScriptValue(QScriptEngine* engine, const PropertyBinding& value); +void propertyBindingFromScriptValue(const QScriptValue& object, PropertyBinding& value); + + class OverlayPanel : public QObject, public PanelAttachable { Q_OBJECT diff --git a/interface/src/ui/overlays/PanelAttachable.cpp b/interface/src/ui/overlays/PanelAttachable.cpp index 5c02ab1184..90b8112de2 100644 --- a/interface/src/ui/overlays/PanelAttachable.cpp +++ b/interface/src/ui/overlays/PanelAttachable.cpp @@ -25,10 +25,6 @@ bool PanelAttachable::getParentVisible() const { void PanelAttachable::applyTransformTo(Transform& transform) { if (getParentPanel()) { -// transform.setTranslation(getParentPanel()->getComputedPosition()); -// transform.setRotation(getParentPanel()->getComputedRotation()); -// transform.postTranslate(getParentPanel()->getOffsetPosition()); -// transform.postRotate(getParentPanel()->getOffsetRotation()); getParentPanel()->applyTransformTo(transform); transform.postTranslate(getOffsetPosition()); transform.postRotate(getOffsetRotation()); diff --git a/interface/src/ui/overlays/PanelAttachable.h b/interface/src/ui/overlays/PanelAttachable.h index 0014b81729..a41f20152e 100644 --- a/interface/src/ui/overlays/PanelAttachable.h +++ b/interface/src/ui/overlays/PanelAttachable.h @@ -18,6 +18,7 @@ #include #include #include +#include class OverlayPanel;