@quinninc/pixi-transformer 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Transformer.d.ts +5 -1
- package/dist/Transformer.js +34 -17
- package/package.json +1 -1
package/dist/Transformer.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class Transformer extends Pixi.Container {
|
|
|
22
22
|
private handleOpacity;
|
|
23
23
|
private controlsSize;
|
|
24
24
|
private handleHitAreaScale;
|
|
25
|
+
private handleHitRadius;
|
|
25
26
|
private controlsDimOpacity;
|
|
26
27
|
private controlsStrokeThickness;
|
|
27
28
|
private lineColor;
|
|
@@ -40,6 +41,7 @@ export declare class Transformer extends Pixi.Container {
|
|
|
40
41
|
* @param p.handleColor - handles' fill color
|
|
41
42
|
* @param p.controlsSize - handles' size in pixels
|
|
42
43
|
* @param p.handleHitAreaScale - scale factor for handle hit area (e.g. 2 = double size)
|
|
44
|
+
* @param p.handleHitRadius - hit area radius in screen pixels around each handle
|
|
43
45
|
* @param p.debug - show scaling distance debug lines
|
|
44
46
|
* @param p.snapKeys - key to hold to enable snapping rotation to 45 degrees // default ['ShiftLeft']
|
|
45
47
|
* @param p.pivotKeys - key to hold to move the pivot point of transformation // default ['AltLeft']
|
|
@@ -62,12 +64,13 @@ export declare class Transformer extends Pixi.Container {
|
|
|
62
64
|
*
|
|
63
65
|
* selectTool.unselect();
|
|
64
66
|
*/
|
|
65
|
-
constructor({ id, lineColor, handleColor, controlsSize, handleHitAreaScale, debug, generateAnchorMark, snapKeys, pivotKeys, }?: {
|
|
67
|
+
constructor({ id, lineColor, handleColor, controlsSize, handleHitAreaScale, handleHitRadius, debug, generateAnchorMark, snapKeys, pivotKeys, }?: {
|
|
66
68
|
id?: string;
|
|
67
69
|
lineColor?: string | number;
|
|
68
70
|
handleColor?: string | number;
|
|
69
71
|
controlsSize?: number;
|
|
70
72
|
handleHitAreaScale?: number;
|
|
73
|
+
handleHitRadius?: number;
|
|
71
74
|
debug?: boolean;
|
|
72
75
|
generateAnchorMark?: false | ((graphic: Pixi.Graphics) => void);
|
|
73
76
|
snapKeys?: string[];
|
|
@@ -79,6 +82,7 @@ export declare class Transformer extends Pixi.Container {
|
|
|
79
82
|
private createHandle;
|
|
80
83
|
private createHandleIndicatorTo;
|
|
81
84
|
private deScale;
|
|
85
|
+
private updateHandleHitArea;
|
|
82
86
|
select(target: Pixi.Container): void;
|
|
83
87
|
unselect(): void;
|
|
84
88
|
onUpdate: (cb: (t?: Transformer) => void) => () => void;
|
package/dist/Transformer.js
CHANGED
|
@@ -7,6 +7,7 @@ export class Transformer extends Pixi.Container {
|
|
|
7
7
|
* @param p.handleColor - handles' fill color
|
|
8
8
|
* @param p.controlsSize - handles' size in pixels
|
|
9
9
|
* @param p.handleHitAreaScale - scale factor for handle hit area (e.g. 2 = double size)
|
|
10
|
+
* @param p.handleHitRadius - hit area radius in screen pixels around each handle
|
|
10
11
|
* @param p.debug - show scaling distance debug lines
|
|
11
12
|
* @param p.snapKeys - key to hold to enable snapping rotation to 45 degrees // default ['ShiftLeft']
|
|
12
13
|
* @param p.pivotKeys - key to hold to move the pivot point of transformation // default ['AltLeft']
|
|
@@ -29,7 +30,7 @@ export class Transformer extends Pixi.Container {
|
|
|
29
30
|
*
|
|
30
31
|
* selectTool.unselect();
|
|
31
32
|
*/
|
|
32
|
-
constructor({ id = "transformer", lineColor = 0x66cfff, handleColor = 0xffffff, controlsSize = 10, handleHitAreaScale = 2, debug = false, generateAnchorMark, snapKeys = ["ShiftLeft"], pivotKeys = ["AltLeft"], } = {}) {
|
|
33
|
+
constructor({ id = "transformer", lineColor = 0x66cfff, handleColor = 0xffffff, controlsSize = 10, handleHitAreaScale = 2, handleHitRadius = 50, debug = false, generateAnchorMark, snapKeys = ["ShiftLeft"], pivotKeys = ["AltLeft"], } = {}) {
|
|
33
34
|
super();
|
|
34
35
|
// target Pixi.Container
|
|
35
36
|
this.target = null;
|
|
@@ -60,6 +61,7 @@ export class Transformer extends Pixi.Container {
|
|
|
60
61
|
this.handleOpacity = 1;
|
|
61
62
|
this.controlsSize = controlsSize;
|
|
62
63
|
this.handleHitAreaScale = handleHitAreaScale;
|
|
64
|
+
this.handleHitRadius = handleHitRadius;
|
|
63
65
|
this.controlsDimOpacity = 1;
|
|
64
66
|
this.controlsStrokeThickness = 2;
|
|
65
67
|
this.movedThreshold = 10;
|
|
@@ -93,10 +95,10 @@ export class Transformer extends Pixi.Container {
|
|
|
93
95
|
alpha: this.handleOpacity * 0.75,
|
|
94
96
|
});
|
|
95
97
|
this.addChild(this.fromPoint, this.toPoint);
|
|
96
|
-
const edgeLong = Math.round(this.controlsSize * 1.
|
|
97
|
-
const edgeShort = Math.round(this.controlsSize * 0.
|
|
98
|
+
const edgeLong = Math.round(this.controlsSize * 1.8);
|
|
99
|
+
const edgeShort = Math.round(this.controlsSize * 0.5);
|
|
98
100
|
const edgeRadius = Math.max(6, Math.round(edgeShort / 2));
|
|
99
|
-
const cornerSize = Math.round(this.controlsSize * 1.
|
|
101
|
+
const cornerSize = Math.round(this.controlsSize * 1.4);
|
|
100
102
|
// scaling handles
|
|
101
103
|
this.scaleTHandle = this.createHandle({
|
|
102
104
|
name: "scaleTHandle",
|
|
@@ -132,6 +134,8 @@ export class Transformer extends Pixi.Container {
|
|
|
132
134
|
shape: "circle",
|
|
133
135
|
width: cornerSize,
|
|
134
136
|
height: cornerSize,
|
|
137
|
+
fillColor: this.lineColor,
|
|
138
|
+
strokeColor: 0xffffff,
|
|
135
139
|
});
|
|
136
140
|
this.scaleTRHandle = this.createHandle({
|
|
137
141
|
name: "scaleTRHandle",
|
|
@@ -139,6 +143,8 @@ export class Transformer extends Pixi.Container {
|
|
|
139
143
|
shape: "circle",
|
|
140
144
|
width: cornerSize,
|
|
141
145
|
height: cornerSize,
|
|
146
|
+
fillColor: this.lineColor,
|
|
147
|
+
strokeColor: 0xffffff,
|
|
142
148
|
});
|
|
143
149
|
this.scaleBRHandle = this.createHandle({
|
|
144
150
|
name: "scaleBRHandle",
|
|
@@ -146,6 +152,8 @@ export class Transformer extends Pixi.Container {
|
|
|
146
152
|
shape: "circle",
|
|
147
153
|
width: cornerSize,
|
|
148
154
|
height: cornerSize,
|
|
155
|
+
fillColor: this.lineColor,
|
|
156
|
+
strokeColor: 0xffffff,
|
|
149
157
|
});
|
|
150
158
|
this.scaleBLHandle = this.createHandle({
|
|
151
159
|
name: "scaleBLHandle",
|
|
@@ -153,14 +161,18 @@ export class Transformer extends Pixi.Container {
|
|
|
153
161
|
shape: "circle",
|
|
154
162
|
width: cornerSize,
|
|
155
163
|
height: cornerSize,
|
|
164
|
+
fillColor: this.lineColor,
|
|
165
|
+
strokeColor: 0xffffff,
|
|
156
166
|
});
|
|
157
167
|
// rotation handle
|
|
158
168
|
this.rotateHandle = this.createHandle({
|
|
159
169
|
name: "Rotate",
|
|
160
170
|
cursor: "pointer",
|
|
161
171
|
shape: "circle",
|
|
162
|
-
width: Math.round(this.controlsSize * 0.
|
|
163
|
-
height: Math.round(this.controlsSize * 0.
|
|
172
|
+
width: Math.round(this.controlsSize * 0.8),
|
|
173
|
+
height: Math.round(this.controlsSize * 0.8),
|
|
174
|
+
fillColor: 0xffffff,
|
|
175
|
+
strokeColor: this.lineColor,
|
|
164
176
|
});
|
|
165
177
|
this.addChild(this.scaleTHandle, this.scaleRHandle, this.scaleBHandle, this.scaleLHandle, this.scaleTLHandle, this.scaleTRHandle, this.scaleBRHandle, this.scaleBLHandle, this.rotateHandle);
|
|
166
178
|
// ------------<MoveTool>---------------
|
|
@@ -488,7 +500,7 @@ export class Transformer extends Pixi.Container {
|
|
|
488
500
|
that[property] = false;
|
|
489
501
|
});
|
|
490
502
|
}
|
|
491
|
-
createHandle({ cursor, name, shape = "square", width, height, radius, }) {
|
|
503
|
+
createHandle({ cursor, name, shape = "square", width, height, radius, fillColor, strokeColor, }) {
|
|
492
504
|
const w = width ?? this.controlsSize;
|
|
493
505
|
const h = height ?? this.controlsSize;
|
|
494
506
|
const r = radius ?? Math.max(4, Math.round(Math.min(w, h) * 0.22));
|
|
@@ -505,17 +517,14 @@ export class Transformer extends Pixi.Container {
|
|
|
505
517
|
handle.roundRect(0, 0, w, h, r);
|
|
506
518
|
}
|
|
507
519
|
handle
|
|
508
|
-
.stroke({
|
|
509
|
-
|
|
520
|
+
.stroke({
|
|
521
|
+
width: this.controlsStrokeThickness,
|
|
522
|
+
color: strokeColor ?? this.lineColor,
|
|
523
|
+
})
|
|
524
|
+
.fill(fillColor ?? this.handleColor);
|
|
510
525
|
handle.pivot.set(w / 2, h / 2);
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
if (shape === "circle") {
|
|
514
|
-
handle.hitArea = new Pixi.Circle(0, 0, Math.max(hitW, hitH) / 2);
|
|
515
|
-
}
|
|
516
|
-
else {
|
|
517
|
-
handle.hitArea = new Pixi.Rectangle(-hitW / 2, -hitH / 2, hitW, hitH);
|
|
518
|
-
}
|
|
526
|
+
handle._handleSize = { w, h, shape };
|
|
527
|
+
this.updateHandleHitArea(handle);
|
|
519
528
|
this.handleHandleEvents(handle, this);
|
|
520
529
|
return handle;
|
|
521
530
|
}
|
|
@@ -540,6 +549,13 @@ export class Transformer extends Pixi.Container {
|
|
|
540
549
|
deScale(target) {
|
|
541
550
|
target.scale.set(1 / this.scale.x, 1 / this.scale.y);
|
|
542
551
|
}
|
|
552
|
+
updateHandleHitArea(handle) {
|
|
553
|
+
const meta = handle._handleSize;
|
|
554
|
+
if (!meta)
|
|
555
|
+
return;
|
|
556
|
+
const radius = this.handleHitRadius * Math.max(this.scale.x, this.scale.y);
|
|
557
|
+
handle.hitArea = new Pixi.Circle(0, 0, radius);
|
|
558
|
+
}
|
|
543
559
|
// public methods:
|
|
544
560
|
select(target) {
|
|
545
561
|
if (!target) {
|
|
@@ -671,6 +687,7 @@ export class Transformer extends Pixi.Container {
|
|
|
671
687
|
// descale all handles
|
|
672
688
|
allHandles.forEach((handle) => {
|
|
673
689
|
this.deScale(handle);
|
|
690
|
+
this.updateHandleHitArea(handle);
|
|
674
691
|
});
|
|
675
692
|
for (const cb of this.updateCallbacks) {
|
|
676
693
|
cb(this);
|