diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 8d1f757cc0..c9047c5690 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -406,11 +406,21 @@ RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray, const QScriptValue& overlayIDsToInclude, const QScriptValue& overlayIDsToDiscard, bool visibleOnly, bool collidableOnly) { - float bestDistance = std::numeric_limits::max(); - bool bestIsFront = false; const QVector overlaysToInclude = qVectorOverlayIDFromScriptValue(overlayIDsToInclude); const QVector overlaysToDiscard = qVectorOverlayIDFromScriptValue(overlayIDsToDiscard); + return findRayIntersectionInternal(ray, precisionPicking, + overlaysToInclude, overlaysToDiscard, visibleOnly, collidableOnly); +} + + +RayToOverlayIntersectionResult Overlays::findRayIntersectionInternal(const PickRay& ray, bool precisionPicking, + const QVector& overlaysToInclude, + const QVector& overlaysToDiscard, + bool visibleOnly, bool collidableOnly) { + float bestDistance = std::numeric_limits::max(); + bool bestIsFront = false; + RayToOverlayIntersectionResult result; QMapIterator i(_overlaysWorld); i.toBack(); @@ -700,8 +710,9 @@ static PointerEvent::Button toPointerButton(const QMouseEvent& event) { } } -PointerEvent Overlays::calculatePointerEvent(Overlay::Pointer overlay, PickRay ray, - RayToOverlayIntersectionResult rayPickResult, QMouseEvent* event, PointerEvent::EventType eventType) { +PointerEvent Overlays::calculatePointerEvent(Overlay::Pointer overlay, PickRay ray, + RayToOverlayIntersectionResult rayPickResult, QMouseEvent* event, + PointerEvent::EventType eventType) { auto thisOverlay = std::dynamic_pointer_cast(overlay); @@ -719,11 +730,41 @@ PointerEvent Overlays::calculatePointerEvent(Overlay::Pointer overlay, PickRay r return pointerEvent; } + +RayToOverlayIntersectionResult Overlays::findRayIntersectionForMouseEvent(PickRay ray) { + QVector overlaysToInclude; + QVector overlaysToDircard; + RayToOverlayIntersectionResult rayPickResult; + + // first priority is tablet screen + overlaysToInclude << qApp->getTabletScreenID(); + rayPickResult = findRayIntersectionInternal(ray, true, overlaysToInclude, overlaysToDircard); + if (rayPickResult.intersects) { + return rayPickResult; + } + // then tablet home button + overlaysToInclude.clear(); + overlaysToInclude << qApp->getTabletHomeButtonID(); + rayPickResult = findRayIntersectionInternal(ray, true, overlaysToInclude, overlaysToDircard); + if (rayPickResult.intersects) { + return rayPickResult; + } + // then tablet frame + overlaysToInclude.clear(); + overlaysToInclude << OverlayID(qApp->getTabletFrameID()); + rayPickResult = findRayIntersectionInternal(ray, true, overlaysToInclude, overlaysToDircard); + if (rayPickResult.intersects) { + return rayPickResult; + } + // then whatever + return findRayIntersection(ray); +} + void Overlays::mousePressEvent(QMouseEvent* event) { PerformanceTimer perfTimer("Overlays::mousePressEvent"); PickRay ray = qApp->computePickRay(event->x(), event->y()); - RayToOverlayIntersectionResult rayPickResult = findRayIntersection(ray); + RayToOverlayIntersectionResult rayPickResult = findRayIntersectionForMouseEvent(ray); if (rayPickResult.intersects) { _currentClickingOnOverlayID = rayPickResult.overlayID; @@ -744,7 +785,7 @@ void Overlays::mouseReleaseEvent(QMouseEvent* event) { PerformanceTimer perfTimer("Overlays::mouseReleaseEvent"); PickRay ray = qApp->computePickRay(event->x(), event->y()); - RayToOverlayIntersectionResult rayPickResult = findRayIntersection(ray); + RayToOverlayIntersectionResult rayPickResult = findRayIntersectionForMouseEvent(ray); if (rayPickResult.intersects) { // Only Web overlays can have focus. @@ -762,7 +803,7 @@ void Overlays::mouseMoveEvent(QMouseEvent* event) { PerformanceTimer perfTimer("Overlays::mouseMoveEvent"); PickRay ray = qApp->computePickRay(event->x(), event->y()); - RayToOverlayIntersectionResult rayPickResult = findRayIntersection(ray); + RayToOverlayIntersectionResult rayPickResult = findRayIntersectionForMouseEvent(ray); if (rayPickResult.intersects) { // Only Web overlays can have focus. diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index 38f62fee48..b369119752 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -327,6 +327,12 @@ private: OverlayID _currentClickingOnOverlayID { UNKNOWN_OVERLAY_ID }; OverlayID _currentHoverOverOverlayID { UNKNOWN_OVERLAY_ID }; + + RayToOverlayIntersectionResult findRayIntersectionInternal(const PickRay& ray, bool precisionPicking, + const QVector& overlaysToInclude, + const QVector& overlaysToDiscard, + bool visibleOnly = false, bool collidableOnly = false); + RayToOverlayIntersectionResult findRayIntersectionForMouseEvent(PickRay ray); }; #endif // hifi_Overlays_h