Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #1630, when resizing selection across a corner or side, invert th…
Browse files Browse the repository at this point in the history
…e selection
  • Loading branch information
ianb committed Oct 13, 2016
1 parent 25ce7f4 commit ae47ad9
Showing 1 changed file with 25 additions and 35 deletions.
60 changes: 25 additions & 35 deletions addon/data/shooter-interactive-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ function eventOptionsForBox(box) {

// This enumerates all the anchors on the selection, and what part of the
// selection they move:
var movements = {
topLeft: ["left", "top"],
top: [null, "top"],
topRight: ["right", "top"],
left: ["left", null],
right: ["right", null],
bottomLeft: ["left", "bottom"],
bottom: [null, "bottom"],
bottomRight: ["right", "bottom"],
const movements = {
topLeft: ["x1", "y1"],
top: [null, "y1"],
topRight: ["x2", "y1"],
left: ["x1", null],
right: ["x2", null],
bottomLeft: ["x1", "y2"],
bottom: [null, "y2"],
bottomRight: ["x2", "y2"],
move: ["*", "*"]
};

Expand Down Expand Up @@ -233,25 +233,17 @@ class Selection {
return Math.abs(this.y1 - this.y2);
}

checkBump(side) {
if (side === "top") {
if (this.height <= this.BUMP_LOWER) {
this.bottom = snapping.guessY(util.truncateY(this.top + this.BUMP_EXPAND));
}
} else if (side === "bottom") {
if (this.height <= this.BUMP_LOWER) {
this.top = snapping.guessY(util.truncateY(this.bottom - this.BUMP_EXPAND));
}
} else if (side === "left") {
if (this.width <= this.BUMP_LOWER) {
this.right = snapping.guessX(util.truncateX(this.left + this.BUMP_EXPAND));
}
} else if (side === "right") {
if (this.width <= this.BUMP_LOWER) {
this.left = snapping.guessX(util.truncateX(this.right - this.BUMP_EXPAND));
}
} else {
throw new Error("Unexpected direction: " + side);
/** Sort x1/x2 and y1/y2 so x1<x2, y1<y2 */
sortCoords() {
if (this.x1 > this.x2) {
let tmp = this.x2;
this.x2 = this.x1;
this.x1 = tmp;
}
if (this.y1 > this.y2) {
let tmp = this.y2;
this.y2 = this.y1;
this.y1 = tmp;
}
}

Expand All @@ -260,9 +252,6 @@ class Selection {
}
}

Selection.prototype.BUMP_LOWER = 3;
Selection.prototype.BUMP_EXPAND = 65;

/** Represents a single x/y point, typically for a mouse click that doesn't have a drag: */
class Pos {
constructor(x, y) {
Expand Down Expand Up @@ -608,9 +597,11 @@ stateHandlers.selected = {
stateHandlers.resizing = {
start: function () {
ui.WholePageOverlay.remove();
selectedPos.sortCoords();
},

startResize: function (event, direction) {
selectedPos.sortCoords();
resizeDirection = direction;
resizeStartPos = new Pos(event.pageX, event.pageY);
resizeStartSelected = selectedPos.clone();
Expand Down Expand Up @@ -652,18 +643,16 @@ stateHandlers.resizing = {
let movement = movements[resizeDirection];
if (movement[0]) {
let moveX = movement[0];
moveX = moveX == "*" ? ["left", "right"] : [moveX];
moveX = moveX == "*" ? ["x1", "x2"] : [moveX];
for (let moveDir of moveX) {
selectedPos[moveDir] = util.truncateX(resizeStartSelected[moveDir] + diffX);
selectedPos.checkBump(moveDir);
}
}
if (movement[1]) {
let moveY = movement[1];
moveY = moveY == "*" ? ["top", "bottom"] : [moveY];
moveY = moveY == "*" ? ["y1", "y2"] : [moveY];
for (let moveDir of moveY) {
selectedPos[moveDir] = util.truncateY(resizeStartSelected[moveDir] + diffY);
selectedPos.checkBump(moveDir);
}
}
if (diffX || diffY) {
Expand All @@ -674,6 +663,7 @@ stateHandlers.resizing = {

end: function () {
resizeDirection = resizeStartPos = resizeStartSelected = null;
selectedPos.sortCoords();
}
};

Expand Down

0 comments on commit ae47ad9

Please sign in to comment.