first experimental cut at overlay image

This commit is contained in:
ZappoMan 2014-02-11 17:18:24 -08:00
parent 5688e22e6c
commit 8e3e7c1537
4 changed files with 152 additions and 0 deletions

View file

@ -1870,6 +1870,9 @@ void Application::init() {
_audio.init(_glWidget);
_testOverlayA.init(_glWidget, QString("./resources/images/hifi-interface-tools.svg"), QRect(100,100,62,40), QRect(0,0,62,40));
_testOverlayB.init(_glWidget, QString("./resources/images/hifi-interface-tools.svg"), QRect(170,100,62,40), QRect(0,80,62,40));
_rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings);
connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView()));
connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
@ -2997,6 +3000,9 @@ void Application::displayOverlay() {
_pieMenu.render();
}
_testOverlayA.render(); //
_testOverlayB.render(); //
glPopMatrix();
}

View file

@ -71,6 +71,7 @@
#include "FileLogger.h"
#include "ParticleTreeRenderer.h"
#include "ControllerScriptingInterface.h"
#include "ui/ImageOverlay.h"
class QAction;
@ -490,6 +491,9 @@ private:
void takeSnapshot();
TouchEvent _lastTouchEvent;
ImageOverlay _testOverlayA;
ImageOverlay _testOverlayB;
};
#endif /* defined(__interface__Application__) */

View file

@ -0,0 +1,69 @@
#include "ImageOverlay.h"
#include <QSvgRenderer>
#include <QPainter>
#include <QGLWidget>
#include <SharedUtil.h>
ImageOverlay::ImageOverlay() :
_parent(NULL),
_textureID(0)
{
}
void ImageOverlay::init(QGLWidget* parent, const QString& filename, const QRect& drawAt, const QRect& fromImage) {
_parent = parent;
qDebug() << "ImageOverlay::init()... filename=" << filename;
_bounds = drawAt;
_fromImage = fromImage;
_textureImage = QImage(filename);
_textureID = _parent->bindTexture(_textureImage);
}
ImageOverlay::~ImageOverlay() {
if (_parent && _textureID) {
// do we need to call this?
//_parent->deleteTexture(_textureID);
}
}
void ImageOverlay::render() {
qDebug() << "ImageOverlay::render _textureID=" << _textureID << "_bounds=" << _bounds;
bool renderImage = false;
if (renderImage) {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _textureID);
}
glColor4f(1.0f, 0.0f, 0.0f, 0.7f); // ???
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="<<w << "h="<<h << "(1.0f - y)=" << (1.0f - y);
glBegin(GL_QUADS);
//glTexCoord2f(x, 1.0f - y);
glVertex2f(_bounds.left(), _bounds.top());
//glTexCoord2f(x + w, 1.0f - y);
glVertex2f(_bounds.right(), _bounds.top());
//glTexCoord2f(x + w, 1.0f - (y + h));
glVertex2f(_bounds.right(), _bounds.bottom());
//glTexCoord2f(x, 1.0f - (y + h));
glVertex2f(_bounds.left(), _bounds.bottom());
glEnd();
if (renderImage) {
glDisable(GL_TEXTURE_2D);
}
}

View file

@ -0,0 +1,73 @@
//
// ImageOverlay.h
// interface
//
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
#ifndef __interface__ImageOverlay__
#define __interface__ImageOverlay__
#include <QImage>
#include <QGLWidget>
#include <QRect>
#include <QString>
#include <QUrl>
#include <SharedUtil.h>
#include "InterfaceConfig.h"
//#include "Util.h"
class ImageOverlay : QObject {
Q_OBJECT
Q_PROPERTY(int x READ getX WRITE setX)
Q_PROPERTY(int y READ getY WRITE setY)
Q_PROPERTY(int width READ getWidth WRITE setWidth)
Q_PROPERTY(int height READ getHeight WRITE setHeight)
Q_PROPERTY(QRect bounds READ getBounds WRITE setBounds)
Q_PROPERTY(QRect subImage READ getClipFromSource WRITE setClipFromSource)
Q_PROPERTY(xColor backgroundColor READ getBackgroundColor WRITE setBackgroundColor)
Q_PROPERTY(float alpha READ getAlpha WRITE setAlpha)
Q_PROPERTY(QUrl imageURL READ getImageURL WRITE setImageURL)
public:
ImageOverlay();
~ImageOverlay();
void init(QGLWidget* parent, const QString& filename, const QRect& drawAt, const QRect& fromImage);
void render();
// getters
int getX() const { return _bounds.x(); }
int getY() const { return _bounds.y(); }
int getWidth() const { return _bounds.width(); }
int getHeight() const { return _bounds.height(); }
const QRect& getBounds() const { return _bounds; }
const QRect& getClipFromSource() const { return _fromImage; }
const xColor& getBackgroundColor() const { return _backgroundColor; }
float getAlpha() const { return _alpha; }
const QUrl& getImageURL() const { return _imageURL; }
// setters
void setX(int x) { }
void setY(int y) { }
void setWidth(int width) { }
void setHeight(int height) { }
void setBounds(const QRect& bounds) { }
void setClipFromSource(const QRect& bounds) { }
void setBackgroundColor(const xColor& color) { }
void setAlpha(float) { }
void setImageURL(const QUrl& ) { }
private:
QUrl _imageURL;
QGLWidget* _parent;
QImage _textureImage;
GLuint _textureID;
QRect _bounds; // where on the screen to draw
QRect _fromImage; // where from in the image to sample
float _alpha;
xColor _backgroundColor;
};
#endif /* defined(__interface__ImageOverlay__) */