From 021dff63b43f7be682bffcf90a5f41ee3b754f07 Mon Sep 17 00:00:00 2001 From: Zander Otavka Date: Wed, 5 Aug 2015 16:57:03 -0700 Subject: [PATCH] Visibility now cascades down panel children. For an overlay to render, it, and all of its ancestor panels, must be set visible. --- examples/example/ui/floatingUIExample.js | 3 +- examples/libraries/overlayManager.js | 31 ++++++------------- interface/src/ui/overlays/FloatingUIPanel.cpp | 16 ++++++++++ interface/src/ui/overlays/FloatingUIPanel.h | 7 ++++- interface/src/ui/overlays/Image3DOverlay.cpp | 2 +- interface/src/ui/overlays/PanelAttachable.cpp | 8 +++++ interface/src/ui/overlays/PanelAttachable.h | 1 + interface/src/ui/overlays/Text3DOverlay.cpp | 2 +- 8 files changed, 45 insertions(+), 25 deletions(-) diff --git a/examples/example/ui/floatingUIExample.js b/examples/example/ui/floatingUIExample.js index 8eaeeff98b..f9baf78eea 100644 --- a/examples/example/ui/floatingUIExample.js +++ b/examples/example/ui/floatingUIExample.js @@ -19,7 +19,7 @@ var RED_DOT_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/red-dot.svg"; var BLUE_SQUARE_IMAGE_URL = HIFI_PUBLIC_BUCKET + "images/blue-square.svg"; var mainPanel = new FloatingUIPanel({ - anchorPositionBinding: null,//{ avatar: "MyAvatar" }, + anchorPositionBinding: { avatar: "MyAvatar" }, offsetRotation: { w: 1, x: 0, y: 0, z: 0 }, offsetPosition: { x: 0, y: 0.4, z: 1 }, facingRotation: { w: 0, x: 0, y: 1, z: 0 } @@ -153,6 +153,7 @@ blueSquare3.offsetPosition = { z: 0 }; +mainPanel.setChildrenVisible(); var mouseDown = {}; diff --git a/examples/libraries/overlayManager.js b/examples/libraries/overlayManager.js index 147df87831..b7c5940929 100644 --- a/examples/libraries/overlayManager.js +++ b/examples/libraries/overlayManager.js @@ -393,7 +393,7 @@ [ "anchorPosition", "anchorPositionBinding", "offsetRotation", "offsetRotationBinding", - "offsetPosition", "facingRotation" + "offsetPosition", "facingRotation", "visible" ].forEach(function(prop) { Object.defineProperty(that.prototype, prop, { get: function() { @@ -408,21 +408,6 @@ }); }); - var PSEUDO_FIELDS = []; - - PSEUDO_FIELDS.push("visible"); - Object.defineProperty(that.prototype, "visible", { - get: function() { - return this._visible; - }, - set: function(visible) { - this._visible = visible; - this._children.forEach(function(child) { - child.visible = visible; - }); - } - }); - Object.defineProperty(that.prototype, "attachedPanel", { get: function() { return findPanel(Overlays.getAttachedPanel(this._id)); @@ -456,14 +441,18 @@ }; that.prototype.setProperties = function(properties) { - for (var i in PSEUDO_FIELDS) { - if (properties[PSEUDO_FIELDS[i]] !== undefined) { - this[PSEUDO_FIELDS[i]] = properties[PSEUDO_FIELDS[i]]; - } - } Overlays.editPanel(this._id, properties); }; + that.prototype.setChildrenVisible = function() { + this._children.forEach(function(child) { + child.visible = true; + if (child.setChildrenVisible !== undefined) { + child.setChildrenVisible(); + } + }); + }; + that.prototype.destroy = function() { Overlays.deletePanel(this._id); }; diff --git a/interface/src/ui/overlays/FloatingUIPanel.cpp b/interface/src/ui/overlays/FloatingUIPanel.cpp index 2fc33bd9ad..a44f26fcc3 100644 --- a/interface/src/ui/overlays/FloatingUIPanel.cpp +++ b/interface/src/ui/overlays/FloatingUIPanel.cpp @@ -56,6 +56,14 @@ glm::quat FloatingUIPanel::getRotation() const { return getComputedOffsetRotation() * getFacingRotation(); } +bool FloatingUIPanel::getParentVisible() const { + if (getAttachedPanel()) { + return getAttachedPanel()->getVisible() && getAttachedPanel()->getParentVisible(); + } else { + return true; + } +} + void FloatingUIPanel::addChild(unsigned int childId) { if (!_children.contains(childId)) { _children.append(childId); @@ -105,6 +113,9 @@ QScriptValue FloatingUIPanel::getProperty(const QString &property) { if (property == "facingRotation") { return quatToScriptValue(_scriptEngine, getFacingRotation()); } + if (property == "visible") { + return getVisible(); + } return QScriptValue(); } @@ -201,4 +212,9 @@ void FloatingUIPanel::setProperties(const QScriptValue &properties) { setFacingRotation(newRotation); } } + + QScriptValue visible = properties.property("visible"); + if (visible.isValid()) { + setVisible(visible.toVariant().toBool()); + } } diff --git a/interface/src/ui/overlays/FloatingUIPanel.h b/interface/src/ui/overlays/FloatingUIPanel.h index fcde560570..1a50848f05 100644 --- a/interface/src/ui/overlays/FloatingUIPanel.h +++ b/interface/src/ui/overlays/FloatingUIPanel.h @@ -37,6 +37,8 @@ public: glm::vec3 getPosition() const; glm::quat getRotation() const; Pointer getAttachedPanel() const { return _attachedPanel; } + bool getVisible() const { return _visible; } + bool getParentVisible() const; // setters void setAnchorPosition(const glm::vec3& position) { _anchorPosition = position; } @@ -44,6 +46,7 @@ public: void setOffsetPosition(const glm::vec3& position) { _offsetPosition = position; } void setFacingRotation(const glm::quat& rotation) { _facingRotation = rotation; } void setAttachedPanel(Pointer panel) { _attachedPanel = panel; } + void setVisible(bool visible) { _visible = visible; } const QList& getChildren() { return _children; } void addChild(unsigned int childId); @@ -66,8 +69,10 @@ private: QUuid _offsetRotationBindEntity; Pointer _attachedPanel = nullptr; - QScriptEngine* _scriptEngine; QList _children; + bool _visible = false; + + QScriptEngine* _scriptEngine; }; #endif // hifi_FloatingUIPanel_h diff --git a/interface/src/ui/overlays/Image3DOverlay.cpp b/interface/src/ui/overlays/Image3DOverlay.cpp index 98e6d31486..349eff9ab9 100644 --- a/interface/src/ui/overlays/Image3DOverlay.cpp +++ b/interface/src/ui/overlays/Image3DOverlay.cpp @@ -47,7 +47,7 @@ void Image3DOverlay::render(RenderArgs* args) { _texture = DependencyManager::get()->getTexture(_url); } - if (!_visible || !_texture || !_texture->isLoaded()) { + if (!_visible || !getParentVisible() || !_texture || !_texture->isLoaded()) { return; } diff --git a/interface/src/ui/overlays/PanelAttachable.cpp b/interface/src/ui/overlays/PanelAttachable.cpp index fa029f12c9..1fb10253b2 100644 --- a/interface/src/ui/overlays/PanelAttachable.cpp +++ b/interface/src/ui/overlays/PanelAttachable.cpp @@ -27,6 +27,14 @@ PanelAttachable::PanelAttachable(const PanelAttachable* panelAttachable) : { } +bool PanelAttachable::getParentVisible() const { + if (getAttachedPanel()) { + return getAttachedPanel()->getVisible() && getAttachedPanel()->getParentVisible(); + } else { + return true; + } +} + void PanelAttachable::setTransforms(Transform& transform) { if (getAttachedPanel()) { transform.setTranslation(getAttachedPanel()->getComputedAnchorPosition()); diff --git a/interface/src/ui/overlays/PanelAttachable.h b/interface/src/ui/overlays/PanelAttachable.h index f22d4cc698..0b1c1a8f14 100644 --- a/interface/src/ui/overlays/PanelAttachable.h +++ b/interface/src/ui/overlays/PanelAttachable.h @@ -25,6 +25,7 @@ public: FloatingUIPanel::Pointer getAttachedPanel() const { return _attachedPanel; } virtual glm::vec3 getOffsetPosition() const { return _offsetPosition; } virtual glm::quat getFacingRotation() const { return _facingRotation; } + bool getParentVisible() const; void setAttachedPanel(FloatingUIPanel::Pointer panel) { _attachedPanel = panel; } virtual void setOffsetPosition(const glm::vec3& position) { _offsetPosition = position; } diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 030043b18c..aaa68f06c3 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -79,7 +79,7 @@ void Text3DOverlay::update(float deltatime) { } void Text3DOverlay::render(RenderArgs* args) { - if (!_visible) { + if (!_visible || !getParentVisible()) { return; // do nothing if we're not visible }