mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 13:32:28 -05:00
get scale working
This commit is contained in:
parent
9216098a3f
commit
3fa8073bd1
3 changed files with 28 additions and 11 deletions
|
@ -60,18 +60,23 @@ class BoundingBoxTool {
|
|||
if (hitResults[i].item.data && hitResults[i].item.data.isScaleHandle) {
|
||||
hitResult = hitResults[i];
|
||||
this.mode = Modes.SCALE;
|
||||
this._modeMap[this.mode].onMouseDown(hitResult, this.boundsPath, getSelectedItems());
|
||||
break;
|
||||
} else if (hitResults[i].item.data && hitResults[i].item.data.isRotHandle) {
|
||||
hitResult = hitResults[i];
|
||||
this.mode = Modes.ROTATE;
|
||||
this._modeMap[this.mode].onMouseDown(hitResult, this.boundsPath, getSelectedItems());
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.mode) {
|
||||
this.mode = Modes.MOVE;
|
||||
}
|
||||
|
||||
if (this.mode === Modes.MOVE) {
|
||||
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
|
||||
|
|
|
@ -15,7 +15,7 @@ class RotateTool {
|
|||
onMouseDown (hitResult, boundsPath, selectedItems) {
|
||||
this.rotGroupPivot = boundsPath.bounds.center;
|
||||
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) {
|
||||
this.rotItems.push(item);
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ class ScaleTool {
|
|||
this.corner = null;
|
||||
this.origSize = null;
|
||||
this.origCenter = null;
|
||||
this.scaleItems = null;
|
||||
this.itemGroup = null;
|
||||
this.boundsPath = null;
|
||||
// Lowest item above all scale items in z index
|
||||
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} 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;
|
||||
this.boundsPath = boundsPath;
|
||||
this.boundsScaleHandles = boundsScaleHandles;
|
||||
this.boundsRotHandles = boundsRotHandles;
|
||||
this.pivot = 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.origSize = this.corner.subtract(this.pivot);
|
||||
this.origCenter = this.boundsPath.bounds.center;
|
||||
this.boundsPath = boundsPath;
|
||||
this.scaleItems = selectedItems;
|
||||
for (const item of selectedItems) {
|
||||
// Scale only root items
|
||||
if (item.parent instanceof paper.Layer) {
|
||||
this.scaleItems.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
onMouseDrag (event) {
|
||||
const scaleTool = this;
|
||||
const modOrigSize = this.origSize;
|
||||
|
||||
// get item to insert below so that scaled items stay in same z position
|
||||
const items = paper.project.getItems({
|
||||
match: function (item) {
|
||||
if (item instanceof paper.Layer) {
|
||||
if (item instanceof paper.Layer || item.data.isHelperItem) {
|
||||
return false;
|
||||
}
|
||||
for (const scaleItem of this.scaleItems) {
|
||||
for (const scaleItem of scaleTool.scaleItems) {
|
||||
if (!scaleItem.isBelow(item)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -107,8 +117,10 @@ class ScaleTool {
|
|||
this.corner = null;
|
||||
this.origSize = null;
|
||||
this.origCenter = null;
|
||||
this.scaleItems = null;
|
||||
this.scaleItems.length = 0;
|
||||
this.boundsPath = null;
|
||||
this.boundsScaleHandles = [];
|
||||
this.boundsRotHandles = [];
|
||||
|
||||
if (!this.itemGroup) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue