From caac5881bf2544f7b2dbb7944db8a5bca7788b56 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 10 Oct 2014 21:39:05 -0700 Subject: [PATCH] correctly handle unselect and dont show highlight when other tool is active --- examples/libraries/entitySelectionTool.js | 9 ++-- examples/newEditEntities.js | 56 ++++++++++++----------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 43c7849ab3..1e39096308 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -2254,8 +2254,9 @@ SelectionDisplay = (function () { break; default: // nothing to do by default - break; + return false; } + return true; }; that.mouseReleaseEvent = function(event) { @@ -2289,9 +2290,9 @@ SelectionDisplay = (function () { }; - // NOTE: mousePressEvent from the main script should call us., so we don't - // hook the Controller.mousePressEvent.connect(that.mousePressEvent); ourselves. - Controller.mouseMoveEvent.connect(that.mouseMoveEvent); + // NOTE: mousePressEvent and mouseMoveEvent from the main script should call us., so we don't hook these: + // Controller.mousePressEvent.connect(that.mousePressEvent); + // Controller.mouseMoveEvent.connect(that.mouseMoveEvent); Controller.mouseReleaseEvent.connect(that.mouseReleaseEvent); return that; diff --git a/examples/newEditEntities.js b/examples/newEditEntities.js index 1fb21caacc..5c50d37048 100644 --- a/examples/newEditEntities.js +++ b/examples/newEditEntities.js @@ -338,13 +338,15 @@ function rayPlaneIntersection(pickRay, point, normal) { function mousePressEvent(event) { mouseLastPosition = { x: event.x, y: event.y }; - entitySelected = false; var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) { // Event handled; do nothing. return; } else { + entitySelected = false; + selectionDisplay.unselectAll(); + // If we aren't active and didn't click on an overlay: quit if (!isActive) { return; @@ -440,34 +442,36 @@ function mouseMoveEvent(event) { if (!isActive) { return; } + + // allow the selectionDisplay to handle the event first, if it doesn't handle it, then do our own thing + if (selectionDisplay.mouseMoveEvent(event)) { + return; + } var pickRay = Camera.computePickRay(event.x, event.y); - if (!entitySelected) { - var entityIntersection = Entities.findRayIntersection(pickRay); - if (entityIntersection.accurate) { - if(highlightedEntityID.isKnownID && highlightedEntityID.id != entityIntersection.entityID.id) { - selectionDisplay.unhighlightSelectable(highlightedEntityID); - highlightedEntityID = { id: -1, isKnownID: false }; - } - - var halfDiagonal = Vec3.length(entityIntersection.properties.dimensions) / 2.0; - - var angularSize = 2 * Math.atan(halfDiagonal / Vec3.distance(Camera.getPosition(), - entityIntersection.properties.position)) * 180 / 3.14; - - var sizeOK = (allowLargeModels || angularSize < MAX_ANGULAR_SIZE) - && (allowSmallModels || angularSize > MIN_ANGULAR_SIZE); - - if (entityIntersection.entityID.isKnownID && sizeOK) { - if (wantEntityGlow) { - Entities.editEntity(entityIntersection.entityID, { glowLevel: 0.25 }); - } - highlightedEntityID = entityIntersection.entityID; - selectionDisplay.highlightSelectable(entityIntersection.entityID); - } - + var entityIntersection = Entities.findRayIntersection(pickRay); + if (entityIntersection.accurate) { + if(highlightedEntityID.isKnownID && highlightedEntityID.id != entityIntersection.entityID.id) { + selectionDisplay.unhighlightSelectable(highlightedEntityID); + highlightedEntityID = { id: -1, isKnownID: false }; } - return; + + var halfDiagonal = Vec3.length(entityIntersection.properties.dimensions) / 2.0; + + var angularSize = 2 * Math.atan(halfDiagonal / Vec3.distance(Camera.getPosition(), + entityIntersection.properties.position)) * 180 / 3.14; + + var sizeOK = (allowLargeModels || angularSize < MAX_ANGULAR_SIZE) + && (allowSmallModels || angularSize > MIN_ANGULAR_SIZE); + + if (entityIntersection.entityID.isKnownID && sizeOK) { + if (wantEntityGlow) { + Entities.editEntity(entityIntersection.entityID, { glowLevel: 0.25 }); + } + highlightedEntityID = entityIntersection.entityID; + selectionDisplay.highlightSelectable(entityIntersection.entityID); + } + } }