Skip to content

Commit 3a13d81

Browse files
committed
all corners scale
1 parent a8cc4ab commit 3a13d81

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/editor-view/selectors/gizmos/scale-gizmo.scss

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
11
$handle-size: 15px;
2-
$size: 20px;
3-
$padding: $size - $handle-size;
2+
$size: 30px;
3+
$padding: ($size - $handle-size)/2;
44

55
phred-scale-gizmo {
66
position: absolute;
77
display: block;
88
box-sizing: border-box;
99
width: $size;
1010
height: $size;
11-
margin: -($size + $handle-size * 0.5)/2;
12-
background-color: transparent;
11+
margin: -($size + 2)/2;
12+
border-radius: $size;
1313
pointer-events: all;
14+
display: flex;
15+
justify-content: center;
16+
align-items: center;
1417

1518
.handle {
1619
box-sizing: border-box;
1720
width: $handle-size;
1821
height: $handle-size;
22+
pointer-events: none;
1923
background-color: chocolate;
2024
border: 1px solid white;
21-
pointer-events: none;
25+
margin: auto;
26+
padding: 0;
2227
}
2328

2429
&.top-left {
25-
padding: $padding 0 0 $padding;
2630
top: 0;
2731
left: 0;
2832
cursor: nwse-resize;
2933
}
3034

3135
&.top-right {
32-
padding: $padding $padding 0 0;
3336
top: 0;
3437
right: 0;
3538
cursor: nesw-resize;
3639
}
3740

3841
&.bottom-left {
39-
padding: 0 0 $padding $padding;
4042
bottom: 0;
4143
left: 0;
4244
cursor: nesw-resize;
4345
}
4446

4547
&.bottom-right {
46-
padding: 0 $padding $padding 0;
4748
bottom: 0;
4849
right: 0;
4950
cursor: nwse-resize;

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@ export class ScaleHandler implements DraggingHandler {
1818
let hside = gizmo.hside;
1919
let vside = gizmo.vside;
2020
console.log(hside, object?.name)
21+
2122
if (hside === undefined || vside === undefined) {
2223
this._object = null;
2324
return;
2425
}
25-
this._object = object;
2626

27+
this._object = object;
2728

2829
// inverting axis
2930
if (object.scale.x < 0) {
3031
if (hside == HSide.Left) hside = HSide.Right;
3132
else if (hside == HSide.Right) hside = HSide.Left;
3233
}
3334

35+
if (object.scale.y < 0) {
36+
if (vside == VSide.Top) vside = VSide.Bottom;
37+
else if (vside == VSide.Bottom) vside = VSide.Top;
38+
}
39+
3440
this._vside = vside;
3541
this._hside = hside;
3642

@@ -44,15 +50,18 @@ export class ScaleHandler implements DraggingHandler {
4450
if (hside === HSide.Right) {
4551
pivotx = 0;
4652
x = object.x - object.pivot.x * object.scale.x;
47-
y = object.y - object.pivot.y;
48-
49-
5053
} else if (hside === HSide.Left) {
51-
const originalWidth = object.width / object.scale.x;
52-
pivotx = Math.abs(originalWidth);
53-
54+
pivotx = Math.abs(object.width / object.scale.x);
5455
x = object.x + object.width - object.pivot.x * object.scale.x;
55-
y = object.y - object.pivot.y;
56+
}
57+
58+
if (vside === VSide.Bottom) {
59+
pivoty = 0;
60+
y = object.y - object.pivot.y * object.scale.y;
61+
62+
} else if (vside === VSide.Top) {
63+
pivoty = Math.abs(object.height / object.scale.y);
64+
y = object.y + object.height - object.pivot.y * object.scale.y;
5665
}
5766

5867
object.pivot.set(pivotx, pivoty);
@@ -79,11 +88,15 @@ export class ScaleHandler implements DraggingHandler {
7988
let dx = 0;
8089
if (this._hside === HSide.Left) dx = lastPoint.x - newPoint.x;
8190
else if (this._hside === HSide.Right) dx = newPoint.x - lastPoint.x;
91+
92+
let dy = 0;
93+
if (this._vside === VSide.Top) dy = lastPoint.y - newPoint.y;
94+
else if (this._vside === VSide.Bottom) dy = newPoint.y - lastPoint.y;
8295
// if (this._corner == Corner.BottomRight) dx = newPoint.x - lastPoint.x;
8396
// else if (this._corner === Corner.BottomLeft) dx = lastPoint.x - newPoint.x;
8497
// const dx = newPoint.x - lastPoint.x; // bottom right
8598
// const dx = lastPoint.x - newPoint.x; // bottom left
86-
const dy = newPoint.y - lastPoint.y;
99+
// const dy = newPoint.y - lastPoint.y;
87100
this._point = newPoint;
88101

89102
this._object.updateTransform();

0 commit comments

Comments
 (0)