Fade drag crosshair if youre far away

This commit is contained in:
DD Liu 2019-12-11 17:08:39 -05:00
parent 23ee224ab1
commit 3907fd4f89

View file

@ -3,7 +3,7 @@ import Modes from '../../lib/modes';
import {isGroup} from '../group'; import {isGroup} from '../group';
import {isCompoundPathItem, getRootItem} from '../item'; import {isCompoundPathItem, getRootItem} from '../item';
import {checkPointsClose, snapDeltaToAngle} from '../math'; import {checkPointsClose, snapDeltaToAngle} from '../math';
import {ART_BOARD_WIDTH, ART_BOARD_HEIGHT} from '../view'; import {ART_BOARD_WIDTH, ART_BOARD_HEIGHT, CENTER} from '../view';
import {clearSelection, cloneSelection, getSelectedLeafItems, getSelectedRootItems, setItemSelection} import {clearSelection, cloneSelection, getSelectedLeafItems, getSelectedRootItems, setItemSelection}
from '../selection'; from '../selection';
import {getDragCrosshairLayer} from '../layer'; import {getDragCrosshairLayer} from '../layer';
@ -31,6 +31,7 @@ class MoveTool {
this.onUpdateImage = onUpdateImage; this.onUpdateImage = onUpdateImage;
this.switchToTextTool = switchToTextTool; this.switchToTextTool = switchToTextTool;
this.boundsPath = null; this.boundsPath = null;
this.firstDrag = false;
} }
/** /**
@ -91,7 +92,7 @@ class MoveTool {
this.selectedItems.push(this.boundsPath); this.selectedItems.push(this.boundsPath);
} }
this.firstDrag = true;
} }
setBoundsPath (boundsPath) { setBoundsPath (boundsPath) {
this.boundsPath = boundsPath; this.boundsPath = boundsPath;
@ -155,13 +156,17 @@ class MoveTool {
} }
} }
if (this.firstDrag) {
// Show the center crosshair above the selected item while dragging. This makes it easier to center sprites. // Show the center crosshair above the selected item while dragging.
// Yes, we're calling it once per drag event, but it's better than having the crosshair pop up
// for a split second every time you click a sprite.
getDragCrosshairLayer().visible = true; getDragCrosshairLayer().visible = true;
this.firstDrag = false;
}
const opacity = Math.max(0, 1 - ((CENTER.getDistance(this.selectionCenter.add(dragVector)) / CENTER.x) * (4 * paper.view.zoom)));
console.log(opacity);
getDragCrosshairLayer().opacity = opacity;
} }
onMouseUp () { onMouseUp () {
this.firstDrag = false;
let moved = false; let moved = false;
// resetting the items origin point for the next usage // resetting the items origin point for the next usage
for (const item of this.selectedItems) { for (const item of this.selectedItems) {