From 563be9ab9171dd03acbbf7303fa4493e883f0181 Mon Sep 17 00:00:00 2001 From: Triplelexx Date: Fri, 16 Mar 2018 20:13:02 +0000 Subject: [PATCH 01/19] tidy inspect.js --- script-archive/inspect.js | 411 +++++++++++++++++++------------------- 1 file changed, 201 insertions(+), 210 deletions(-) diff --git a/script-archive/inspect.js b/script-archive/inspect.js index 555b4105b7..45fc281792 100644 --- a/script-archive/inspect.js +++ b/script-archive/inspect.js @@ -26,14 +26,14 @@ var RADIUS_RATE = 1.0 / 100.0; var PAN_RATE = 250.0; var Y_AXIS = { - x: 0, - y: 1, - z: 0 + x: 0, + y: 1, + z: 0 }; var X_AXIS = { - x: 1, - y: 0, - z: 0 + x: 1, + y: 0, + z: 0 }; var LOOK_AT_TIME = 500; @@ -58,19 +58,19 @@ var mouseLastY = 0; var center = { - x: 0, - y: 0, - z: 0 + x: 0, + y: 0, + z: 0 }; var position = { - x: 0, - y: 0, - z: 0 + x: 0, + y: 0, + z: 0 }; var vector = { - x: 0, - y: 0, - z: 0 + x: 0, + y: 0, + z: 0 }; var radius = 0.0; var azimuth = 0.0; @@ -83,258 +83,249 @@ var rotatingTowardsTarget = false; var targetCamOrientation; var oldPosition, oldOrientation; - function orientationOf(vector) { - var direction, - yaw, - pitch; + var direction, + yaw, + pitch; - direction = Vec3.normalize(vector); - yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS); - pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS); - return Quat.multiply(yaw, pitch); + direction = Vec3.normalize(vector); + yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS); + pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS); + return Quat.multiply(yaw, pitch); } - function handleRadialMode(dx, dy) { - azimuth += dx / AZIMUTH_RATE; - radius += radius * dy * RADIUS_RATE; - if (radius < 1) { - radius = 1; - } + azimuth += dx / AZIMUTH_RATE; + radius += radius * dy * RADIUS_RATE; + if (radius < 1) { + radius = 1; + } - vector = { - x: (Math.cos(altitude) * Math.cos(azimuth)) * radius, - y: Math.sin(altitude) * radius, - z: (Math.cos(altitude) * Math.sin(azimuth)) * radius - }; - position = Vec3.sum(center, vector); - Camera.setPosition(position); - Camera.setOrientation(orientationOf(vector)); + vector = { + x: (Math.cos(altitude) * Math.cos(azimuth)) * radius, + y: Math.sin(altitude) * radius, + z: (Math.cos(altitude) * Math.sin(azimuth)) * radius + }; + position = Vec3.sum(center, vector); + Camera.setPosition(position); + Camera.setOrientation(orientationOf(vector)); } function handleOrbitMode(dx, dy) { - azimuth += dx / AZIMUTH_RATE; - altitude += dy / ALTITUDE_RATE; - if (altitude > PI / 2.0) { - altitude = PI / 2.0; - } - if (altitude < -PI / 2.0) { - altitude = -PI / 2.0; - } + azimuth += dx / AZIMUTH_RATE; + altitude += dy / ALTITUDE_RATE; + if (altitude > PI / 2.0) { + altitude = PI / 2.0; + } + if (altitude < -PI / 2.0) { + altitude = -PI / 2.0; + } - vector = { - x: (Math.cos(altitude) * Math.cos(azimuth)) * radius, - y: Math.sin(altitude) * radius, - z: (Math.cos(altitude) * Math.sin(azimuth)) * radius - }; - position = Vec3.sum(center, vector); - Camera.setPosition(position); - Camera.setOrientation(orientationOf(vector)); + vector = { + x: (Math.cos(altitude) * Math.cos(azimuth)) * radius, + y: Math.sin(altitude) * radius, + z: (Math.cos(altitude) * Math.sin(azimuth)) * radius + }; + position = Vec3.sum(center, vector); + Camera.setPosition(position); + Camera.setOrientation(orientationOf(vector)); } - function handlePanMode(dx, dy) { - var up = Quat.getUp(Camera.getOrientation()); - var right = Quat.getRight(Camera.getOrientation()); - var distance = Vec3.length(vector); + var up = Quat.getUp(Camera.getOrientation()); + var right = Quat.getRight(Camera.getOrientation()); + var distance = Vec3.length(vector); - var dv = Vec3.sum(Vec3.multiply(up, distance * dy / PAN_RATE), Vec3.multiply(right, -distance * dx / PAN_RATE)); + var dv = Vec3.sum(Vec3.multiply(up, distance * dy / PAN_RATE), Vec3.multiply(right, -distance * dx / PAN_RATE)); - center = Vec3.sum(center, dv); - position = Vec3.sum(position, dv); + center = Vec3.sum(center, dv); + position = Vec3.sum(position, dv); - Camera.setPosition(position); - Camera.setOrientation(orientationOf(vector)); + Camera.setPosition(position); + Camera.setOrientation(orientationOf(vector)); } function saveCameraState() { - oldMode = Camera.mode; - oldPosition = Camera.getPosition(); - oldOrientation = Camera.getOrientation(); + oldMode = Camera.mode; + oldPosition = Camera.getPosition(); + oldOrientation = Camera.getOrientation(); - Camera.mode = "independent"; - Camera.setPosition(oldPosition); + Camera.mode = "independent"; + Camera.setPosition(oldPosition); } function restoreCameraState() { - Camera.mode = oldMode; - Camera.setPosition(oldPosition); - Camera.setOrientation(oldOrientation); + Camera.mode = oldMode; + Camera.setPosition(oldPosition); + Camera.setOrientation(oldOrientation); } function handleModes() { - var newMode = (mode == noMode) ? noMode : detachedMode; - if (alt) { - if (control) { - if (shift) { - newMode = panningMode; - } else { - newMode = orbitMode; - } - } else { - newMode = radialMode; + var newMode = (mode == noMode) ? noMode : detachedMode; + if (alt) { + if (control) { + if (shift) { + newMode = panningMode; + } else { + newMode = orbitMode; + } + } else { + newMode = radialMode; + } } - } - // if entering detachMode - if (newMode == detachedMode && mode != detachedMode) { - avatarPosition = MyAvatar.position; - avatarOrientation = MyAvatar.orientation; - } - // if leaving detachMode - if (mode == detachedMode && newMode == detachedMode && - (avatarPosition.x != MyAvatar.position.x || - avatarPosition.y != MyAvatar.position.y || - avatarPosition.z != MyAvatar.position.z || - avatarOrientation.x != MyAvatar.orientation.x || - avatarOrientation.y != MyAvatar.orientation.y || - avatarOrientation.z != MyAvatar.orientation.z || - avatarOrientation.w != MyAvatar.orientation.w)) { - newMode = noMode; - } + // if entering detachMode + if (newMode == detachedMode && mode != detachedMode) { + avatarPosition = MyAvatar.position; + avatarOrientation = MyAvatar.orientation; + } + // if leaving detachMode + if (mode == detachedMode && newMode == detachedMode && + (avatarPosition.x != MyAvatar.position.x || + avatarPosition.y != MyAvatar.position.y || + avatarPosition.z != MyAvatar.position.z || + avatarOrientation.x != MyAvatar.orientation.x || + avatarOrientation.y != MyAvatar.orientation.y || + avatarOrientation.z != MyAvatar.orientation.z || + avatarOrientation.w != MyAvatar.orientation.w)) { + newMode = noMode; + } - if (mode == noMode && newMode != noMode && Camera.mode == "independent") { - newMode = noMode; - } + if (mode == noMode && newMode != noMode && Camera.mode == "independent") { + newMode = noMode; + } - // if leaving noMode - if (mode == noMode && newMode != noMode) { - saveCameraState(); - } - // if entering noMode - if (newMode == noMode && mode != noMode) { - restoreCameraState(); - } + // if leaving noMode + if (mode == noMode && newMode != noMode) { + saveCameraState(); + } + // if entering noMode + if (newMode == noMode && mode != noMode) { + restoreCameraState(); + } - mode = newMode; + mode = newMode; } function keyPressEvent(event) { - var changed = false; + var changed = false; - if (event.text == "ALT") { - alt = true; - changed = true; - } - if (event.text == "CONTROL") { - control = true; - changed = true; - } - if (event.text == "SHIFT") { - shift = true; - changed = true; - } + if (event.text == "ALT") { + alt = true; + changed = true; + } + if (event.text == "CONTROL") { + control = true; + changed = true; + } + if (event.text == "SHIFT") { + shift = true; + changed = true; + } - if (changed) { - handleModes(); - } + if (changed) { + handleModes(); + } } function keyReleaseEvent(event) { - var changed = false; + var changed = false; - if (event.text == "ALT") { - alt = false; - changed = true; - mode = noMode; - restoreCameraState(); - } - if (event.text == "CONTROL") { - control = false; - changed = true; - } - if (event.text == "SHIFT") { - shift = false; - changed = true; - } - - if (changed) { - handleModes(); - } -} - - - -function mousePressEvent(event) { - if (alt && !isActive) { - mouseLastX = event.x; - mouseLastY = event.y; - - // Compute trajectories related values - var pickRay = Camera.computePickRay(mouseLastX, mouseLastY); - var modelIntersection = Entities.findRayIntersection(pickRay, true); - - position = Camera.getPosition(); - - var avatarTarget = MyAvatar.getTargetAvatarPosition(); - - - var distance = -1; - var string; - - if (modelIntersection.intersects && modelIntersection.accurate) { - distance = modelIntersection.distance; - center = modelIntersection.intersection; - string = "Inspecting model"; - //We've selected our target, now orbit towards it automatically - rotatingTowardsTarget = true; - //calculate our target cam rotation - Script.setTimeout(function() { - rotatingTowardsTarget = false; - }, LOOK_AT_TIME); - - vector = Vec3.subtract(position, center); - targetCamOrientation = orientationOf(vector); - radius = Vec3.length(vector); - azimuth = Math.atan2(vector.z, vector.x); - altitude = Math.asin(vector.y / Vec3.length(vector)); - - isActive = true; + if (event.text == "ALT") { + alt = false; + changed = true; + mode = noMode; + restoreCameraState(); + } + if (event.text == "CONTROL") { + control = false; + changed = true; + } + if (event.text == "SHIFT") { + shift = false; + changed = true; } - } + if (changed) { + handleModes(); + } +} + +function mousePressEvent(event) { + if (alt && !isActive) { + mouseLastX = event.x; + mouseLastY = event.y; + + // Compute trajectories related values + var pickRay = Camera.computePickRay(mouseLastX, mouseLastY); + var modelIntersection = Entities.findRayIntersection(pickRay, true); + + position = Camera.getPosition(); + + var distance = -1; + var string = ""; + + if (modelIntersection.intersects && modelIntersection.accurate) { + distance = modelIntersection.distance; + center = modelIntersection.intersection; + string = "Inspecting model"; + // We've selected our target, now orbit towards it automatically + rotatingTowardsTarget = true; + // calculate our target cam rotation + Script.setTimeout(function () { + rotatingTowardsTarget = false; + }, LOOK_AT_TIME); + + vector = Vec3.subtract(position, center); + targetCamOrientation = orientationOf(vector); + radius = Vec3.length(vector); + azimuth = Math.atan2(vector.z, vector.x); + altitude = Math.asin(vector.y / Vec3.length(vector)); + + isActive = true; + } + + } } function mouseReleaseEvent(event) { - if (isActive) { - isActive = false; - } + if (isActive) { + isActive = false; + } } function mouseMoveEvent(event) { - if (isActive && mode != noMode && !rotatingTowardsTarget) { - if (mode == radialMode) { - handleRadialMode(event.x - mouseLastX, event.y - mouseLastY); + if (isActive && mode != noMode && !rotatingTowardsTarget) { + if (mode == radialMode) { + handleRadialMode(event.x - mouseLastX, event.y - mouseLastY); + } + if (mode == orbitMode) { + handleOrbitMode(event.x - mouseLastX, event.y - mouseLastY); + } + if (mode == panningMode) { + handlePanMode(event.x - mouseLastX, event.y - mouseLastY); + } } - if (mode == orbitMode) { - handleOrbitMode(event.x - mouseLastX, event.y - mouseLastY); - } - if (mode == panningMode) { - handlePanMode(event.x - mouseLastX, event.y - mouseLastY); - } - - } - mouseLastX = event.x; - mouseLastY = event.y; + mouseLastX = event.x; + mouseLastY = event.y; } function update() { - handleModes(); - if (rotatingTowardsTarget) { - rotateTowardsTarget(); - } + handleModes(); + if (rotatingTowardsTarget) { + rotateTowardsTarget(); + } } function rotateTowardsTarget() { - var newOrientation = Quat.mix(Camera.getOrientation(), targetCamOrientation, .1); - Camera.setOrientation(newOrientation); + var newOrientation = Quat.mix(Camera.getOrientation(), targetCamOrientation, 0.1); + Camera.setOrientation(newOrientation); } function scriptEnding() { - if (mode != noMode) { - restoreCameraState(); - } + if (mode != noMode) { + restoreCameraState(); + } } Controller.keyPressEvent.connect(keyPressEvent); @@ -345,4 +336,4 @@ Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Controller.mouseMoveEvent.connect(mouseMoveEvent); Script.update.connect(update); -Script.scriptEnding.connect(scriptEnding); \ No newline at end of file +Script.scriptEnding.connect(scriptEnding); From 7101a37bf983e890b772adee24c357c25b28c522 Mon Sep 17 00:00:00 2001 From: Triplelexx Date: Fri, 16 Mar 2018 20:27:05 +0000 Subject: [PATCH 02/19] add inspect avatars --- script-archive/inspect.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/script-archive/inspect.js b/script-archive/inspect.js index 45fc281792..18b26ab709 100644 --- a/script-archive/inspect.js +++ b/script-archive/inspect.js @@ -56,7 +56,6 @@ var mode = noMode; var mouseLastX = 0; var mouseLastY = 0; - var center = { x: 0, y: 0, @@ -259,16 +258,16 @@ function mousePressEvent(event) { // Compute trajectories related values var pickRay = Camera.computePickRay(mouseLastX, mouseLastY); var modelIntersection = Entities.findRayIntersection(pickRay, true); + var avatarIntersection = AvatarList.findRayIntersection(pickRay); position = Camera.getPosition(); - var distance = -1; - var string = ""; - - if (modelIntersection.intersects && modelIntersection.accurate) { - distance = modelIntersection.distance; - center = modelIntersection.intersection; - string = "Inspecting model"; + if (avatarIntersection.intersects || (modelIntersection.intersects && modelIntersection.accurate)) { + if (avatarIntersection.intersects) { + center = avatarIntersection.intersection; + } else { + center = modelIntersection.intersection; + } // We've selected our target, now orbit towards it automatically rotatingTowardsTarget = true; // calculate our target cam rotation @@ -284,7 +283,6 @@ function mousePressEvent(event) { isActive = true; } - } } From 0d6bfada40f94fe921e78d7a6b17d4eb9f9bb553 Mon Sep 17 00:00:00 2001 From: Cristian Duarte Date: Tue, 20 Mar 2018 17:24:38 -0300 Subject: [PATCH 03/19] Prevent Go To and Avatar windows to move Radar Mode's camera when touched or interacted with --- scripts/+android/defaultScripts.js | 5 +-- scripts/system/+android/androidCombined.js | 24 ++++++++++++++ scripts/system/+android/avatarSelection.js | 1 + scripts/system/+android/bottombar.js | 38 +++++++++++++++++++++- scripts/system/+android/modes.js | 29 ++++++++++++----- 5 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 scripts/system/+android/androidCombined.js diff --git a/scripts/+android/defaultScripts.js b/scripts/+android/defaultScripts.js index a8f6bf42a1..82e32a6d00 100644 --- a/scripts/+android/defaultScripts.js +++ b/scripts/+android/defaultScripts.js @@ -14,9 +14,10 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/progress.js", "system/+android/touchscreenvirtualpad.js", + "system/+android/audio.js", + "system/+android/androidCombined.js"/*, "system/+android/bottombar.js", - "system/+android/audio.js" , - "system/+android/modes.js"/*, + "system/+android/modes.js", "system/away.js", "system/controllers/controllerDisplayManager.js", "system/controllers/handControllerGrabAndroid.js", diff --git a/scripts/system/+android/androidCombined.js b/scripts/system/+android/androidCombined.js new file mode 100644 index 0000000000..76a52bcab7 --- /dev/null +++ b/scripts/system/+android/androidCombined.js @@ -0,0 +1,24 @@ +"use strict"; +// +// androidCombined.js +// scripts/system/ +// +// Created by Gabriel Calero & Cristian Duarte on Mar 20, 2018 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { // BEGIN LOCAL_SCOPE + +var modesInterface = Script.require('./modes.js'); +var bottombarInterface = Script.require('./bottombar.js'); + +function init() { + modesInterface.isRadarModeValidTouch = bottombarInterface.isRadarModeValidTouch;// set new function +} + +init(); + +}()); // END LOCAL_SCOPE \ No newline at end of file diff --git a/scripts/system/+android/avatarSelection.js b/scripts/system/+android/avatarSelection.js index 2b28fe2c9b..2946e541b5 100644 --- a/scripts/system/+android/avatarSelection.js +++ b/scripts/system/+android/avatarSelection.js @@ -35,6 +35,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See break; case 'hide': Controller.setVPadHidden(false); + module.exports.hide(); module.exports.onHidden(); break; default: diff --git a/scripts/system/+android/bottombar.js b/scripts/system/+android/bottombar.js index 3435edb548..2fb332a33d 100644 --- a/scripts/system/+android/bottombar.js +++ b/scripts/system/+android/bottombar.js @@ -21,7 +21,9 @@ var loginBtn; var gotoScript = Script.require('./goto.js'); var avatarSelection = Script.require('./avatarSelection.js'); -var logEnabled = false; +var bottombarInterface = []; + +var logEnabled = true; function printd(str) { if (logEnabled) { @@ -262,6 +264,40 @@ Script.scriptEnding.connect(function () { GlobalServices.disconnected.disconnect(handleLogout); }); +function isRadarModeValidTouch(coords) { + var qmlFragments = [bottombar, bottomHudOptionsBar.qmlFragment]; + var windows = [gotoScript, avatarSelection]; + for (var i=0; i < qmlFragments.length; i++) { + var aQmlFrag = qmlFragments[i]; + if (aQmlFrag != null && aQmlFrag.isVisible() && + coords.x >= aQmlFrag.position.x && coords.x <= aQmlFrag.position.x + aQmlFrag.size.x && + coords.y >= aQmlFrag.position.y && coords.y <= aQmlFrag.position.y + aQmlFrag.size.y + ) { + printd("isRadarModeValidTouch- false because of qmlFragments!? idx " + i); + return false; + } + } + + for (var i=0; i < windows.length; i++) { + var aWin = windows[i]; + if (aWin != null && aWin.position() != null && aWin.isVisible() && + coords.x >= aWin.position().x && coords.x <= aWin.position().x + aWin.width() && + coords.y >= aWin.position().y && coords.y <= aWin.position().y + aWin.height() + ) { + printd("isRadarModeValidTouch- false because of windows!? idx " + i); + return false; + } else { + printd("isRadarModeValidTouch- discarded of window idx " + i + " visible= " + aWin.isVisible()); + } + } + printd("isRadarModeValidTouch- true by default "); + return true; +} + +bottombarInterface.isRadarModeValidTouch = isRadarModeValidTouch; + +module.exports = bottombarInterface; + init(); }()); // END LOCAL_SCOPE diff --git a/scripts/system/+android/modes.js b/scripts/system/+android/modes.js index 097798e393..4bc4333a09 100644 --- a/scripts/system/+android/modes.js +++ b/scripts/system/+android/modes.js @@ -23,6 +23,8 @@ var logEnabled = true; var radar = Script.require('./radar.js'); var uniqueColor = Script.require('./uniqueColor.js'); +var modesInterface = {}; + function printd(str) { if (logEnabled) { print("[modes.js] " + str); @@ -184,33 +186,44 @@ function onButtonClicked(clickedButton, whatToDo, hideAllAfter) { } function isRadarModeValidTouch(coords) { + if (!modesInterface.isRadarModeValidTouch(coords)) { + printd("isRadarModeValidTouch- false because of modesInterface"); + return false; + } + printd("isRadarModeValidTouch- modesInterface is true, evaluating modesbar qmls.."); + var qmlFragments = [modesbar.qmlFragment]; var windows = []; for (var i=0; i < qmlFragments.length; i++) { var aQmlFrag = qmlFragments[i]; if (aQmlFrag != null && aQmlFrag.isVisible() && - coords.x >= aQmlFrag.position.x * 3 && coords.x <= aQmlFrag.position.x * 3 + aQmlFrag.size.x * 3 && - coords.y >= aQmlFrag.position.y * 3 && coords.y <= aQmlFrag.position.y * 3 + aQmlFrag.size.y * 3 + coords.x >= aQmlFrag.position.x && coords.x <= aQmlFrag.position.x + aQmlFrag.size.x && + coords.y >= aQmlFrag.position.y && coords.y <= aQmlFrag.position.y + aQmlFrag.size.y ) { - printd("godViewModeTouchValid- false because of qmlFragments!? idx " + i); + printd("isRadarModeValidTouch- false because of qmlFragments!? idx " + i); return false; } } for (var i=0; i < windows.length; i++) { var aWin = windows[i]; - if (aWin != null && aWin.position() != null && - coords.x >= aWin.position().x * 3 && coords.x <= aWin.position().x * 3 + aWin.width() * 3 && - coords.y >= aWin.position().y * 3 && coords.y <= aWin.position().y * 3 + aWin.height() * 3 + if (aWin != null && aWin.position() != null && aWin.isVisible() && + coords.x >= aWin.position().x && coords.x <= aWin.position().x + aWin.width() && + coords.y >= aWin.position().y && coords.y <= aWin.position().y + aWin.height() ) { - printd("godViewModeTouchValid- false because of windows!?"); + printd("isRadarModeValidTouch- false because of windows!? idx " + i); return false; } } - printd("godViewModeTouchValid- true by default "); + printd("isRadarModeValidTouch- true by default "); return true; } +// default +modesInterface.isRadarModeValidTouch = function(coords) {return true;}; + +module.exports = modesInterface; + Script.scriptEnding.connect(function () { shutdown(); }); From 05efc5a231cd96c53034a7fd838cd2a2fbfb9ea6 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 21 Mar 2018 15:36:39 +1300 Subject: [PATCH 04/19] Revert "Remove Overlays.getOverlayObject() from JavaScript API" This reverts commit 8e2a3e8c99ff2bc1f36349db28d5d9a92d3dbfc7. --- interface/src/ui/overlays/Overlays.cpp | 15 +++++++++++++++ interface/src/ui/overlays/Overlays.h | 9 +++++++++ scripts/system/libraries/WebTablet.js | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 35274e4fbe..6898b5ed2b 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -388,6 +388,21 @@ QString Overlays::getOverlayType(OverlayID overlayId) { return ""; } +QObject* Overlays::getOverlayObject(OverlayID id) { + if (QThread::currentThread() != thread()) { + QObject* result; + PROFILE_RANGE(script, __FUNCTION__); + BLOCKING_INVOKE_METHOD(this, "getOverlayObject", Q_RETURN_ARG(QObject*, result), Q_ARG(OverlayID, id)); + return result; + } + + Overlay::Pointer thisOverlay = getOverlay(id); + if (thisOverlay) { + return qobject_cast(&(*thisOverlay)); + } + return nullptr; +} + OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) { if (!_enabled) { return UNKNOWN_OVERLAY_ID; diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index c3d87642f1..544aea75e0 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -235,6 +235,15 @@ public slots: */ QString getOverlayType(OverlayID overlayId); + /**jsdoc + * Get the overlay script object. + * @function Overlays.getOverlayObject + * @deprecated This function is deprecated and will soon be removed. + * @param {Uuid} overlayID - The ID of the overlay to get the script object of. + * @returns {object} The script object for the overlay if found. + */ + QObject* getOverlayObject(OverlayID id); + /**jsdoc * Get the ID of the 2D overlay at a particular point on the screen or HUD. * @function Overlays.getOverlayAtPoint diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 511bb6989e..a7186f55bd 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -307,6 +307,10 @@ WebTablet.prototype.setScriptURL = function (scriptURL) { Overlays.editOverlay(this.webOverlayID, { scriptURL: scriptURL }); }; +WebTablet.prototype.getOverlayObject = function () { + return Overlays.getOverlayObject(this.webOverlayID); +}; + WebTablet.prototype.setWidth = function (width) { // imported from libraries/utils.js resizeTablet(width); From 8df6cd58c67bb649f7140872b32f100a2a18f471 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 21 Mar 2018 15:50:22 +1300 Subject: [PATCH 05/19] Document Overlays.getOverlayObject's use for web3d event bridge --- interface/src/ui/overlays/Overlays.h | 39 ++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index 544aea75e0..a47a85624c 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -236,11 +236,46 @@ public slots: QString getOverlayType(OverlayID overlayId); /**jsdoc - * Get the overlay script object. + * Get the overlay script object. In particular, this is useful for accessing the event bridge for a web3d + * overlay. * @function Overlays.getOverlayObject - * @deprecated This function is deprecated and will soon be removed. * @param {Uuid} overlayID - The ID of the overlay to get the script object of. * @returns {object} The script object for the overlay if found. + * @example Receive "hello" messages from a web3d overlay. + * // HTML file: name "web3d.html". + * + * + * + * HELLO + * + * + *

HELLO

+ * + * + * + * + * // Script file. + * var web3dOverlay = Overlays.addOverlay("web3d", { + * position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 0.5, z: -3 })), + * rotation: MyAvatar.orientation, + * url: Script.resolvePath("web3d.html"), + * alpha: 1.0 + * }); + * + * function onWebEventReceived(event) { + * print("onWebEventReceived() : " + JSON.stringify(event)); + * } + * + * overlayObject = Overlays.getOverlayObject(web3dOverlay); + * overlayObject.webEventReceived.connect(onWebEventReceived); + * + * Script.scriptEnding.connect(function () { + * Overlays.deleteOverlay(web3dOverlay); + * }); */ QObject* getOverlayObject(OverlayID id); From f62e1ed54e9e2d30654b7fa0032a0e7e0a3e7b9c Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Thu, 22 Mar 2018 15:29:41 -0700 Subject: [PATCH 06/19] disable add button on model until text is entered --- .../resources/qml/hifi/tablet/NewModelDialog.qml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/NewModelDialog.qml b/interface/resources/qml/hifi/tablet/NewModelDialog.qml index 3debc8b9e7..4586daf2a7 100644 --- a/interface/resources/qml/hifi/tablet/NewModelDialog.qml +++ b/interface/resources/qml/hifi/tablet/NewModelDialog.qml @@ -71,6 +71,10 @@ Rectangle { onAccepted: { newModelDialog.keyboardEnabled = false; } + + onTextChanged : { + button1.enabled = true; + } MouseArea { anchors.fill: parent @@ -118,13 +122,6 @@ Rectangle { height: 400 spacing: 20 - Image { - id: image1 - width: 30 - height: 30 - source: "qrc:/qtquickplugin/images/template_image.png" - } - Text { id: text2 width: 160 @@ -200,6 +197,7 @@ Rectangle { id: button1 text: qsTr("Add") z: -1 + enabled: false onClicked: { newModelDialog.sendToScript({ method: "newModelDialogAdd", From 0647155c30317406637ca372ca0670f6592d3cbe Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Thu, 22 Mar 2018 15:33:23 -0700 Subject: [PATCH 07/19] re-add experimental image removal --- interface/resources/qml/hifi/tablet/NewModelDialog.qml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/interface/resources/qml/hifi/tablet/NewModelDialog.qml b/interface/resources/qml/hifi/tablet/NewModelDialog.qml index 4586daf2a7..9994d9708d 100644 --- a/interface/resources/qml/hifi/tablet/NewModelDialog.qml +++ b/interface/resources/qml/hifi/tablet/NewModelDialog.qml @@ -122,6 +122,13 @@ Rectangle { height: 400 spacing: 20 + Image { + id: image1 + width: 30 + height: 30 + source: "qrc:/qtquickplugin/images/template_image.png" + } + Text { id: text2 width: 160 From 12445596181d0bcdc6e89da1bb081c7fda50f23b Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Thu, 22 Mar 2018 15:37:12 -0700 Subject: [PATCH 08/19] remove spaces for clean-ness --- interface/resources/qml/hifi/tablet/NewModelDialog.qml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/NewModelDialog.qml b/interface/resources/qml/hifi/tablet/NewModelDialog.qml index 9994d9708d..ec8289d68e 100644 --- a/interface/resources/qml/hifi/tablet/NewModelDialog.qml +++ b/interface/resources/qml/hifi/tablet/NewModelDialog.qml @@ -122,11 +122,11 @@ Rectangle { height: 400 spacing: 20 - Image { - id: image1 - width: 30 - height: 30 - source: "qrc:/qtquickplugin/images/template_image.png" + Image { + id: image1 + width: 30 + height: 30 + source: "qrc:/qtquickplugin/images/template_image.png" } Text { From 242b009562de3f10c7b9f58a35d9a59883369e62 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Fri, 23 Mar 2018 18:59:55 -0300 Subject: [PATCH 09/19] Android - Use mouse events for interacting with UI. Now LoginDialog UI interation does not move radar camera. Remove repeated tooggle call in audio.js. Adapt button to simulated mouse events. --- .../resources/qml/hifi/+android/button.qml | 4 +- libraries/qml/src/qml/OffscreenSurface.cpp | 37 +++++++++++++------ scripts/system/+android/audio.js | 1 - 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/interface/resources/qml/hifi/+android/button.qml b/interface/resources/qml/hifi/+android/button.qml index 4822b6bf33..3e9ce39351 100644 --- a/interface/resources/qml/hifi/+android/button.qml +++ b/interface/resources/qml/hifi/+android/button.qml @@ -118,7 +118,7 @@ Item { tabletRoot.playButtonClickSound(); }*/ } - onEntered: { + onPressed: { button.isEntered = true; button.entered(); if (button.isActive) { @@ -127,7 +127,7 @@ Item { button.state = "hover state"; } } - onExited: { + onReleased: { button.isEntered = false; button.exited() if (button.isActive) { diff --git a/libraries/qml/src/qml/OffscreenSurface.cpp b/libraries/qml/src/qml/OffscreenSurface.cpp index 6580c5b1e8..ff36589b61 100644 --- a/libraries/qml/src/qml/OffscreenSurface.cpp +++ b/libraries/qml/src/qml/OffscreenSurface.cpp @@ -166,18 +166,33 @@ bool OffscreenSurface::eventFilter(QObject* originalDestination, QEvent* event) case QEvent::TouchUpdate: case QEvent::TouchEnd: { QTouchEvent *originalEvent = static_cast(event); - QTouchEvent fakeEvent(*originalEvent); - auto newTouchPoints = fakeEvent.touchPoints(); - for (size_t i = 0; i < newTouchPoints.size(); ++i) { - const auto &originalPoint = originalEvent->touchPoints()[i]; - auto &newPoint = newTouchPoints[i]; - newPoint.setPos(originalPoint.pos()); + QEvent::Type fakeMouseEventType = QEvent::None; + Qt::MouseButton fakeMouseButton = Qt::NoButton; + Qt::MouseButtons fakeMouseButtons = Qt::NoButton; + switch (event->type()) { + case QEvent::TouchBegin: + fakeMouseEventType = QEvent::MouseButtonPress; + fakeMouseButton = Qt::LeftButton; + fakeMouseButtons = Qt::LeftButton; + break; + case QEvent::TouchUpdate: + fakeMouseEventType = QEvent::MouseMove; + fakeMouseButton = Qt::LeftButton; + fakeMouseButtons = Qt::LeftButton; + break; + case QEvent::TouchEnd: + fakeMouseEventType = QEvent::MouseButtonRelease; + fakeMouseButton = Qt::LeftButton; + fakeMouseButtons = Qt::NoButton; + break; } - fakeEvent.setTouchPoints(newTouchPoints); - if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &fakeEvent)) { - qInfo() << __FUNCTION__ << "sent fake touch event:" << fakeEvent.type() - << "_quickWindow handled it... accepted:" << fakeEvent.isAccepted(); - return false; //event->isAccepted(); + if (fakeMouseEventType == QEvent::None) break; + QMouseEvent fakeMouseEvent(fakeMouseEventType, originalEvent->touchPoints()[0].pos(), fakeMouseButton, fakeMouseButtons, Qt::NoModifier); + fakeMouseEvent.ignore(); + if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &fakeMouseEvent)) { + qInfo() << __FUNCTION__ << "sent fake touch event:" << fakeMouseEvent.type() + << "_quickWindow handled it... accepted:" << fakeMouseEvent.isAccepted(); + return fakeMouseEvent.isAccepted(); } break; } diff --git a/scripts/system/+android/audio.js b/scripts/system/+android/audio.js index b4f156d4bf..955f74d63a 100644 --- a/scripts/system/+android/audio.js +++ b/scripts/system/+android/audio.js @@ -46,7 +46,6 @@ function onMuteClicked() { printd("On Mute Clicked"); //Menu.setIsOptionChecked("Mute Microphone", !Menu.isOptionChecked("Mute Microphone")); Audio.muted = !Audio.muted; - onMuteToggled(); } function onMuteToggled() { From 686af4ff777e1fa04a226105b2a6078d0877963e Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Fri, 23 Mar 2018 20:02:51 -0300 Subject: [PATCH 10/19] Clean code that manually checked for windows coordinates to disable radar touch --- .../qml/+android/AddressBarDialog.qml | 4 ++ .../qml/hifi/+android/avatarSelection.qml | 4 ++ scripts/+android/defaultScripts.js | 5 +-- scripts/system/+android/androidCombined.js | 24 ----------- scripts/system/+android/bottombar.js | 38 +---------------- scripts/system/+android/modes.js | 42 ------------------- scripts/system/+android/radar.js | 6 ++- 7 files changed, 16 insertions(+), 107 deletions(-) delete mode 100644 scripts/system/+android/androidCombined.js diff --git a/interface/resources/qml/+android/AddressBarDialog.qml b/interface/resources/qml/+android/AddressBarDialog.qml index b8d6b5e270..4477d512fc 100644 --- a/interface/resources/qml/+android/AddressBarDialog.qml +++ b/interface/resources/qml/+android/AddressBarDialog.qml @@ -67,6 +67,10 @@ Item { fill: parent } + MouseArea { + anchors.fill: parent + } + QmlHifi.WindowHeader { id: header iconSource: "../../../icons/goto-i.svg" diff --git a/interface/resources/qml/hifi/+android/avatarSelection.qml b/interface/resources/qml/hifi/+android/avatarSelection.qml index 3090204308..afa5634575 100644 --- a/interface/resources/qml/hifi/+android/avatarSelection.qml +++ b/interface/resources/qml/hifi/+android/avatarSelection.qml @@ -58,6 +58,10 @@ Item { width: parent ? parent.width : 0 height: parent ? parent.height : 0 + MouseArea { + anchors.fill: parent + } + gradient: Gradient { GradientStop { position: 0.0; color: android.color.gradientTop } GradientStop { position: 1.0; color: android.color.gradientBottom } diff --git a/scripts/+android/defaultScripts.js b/scripts/+android/defaultScripts.js index 82e32a6d00..9094952e62 100644 --- a/scripts/+android/defaultScripts.js +++ b/scripts/+android/defaultScripts.js @@ -14,10 +14,9 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/progress.js", "system/+android/touchscreenvirtualpad.js", - "system/+android/audio.js", - "system/+android/androidCombined.js"/*, "system/+android/bottombar.js", - "system/+android/modes.js", + "system/+android/audio.js", + "system/+android/modes.js"/*, "system/away.js", "system/controllers/controllerDisplayManager.js", "system/controllers/handControllerGrabAndroid.js", diff --git a/scripts/system/+android/androidCombined.js b/scripts/system/+android/androidCombined.js deleted file mode 100644 index 76a52bcab7..0000000000 --- a/scripts/system/+android/androidCombined.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -// -// androidCombined.js -// scripts/system/ -// -// Created by Gabriel Calero & Cristian Duarte on Mar 20, 2018 -// Copyright 2018 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { // BEGIN LOCAL_SCOPE - -var modesInterface = Script.require('./modes.js'); -var bottombarInterface = Script.require('./bottombar.js'); - -function init() { - modesInterface.isRadarModeValidTouch = bottombarInterface.isRadarModeValidTouch;// set new function -} - -init(); - -}()); // END LOCAL_SCOPE \ No newline at end of file diff --git a/scripts/system/+android/bottombar.js b/scripts/system/+android/bottombar.js index 2fb332a33d..3435edb548 100644 --- a/scripts/system/+android/bottombar.js +++ b/scripts/system/+android/bottombar.js @@ -21,9 +21,7 @@ var loginBtn; var gotoScript = Script.require('./goto.js'); var avatarSelection = Script.require('./avatarSelection.js'); -var bottombarInterface = []; - -var logEnabled = true; +var logEnabled = false; function printd(str) { if (logEnabled) { @@ -264,40 +262,6 @@ Script.scriptEnding.connect(function () { GlobalServices.disconnected.disconnect(handleLogout); }); -function isRadarModeValidTouch(coords) { - var qmlFragments = [bottombar, bottomHudOptionsBar.qmlFragment]; - var windows = [gotoScript, avatarSelection]; - for (var i=0; i < qmlFragments.length; i++) { - var aQmlFrag = qmlFragments[i]; - if (aQmlFrag != null && aQmlFrag.isVisible() && - coords.x >= aQmlFrag.position.x && coords.x <= aQmlFrag.position.x + aQmlFrag.size.x && - coords.y >= aQmlFrag.position.y && coords.y <= aQmlFrag.position.y + aQmlFrag.size.y - ) { - printd("isRadarModeValidTouch- false because of qmlFragments!? idx " + i); - return false; - } - } - - for (var i=0; i < windows.length; i++) { - var aWin = windows[i]; - if (aWin != null && aWin.position() != null && aWin.isVisible() && - coords.x >= aWin.position().x && coords.x <= aWin.position().x + aWin.width() && - coords.y >= aWin.position().y && coords.y <= aWin.position().y + aWin.height() - ) { - printd("isRadarModeValidTouch- false because of windows!? idx " + i); - return false; - } else { - printd("isRadarModeValidTouch- discarded of window idx " + i + " visible= " + aWin.isVisible()); - } - } - printd("isRadarModeValidTouch- true by default "); - return true; -} - -bottombarInterface.isRadarModeValidTouch = isRadarModeValidTouch; - -module.exports = bottombarInterface; - init(); }()); // END LOCAL_SCOPE diff --git a/scripts/system/+android/modes.js b/scripts/system/+android/modes.js index 4bc4333a09..c41ae1f327 100644 --- a/scripts/system/+android/modes.js +++ b/scripts/system/+android/modes.js @@ -23,8 +23,6 @@ var logEnabled = true; var radar = Script.require('./radar.js'); var uniqueColor = Script.require('./uniqueColor.js'); -var modesInterface = {}; - function printd(str) { if (logEnabled) { print("[modes.js] " + str); @@ -35,7 +33,6 @@ function init() { radar.setUniqueColor(uniqueColor); radar.init(); setupModesBar(); - radar.isTouchValid = isRadarModeValidTouch; } function shutdown() { @@ -185,45 +182,6 @@ function onButtonClicked(clickedButton, whatToDo, hideAllAfter) { } } -function isRadarModeValidTouch(coords) { - if (!modesInterface.isRadarModeValidTouch(coords)) { - printd("isRadarModeValidTouch- false because of modesInterface"); - return false; - } - printd("isRadarModeValidTouch- modesInterface is true, evaluating modesbar qmls.."); - - var qmlFragments = [modesbar.qmlFragment]; - var windows = []; - for (var i=0; i < qmlFragments.length; i++) { - var aQmlFrag = qmlFragments[i]; - if (aQmlFrag != null && aQmlFrag.isVisible() && - coords.x >= aQmlFrag.position.x && coords.x <= aQmlFrag.position.x + aQmlFrag.size.x && - coords.y >= aQmlFrag.position.y && coords.y <= aQmlFrag.position.y + aQmlFrag.size.y - ) { - printd("isRadarModeValidTouch- false because of qmlFragments!? idx " + i); - return false; - } - } - - for (var i=0; i < windows.length; i++) { - var aWin = windows[i]; - if (aWin != null && aWin.position() != null && aWin.isVisible() && - coords.x >= aWin.position().x && coords.x <= aWin.position().x + aWin.width() && - coords.y >= aWin.position().y && coords.y <= aWin.position().y + aWin.height() - ) { - printd("isRadarModeValidTouch- false because of windows!? idx " + i); - return false; - } - } - printd("isRadarModeValidTouch- true by default "); - return true; -} - -// default -modesInterface.isRadarModeValidTouch = function(coords) {return true;}; - -module.exports = modesInterface; - Script.scriptEnding.connect(function () { shutdown(); }); diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 84fb66403f..2bcdc60db7 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -13,7 +13,7 @@ var radarModeInterface = {}; -var logEnabled = true; +var logEnabled = false; function printd(str) { if (logEnabled) { print("[radar.js] " + str); @@ -1390,6 +1390,10 @@ radarModeInterface.setUniqueColor = function(c) { uniqueColor = c; }; +radarModeInterface.isTouchValid = function(coords) { + return true; // by default +} + module.exports = radarModeInterface; function updateRadar() { From d1d58eceab9c8f97fa43cd0e7ee2ffe3e01846d7 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 27 Mar 2018 13:04:50 +1300 Subject: [PATCH 11/19] Add Window.raise() as replacement for Window.raiseMainWindow() --- interface/src/scripting/WindowScriptingInterface.cpp | 6 +++++- interface/src/scripting/WindowScriptingInterface.h | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 78f55f0d6e..58ec744f4e 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -78,13 +78,17 @@ void WindowScriptingInterface::setFocus() { }); } -void WindowScriptingInterface::raiseMainWindow() { +void WindowScriptingInterface::raise() { // It's forbidden to call raise() from another thread. qApp->postLambdaEvent([] { qApp->raise(); }); } +void WindowScriptingInterface::raiseMainWindow() { + raise(); +} + /// Display an alert box /// \param const QString& message message to display /// \return QScriptValue::UndefinedValue diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 997e425e53..e3b092d011 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -68,9 +68,16 @@ public slots: */ void setFocus(); + /**jsdoc + * Raise the Interface window if it is minimized. If raised, the window gains focus. + * @function Window.raise + */ + void raise(); + /**jsdoc * Raise the Interface window if it is minimized. If raised, the window gains focus. * @function Window.raiseMainWindow + * @deprecated Use {@link Window.raise|raise} instead. */ void raiseMainWindow(); From eb20181b6086c487542ac56e1773da8ef0d19d91 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 27 Mar 2018 14:18:01 -0700 Subject: [PATCH 12/19] Shut down the overlay interface on exit --- interface/src/ui/overlays/Overlays.cpp | 34 +++++++++++++++++++++++++- interface/src/ui/overlays/Overlays.h | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 35274e4fbe..ee2f62c6bb 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -54,6 +54,7 @@ Overlays::Overlays() { } void Overlays::cleanupAllOverlays() { + _shuttingDown = true; QMap overlaysHUD; QMap overlaysWorld; { @@ -147,6 +148,10 @@ void Overlays::enable() { // Note, can't be invoked by scripts, but can be called by the InterfaceParentFinder // class on packet processing threads Overlay::Pointer Overlays::getOverlay(OverlayID id) const { + if (_shuttingDown) { + return nullptr; + } + QMutexLocker locker(&_mutex); if (_overlaysHUD.contains(id)) { return _overlaysHUD[id]; @@ -157,6 +162,10 @@ Overlay::Pointer Overlays::getOverlay(OverlayID id) const { } OverlayID Overlays::addOverlay(const QString& type, const QVariant& properties) { + if (_shuttingDown) { + return UNKNOWN_OVERLAY_ID; + } + if (QThread::currentThread() != thread()) { OverlayID result; PROFILE_RANGE(script, __FUNCTION__); @@ -261,6 +270,10 @@ OverlayID Overlays::addOverlay(const QString& type, const QVariant& properties) } OverlayID Overlays::addOverlay(const Overlay::Pointer& overlay) { + if (_shuttingDown) { + return UNKNOWN_OVERLAY_ID; + } + OverlayID thisID = OverlayID(QUuid::createUuid()); overlay->setOverlayID(thisID); overlay->setStackOrder(_stackOrder++); @@ -283,6 +296,10 @@ OverlayID Overlays::addOverlay(const Overlay::Pointer& overlay) { } OverlayID Overlays::cloneOverlay(OverlayID id) { + if (_shuttingDown) { + return UNKNOWN_OVERLAY_ID; + } + if (QThread::currentThread() != thread()) { OverlayID result; PROFILE_RANGE(script, __FUNCTION__); @@ -301,6 +318,10 @@ OverlayID Overlays::cloneOverlay(OverlayID id) { } bool Overlays::editOverlay(OverlayID id, const QVariant& properties) { + if (_shuttingDown) { + return false; + } + auto thisOverlay = getOverlay(id); if (!thisOverlay) { return false; @@ -320,6 +341,10 @@ bool Overlays::editOverlay(OverlayID id, const QVariant& properties) { } bool Overlays::editOverlays(const QVariant& propertiesById) { + if (_shuttingDown) { + return false; + } + bool defer2DOverlays = QThread::currentThread() != thread(); QVariantMap deferrred; @@ -351,6 +376,10 @@ bool Overlays::editOverlays(const QVariant& propertiesById) { } void Overlays::deleteOverlay(OverlayID id) { + if (_shuttingDown) { + return; + } + if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "deleteOverlay", Q_ARG(OverlayID, id)); return; @@ -374,6 +403,9 @@ void Overlays::deleteOverlay(OverlayID id) { } QString Overlays::getOverlayType(OverlayID overlayId) { + if (_shuttingDown) { + return ""; + } if (QThread::currentThread() != thread()) { QString result; PROFILE_RANGE(script, __FUNCTION__); @@ -389,7 +421,7 @@ QString Overlays::getOverlayType(OverlayID overlayId) { } OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) { - if (!_enabled) { + if (_shuttingDown || !_enabled) { return UNKNOWN_OVERLAY_ID; } diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index c3d87642f1..8eccbfa4c5 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -680,6 +680,7 @@ private: unsigned int _stackOrder { 1 }; bool _enabled = true; + std::atomic _shuttingDown{ false }; PointerEvent calculateOverlayPointerEvent(OverlayID overlayID, PickRay ray, RayToOverlayIntersectionResult rayPickResult, QMouseEvent* event, PointerEvent::EventType eventType); From 29106fbbbe422527fed7b5f10a6f57bea2528124 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 27 Mar 2018 14:18:19 -0700 Subject: [PATCH 13/19] Prevent potential double delete of QML overlays --- interface/src/ui/overlays/QmlOverlay.cpp | 32 ++++++++++++------------ interface/src/ui/overlays/QmlOverlay.h | 3 ++- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/interface/src/ui/overlays/QmlOverlay.cpp b/interface/src/ui/overlays/QmlOverlay.cpp index f4a9034187..2a583e0450 100644 --- a/interface/src/ui/overlays/QmlOverlay.cpp +++ b/interface/src/ui/overlays/QmlOverlay.cpp @@ -39,18 +39,20 @@ void QmlOverlay::buildQmlElement(const QUrl& url) { auto offscreenUi = DependencyManager::get(); offscreenUi->load(url, [=](QQmlContext* context, QObject* object) { - QQuickItem* rawPtr = dynamic_cast(object); - // Create a shared ptr with a custom deleter lambda, that calls deleteLater - _qmlElement = std::shared_ptr(rawPtr, [](QQuickItem* ptr) { - if (ptr) { - ptr->deleteLater(); - } - }); + _qmlElement = dynamic_cast(object); + connect(_qmlElement, &QObject::destroyed, this, &QmlOverlay::qmlElementDestroyed); }); } +void QmlOverlay::qmlElementDestroyed() { + _qmlElement = nullptr; +} + QmlOverlay::~QmlOverlay() { - _qmlElement.reset(); + if (_qmlElement) { + _qmlElement->deleteLater(); + } + _qmlElement = nullptr; } // QmlOverlay replaces Overlay's properties with those defined in the QML file used but keeps Overlay2D's properties. @@ -62,15 +64,13 @@ void QmlOverlay::setProperties(const QVariantMap& properties) { Overlay2D::setProperties(properties); auto bounds = _bounds; - std::weak_ptr weakQmlElement = _qmlElement; // check to see if qmlElement still exists - auto qmlElement = weakQmlElement.lock(); - if (qmlElement) { - qmlElement->setX(bounds.left()); - qmlElement->setY(bounds.top()); - qmlElement->setWidth(bounds.width()); - qmlElement->setHeight(bounds.height()); - QMetaObject::invokeMethod(qmlElement.get(), "updatePropertiesFromScript", Qt::DirectConnection, Q_ARG(QVariant, properties)); + if (_qmlElement) { + _qmlElement->setX(bounds.left()); + _qmlElement->setY(bounds.top()); + _qmlElement->setWidth(bounds.width()); + _qmlElement->setHeight(bounds.height()); + QMetaObject::invokeMethod(_qmlElement, "updatePropertiesFromScript", Qt::DirectConnection, Q_ARG(QVariant, properties)); } } diff --git a/interface/src/ui/overlays/QmlOverlay.h b/interface/src/ui/overlays/QmlOverlay.h index ced2b6fa1f..7f2cf5a918 100644 --- a/interface/src/ui/overlays/QmlOverlay.h +++ b/interface/src/ui/overlays/QmlOverlay.h @@ -32,10 +32,11 @@ public: void render(RenderArgs* args) override; private: + Q_INVOKABLE void qmlElementDestroyed(); Q_INVOKABLE void buildQmlElement(const QUrl& url); protected: - std::shared_ptr _qmlElement; + QQuickItem* _qmlElement{ nullptr }; }; #endif // hifi_QmlOverlay_h From aacfe927518d941ac8e024602f1266471e0ac6d3 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 28 Mar 2018 09:09:56 -0700 Subject: [PATCH 14/19] Don't trigger crashes from timers while waiting for some operation on exit --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 968af3e298..56068fba68 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -7488,7 +7488,7 @@ DisplayPluginPointer Application::getActiveDisplayPlugin() const { return _displayPlugin; } - if (!_displayPlugin) { + if (!_aboutToQuit && !_displayPlugin) { const_cast(this)->updateDisplayMode(); Q_ASSERT(_displayPlugin); } From 9be162de95293d911cbaddfb1e772c53e4599ddf Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 28 Mar 2018 09:13:46 -0700 Subject: [PATCH 15/19] Synchronously shut down QML rendering threads --- libraries/qml/src/qml/impl/SharedObject.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/qml/src/qml/impl/SharedObject.cpp b/libraries/qml/src/qml/impl/SharedObject.cpp index f2af5bd036..d66f0f1dab 100644 --- a/libraries/qml/src/qml/impl/SharedObject.cpp +++ b/libraries/qml/src/qml/impl/SharedObject.cpp @@ -69,6 +69,7 @@ SharedObject::SharedObject() { _quickWindow->setColor(QColor(255, 255, 255, 0)); _quickWindow->setClearBeforeRendering(true); + QObject::connect(qApp, &QCoreApplication::aboutToQuit, this, &SharedObject::onAboutToQuit); } @@ -124,6 +125,7 @@ void SharedObject::setRootItem(QQuickItem* rootItem) { _renderThread->setObjectName(objectName()); _renderThread->start(); + // Create event handler for the render thread _renderObject = new RenderEventHandler(this, _renderThread); QCoreApplication::postEvent(this, new OffscreenEvent(OffscreenEvent::Initialize)); @@ -152,9 +154,16 @@ void SharedObject::destroy() { QObject::disconnect(_renderControl); QObject::disconnect(qApp); - QMutexLocker lock(&_mutex); - _quit = true; - QCoreApplication::postEvent(_renderObject, new OffscreenEvent(OffscreenEvent::Quit)); + { + QMutexLocker lock(&_mutex); + _quit = true; + QCoreApplication::postEvent(_renderObject, new OffscreenEvent(OffscreenEvent::Quit), Qt::HighEventPriority); + } + // Block until the rendering thread has stopped + // FIXME this is undesirable because this is blocking the main thread, + // but I haven't found a reliable way to do this only at application + // shutdown + _renderThread->wait(); } From 0172c24cf2f3a2557c56e0cef46cfc6157dc12fb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 28 Mar 2018 14:47:09 -0700 Subject: [PATCH 16/19] fix cmake changes for script copy for dev builds --- interface/CMakeLists.txt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index e316556d29..fe00d86c3a 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -312,7 +312,7 @@ if (APPLE) COMPONENT ${CLIENT_COMPONENT} ) - set(RESOURCES_INSTALL_DIR "${INTERFACE_INSTALL_APP_PATH}/Contents/Resources") + set(SCRIPTS_INSTALL_DIR "${INTERFACE_INSTALL_APP_PATH}/Contents/Resources") set(RESOURCES_DEV_DIR "$/../Resources") # copy script files beside the executable @@ -326,13 +326,14 @@ if (APPLE) fixup_interface() else() - set(RESOURCES_DEV_DIR "$/resources") + set(INTERFACE_EXEC_DIR "$") + set(RESOURCES_DEV_DIR "${INTERFACE_EXEC_DIR}/resources") # copy the resources files beside the executable add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${RESOURCES_RCC}" - "$" + "${INTERFACE_EXEC_DIR}" # FIXME, the edit script code loads HTML from the scripts folder # which in turn relies on CSS that refers to the fonts. In theory # we should be able to modify the CSS to reference the QRC path to @@ -340,13 +341,13 @@ else() # so we have to retain a copy of the fonts outside of the resources binary COMMAND "${CMAKE_COMMAND}" -E copy_directory "${PROJECT_SOURCE_DIR}/resources/fonts" - "$/resources/fonts" + "${RESOURCES_DEV_DIR}/fonts" COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/scripts" - "${RESOURCES_DEV_DIR}/scripts" + "${INTERFACE_EXEC_DIR}/scripts" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${PROJECT_SOURCE_DIR}/resources/serverless/tutorial.json" - "$/resources/serverless/tutorial.json" + "${RESOURCES_DEV_DIR}/serverless/tutorial.json" ) # link target to external libraries @@ -363,7 +364,7 @@ else() PATTERN "*.exp" EXCLUDE ) - set(RESOURCES_INSTALL_DIR "${INTERFACE_INSTALL_DIR}") + set(SCRIPTS_INSTALL_DIR "${INTERFACE_INSTALL_DIR}") set(EXECUTABLE_COMPONENT ${CLIENT_COMPONENT}) @@ -371,11 +372,11 @@ else() endif() endif() -if (RESOURCES_INSTALL_DIR) +if (SCRIPTS_INSTALL_DIR) # setup install of scripts beside interface executable install( DIRECTORY "${CMAKE_SOURCE_DIR}/scripts/" - DESTINATION ${RESOURCES_INSTALL_DIR}/scripts + DESTINATION ${SCRIPTS_INSTALL_DIR}/scripts COMPONENT ${CLIENT_COMPONENT} ) endif() From fe9481b28d9b7c936e1fa23ea05153e52f617084 Mon Sep 17 00:00:00 2001 From: Cristian Luis Duarte Date: Wed, 28 Mar 2018 19:50:44 -0300 Subject: [PATCH 17/19] Cleanup code, comment out log, simplify radar is valid touch code (no more flag) --- libraries/qml/src/qml/OffscreenSurface.cpp | 11 ++--- scripts/system/+android/radar.js | 51 +--------------------- 2 files changed, 6 insertions(+), 56 deletions(-) diff --git a/libraries/qml/src/qml/OffscreenSurface.cpp b/libraries/qml/src/qml/OffscreenSurface.cpp index ff36589b61..9c1bb79355 100644 --- a/libraries/qml/src/qml/OffscreenSurface.cpp +++ b/libraries/qml/src/qml/OffscreenSurface.cpp @@ -167,31 +167,28 @@ bool OffscreenSurface::eventFilter(QObject* originalDestination, QEvent* event) case QEvent::TouchEnd: { QTouchEvent *originalEvent = static_cast(event); QEvent::Type fakeMouseEventType = QEvent::None; - Qt::MouseButton fakeMouseButton = Qt::NoButton; + Qt::MouseButton fakeMouseButton = Qt::LeftButton; Qt::MouseButtons fakeMouseButtons = Qt::NoButton; switch (event->type()) { case QEvent::TouchBegin: fakeMouseEventType = QEvent::MouseButtonPress; - fakeMouseButton = Qt::LeftButton; fakeMouseButtons = Qt::LeftButton; break; case QEvent::TouchUpdate: fakeMouseEventType = QEvent::MouseMove; - fakeMouseButton = Qt::LeftButton; fakeMouseButtons = Qt::LeftButton; break; case QEvent::TouchEnd: fakeMouseEventType = QEvent::MouseButtonRelease; - fakeMouseButton = Qt::LeftButton; fakeMouseButtons = Qt::NoButton; break; } - if (fakeMouseEventType == QEvent::None) break; + // Same case as OffscreenUi.cpp::eventFilter: touch events are always being accepted so we now use mouse events and consider one touch, touchPoints()[0]. QMouseEvent fakeMouseEvent(fakeMouseEventType, originalEvent->touchPoints()[0].pos(), fakeMouseButton, fakeMouseButtons, Qt::NoModifier); fakeMouseEvent.ignore(); if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &fakeMouseEvent)) { - qInfo() << __FUNCTION__ << "sent fake touch event:" << fakeMouseEvent.type() - << "_quickWindow handled it... accepted:" << fakeMouseEvent.isAccepted(); + /*qInfo() << __FUNCTION__ << "sent fake touch event:" << fakeMouseEvent.type() + << "_quickWindow handled it... accepted:" << fakeMouseEvent.isAccepted();*/ return fakeMouseEvent.isAccepted(); } break; diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 2bcdc60db7..455299dd5f 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -118,19 +118,10 @@ function actionOnObjectFromEvent(event) { } function mousePress(event) { - if (!isTouchValid(coords)) { - currentTouchIsValid = false; - return; - } else { - currentTouchIsValid = true; - } mousePressOrTouchEnd(event); } function mousePressOrTouchEnd(event) { - if (!currentTouchIsValid) { - return; - } if (radar) { if (actionOnObjectFromEvent(event)) { return; @@ -155,9 +146,6 @@ function fakeDoubleTap(event) { teleporter.dragTeleportRelease(event); } -var currentTouchIsValid = false; // Currently used to know if touch hasn't - // started on a UI overlay - var DOUBLE_TAP_TIME = 300; var fakeDoubleTapStart = Date.now(); var touchEndCount = 0; @@ -238,12 +226,6 @@ function touchEnd(event) { return; } - // if touch is invalid, cancel - if (!currentTouchIsValid) { - printd("touchEnd fail because !currentTouchIsValid"); - return; - } - if (analyzeDoubleTap(event)) return; // double tap detected, finish @@ -345,20 +327,6 @@ function computePointAtPlaneY(x, y, py) { p2.z, py); } -/******************************************************************************* - * - ******************************************************************************/ - -function isTouchValid(coords) { - // TODO: Extend to the detection of touches on new menu bars - var radarModeTouchValid = radarModeInterface.isTouchValid(coords); - - // getItemAtPoint does not exist anymore, look for another way to know if we - // are touching buttons - // is it still needed? - return /* !tablet.getItemAtPoint(coords) && */radarModeTouchValid; -} - /******************************************************************************* * ******************************************************************************/ @@ -373,16 +341,8 @@ function touchBegin(event) { x : event.x, y : event.y }; - if (!isTouchValid(coords)) { - printd("analyze touch - RADAR_TOUCH - INVALID"); - currentTouchIsValid = false; - touchStartingCoordinates = null; - } else { - printd("analyze touch - RADAR_TOUCH - ok"); - currentTouchIsValid = true; - touchStartingCoordinates = coords; - touchBeginTime = Date.now(); - } + touchStartingCoordinates = coords; + touchBeginTime = Date.now(); } var startedDraggingCamera = false; // first time @@ -848,9 +808,6 @@ function oneFingerTouchUpdate(event) { } function touchUpdate(event) { - if (!currentTouchIsValid) { - return; // avoid moving and zooming when tap is over UI entities - } if (event.isPinching || event.isPinchOpening) { pinchUpdate(event); } else { @@ -1390,10 +1347,6 @@ radarModeInterface.setUniqueColor = function(c) { uniqueColor = c; }; -radarModeInterface.isTouchValid = function(coords) { - return true; // by default -} - module.exports = radarModeInterface; function updateRadar() { From 2ee0af03c8fd14b43ead453f06933dbfc61f5a02 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 28 Mar 2018 16:17:55 -0700 Subject: [PATCH 18/19] Add an extra sanity check when calling fetchMetaSubItems when the subItems is not allocated yet --- libraries/render/src/render/Item.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries/render/src/render/Item.cpp b/libraries/render/src/render/Item.cpp index ed052adf6e..9c5efb9fa7 100644 --- a/libraries/render/src/render/Item.cpp +++ b/libraries/render/src/render/Item.cpp @@ -118,9 +118,15 @@ uint32_t Item::fetchMetaSubItemBounds(ItemBounds& subItemBounds, Scene& scene) c auto numSubs = fetchMetaSubItems(subItems); for (auto id : subItems) { - auto& item = scene.getItem(id); - if (item.exist()) { - subItemBounds.emplace_back(id, item.getBound()); + // TODO: Adding an extra check here even thought we shouldn't have too. + // We have cases when the id returned by fetchMetaSubItems is not allocated + if (scene.isAllocatedID(id)) { + auto& item = scene.getItem(id); + if (item.exist()) { + subItemBounds.emplace_back(id, item.getBound()); + } else { + numSubs--; + } } else { numSubs--; } From 387ff680d5dbe989eac0056f95a660bd29f47dae Mon Sep 17 00:00:00 2001 From: Liv Erickson Date: Wed, 28 Mar 2018 18:12:30 -0700 Subject: [PATCH 19/19] support deleted scenario --- interface/resources/qml/hifi/tablet/NewModelDialog.qml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/tablet/NewModelDialog.qml b/interface/resources/qml/hifi/tablet/NewModelDialog.qml index ec8289d68e..5216bf45d5 100644 --- a/interface/resources/qml/hifi/tablet/NewModelDialog.qml +++ b/interface/resources/qml/hifi/tablet/NewModelDialog.qml @@ -73,7 +73,11 @@ Rectangle { } onTextChanged : { - button1.enabled = true; + if (modelURL.text.length === 0){ + button1.enabled = false; + } else { + button1.enabled = true; + } } MouseArea {