From 05c135b9d8d86df89511ecb596b1ccbc189c7496 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 16 Feb 2017 21:22:23 -0800 Subject: [PATCH] uuid keys for overlays appears to work --- interface/src/Application.cpp | 10 ++--- interface/src/devices/DdeFaceTracker.cpp | 2 +- interface/src/ui/overlays/Base3DOverlay.h | 3 ++ interface/src/ui/overlays/Overlay.cpp | 10 ++--- interface/src/ui/overlays/Overlay.h | 32 ++++++---------- interface/src/ui/overlays/OverlayPanel.cpp | 2 +- interface/src/ui/overlays/Overlays.cpp | 43 ++++++++-------------- interface/src/ui/overlays/Overlays.h | 5 +-- 8 files changed, 43 insertions(+), 64 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a00cfb37d2..5f26fda674 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -529,7 +529,7 @@ bool setupEssentials(int& argc, char** argv) { // to take care of highlighting keyboard focused items, rather than // continuing to overburden Application.cpp std::shared_ptr _keyboardFocusHighlight{ nullptr }; -OverlayID _keyboardFocusHighlightID{ -1 }; +OverlayID _keyboardFocusHighlightID{ UNKNOWN_OVERLAY_ID }; // FIXME hack access to the internal share context for the Chromium helper @@ -1683,9 +1683,9 @@ void Application::cleanupBeforeQuit() { _applicationStateDevice.reset(); { - if (_keyboardFocusHighlightID) { + if (_keyboardFocusHighlightID != UNKNOWN_OVERLAY_ID) { getOverlays().deleteOverlay(_keyboardFocusHighlightID); - _keyboardFocusHighlightID = UNKNOWN_OVERLAY_ID; + _keyboardFocusHighlightID = UNKNOWN_OVERLAY_ID; } _keyboardFocusHighlight = nullptr; } @@ -3072,7 +3072,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { buttons, event->modifiers()); if (compositor.getReticleVisible() || !isHMDMode() || !compositor.getReticleOverDesktop() || - getOverlays().getOverlayAtPoint(glm::vec2(transformedPos.x(), transformedPos.y()))) { + getOverlays().getOverlayAtPoint(glm::vec2(transformedPos.x(), transformedPos.y())) != UNKNOWN_OVERLAY_ID) { getOverlays().mouseMoveEvent(&mappedEvent); getEntities()->mouseMoveEvent(&mappedEvent); } @@ -4091,7 +4091,7 @@ void Application::rotationModeChanged() const { void Application::setKeyboardFocusHighlight(const glm::vec3& position, const glm::quat& rotation, const glm::vec3& dimensions) { // Create focus - if (_keyboardFocusHighlightID == UNKNOWN_OVERLAY_ID || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) { + if (_keyboardFocusHighlightID == UNKNOWN_OVERLAY_ID || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) { _keyboardFocusHighlight = std::make_shared(); _keyboardFocusHighlight->setAlpha(1.0f); _keyboardFocusHighlight->setBorderSize(1.0f); diff --git a/interface/src/devices/DdeFaceTracker.cpp b/interface/src/devices/DdeFaceTracker.cpp index 2ddd8d9d04..fa7b2c173e 100644 --- a/interface/src/devices/DdeFaceTracker.cpp +++ b/interface/src/devices/DdeFaceTracker.cpp @@ -193,7 +193,7 @@ DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 serverPort, qui _calibrationCount(0), _calibrationValues(), _calibrationBillboard(NULL), - _calibrationBillboardID(0), + _calibrationBillboardID(UNKNOWN_OVERLAY_ID), _calibrationMessage(QString()), _isCalibrated(false) { diff --git a/interface/src/ui/overlays/Base3DOverlay.h b/interface/src/ui/overlays/Base3DOverlay.h index 18936df504..7906b9d6c0 100644 --- a/interface/src/ui/overlays/Base3DOverlay.h +++ b/interface/src/ui/overlays/Base3DOverlay.h @@ -23,6 +23,9 @@ public: Base3DOverlay(); Base3DOverlay(const Base3DOverlay* base3DOverlay); + virtual OverlayID getOverlayID() const override { return OverlayID(getID().toString()); } + void setOverlayID(OverlayID overlayID) override { setID(overlayID); } + // getters virtual bool is3D() const override { return true; } diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index 8ce4b7e97a..0ad2c94241 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -189,7 +189,7 @@ float Overlay::updatePulse() { _pulseDirection *= -1.0f; } _pulse += pulseDelta; - + return _pulse; } @@ -205,11 +205,11 @@ void Overlay::removeFromScene(Overlay::Pointer overlay, std::shared_ptr qVectorOverlayIDFromScriptValue(const QScriptValue& array) { @@ -220,9 +220,7 @@ QVector qVectorOverlayIDFromScriptValue(const QScriptValue& array) { int length = array.property("length").toInteger(); newVector.reserve(length); for (int i = 0; i < length; i++) { - OverlayID id; - OverlayIDfromScriptValue(array.property(i), id); - newVector << id; + newVector << OverlayID(array.property(i).toString()); } return newVector; } diff --git a/interface/src/ui/overlays/Overlay.h b/interface/src/ui/overlays/Overlay.h index d55b72a189..320cd532c4 100644 --- a/interface/src/ui/overlays/Overlay.h +++ b/interface/src/ui/overlays/Overlay.h @@ -15,22 +15,11 @@ #include // for xColor #include -class OverlayID { +class OverlayID : public QUuid { public: - OverlayID() {} - OverlayID(int value) { id = value; } - - OverlayID& operator=(const OverlayID& other) { id = other.id; return *this; } - OverlayID& operator++() { id++; return *this; } - - // OverlayID& operator=(unsigned int value) { id = value; return *this; } - bool operator==(const OverlayID& other) const { return id == other.id; } - bool operator!=(const OverlayID& other) const { return id != other.id; } - // bool operator<(const OverlayID& other) const { return id < other.id; } - // bool operator>(const OverlayID& other) const { return id > other.id; } - operator bool() const { return id != 0; } - - unsigned int id; + OverlayID() : QUuid() {} + OverlayID(QString v) : QUuid(v) {} + OverlayID(QUuid v) : QUuid(v) {} }; class Overlay : public QObject { @@ -50,8 +39,8 @@ public: Overlay(const Overlay* overlay); ~Overlay(); - OverlayID getOverlayID() { return _overlayID; } - void setOverlayID(OverlayID overlayID) { _overlayID = overlayID; } + virtual OverlayID getOverlayID() const { return _overlayID; } + virtual void setOverlayID(OverlayID overlayID) { _overlayID = overlayID; } virtual void update(float deltatime) {} virtual void render(RenderArgs* args) = 0; @@ -107,8 +96,6 @@ protected: render::ItemID _renderItemID{ render::Item::INVALID_ITEM_ID }; - OverlayID _overlayID; // what Overlays.cpp knows this instance as - bool _isLoaded; float _alpha; @@ -125,10 +112,13 @@ protected: xColor _color; bool _visible; // should the overlay be drawn at all Anchor _anchor; + +private: + OverlayID _overlayID; // only used for non-3d overlays }; namespace render { - template <> const ItemKey payloadGetKey(const Overlay::Pointer& overlay); + template <> const ItemKey payloadGetKey(const Overlay::Pointer& overlay); template <> const Item::Bound payloadGetBound(const Overlay::Pointer& overlay); template <> int payloadGetLayer(const Overlay::Pointer& overlay); template <> void payloadRender(const Overlay::Pointer& overlay, RenderArgs* args); @@ -141,5 +131,5 @@ QScriptValue OverlayIDtoScriptValue(QScriptEngine* engine, const OverlayID& id); void OverlayIDfromScriptValue(const QScriptValue &object, OverlayID& id); QVector qVectorOverlayIDFromScriptValue(const QScriptValue& array); - + #endif // hifi_Overlay_h diff --git a/interface/src/ui/overlays/OverlayPanel.cpp b/interface/src/ui/overlays/OverlayPanel.cpp index 484e1da216..df2b91c4ef 100644 --- a/interface/src/ui/overlays/OverlayPanel.cpp +++ b/interface/src/ui/overlays/OverlayPanel.cpp @@ -89,7 +89,7 @@ QVariant OverlayPanel::getProperty(const QString &property) { if (property == "children") { QVariantList array; for (int i = 0; i < _children.length(); i++) { - array.append(OverlayIDtoScriptValue(nullptr, _children[i])); + array.append(OverlayIDtoScriptValue(nullptr, _children[i]).toVariant()); } return array; } diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 42e6d2c679..98590e2166 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -39,9 +39,6 @@ Q_LOGGING_CATEGORY(trace_render_overlays, "trace.render.overlays") -Overlays::Overlays() : - _nextOverlayID(1) {} - void Overlays::cleanupAllOverlays() { { QWriteLocker lock(&_lock); @@ -188,14 +185,13 @@ OverlayID Overlays::addOverlay(const QString& type, const QVariant& properties) thisOverlay->setProperties(properties.toMap()); return addOverlay(thisOverlay); } - return 0; + return UNKNOWN_OVERLAY_ID; } OverlayID Overlays::addOverlay(Overlay::Pointer overlay) { QWriteLocker lock(&_lock); - OverlayID thisID = _nextOverlayID; + OverlayID thisID = OverlayID(QUuid::createUuid()); overlay->setOverlayID(thisID); - ++_nextOverlayID; if (overlay->is3D()) { _overlaysWorld[thisID] = overlay; @@ -220,9 +216,9 @@ OverlayID Overlays::cloneOverlay(OverlayID id) { attachable->getParentPanel()->addChild(cloneId); } return cloneId; - } - - return 0; // Not found + } + + return UNKNOWN_OVERLAY_ID; // Not found } bool Overlays::editOverlay(OverlayID id, const QVariant& properties) { @@ -242,13 +238,7 @@ bool Overlays::editOverlays(const QVariant& propertiesById) { bool success = true; QWriteLocker lock(&_lock); for (const auto& key : map.keys()) { - bool convertSuccess; - OverlayID id = key.toUInt(&convertSuccess); - if (!convertSuccess) { - success = false; - continue; - } - + OverlayID id = OverlayID(key); Overlay::Pointer thisOverlay = getOverlay(id); if (!thisOverlay) { success = false; @@ -310,7 +300,7 @@ OverlayID Overlays::getParentPanel(OverlayID childId) const { } else if (_panels.contains(childId)) { return _panels.key(getPanel(childId)->getParentPanel()); } - return 0; + return UNKNOWN_OVERLAY_ID; } void Overlays::setParentPanel(OverlayID childId, OverlayID panelId) { @@ -347,7 +337,7 @@ OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) { glm::vec2 pointCopy = point; QReadLocker lock(&_lock); if (!_enabled) { - return 0; + return UNKNOWN_OVERLAY_ID; } QMapIterator i(_overlaysHUD); i.toBack(); @@ -378,7 +368,7 @@ OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) { } } - return 0; // not found + return UNKNOWN_OVERLAY_ID; // not found } OverlayPropertyResult Overlays::getProperty(OverlayID id, const QString& property) { @@ -447,14 +437,14 @@ RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray, return result; } -RayToOverlayIntersectionResult::RayToOverlayIntersectionResult() : - intersects(false), - overlayID(-1), +RayToOverlayIntersectionResult::RayToOverlayIntersectionResult() : + intersects(false), + overlayID(UNKNOWN_OVERLAY_ID), distance(0), face(), intersection(), extraInfo() -{ +{ } QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine, const RayToOverlayIntersectionResult& value) { @@ -463,7 +453,7 @@ QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine, obj.setProperty("overlayID", OverlayIDtoScriptValue(engine, value.overlayID)); obj.setProperty("distance", value.distance); - QString faceName = ""; + QString faceName = ""; // handle BoxFace switch (value.face) { case MIN_X_FACE: @@ -499,7 +489,7 @@ QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine, void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& objectVar, RayToOverlayIntersectionResult& value) { QVariantMap object = objectVar.toVariant().toMap(); value.intersects = object["intersects"].toBool(); - value.overlayID = object["overlayID"].toInt(); + value.overlayID = OverlayID(QUuid(object["overlayID"].toString())); value.distance = object["distance"].toFloat(); QString faceName = object["face"].toString(); @@ -556,8 +546,7 @@ QSizeF Overlays::textSize(OverlayID id, const QString& text) const { OverlayID Overlays::addPanel(OverlayPanel::Pointer panel) { QWriteLocker lock(&_lock); - OverlayID thisID = _nextOverlayID; - ++_nextOverlayID; + OverlayID thisID = QUuid::createUuid(); _panels[thisID] = panel; return thisID; diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index 5c784739cb..4a4d6f9466 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -77,7 +77,7 @@ void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& object, R * @namespace Overlays */ -const OverlayID UNKNOWN_OVERLAY_ID = 0; +const OverlayID UNKNOWN_OVERLAY_ID = OverlayID(); class Overlays : public QObject { Q_OBJECT @@ -85,7 +85,7 @@ class Overlays : public QObject { Q_PROPERTY(OverlayID keyboardFocusOverlay READ getKeyboardFocusOverlay WRITE setKeyboardFocusOverlay) public: - Overlays(); + Overlays() {}; void init(); void update(float deltatime); @@ -305,7 +305,6 @@ private: QMap _overlaysWorld; QMap _panels; QList _overlaysToDelete; - OverlayID _nextOverlayID; QReadWriteLock _lock; QReadWriteLock _deleteLock;