From 867e24762b713182be2515b86a8a09922461a83e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 17 Feb 2017 09:23:07 +1300 Subject: [PATCH] Disable lasers and grabbing while painting if tablet not displayed --- scripts/system/fingerPaint.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/scripts/system/fingerPaint.js b/scripts/system/fingerPaint.js index 7f1f90c640..d35e053d6b 100644 --- a/scripts/system/fingerPaint.js +++ b/scripts/system/fingerPaint.js @@ -17,7 +17,9 @@ rightHand, leftBrush, rightBrush, - CONTROLLER_MAPPING_NAME = "com.highfidelity.fingerPaint"; + CONTROLLER_MAPPING_NAME = "com.highfidelity.fingerPaint", + isTabletDisplayed = false, + HIFI_GRAB_DISABLE_MESSAGE_CHANNEL = "Hifi-Grab-Disable"; function paintBrush(name) { // Paints in 3D. @@ -94,6 +96,17 @@ }; } + function updateHandControllerGrab() { + // Send message to handControllerGrab.js to handle. + var enabled = !isFingerPainting || isTabletDisplayed; + + Messages.sendMessage(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL, JSON.stringify({ + holdEnabled: enabled, + nearGrabEnabled: enabled, + farGrabEnabled: enabled + })); + } + function onButtonClicked() { var wasFingerPainting = isFingerPainting; @@ -107,6 +120,15 @@ leftBrush.cancelLine(); rightBrush.cancelLine(); } + + updateHandControllerGrab(); + } + + function onTabletScreenChanged(type, url) { + var TABLET_SCREEN_CLOSED = "Closed"; + + isTabletDisplayed = type !== TABLET_SCREEN_CLOSED; + updateHandControllerGrab(); } function setUp() { @@ -124,6 +146,9 @@ }); button.clicked.connect(onButtonClicked); + // Track whether tablet is displayed or not. + tablet.screenChanged.connect(onTabletScreenChanged); + // Connect controller API to handController objects. leftHand = handController("left"); rightHand = handController("right"); @@ -145,6 +170,9 @@ rightHand.triggerPressing = rightBrush.drawLine; rightHand.trigerRelease = rightBrush.finishLine; rightHand.gripPressed = rightBrush.eraseLine; + + // Messages channel for disabling/enabling laser pointers and grabbing. + Messages.subscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL); } function tearDown() { @@ -155,6 +183,8 @@ button.clicked.disconnect(onButtonClicked); tablet.removeButton(button); + tablet.screenChanged.disconnect(onTabletScreenChanged); + Controller.disableMapping(CONTROLLER_MAPPING_NAME); leftBrush.tearDown(); @@ -166,6 +196,8 @@ rightBrush = null; rightHand.tearDown(); rightHand = null; + + Messages.unsubscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL); } setUp();