get scale working

This commit is contained in:
DD 2017-09-13 17:45:06 -04:00
parent 9216098a3f
commit 3fa8073bd1
3 changed files with 28 additions and 11 deletions

View file

@ -60,18 +60,23 @@ class BoundingBoxTool {
if (hitResults[i].item.data && hitResults[i].item.data.isScaleHandle) { if (hitResults[i].item.data && hitResults[i].item.data.isScaleHandle) {
hitResult = hitResults[i]; hitResult = hitResults[i];
this.mode = Modes.SCALE; this.mode = Modes.SCALE;
this._modeMap[this.mode].onMouseDown(hitResult, this.boundsPath, getSelectedItems());
break; break;
} else if (hitResults[i].item.data && hitResults[i].item.data.isRotHandle) { } else if (hitResults[i].item.data && hitResults[i].item.data.isRotHandle) {
hitResult = hitResults[i]; hitResult = hitResults[i];
this.mode = Modes.ROTATE; this.mode = Modes.ROTATE;
this._modeMap[this.mode].onMouseDown(hitResult, this.boundsPath, getSelectedItems());
} }
} }
if (!this.mode) { if (!this.mode) {
this.mode = Modes.MOVE; this.mode = Modes.MOVE;
}
if (this.mode === Modes.MOVE) {
this._modeMap[this.mode].onMouseDown(hitResult, clone, multiselect); this._modeMap[this.mode].onMouseDown(hitResult, clone, multiselect);
} else if (this.mode === Modes.SCALE) {
this._modeMap[this.mode].onMouseDown(
hitResult, this.boundsPath, this.boundsScaleHandles, this.boundsRotHandles, getSelectedItems());
} else if (this.mode === Modes.ROTATE) {
this._modeMap[this.mode].onMouseDown(hitResult, this.boundsPath, getSelectedItems());
} }
// while transforming object, never show the bounds stuff // while transforming object, never show the bounds stuff

View file

@ -15,7 +15,7 @@ class RotateTool {
onMouseDown (hitResult, boundsPath, selectedItems) { onMouseDown (hitResult, boundsPath, selectedItems) {
this.rotGroupPivot = boundsPath.bounds.center; this.rotGroupPivot = boundsPath.bounds.center;
for (const item of selectedItems) { for (const item of selectedItems) {
// Rotate only root items; all nested items shouldn't get rotated again. // Rotate only root items
if (item.parent instanceof paper.Layer) { if (item.parent instanceof paper.Layer) {
this.rotItems.push(item); this.rotItems.push(item);
} }

View file

@ -7,11 +7,13 @@ class ScaleTool {
this.corner = null; this.corner = null;
this.origSize = null; this.origSize = null;
this.origCenter = null; this.origCenter = null;
this.scaleItems = null;
this.itemGroup = null; this.itemGroup = null;
this.boundsPath = null; this.boundsPath = null;
// Lowest item above all scale items in z index // Lowest item above all scale items in z index
this.itemToInsertBelow = null; this.itemToInsertBelow = null;
this.scaleItems = [];
this.boundsScaleHandles = [];
this.boundsRotHandles = [];
} }
/** /**
@ -21,26 +23,34 @@ class ScaleTool {
* @param {boolean} clone Whether to clone on mouse down (e.g. alt key held) * @param {boolean} clone Whether to clone on mouse down (e.g. alt key held)
* @param {boolean} multiselect Whether to multiselect on mouse down (e.g. shift key held) * @param {boolean} multiselect Whether to multiselect on mouse down (e.g. shift key held)
*/ */
onMouseDown (hitResult, boundsPath, selectedItems) { onMouseDown (hitResult, boundsPath, boundsScaleHandles, boundsRotHandles, selectedItems) {
const index = hitResult.item.data.index; const index = hitResult.item.data.index;
this.boundsPath = boundsPath;
this.boundsScaleHandles = boundsScaleHandles;
this.boundsRotHandles = boundsRotHandles;
this.pivot = this.boundsPath.bounds[this.getOpposingRectCornerNameByIndex(index)].clone(); this.pivot = this.boundsPath.bounds[this.getOpposingRectCornerNameByIndex(index)].clone();
this.origPivot = this.boundsPath.bounds[this.getOpposingRectCornerNameByIndex(index)].clone(); this.origPivot = this.boundsPath.bounds[this.getOpposingRectCornerNameByIndex(index)].clone();
this.corner = this.boundsPath.bounds[this.getRectCornerNameByIndex(index)].clone(); this.corner = this.boundsPath.bounds[this.getRectCornerNameByIndex(index)].clone();
this.origSize = this.corner.subtract(this.pivot); this.origSize = this.corner.subtract(this.pivot);
this.origCenter = this.boundsPath.bounds.center; this.origCenter = this.boundsPath.bounds.center;
this.boundsPath = boundsPath; for (const item of selectedItems) {
this.scaleItems = selectedItems; // Scale only root items
if (item.parent instanceof paper.Layer) {
this.scaleItems.push(item);
}
}
} }
onMouseDrag (event) { onMouseDrag (event) {
const scaleTool = this;
const modOrigSize = this.origSize; const modOrigSize = this.origSize;
// get item to insert below so that scaled items stay in same z position // get item to insert below so that scaled items stay in same z position
const items = paper.project.getItems({ const items = paper.project.getItems({
match: function (item) { match: function (item) {
if (item instanceof paper.Layer) { if (item instanceof paper.Layer || item.data.isHelperItem) {
return false; return false;
} }
for (const scaleItem of this.scaleItems) { for (const scaleItem of scaleTool.scaleItems) {
if (!scaleItem.isBelow(item)) { if (!scaleItem.isBelow(item)) {
return false; return false;
} }
@ -107,8 +117,10 @@ class ScaleTool {
this.corner = null; this.corner = null;
this.origSize = null; this.origSize = null;
this.origCenter = null; this.origCenter = null;
this.scaleItems = null; this.scaleItems.length = 0;
this.boundsPath = null; this.boundsPath = null;
this.boundsScaleHandles = [];
this.boundsRotHandles = [];
if (!this.itemGroup) { if (!this.itemGroup) {
return; return;