From 37004e43471036c37a06e5ad0cf8dd6e980f8f20 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 23 Feb 2017 08:11:31 -0800 Subject: [PATCH] steps toward making mouse work on tablet --- interface/src/Application.cpp | 7 +++- interface/src/Application.h | 1 + interface/src/avatar/MyAvatar.cpp | 2 +- .../src/scripting/HMDScriptingInterface.h | 12 +++---- scripts/system/libraries/WebTablet.js | 32 +++++++++++++------ scripts/system/tablet-ui/tabletUI.js | 5 ++- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 758953ade4..02291cc619 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6909,5 +6909,10 @@ OverlayID Application::getTabletScreenID() const { OverlayID Application::getTabletHomeButtonID() const { auto HMD = DependencyManager::get(); - return HMD->getCurrentHomeButtonUUID(); + return HMD->getCurrentHomeButtonID(); +} + +QUuid Application::getTabletFrameID() const { + auto HMD = DependencyManager::get(); + return HMD->getCurrentTabletFrameID(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 60001496f9..13c1458aee 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -302,6 +302,7 @@ public: OverlayID getTabletScreenID() const; OverlayID getTabletHomeButtonID() const; + QUuid getTabletFrameID() const; // may be an entity or an overlay signals: void svoImportRequested(const QString& url); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 47297c6bdb..2f5a0edd9e 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -807,7 +807,7 @@ void MyAvatar::saveData() { auto hmdInterface = DependencyManager::get(); _avatarEntitiesLock.withReadLock([&] { for (auto entityID : _avatarEntityData.keys()) { - if (hmdInterface->getCurrentTabletUIID() == entityID) { + if (hmdInterface->getCurrentTabletFrameID() == entityID) { // don't persist the tablet between domains / sessions continue; } diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index 463a21ded8..d895d5da4c 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -29,8 +29,8 @@ class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Depen Q_PROPERTY(glm::quat orientation READ getOrientation) Q_PROPERTY(bool mounted READ isMounted) Q_PROPERTY(bool showTablet READ getShouldShowTablet) - Q_PROPERTY(QUuid tabletID READ getCurrentTabletUIID WRITE setCurrentTabletUIID) - Q_PROPERTY(QUuid homeButtonID READ getCurrentHomeButtonUUID WRITE setCurrentHomeButtonUUID) + Q_PROPERTY(QUuid tabletID READ getCurrentTabletFrameID WRITE setCurrentTabletFrameID) + Q_PROPERTY(QUuid homeButtonID READ getCurrentHomeButtonID WRITE setCurrentHomeButtonID) Q_PROPERTY(QUuid tabletScreenID READ getCurrentTabletScreenID WRITE setCurrentTabletScreenID) public: @@ -90,11 +90,11 @@ public: void setShouldShowTablet(bool value) { _showTablet = value; } bool getShouldShowTablet() const { return _showTablet; } - void setCurrentTabletUIID(QUuid tabletID) { _tabletUIID = tabletID; } - QUuid getCurrentTabletUIID() const { return _tabletUIID; } + void setCurrentTabletFrameID(QUuid tabletID) { _tabletUIID = tabletID; } + QUuid getCurrentTabletFrameID() const { return _tabletUIID; } - void setCurrentHomeButtonUUID(QUuid homeButtonID) { _homeButtonID = homeButtonID; } - QUuid getCurrentHomeButtonUUID() const { return _homeButtonID; } + void setCurrentHomeButtonID(QUuid homeButtonID) { _homeButtonID = homeButtonID; } + QUuid getCurrentHomeButtonID() const { return _homeButtonID; } void setCurrentTabletScreenID(QUuid tabletID) { _tabletScreenID = tabletID; } QUuid getCurrentTabletScreenID() const { return _tabletScreenID; } diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 746f0b5680..26b6f82520 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -161,7 +161,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { }); var HOME_BUTTON_Y_OFFSET = (this.height / 2) - 0.035; - this.homeButtonEntity = Overlays.addOverlay("sphere", { + this.homeButtonID = Overlays.addOverlay("sphere", { name: "homeButton", localPosition: {x: 0.0, y: -HOME_BUTTON_Y_OFFSET, z: -0.01}, localRotation: Quat.angleAxis(0, Y_AXIS), @@ -174,7 +174,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { }); this.receive = function (channel, senderID, senderUUID, localOnly) { - if (_this.homeButtonEntity == senderID) { + if (_this.homeButtonID == senderID) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var onHomeScreen = tablet.onHomeScreen(); if (onHomeScreen) { @@ -256,7 +256,7 @@ WebTablet.prototype.destroy = function () { } else { Entities.deleteEntity(this.tabletEntityID); } - Overlays.deleteOverlay(this.homeButtonEntity); + Overlays.deleteOverlay(this.homeButtonID); HMD.displayModeChanged.disconnect(this.myOnHmdChanged); Controller.mousePressEvent.disconnect(this.myMousePressEvent); @@ -439,10 +439,16 @@ WebTablet.prototype.getPosition = function () { WebTablet.prototype.mousePressEvent = function (event) { var pickRay = Camera.computePickRay(event.x, event.y); - var entityPickResults = Entities.findRayIntersection(pickRay, true, [this.tabletEntityID]); // non-accurate picking - if (entityPickResults.intersects && entityPickResults.entityID === this.tabletEntityID) { - var overlayPickResults = Overlays.findRayIntersection(pickRay); - if (overlayPickResults.intersects && overlayPickResults.overlayID === HMD.homeButtonID) { + var entityPickResults; + if (this.tabletIsOverlay) { + entityPickResults = Overlays.findRayIntersection(pickRay, true, [this.tabletEntityID]); + } else { + entityPickResults = Entities.findRayIntersection(pickRay, true, [this.tabletEntityID]); + } + if (entityPickResults.intersects && (entityPickResults.entityID === this.tabletEntityID || + entityPickResults.overlayID === this.tabletEntityID)) { + var overlayPickResults = Overlays.findRayIntersection(pickRay, true, [this.webOverlayID, this.homeButtonID], []); + if (overlayPickResults.intersects && overlayPickResults.overlayID === this.homeButtonID) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var onHomeScreen = tablet.onHomeScreen(); if (onHomeScreen) { @@ -501,9 +507,15 @@ WebTablet.prototype.mouseMoveEvent = function (event) { var localIntersectionPoint = Vec3.sum(localPickRay.origin, Vec3.multiply(localPickRay.direction, result.distance)); var localOffset = Vec3.subtract(localIntersectionPoint, this.initialLocalIntersectionPoint); var localPosition = Vec3.sum(this.initialLocalPosition, localOffset); - Entities.editEntity(this.tabletEntityID, { - localPosition: localPosition - }); + if (this.tabletIsOverlay) { + Overlays.editOverlay(this.tabletEntityID, { + localPosition: localPosition + }); + } else { + Entities.editEntity(this.tabletEntityID, { + localPosition: localPosition + }); + } } } }; diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 632cb40bb5..42fb32114d 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -31,7 +31,8 @@ UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", DEFAULT_WIDTH * (HMD_TABLET_SCALE / 100), null, activeHand, true); UIWebTablet.register(); HMD.tabletID = UIWebTablet.tabletEntityID; - HMD.homeButtonID = UIWebTablet.homeButtonEntity; + HMD.homeButtonID = UIWebTablet.homeButtonID; + HMD.tabletScreenID = UIWebTablet.webOverlayID; } function hideTabletUI() { @@ -48,6 +49,7 @@ UIWebTablet = null; HMD.tabletID = null; HMD.homeButtonID = null; + HMD.tabletScreenID = null; } } @@ -126,5 +128,6 @@ Entities.deleteEntity(HMD.tabletID); HMD.tabletID = null; HMD.homeButtonID = null; + HMD.tabletScreenID = null; }); }()); // END LOCAL_SCOPE