From 409e785aa3d4baeac8d7eb70d5ab5852aeffb77c Mon Sep 17 00:00:00 2001 From: David Kelly Date: Mon, 9 Jan 2017 08:42:43 -0700 Subject: [PATCH] fix un-hover, add some comments --- scripts/system/pal.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/system/pal.js b/scripts/system/pal.js index 6428749bee..72955bf3ab 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -86,6 +86,10 @@ ExtendedOverlay.prototype.hover = function (hovering) { this.model.editOverlay({textures: textures(this.selected, hovering)}); } if (hovering) { + // un-hover the last hovering overlay + if (lastHoveringId && lastHoveringId != this.key) { + ExtendedOverlay.get(lastHoveringId).hover(false); + } lastHoveringId = this.key; } } @@ -116,7 +120,10 @@ ExtendedOverlay.some = function (iterator) { // Bails early as soon as iterator } } }; -ExtendedOverlay.applyPickRay = function (pickRay, cb, noHit) { // cb(overlay) on the one overlay intersected by pickRay, if any. + +// hit(overlay) on the one overlay intersected by pickRay, if any. +// noHit() if no ExtendedOverlay was intersected (helps with hover) +ExtendedOverlay.applyPickRay = function (pickRay, hit, noHit) { // cb(overlay) on the one overlay intersected by pickRay, if any. var pickedOverlay = Overlays.findRayIntersection(pickRay); // Depends on nearer coverOverlays to extend closer to us than farther ones. if (!pickedOverlay.intersects) { if (noHit) { @@ -126,7 +133,7 @@ ExtendedOverlay.applyPickRay = function (pickRay, cb, noHit) { // cb(overlay) on } ExtendedOverlay.some(function (overlay) { // See if pickedOverlay is one of ours. if ((overlay.activeOverlay) === pickedOverlay.overlayID) { - cb(overlay); + hit(overlay); return true; } }); @@ -363,7 +370,7 @@ function handleMouseMoveEvent(event) { // find out which overlay (if any) is over the mouse position // var overlayAtPoint = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); var pickRay = Camera.computePickRay(event.x, event.y); - var hit = ExtendedOverlay.applyPickRay(pickRay, function (overlay) { + ExtendedOverlay.applyPickRay(pickRay, function (overlay) { overlay.hover(true); }, function () { ExtendedOverlay.some(function (overlay) { overlay.hover(false); });