Skip to content

Commit a8cc4ab

Browse files
committed
horizontal scaling
1 parent 6d9a1c2 commit a8cc4ab

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/editor-view/selectors/handlers/scale.handler.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ export class ScaleHandler implements DraggingHandler {
1717
const gizmo = e.target as ScaleGizmo;
1818
let hside = gizmo.hside;
1919
let vside = gizmo.vside;
20+
console.log(hside, object?.name)
21+
if (hside === undefined || vside === undefined) {
22+
this._object = null;
23+
return;
24+
}
2025
this._object = object;
2126

27+
2228
// inverting axis
2329
if (object.scale.x < 0) {
2430
if (hside == HSide.Left) hside = HSide.Right;
@@ -30,23 +36,27 @@ export class ScaleHandler implements DraggingHandler {
3036

3137
object.updateTransform();
3238

39+
let pivotx = 0;
40+
let pivoty = 0;
41+
let x = 0;
42+
let y = 0;
43+
3344
if (hside === HSide.Right) {
34-
object.position.set(
35-
object.x - object.pivot.x * object.scale.x,
36-
object.y - object.pivot.y);
37-
object.pivot.set(0, 0);
45+
pivotx = 0;
46+
x = object.x - object.pivot.x * object.scale.x;
47+
y = object.y - object.pivot.y;
3848

3949

4050
} else if (hside === HSide.Left) {
4151
const originalWidth = object.width / object.scale.x;
42-
object.position.set(
43-
object.x + object.width - object.pivot.x * object.scale.x,
44-
object.y - object.pivot.y);
45-
46-
object.pivot.set(Math.abs(originalWidth), 0);
47-
console.log(originalWidth)
52+
pivotx = Math.abs(originalWidth);
53+
54+
x = object.x + object.width - object.pivot.x * object.scale.x;
55+
y = object.y - object.pivot.y;
4856
}
4957

58+
object.pivot.set(pivotx, pivoty);
59+
object.position.set(x, y);
5060

5161
// this._isGroup = !object.anchor;
5262
// if (this._isGroup) {
@@ -58,6 +68,7 @@ export class ScaleHandler implements DraggingHandler {
5868
}
5969

6070
public handle(e: MouseEvent): void {
71+
if (!this._object) return;
6172
if (!this._point) {
6273
this._point = SelectionUtil.mouseEventToGamePoint(e, { x: 0, y: 0 });
6374
}

0 commit comments

Comments
 (0)