From f6adce255d355d0914c3604553ae8bb77a46b2ef Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 15 Feb 2014 16:26:34 -0800 Subject: [PATCH] more work on image overlays --- examples/overlaysExample.js | 125 +++++++++++++++++++++++++++++- interface/src/ui/ImageOverlay.cpp | 106 ++++++++++++++++--------- interface/src/ui/ImageOverlay.h | 22 +++--- 3 files changed, 202 insertions(+), 51 deletions(-) diff --git a/examples/overlaysExample.js b/examples/overlaysExample.js index d297e2525d..36e88ea43c 100644 --- a/examples/overlaysExample.js +++ b/examples/overlaysExample.js @@ -18,6 +18,61 @@ QRect(170,100,62,40), QRect(0,80,62,40)); */ +var swatch1 = Overlays.addOverlay({ + x: 100, + y: 200, + width: 31, + height: 54, + subImage: { x: 39, y: 0, width: 30, height: 54 }, + imageURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/images/testing-swatches.svg", + backgroundColor: { red: 255, green: 0, blue: 0}, + alpha: 1 + }); + +var swatch2 = Overlays.addOverlay({ + x: 130, + y: 200, + width: 31, + height: 54, + subImage: { x: 39, y: 55, width: 30, height: 54 }, + imageURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/images/testing-swatches.svg", + backgroundColor: { red: 0, green: 255, blue: 0}, + alpha: 1.0 + }); + +var swatch3 = Overlays.addOverlay({ + x: 160, + y: 200, + width: 31, + height: 54, + subImage: { x: 39, y: 0, width: 30, height: 54 }, + imageURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/images/testing-swatches.svg", + backgroundColor: { red: 0, green: 0, blue: 255}, + alpha: 1.0 + }); + +var swatch4 = Overlays.addOverlay({ + x: 190, + y: 200, + width: 31, + height: 54, + subImage: { x: 39, y: 0, width: 30, height: 54 }, + imageURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/images/testing-swatches.svg", + backgroundColor: { red: 0, green: 255, blue: 255}, + alpha: 1.0 + }); + +var swatch5 = Overlays.addOverlay({ + x: 220, + y: 200, + width: 31, + height: 54, + subImage: { x: 39, y: 0, width: 30, height: 54 }, + imageURL: "http://highfidelity-public.s3-us-west-1.amazonaws.com/images/testing-swatches.svg", + backgroundColor: { red: 255, green: 255, blue: 0}, + alpha: 1.0 + }); + var toolA = Overlays.addOverlay({ x: 100, y: 100, @@ -25,11 +80,77 @@ var toolA = Overlays.addOverlay({ height: 40, subImage: { x: 0, y: 0, width: 62, height: 40 }, imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/hifi-interface-tools.svg", - backgroundColor: { red: 255, green: 0, blue: 255}, - alpha: 1.0 + backgroundColor: { red: 255, green: 255, blue: 255}, + alpha: 0.7, + visible: false }); +var slider = Overlays.addOverlay({ + // alternate form of expressing bounds + bounds: { x: 100, y: 300, width: 158, height: 35}, + imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/slider.png", + backgroundColor: { red: 255, green: 255, blue: 255}, + alpha: 1 + }); + +var thumb = Overlays.addOverlay({ + x: 130, + y: 309, + width: 18, + height: 17, + imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", + backgroundColor: { red: 255, green: 255, blue: 255}, + alpha: 1 + }); + + +// 270x 109 +// 109... 109/2 = 54,1,54 +// 270... 39 to 66 = 28 x 9 swatches with +// unselected: +// 38,0,28,54 +// selected: +// 38,55,28,54 +//http://highfidelity-public.s3-us-west-1.amazonaws.com/images/swatches.svg + +// 123456789*123456789*123456789* +// 0123456789*123456789*123456789* + function scriptEnding() { Overlays.deleteOverlay(toolA); + //Overlays.deleteOverlay(toolB); + //Overlays.deleteOverlay(toolC); + Overlays.deleteOverlay(swatch1); + Overlays.deleteOverlay(swatch2); + Overlays.deleteOverlay(swatch3); + Overlays.deleteOverlay(swatch4); + Overlays.deleteOverlay(swatch5); + Overlays.deleteOverlay(thumb); + Overlays.deleteOverlay(slider); } Script.scriptEnding.connect(scriptEnding); + + +var toolAVisible = false; +var minX = 130; +var maxX = minX + 65; +var moveX = (minX + maxX)/2; +var dX = 1; +function update() { + moveX = moveX + dX; + if (moveX > maxX) { + dX = -1; + } + if (moveX < minX) { + dX = 1; + if (toolAVisible) { + toolAVisible = false; + } else { + toolAVisible = true; + } + Overlays.editOverlay(toolA, { visible: toolAVisible } ); + } + Overlays.editOverlay(thumb, { x: moveX } ); + +} +Script.willSendVisualDataCallback.connect(update); diff --git a/interface/src/ui/ImageOverlay.cpp b/interface/src/ui/ImageOverlay.cpp index b85f05f557..7024cff533 100644 --- a/interface/src/ui/ImageOverlay.cpp +++ b/interface/src/ui/ImageOverlay.cpp @@ -18,21 +18,16 @@ ImageOverlay::ImageOverlay() : _textureID(0), _alpha(DEFAULT_ALPHA), _backgroundColor(DEFAULT_BACKGROUND_COLOR), + _visible(true), _renderImage(false), - _textureBound(false) + _textureBound(false), + _wantClipFromImage(false) { } void ImageOverlay::init(QGLWidget* parent) { qDebug() << "ImageOverlay::init() parent=" << parent; _parent = parent; - - /* - qDebug() << "ImageOverlay::init()... url=" << url; - _bounds = drawAt; - _fromImage = fromImage; - setImageURL(url); - */ } @@ -43,6 +38,7 @@ ImageOverlay::~ImageOverlay() { } } +// TODO: handle setting image multiple times, how do we manage releasing the bound texture? void ImageOverlay::setImageURL(const QUrl& url) { // TODO: are we creating too many QNetworkAccessManager() when multiple calls to setImageURL are made? QNetworkAccessManager* manager = new QNetworkAccessManager(this); @@ -51,24 +47,18 @@ void ImageOverlay::setImageURL(const QUrl& url) { } void ImageOverlay::replyFinished(QNetworkReply* reply) { - qDebug() << "ImageOverlay::replyFinished() reply=" << reply; + // replace our byte array with the downloaded data QByteArray rawData = reply->readAll(); _textureImage.loadFromData(rawData); _renderImage = true; - // TODO: handle setting image multiple times, how do we manage releasing the bound texture - qDebug() << "ImageOverlay::replyFinished() about to call _parent->bindTexture(_textureImage)... _parent" << _parent; - - - qDebug() << "ImageOverlay::replyFinished _textureID=" << _textureID - << "_textureImage.width()=" << _textureImage.width() - << "_textureImage.height()=" << _textureImage.height(); } void ImageOverlay::render() { - //qDebug() << "ImageOverlay::render _textureID=" << _textureID << "_bounds=" << _bounds; - + if (!_visible) { + return; // do nothing if we're not visible + } if (_renderImage && !_textureBound) { _textureID = _parent->bindTexture(_textureImage); _textureBound = true; @@ -79,17 +69,25 @@ void ImageOverlay::render() { glBindTexture(GL_TEXTURE_2D, _textureID); } const float MAX_COLOR = 255; - glColor4f((_backgroundColor.red / MAX_COLOR), (_backgroundColor.green / MAX_COLOR), (_backgroundColor.blue / MAX_COLOR), _alpha); + glColor4f(_backgroundColor.red / MAX_COLOR, _backgroundColor.green / MAX_COLOR, _backgroundColor.blue / MAX_COLOR, _alpha); float imageWidth = _textureImage.width(); float imageHeight = _textureImage.height(); - float x = _fromImage.x() / imageWidth; - float y = _fromImage.y() / imageHeight; - float w = _fromImage.width() / imageWidth; // ?? is this what we want? not sure - float h = _fromImage.height() / imageHeight; - - //qDebug() << "ImageOverlay::render x=" << x << "y=" << y << "w="<