From 48ee7a3b1a52c112d83d0b05225474758c7151cb Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 29 Jul 2017 17:39:23 +1200 Subject: [PATCH] Add icon for clone tool --- scripts/vr-edit/modules/toolIcon.js | 12 +++++----- scripts/vr-edit/modules/toolMenu.js | 4 ++-- scripts/vr-edit/vr-edit.js | 36 +++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/scripts/vr-edit/modules/toolIcon.js b/scripts/vr-edit/modules/toolIcon.js index 8af0e3a884..c9f955ecf5 100644 --- a/scripts/vr-edit/modules/toolIcon.js +++ b/scripts/vr-edit/modules/toolIcon.js @@ -15,12 +15,12 @@ ToolIcon = function (side) { "use strict"; - var NONE = 0, - SCALE_HANDLES = 1, + var SCALE_TOOL = 0, + CLONE_TOOL = 1, ICON_COLORS = [ - { red: 0, green: 0, blue: 0 }, // Unused entry for NONE. - { red: 0, green: 240, blue: 240 } + { red: 0, green: 240, blue: 240 }, + { red: 240, green: 0, blue: 240 } ], LEFT_HAND = 0, @@ -98,8 +98,8 @@ ToolIcon = function (side) { } return { - NONE: NONE, - SCALE_HANDLES: SCALE_HANDLES, + SCALE_TOOL: SCALE_TOOL, + CLONE_TOOL: CLONE_TOOL, setHand: setHand, update: update, display: display, diff --git a/scripts/vr-edit/modules/toolMenu.js b/scripts/vr-edit/modules/toolMenu.js index ac8c04af18..7684fa66d3 100644 --- a/scripts/vr-edit/modules/toolMenu.js +++ b/scripts/vr-edit/modules/toolMenu.js @@ -10,7 +10,7 @@ /* global ToolMenu */ -ToolMenu = function (side, leftInputs, rightInputs, setAppScaleWithHandlesCallback) { +ToolMenu = function (side, leftInputs, rightInputs, setToolCallback) { // Tool menu displayed on top of forearm. "use strict"; @@ -150,7 +150,7 @@ ToolMenu = function (side, leftInputs, rightInputs, setAppScaleWithHandlesCallba }); } if (isButtonPressed) { - setAppScaleWithHandlesCallback(); + setToolCallback(intersectionOverlayID === scaleButtonOverlay ? "scale" : "clone"); } } } diff --git a/scripts/vr-edit/vr-edit.js b/scripts/vr-edit/vr-edit.js index 190110e261..06d438a19e 100644 --- a/scripts/vr-edit/vr-edit.js +++ b/scripts/vr-edit/vr-edit.js @@ -20,6 +20,7 @@ // Application state isAppActive = false, isAppScaleWithHandles = false, + isAppCloneEntities = false, dominantHand, // Primary objects @@ -165,7 +166,7 @@ }; - UI = function (side, leftInputs, rightInputs, setAppScaleWithHandlesCallback) { + UI = function (side, leftInputs, rightInputs, setToolCallback) { // Tool menu and Create palette. var // Primary objects. @@ -183,7 +184,7 @@ } toolIcon = new ToolIcon(otherHand(side)); - toolMenu = new ToolMenu(side, leftInputs, rightInputs, setAppScaleWithHandlesCallback); + toolMenu = new ToolMenu(side, leftInputs, rightInputs, setToolCallback); createPalette = new CreatePalette(side, leftInputs, rightInputs); getIntersection = side === LEFT_HAND ? rightInputs.intersection : leftInputs.intersection; @@ -254,7 +255,8 @@ setHand: setHand, setToolIcon: setToolIcon, clearToolIcon: clearToolIcon, - SCALE_HANDLES: toolIcon.SCALE_HANDLES, + SCALE_TOOL: toolIcon.SCALE_TOOL, + CLONE_TOOL: toolIcon.CLONE_TOOL, display: display, update: update, clear: clear, @@ -742,8 +744,9 @@ function updateTool() { var isGripClicked = hand.gripClicked(); - if (!wasGripClicked && isGripClicked && isAppScaleWithHandles) { + if (!wasGripClicked && isGripClicked && (isAppScaleWithHandles || isAppCloneEntities)) { isAppScaleWithHandles = false; + isAppCloneEntities = false; ui.clearToolIcon(); } wasGripClicked = isGripClicked; @@ -1010,9 +1013,21 @@ Settings.setValue(VR_EDIT_SETTING, isAppActive); } - function setAppScaleWithHandles() { - isAppScaleWithHandles = true; - ui.setToolIcon(ui.SCALE_HANDLES); + function setTool(tool) { + switch (tool) { + case "scale": + isAppScaleWithHandles = true; + isAppCloneEntities = false; + ui.setToolIcon(ui.SCALE_TOOL); + break; + case "clone": + isAppScaleWithHandles = false; + isAppCloneEntities = true; + ui.setToolIcon(ui.CLONE_TOOL); + break; + default: + debug("ERROR: Unexpected condition in setTool()!"); + } } function onAppButtonClicked() { @@ -1052,7 +1067,10 @@ // Swap UI hands. ui.setHand(otherHand(dominantHand)); if (isAppScaleWithHandles) { - ui.setToolIcon(ui.SCALE_HANDLES); + ui.setToolIcon(ui.SCALE_TOOL); + } + if (isAppCloneEntities) { + ui.setToolIcon(ui.CLONE_TOOL); } if (isAppActive) { @@ -1090,7 +1108,7 @@ inputs[RIGHT_HAND] = new Inputs(RIGHT_HAND); // UI object. - ui = new UI(otherHand(dominantHand), inputs[LEFT_HAND], inputs[RIGHT_HAND], setAppScaleWithHandles); + ui = new UI(otherHand(dominantHand), inputs[LEFT_HAND], inputs[RIGHT_HAND], setTool); // Editor objects. editors[LEFT_HAND] = new Editor(LEFT_HAND);