@quinninc/pixi-transformer 0.1.3 → 0.1.7
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 +4 -1
- package/dist/Transformer.js +52 -6
- package/package.json +1 -1
package/dist/Transformer.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class Transformer extends Pixi.Container {
|
|
|
21
21
|
private updateCallbacks;
|
|
22
22
|
private handleOpacity;
|
|
23
23
|
private controlsSize;
|
|
24
|
+
private handleHitAreaScale;
|
|
24
25
|
private controlsDimOpacity;
|
|
25
26
|
private controlsStrokeThickness;
|
|
26
27
|
private lineColor;
|
|
@@ -38,6 +39,7 @@ export declare class Transformer extends Pixi.Container {
|
|
|
38
39
|
* @param p.lineColor - border line color
|
|
39
40
|
* @param p.handleColor - handles' fill color
|
|
40
41
|
* @param p.controlsSize - handles' size in pixels
|
|
42
|
+
* @param p.handleHitAreaScale - scale factor for handle hit area (e.g. 2 = double size)
|
|
41
43
|
* @param p.debug - show scaling distance debug lines
|
|
42
44
|
* @param p.snapKeys - key to hold to enable snapping rotation to 45 degrees // default ['ShiftLeft']
|
|
43
45
|
* @param p.pivotKeys - key to hold to move the pivot point of transformation // default ['AltLeft']
|
|
@@ -60,11 +62,12 @@ export declare class Transformer extends Pixi.Container {
|
|
|
60
62
|
*
|
|
61
63
|
* selectTool.unselect();
|
|
62
64
|
*/
|
|
63
|
-
constructor({ id, lineColor, handleColor, controlsSize, debug, generateAnchorMark, snapKeys, pivotKeys, }?: {
|
|
65
|
+
constructor({ id, lineColor, handleColor, controlsSize, handleHitAreaScale, debug, generateAnchorMark, snapKeys, pivotKeys, }?: {
|
|
64
66
|
id?: string;
|
|
65
67
|
lineColor?: string | number;
|
|
66
68
|
handleColor?: string | number;
|
|
67
69
|
controlsSize?: number;
|
|
70
|
+
handleHitAreaScale?: number;
|
|
68
71
|
debug?: boolean;
|
|
69
72
|
generateAnchorMark?: false | ((graphic: Pixi.Graphics) => void);
|
|
70
73
|
snapKeys?: string[];
|
package/dist/Transformer.js
CHANGED
|
@@ -6,6 +6,7 @@ export class Transformer extends Pixi.Container {
|
|
|
6
6
|
* @param p.lineColor - border line color
|
|
7
7
|
* @param p.handleColor - handles' fill color
|
|
8
8
|
* @param p.controlsSize - handles' size in pixels
|
|
9
|
+
* @param p.handleHitAreaScale - scale factor for handle hit area (e.g. 2 = double size)
|
|
9
10
|
* @param p.debug - show scaling distance debug lines
|
|
10
11
|
* @param p.snapKeys - key to hold to enable snapping rotation to 45 degrees // default ['ShiftLeft']
|
|
11
12
|
* @param p.pivotKeys - key to hold to move the pivot point of transformation // default ['AltLeft']
|
|
@@ -28,7 +29,7 @@ export class Transformer extends Pixi.Container {
|
|
|
28
29
|
*
|
|
29
30
|
* selectTool.unselect();
|
|
30
31
|
*/
|
|
31
|
-
constructor({ id = "transformer", lineColor = 0x66cfff, handleColor = 0xffffff, controlsSize = 10, debug = false, generateAnchorMark, snapKeys = ["ShiftLeft"], pivotKeys = ["AltLeft"], } = {}) {
|
|
32
|
+
constructor({ id = "transformer", lineColor = 0x66cfff, handleColor = 0xffffff, controlsSize = 10, handleHitAreaScale = 2, debug = false, generateAnchorMark, snapKeys = ["ShiftLeft"], pivotKeys = ["AltLeft"], } = {}) {
|
|
32
33
|
super();
|
|
33
34
|
// target Pixi.Container
|
|
34
35
|
this.target = null;
|
|
@@ -58,6 +59,7 @@ export class Transformer extends Pixi.Container {
|
|
|
58
59
|
this.handleColor = handleColor;
|
|
59
60
|
this.handleOpacity = 1;
|
|
60
61
|
this.controlsSize = controlsSize;
|
|
62
|
+
this.handleHitAreaScale = handleHitAreaScale;
|
|
61
63
|
this.controlsDimOpacity = 1;
|
|
62
64
|
this.controlsStrokeThickness = 2;
|
|
63
65
|
this.movedThreshold = 10;
|
|
@@ -91,44 +93,74 @@ export class Transformer extends Pixi.Container {
|
|
|
91
93
|
alpha: this.handleOpacity * 0.75,
|
|
92
94
|
});
|
|
93
95
|
this.addChild(this.fromPoint, this.toPoint);
|
|
96
|
+
const edgeLong = Math.round(this.controlsSize * 1.4);
|
|
97
|
+
const edgeShort = Math.round(this.controlsSize * 0.55);
|
|
98
|
+
const edgeRadius = Math.max(6, Math.round(edgeShort / 2));
|
|
99
|
+
const cornerSize = Math.round(this.controlsSize * 1.1);
|
|
94
100
|
// scaling handles
|
|
95
101
|
this.scaleTHandle = this.createHandle({
|
|
96
102
|
name: "scaleTHandle",
|
|
97
103
|
cursor: "n-resize",
|
|
104
|
+
width: edgeLong,
|
|
105
|
+
height: edgeShort,
|
|
106
|
+
radius: edgeRadius,
|
|
98
107
|
});
|
|
99
108
|
this.scaleRHandle = this.createHandle({
|
|
100
109
|
name: "scaleRHandle",
|
|
101
110
|
cursor: "w-resize",
|
|
111
|
+
width: edgeShort,
|
|
112
|
+
height: edgeLong,
|
|
113
|
+
radius: edgeRadius,
|
|
102
114
|
});
|
|
103
115
|
this.scaleBHandle = this.createHandle({
|
|
104
116
|
name: "scaleBHandle",
|
|
105
117
|
cursor: "s-resize",
|
|
118
|
+
width: edgeLong,
|
|
119
|
+
height: edgeShort,
|
|
120
|
+
radius: edgeRadius,
|
|
106
121
|
});
|
|
107
122
|
this.scaleLHandle = this.createHandle({
|
|
108
123
|
name: "scaleLHandle",
|
|
109
124
|
cursor: "e-resize",
|
|
125
|
+
width: edgeShort,
|
|
126
|
+
height: edgeLong,
|
|
127
|
+
radius: edgeRadius,
|
|
110
128
|
});
|
|
111
129
|
this.scaleTLHandle = this.createHandle({
|
|
112
130
|
name: "scaleTLHandle",
|
|
113
131
|
cursor: "nw-resize",
|
|
132
|
+
shape: "circle",
|
|
133
|
+
width: cornerSize,
|
|
134
|
+
height: cornerSize,
|
|
114
135
|
});
|
|
115
136
|
this.scaleTRHandle = this.createHandle({
|
|
116
137
|
name: "scaleTRHandle",
|
|
117
138
|
cursor: "ne-resize",
|
|
139
|
+
shape: "circle",
|
|
140
|
+
width: cornerSize,
|
|
141
|
+
height: cornerSize,
|
|
118
142
|
});
|
|
119
143
|
this.scaleBRHandle = this.createHandle({
|
|
120
144
|
name: "scaleBRHandle",
|
|
121
145
|
cursor: "se-resize",
|
|
146
|
+
shape: "circle",
|
|
147
|
+
width: cornerSize,
|
|
148
|
+
height: cornerSize,
|
|
122
149
|
});
|
|
123
150
|
this.scaleBLHandle = this.createHandle({
|
|
124
151
|
name: "scaleBLHandle",
|
|
125
152
|
cursor: "sw-resize",
|
|
153
|
+
shape: "circle",
|
|
154
|
+
width: cornerSize,
|
|
155
|
+
height: cornerSize,
|
|
126
156
|
});
|
|
127
157
|
// rotation handle
|
|
128
158
|
this.rotateHandle = this.createHandle({
|
|
129
159
|
name: "Rotate",
|
|
130
160
|
cursor: "pointer",
|
|
131
161
|
shape: "circle",
|
|
162
|
+
width: Math.round(this.controlsSize * 0.85),
|
|
163
|
+
height: Math.round(this.controlsSize * 0.85),
|
|
132
164
|
});
|
|
133
165
|
this.addChild(this.scaleTHandle, this.scaleRHandle, this.scaleBHandle, this.scaleLHandle, this.scaleTLHandle, this.scaleTRHandle, this.scaleBRHandle, this.scaleBLHandle, this.rotateHandle);
|
|
134
166
|
// ------------<MoveTool>---------------
|
|
@@ -142,6 +174,7 @@ export class Transformer extends Pixi.Container {
|
|
|
142
174
|
this.handleHandleEvents(this.moveHandle, this);
|
|
143
175
|
this.moveHandle.hitArea = new Pixi.Rectangle(0, 0, this.controlsSize, this.controlsSize);
|
|
144
176
|
this.addChild(this.moveHandle);
|
|
177
|
+
this.setChildIndex(this.moveHandle, 0);
|
|
145
178
|
function changeAnchorPoint(ev) {
|
|
146
179
|
if (!that.pivotKey)
|
|
147
180
|
return;
|
|
@@ -455,21 +488,34 @@ export class Transformer extends Pixi.Container {
|
|
|
455
488
|
that[property] = false;
|
|
456
489
|
});
|
|
457
490
|
}
|
|
458
|
-
createHandle({ cursor, name, shape = "square", }) {
|
|
491
|
+
createHandle({ cursor, name, shape = "square", width, height, radius, }) {
|
|
492
|
+
const w = width ?? this.controlsSize;
|
|
493
|
+
const h = height ?? this.controlsSize;
|
|
494
|
+
const r = radius ?? Math.max(4, Math.round(Math.min(w, h) * 0.22));
|
|
459
495
|
const handle = new Pixi.Graphics();
|
|
460
496
|
handle.label = this.id;
|
|
461
497
|
handle.eventMode = "dynamic";
|
|
462
498
|
handle.alpha = this.handleOpacity;
|
|
463
499
|
this.addToolTip(handle, name, cursor);
|
|
464
500
|
if (shape === "circle") {
|
|
465
|
-
|
|
501
|
+
const radius = Math.min(w, h) / 2;
|
|
502
|
+
handle.ellipse(w / 2, h / 2, radius, radius);
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
handle.roundRect(0, 0, w, h, r);
|
|
466
506
|
}
|
|
467
|
-
else
|
|
468
|
-
handle.rect(0, 0, this.controlsSize, this.controlsSize);
|
|
469
507
|
handle
|
|
470
508
|
.stroke({ width: this.controlsStrokeThickness, color: this.lineColor })
|
|
471
509
|
.fill(this.handleColor);
|
|
472
|
-
handle.pivot.set(
|
|
510
|
+
handle.pivot.set(w / 2, h / 2);
|
|
511
|
+
const hitW = w * this.handleHitAreaScale;
|
|
512
|
+
const hitH = h * this.handleHitAreaScale;
|
|
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
|
+
}
|
|
473
519
|
this.handleHandleEvents(handle, this);
|
|
474
520
|
return handle;
|
|
475
521
|
}
|