Visibility now cascades down panel children.

For an overlay to render, it, and all of its ancestor panels, must be
set visible.
This commit is contained in:
Zander Otavka 2015-08-05 16:57:03 -07:00
parent 865067aad9
commit 021dff63b4
8 changed files with 45 additions and 25 deletions

View file

@ -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 = {};

View file

@ -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);
};

View file

@ -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());
}
}

View file

@ -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<unsigned int>& getChildren() { return _children; }
void addChild(unsigned int childId);
@ -66,8 +69,10 @@ private:
QUuid _offsetRotationBindEntity;
Pointer _attachedPanel = nullptr;
QScriptEngine* _scriptEngine;
QList<unsigned int> _children;
bool _visible = false;
QScriptEngine* _scriptEngine;
};
#endif // hifi_FloatingUIPanel_h

View file

@ -47,7 +47,7 @@ void Image3DOverlay::render(RenderArgs* args) {
_texture = DependencyManager::get<TextureCache>()->getTexture(_url);
}
if (!_visible || !_texture || !_texture->isLoaded()) {
if (!_visible || !getParentVisible() || !_texture || !_texture->isLoaded()) {
return;
}

View file

@ -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());

View file

@ -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; }

View file

@ -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
}