From 20918641f48b85cdc8283f7b0a131d41f7b83d60 Mon Sep 17 00:00:00 2001 From: druiz17 Date: Fri, 29 Sep 2017 16:48:25 -0700 Subject: [PATCH 1/3] saving work --- interface/resources/qml/desktop/Desktop.qml | 19 ++++++++++++++++++- .../scripting/WindowScriptingInterface.cpp | 5 +++++ .../src/scripting/WindowScriptingInterface.h | 1 + libraries/ui/src/OffscreenUi.cpp | 9 +++++++++ libraries/ui/src/OffscreenUi.h | 1 + .../controllerModules/hudOverlayPointer.js | 4 ++-- 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index 579b4e7fd6..6bf832865f 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -223,7 +223,7 @@ FocusScope { //offscreenWindow.activeFocusItemChanged.connect(onWindowFocusChanged); focusHack.start(); } - + function onWindowFocusChanged() { //console.log("Focus item is " + offscreenWindow.activeFocusItem); @@ -298,6 +298,23 @@ FocusScope { pinned = !pinned } + function isPointOnWindow(point) { + for (var i = 0; i < desktop.visibleChildren.length; i++) { + var child = desktop.visibleChildren[i]; + if (child.visible) { + if (child.hasOwnProperty("modality")) { + var mappedPoint = child.mapFromGlobal(point.x, point.y); + console.log(mappedPoint); + if (child.contains(mappedPoint)) { + return true; + console.log(child); + } + } + } + } + return false; + } + function setPinned(newPinned) { pinned = newPinned } diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 4b981207f1..c99e190d12 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -171,6 +171,11 @@ void WindowScriptingInterface::setPreviousBrowseAssetLocation(const QString& loc Setting::Handle(LAST_BROWSE_ASSETS_LOCATION_SETTING).set(location); } +bool WindowScriptingInterface::isPointOnDesktopWindow(QVariant point) { + auto offscreenUi = DependencyManager::get(); + return offscreenUi->isPointOnDesktopWindow(point); +} + /// Makes sure that the reticle is visible, use this in blocking forms that require a reticle and /// might be in same thread as a script that sets the reticle to invisible void WindowScriptingInterface::ensureReticleVisible() const { diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 0d58e6162d..61aaec7bea 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -72,6 +72,7 @@ public slots: void shareSnapshot(const QString& path, const QUrl& href = QUrl("")); bool isPhysicsEnabled(); bool setDisplayTexture(const QString& name); + bool isPointOnDesktopWindow(QVariant point); int openMessageBox(QString title, QString text, int buttons, int defaultButton); void updateMessageBox(int id, QString title, QString text, int buttons, int defaultButton); diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 9dfe831081..1cd30132ae 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -136,6 +136,15 @@ void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function invoke method isPointOnWindow <------"; + return result.toBool(); +} + void OffscreenUi::hide(const QString& name) { QQuickItem* item = getRootItem()->findChild(name); if (item) { diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index 391d7da6c7..93c55d06f7 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -78,6 +78,7 @@ public: bool eventFilter(QObject* originalDestination, QEvent* event) override; void addMenuInitializer(std::function f); QObject* getFlags(); + Q_INVOKABLE bool isPointOnDesktopWindow(QVariant point); QQuickItem* getDesktop(); QQuickItem* getToolWindow(); QObject* getRootMenu(); diff --git a/scripts/system/controllers/controllerModules/hudOverlayPointer.js b/scripts/system/controllers/controllerModules/hudOverlayPointer.js index 487e491201..d286f26108 100644 --- a/scripts/system/controllers/controllerModules/hudOverlayPointer.js +++ b/scripts/system/controllers/controllerModules/hudOverlayPointer.js @@ -178,11 +178,11 @@ } var hudRayPick = controllerData.hudRayPicks[this.hand]; var point2d = this.calculateNewReticlePosition(hudRayPick.intersection); - this.setReticlePosition(point2d); - if (!Reticle.isPointingAtSystemOverlay(point2d)) { + if (!Window.isPointOnDesktopWindow(point2d)) { this.exitModule(); return false; } + this.setReticlePosition(point2d); Reticle.visible = false; this.movedAway = false; this.triggerClicked = controllerData.triggerClicks[this.hand]; From 8a0ecf4e6f5957488f824fcc4266446f89285a70 Mon Sep 17 00:00:00 2001 From: druiz17 Date: Mon, 2 Oct 2017 16:46:43 -0700 Subject: [PATCH 2/3] propertly determine is laser intersects with HUD UI --- interface/resources/qml/desktop/Desktop.qml | 6 ++--- interface/resources/qml/windows/Frame.qml | 3 ++- libraries/ui/src/OffscreenUi.cpp | 1 - .../controllerModules/farActionGrabEntity.js | 24 +++++++++++++++++-- .../controllerModules/hudOverlayPointer.js | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index 6bf832865f..4e8090ce98 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -304,10 +304,10 @@ FocusScope { if (child.visible) { if (child.hasOwnProperty("modality")) { var mappedPoint = child.mapFromGlobal(point.x, point.y); - console.log(mappedPoint); - if (child.contains(mappedPoint)) { + var outLine = child.frame.children[2]; + var framePoint = outLine.mapFromGlobal(point.x, point.y); + if (child.contains(mappedPoint) || outLine.contains(framePoint)) { return true; - console.log(child); } } } diff --git a/interface/resources/qml/windows/Frame.qml b/interface/resources/qml/windows/Frame.qml index 030af974f6..c3b8399e01 100644 --- a/interface/resources/qml/windows/Frame.qml +++ b/interface/resources/qml/windows/Frame.qml @@ -26,6 +26,7 @@ Item { readonly property int frameMarginRight: frame.decoration ? frame.decoration.frameMarginRight : 0 readonly property int frameMarginTop: frame.decoration ? frame.decoration.frameMarginTop : 0 readonly property int frameMarginBottom: frame.decoration ? frame.decoration.frameMarginBottom : 0 + readonly property int offsetCorrection: 20 // Frames always fill their parents, but their decorations may extend // beyond the window via negative margin sizes @@ -73,7 +74,7 @@ Item { Rectangle { id: sizeOutline x: -frameMarginLeft - y: -frameMarginTop + y: -frameMarginTop - offsetCorrection width: window ? window.width + frameMarginLeft + frameMarginRight + 2 : 0 height: window ? window.height + frameMarginTop + frameMarginBottom + 2 : 0 color: hifi.colors.baseGrayHighlight15 diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 1cd30132ae..297ed9ca50 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -141,7 +141,6 @@ bool OffscreenUi::isPointOnDesktopWindow(QVariant point) { BLOCKING_INVOKE_METHOD(_desktop, "isPointOnWindow", Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, point)); - qDebug() << "------> invoke method isPointOnWindow <------"; return result.toBool(); } diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index c5b82f75f0..0ef0e67471 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -108,13 +108,17 @@ Script.include("/~/system/libraries/controllers.js"); "userData" ]; - + var MARGIN = 25; function FarActionGrabEntity(hand) { this.hand = hand; this.grabbedThingID = null; this.actionID = null; // action this script created... this.entityWithContextOverlay = false; this.contextOverlayTimer = false; + this.reticleMinX = MARGIN; + this.reticleMaxX; + this.reticleMinY = MARGIN; + this.reticleMaxY; var ACTION_TTL = 15; // seconds @@ -344,12 +348,28 @@ Script.include("/~/system/libraries/controllers.js"); this.grabbedThingID = null; }; + this.updateRecommendedArea = function() { + var dims = Controller.getViewportDimensions(); + this.reticleMaxX = dims.x - MARGIN; + this.reticleMaxY = dims.y - MARGIN; + }; + + this.calculateNewReticlePosition = function(intersection) { + this.updateRecommendedArea(); + var point2d = HMD.overlayFromWorldPoint(intersection); + point2d.x = Math.max(this.reticleMinX, Math.min(point2d.x, this.reticleMaxX)); + point2d.y = Math.max(this.reticleMinY, Math.min(point2d.y, this.reticleMaxY)); + return point2d; + }; + this.notPointingAtEntity = function(controllerData) { var intersection = controllerData.rayPicks[this.hand]; var entityProperty = Entities.getEntityProperties(intersection.objectID); var entityType = entityProperty.type; + var hudRayPick = controllerData.hudRayPicks[this.hand]; + var point2d = this.calculateNewReticlePosition(hudRayPick.intersection); if ((intersection.type === RayPick.INTERSECTED_ENTITY && entityType === "Web") || - intersection.type === RayPick.INTERSECTED_OVERLAY) { + intersection.type === RayPick.INTERSECTED_OVERLAY || Window.isPointOnDesktopWindow(point2d)) { return true; } return false; diff --git a/scripts/system/controllers/controllerModules/hudOverlayPointer.js b/scripts/system/controllers/controllerModules/hudOverlayPointer.js index d286f26108..add673df0c 100644 --- a/scripts/system/controllers/controllerModules/hudOverlayPointer.js +++ b/scripts/system/controllers/controllerModules/hudOverlayPointer.js @@ -178,7 +178,7 @@ } var hudRayPick = controllerData.hudRayPicks[this.hand]; var point2d = this.calculateNewReticlePosition(hudRayPick.intersection); - if (!Window.isPointOnDesktopWindow(point2d)) { + if (!Window.isPointOnDesktopWindow(point2d) && !controllerData.triggerClicks[this.hand]) { this.exitModule(); return false; } From 86f580919c5d42f1ebf3f3130b86aa75e48e190e Mon Sep 17 00:00:00 2001 From: druiz17 Date: Mon, 2 Oct 2017 17:43:43 -0700 Subject: [PATCH 3/3] remove what space --- interface/resources/qml/desktop/Desktop.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index 4e8090ce98..000e310a66 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -223,7 +223,7 @@ FocusScope { //offscreenWindow.activeFocusItemChanged.connect(onWindowFocusChanged); focusHack.start(); } - + function onWindowFocusChanged() { //console.log("Focus item is " + offscreenWindow.activeFocusItem);