in src/canvastools/ts/CanvasTools/Region/Rect/AnchorsElements.ts [133:236]
protected updateRegion(p: Point2D) {
let x1: number = p.x;
let y1: number = p.y;
let x2: number;
let y2: number;
let flipX: boolean = false;
let flipY: boolean = false;
let activeAnchor = this.getActiveAnchor();
switch (activeAnchor) {
case "TL": {
x2 = this.x + this.width;
y2 = this.y + this.height;
flipX = x2 < x1;
flipY = y2 < y1;
break;
}
case "TR": {
x2 = this.x;
y2 = this.y + this.height;
flipX = x1 < x2;
flipY = y2 < y1;
break;
}
case "BL": {
y2 = this.y;
x2 = this.x + this.width;
flipX = x2 < x1;
flipY = y1 < y2;
break;
}
case "BR": {
x2 = this.x;
y2 = this.y;
flipX = x1 < x2;
flipY = y1 < y2;
break;
}
case "T": {
x1 = this.x;
x2 = this.x + this.width;
y2 = this.y + this.height;
flipY = y1 > y2;
break;
}
case "R": {
x2 = this.x;
y1 = this.y;
y2 = this.y + this.height;
flipX = x2 > x1;
break;
}
case "B": {
x1 = this.x;
x2 = this.x + this.width;
y2 = this.y;
flipY = y1 < y2;
break;
}
case "L": {
x2 = this.x + this.width;
y1 = this.y;
y2 = this.y + this.height;
flipX = x1 > x2;
break;
}
}
let newAA: string = "";
if (activeAnchor !== "" && activeAnchor.length === 2) {
newAA += (activeAnchor[0] === "T") ? (flipY ? "B" : "T") : (flipY ? "T" : "B");
newAA += (activeAnchor[1] === "L") ? (flipX ? "R" : "L") : (flipX ? "L" : "R");
}
if (activeAnchor !== "" && activeAnchor.length === 1) {
if (flipX) {
newAA = (activeAnchor === "R") ? "L" : "R";
} else if (flipY) {
newAA = (activeAnchor === "T") ? "B" : "T";
} else {
newAA = activeAnchor;
}
}
if (activeAnchor !== newAA) {
this.ghostAnchor.removeClass(activeAnchor);
if (newAA.length === 2) {
this.activeAnchorIndex = this.anchorPointStyles.indexOf(newAA) + 1;
} else {
this.activeAnchorIndex = - (this.anchorBoneStyles.indexOf(newAA) + 1);
}
activeAnchor = newAA;
this.ghostAnchor.addClass(newAA);
}
const p1 = new Point2D(Math.min(x1, x2), Math.min(y1, y2)).boundToRect(this.paperRect);
const p2 = new Point2D(Math.max(x1, x2), Math.max(y1, y2)).boundToRect(this.paperRect);
const rd = this.regionData.copy();
rd.setPoints([p1, new Point2D(p2.x, p1.y), p2, new Point2D(p1.x, p2.y)]);
this.callbacks.onChange(this, rd, ChangeEventType.MOVING);
}