From e25b2f6e0f3e02fc569a126262edfad3737444a2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 21 Aug 2018 16:47:40 +1200 Subject: [PATCH] Support stylus input on the mini tablet --- .../controllerModules/stylusInput.js | 27 +++++++++++++++++++ scripts/system/miniTablet.js | 6 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/scripts/system/controllers/controllerModules/stylusInput.js b/scripts/system/controllers/controllerModules/stylusInput.js index a512fd89db..77615e361f 100644 --- a/scripts/system/controllers/controllerModules/stylusInput.js +++ b/scripts/system/controllers/controllerModules/stylusInput.js @@ -58,6 +58,12 @@ Script.include("/~/system/libraries/controllers.js"); enabled: true }); + this.miniTabletID = null; + + this.setMiniTabletID = function (id) { + this.miniTabletID = id; + }; + this.disable = false; this.otherModuleNeedsToRun = function(controllerData) { @@ -123,6 +129,14 @@ Script.include("/~/system/libraries/controllers.js"); } } + // Add the mini tablet. + if (this.miniTabletID && Overlays.getProperty(this.miniTabletID, "visible")) { + stylusTarget = getOverlayDistance(controllerPosition, this.miniTabletID); + if (stylusTarget) { + stylusTargets.push(stylusTarget); + } + } + var WEB_DISPLAY_STYLUS_DISTANCE = 0.5; var nearStylusTarget = isNearStylusTarget(stylusTargets, WEB_DISPLAY_STYLUS_DISTANCE * sensorScaleFactor); @@ -191,6 +205,15 @@ Script.include("/~/system/libraries/controllers.js"); } } + function onMessageReceived(channel, message, sender) { + if (sender === MyAvatar.sessionUUID) { + if (channel === 'Hifi-MiniTablet-UI-ID') { + leftTabletStylusInput.setMiniTabletID(message); + rightTabletStylusInput.setMiniTabletID(message); + } + } + } + var leftTabletStylusInput = new StylusInput(LEFT_HAND); var rightTabletStylusInput = new StylusInput(RIGHT_HAND); @@ -201,7 +224,11 @@ Script.include("/~/system/libraries/controllers.js"); Overlays.hoverLeaveOverlay.connect(mouseHoverLeave); Overlays.mousePressOnOverlay.connect(mousePress); + Messages.subscribe('Hifi-MiniTablet-UI-ID'); + Messages.messageReceived.connect(onMessageReceived); + this.cleanup = function () { + Messages.messageReceived.disconnect(onMessageReceived); leftTabletStylusInput.cleanup(); rightTabletStylusInput.cleanup(); disableDispatcherModule("LeftTabletStylusInput"); diff --git a/scripts/system/miniTablet.js b/scripts/system/miniTablet.js index dcbaa34ad5..30594392e2 100644 --- a/scripts/system/miniTablet.js +++ b/scripts/system/miniTablet.js @@ -180,6 +180,8 @@ function updateMiniTabletID() { // Send mini-tablet overlay ID to controllerDispatcher so that it can use a smaller near grab distance. Messages.sendLocalMessage("Hifi-MiniTablet-ID", proxyOverlay); + // Send mini-tablet UI overlay ID to stylusInput so that it styluses can be used on it. + Messages.sendLocalMessage("Hifi-MiniTablet-UI-ID", proxyUIOverlay); } function updateMutedStatus() { @@ -271,7 +273,7 @@ proxyOverlayObject = Overlays.getOverlayObject(proxyUIOverlay); proxyOverlayObject.webEventReceived.connect(onWebEventReceived); - updateMiniTabletID(); + // updateMiniTabletID(); Other scripts relying on this may not be ready yet so do this in showUI(). } function showUI() { @@ -293,6 +295,8 @@ visible: true }); + updateMiniTabletID(); + if (!proxyUIOverlayEnabled) { // Overlay content is created the first time it is visible to the user. The initial creation displays artefacts. // Delay showing UI overlay until after giving it time for its content to be created.