Update overlays to handle updates in drawOnHUD after creation

This commit is contained in:
Ryan Huffman 2014-12-31 10:15:15 -08:00
parent 3bfc298349
commit 5caec4dea5
4 changed files with 40 additions and 6 deletions

View file

@ -14,6 +14,7 @@
#include <QGLWidget>
#include <SharedUtil.h>
#include "Application.h"
#include "Base3DOverlay.h"
const glm::vec3 DEFAULT_POSITION = glm::vec3(0.0f, 0.0f, 0.0f);
@ -47,6 +48,13 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) :
Base3DOverlay::~Base3DOverlay() {
}
void Base3DOverlay::setDrawOnHUD(bool value) {
if (_drawOnHUD != value) {
_drawOnHUD = value;
Application::getInstance()->getOverlays().overlayDrawOnChanged(this);
}
}
void Base3DOverlay::setProperties(const QScriptValue& properties) {
Overlay::setProperties(properties);

View file

@ -47,7 +47,7 @@ public:
void setRotation(const glm::quat& value) { _rotation = value; }
void setIgnoreRayIntersection(bool value) { _ignoreRayIntersection = value; }
void setDrawInFront(bool value) { _drawInFront = value; }
void setDrawOnHUD(bool value) { _drawOnHUD = value; }
void setDrawOnHUD(bool value);
virtual void setProperties(const QScriptValue& properties);
virtual QScriptValue getProperty(const QString& property);

View file

@ -228,11 +228,13 @@ unsigned int Overlays::cloneOverlay(unsigned int id) {
bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) {
Overlay* thisOverlay = NULL;
QWriteLocker lock(&_lock);
if (_overlaysHUD.contains(id)) {
thisOverlay = _overlaysHUD[id];
} else if (_overlaysWorld.contains(id)) {
thisOverlay = _overlaysWorld[id];
{
QReadLocker lock(&_lock);
if (_overlaysHUD.contains(id)) {
thisOverlay = _overlaysHUD[id];
} else if (_overlaysWorld.contains(id)) {
thisOverlay = _overlaysWorld[id];
}
}
if (thisOverlay) {
thisOverlay->setProperties(properties);
@ -451,6 +453,26 @@ void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& object, R
value.extraInfo = object.property("extraInfo").toVariant().toString();
}
void Overlays::overlayDrawOnChanged(Base3DOverlay* overlay) {
if (overlay->getDrawOnHUD()) {
for (unsigned int id : _overlaysWorld.keys()) {
if (_overlaysWorld[id] == overlay) {
QWriteLocker lock(&_lock);
_overlaysWorld.remove(id);
_overlaysHUD[id] = overlay;
}
}
} else {
for (unsigned int id : _overlaysHUD.keys()) {
if (_overlaysHUD[id] == overlay) {
QWriteLocker lock(&_lock);
_overlaysHUD.remove(id);
_overlaysWorld[id] = overlay;
}
}
}
}
bool Overlays::isLoaded(unsigned int id) {
QReadLocker lock(&_lock);
Overlay* thisOverlay = NULL;

View file

@ -15,6 +15,7 @@
#include <QScriptValue>
#include <QSignalMapper>
#include "Base3DOverlay.h"
#include "Overlay.h"
class OverlayPropertyResult {
@ -81,6 +82,9 @@ public slots:
/// returns details about the closest 3D Overlay hit by the pick ray
RayToOverlayIntersectionResult findRayIntersection(const PickRay& ray);
// called by Base3DOverlay when drawOnHUD changes
void overlayDrawOnChanged(Base3DOverlay* overlay);
/// returns whether the overlay's assets are loaded or not
bool isLoaded(unsigned int id);