From 725d56d41f23dbe8a7af73e3dc79e778e90971a2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 12 Nov 2014 16:50:13 -0800 Subject: [PATCH] Add property getting for all 2D overlays --- examples/overlaysExample.js | 14 +++++++++- interface/src/ui/overlays/ImageOverlay.cpp | 14 ++++++++++ interface/src/ui/overlays/ImageOverlay.h | 1 + interface/src/ui/overlays/Overlay.cpp | 31 ++++++++++++++++++++++ interface/src/ui/overlays/Overlay2D.cpp | 21 +++++++++++++++ interface/src/ui/overlays/TextOverlay.cpp | 17 ++++++++++-- 6 files changed, 95 insertions(+), 3 deletions(-) diff --git a/examples/overlaysExample.js b/examples/overlaysExample.js index 1dcb088d78..d64a29046a 100644 --- a/examples/overlaysExample.js +++ b/examples/overlaysExample.js @@ -168,7 +168,19 @@ var clipboardPreview = Overlays.addOverlay("clipboard", { // Demonstrate retrieving overlay properties print("Text overlay text property value =\n" + Overlays.getProperty(text, "text")); -print("Text overlay unknown property vale =\n" + Overlays.getProperty(text, "unknown")); // value = undefined +print("Text overlay alpha =\n" + Overlays.getProperty(text, "alpha")); +print("Text overlay visible =\n" + Overlays.getProperty(text, "visible")); +print("Text overlay font size =\n" + Overlays.getProperty(text, "font").size); +print("Text overlay anchor =\n" + Overlays.getProperty(text, "anchor")); +print("Text overlay unknown property value =\n" + Overlays.getProperty(text, "unknown")); // value = undefined +var sliderBounds = Overlays.getProperty(slider, "bounds"); +print("Slider overlay bounds =\n" + + "x: " + sliderBounds.x + "\n" + + "y: " + sliderBounds.y + "\n" + + "width: " + sliderBounds.width + "\n" + + "height: " + sliderBounds.height + ); + var cubePosition = Overlays.getProperty(cube, "position"); print("Cube overlay position =\n" + "x: " + cubePosition.x + "\n" diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 3b9d95af2e..f2e93c2e0e 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -151,4 +151,18 @@ 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; + } + if (property == "imageURL") { + return _imageURL.toString(); + } + return Overlay2D::getProperty(property); +} diff --git a/interface/src/ui/overlays/ImageOverlay.h b/interface/src/ui/overlays/ImageOverlay.h index ef1ead8c02..bf4f2860ad 100644 --- a/interface/src/ui/overlays/ImageOverlay.h +++ b/interface/src/ui/overlays/ImageOverlay.h @@ -44,6 +44,7 @@ public: void setClipFromSource(const QRect& bounds) { _fromImage = bounds; _wantClipFromImage = true; } void setImageURL(const QUrl& url); virtual void setProperties(const QScriptValue& properties); + virtual QScriptValue getProperty(const QString& property); private slots: void replyFinished(); // we actually want to hide this... diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index ba7269c5dc..a7c38946b7 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -109,6 +109,37 @@ QScriptValue Overlay::getProperty(const QString& property) { if (property == "color") { return xColorToScriptValue(_scriptEngine, _color); } + if (property == "alpha") { + return _alpha; + } + if (property == "glowLevel") { + return _glowLevel; + } + if (property == "pulseMax") { + return _pulseMax; + } + if (property == "pulseMin") { + return _pulseMin; + } + if (property == "pulsePeriod") { + return _pulsePeriod; + } + if (property == "glowLevelPulse") { + return _glowLevelPulse; + } + if (property == "alphaPulse") { + return _alphaPulse; + } + if (property == "colorPulse") { + return _colorPulse; + } + if (property == "visible") { + return _visible; + } + if (property == "anchor") { + return _anchor == MY_AVATAR ? "MyAvatar" : ""; + } + return QScriptValue(); } diff --git a/interface/src/ui/overlays/Overlay2D.cpp b/interface/src/ui/overlays/Overlay2D.cpp index 5a42a4fc2b..d71f8cac05 100644 --- a/interface/src/ui/overlays/Overlay2D.cpp +++ b/interface/src/ui/overlays/Overlay2D.cpp @@ -66,5 +66,26 @@ 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; + } + if (property == "x") { + return _bounds.x(); + } + if (property == "y") { + return _bounds.y(); + } + if (property == "width") { + return _bounds.width(); + } + if (property == "height") { + return _bounds.height(); + } + return Overlay::getProperty(property); } diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 3bbdd70388..a17d381a85 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -125,13 +125,26 @@ void TextOverlay::setProperties(const QScriptValue& properties) { } } - QScriptValue TextOverlay::getProperty(const QString& property) { + if (property == "font") { + QScriptValue font = _scriptEngine->newObject(); + font.setProperty("size", _fontSize); + return font; + } if (property == "text") { return _text; } + if (property == "backgroundColor") { + return xColorToScriptValue(_scriptEngine, _backgroundColor); + } + if (property == "leftMargin") { + return _leftMargin; + } + if (property == "topMargin") { + return _topMargin; + } - return Overlay::getProperty(property); + return Overlay2D::getProperty(property); }