@quinninc/pixi-transformer 0.1.3 → 0.1.6
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 +42 -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,65 @@ 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.6);
|
|
97
|
+
const edgeShort = Math.round(this.controlsSize * 0.7);
|
|
98
|
+
const edgeRadius = Math.max(6, Math.round(edgeShort / 2));
|
|
94
99
|
// scaling handles
|
|
95
100
|
this.scaleTHandle = this.createHandle({
|
|
96
101
|
name: "scaleTHandle",
|
|
97
102
|
cursor: "n-resize",
|
|
103
|
+
width: edgeLong,
|
|
104
|
+
height: edgeShort,
|
|
105
|
+
radius: edgeRadius,
|
|
98
106
|
});
|
|
99
107
|
this.scaleRHandle = this.createHandle({
|
|
100
108
|
name: "scaleRHandle",
|
|
101
109
|
cursor: "w-resize",
|
|
110
|
+
width: edgeShort,
|
|
111
|
+
height: edgeLong,
|
|
112
|
+
radius: edgeRadius,
|
|
102
113
|
});
|
|
103
114
|
this.scaleBHandle = this.createHandle({
|
|
104
115
|
name: "scaleBHandle",
|
|
105
116
|
cursor: "s-resize",
|
|
117
|
+
width: edgeLong,
|
|
118
|
+
height: edgeShort,
|
|
119
|
+
radius: edgeRadius,
|
|
106
120
|
});
|
|
107
121
|
this.scaleLHandle = this.createHandle({
|
|
108
122
|
name: "scaleLHandle",
|
|
109
123
|
cursor: "e-resize",
|
|
124
|
+
width: edgeShort,
|
|
125
|
+
height: edgeLong,
|
|
126
|
+
radius: edgeRadius,
|
|
110
127
|
});
|
|
111
128
|
this.scaleTLHandle = this.createHandle({
|
|
112
129
|
name: "scaleTLHandle",
|
|
113
130
|
cursor: "nw-resize",
|
|
131
|
+
shape: "circle",
|
|
114
132
|
});
|
|
115
133
|
this.scaleTRHandle = this.createHandle({
|
|
116
134
|
name: "scaleTRHandle",
|
|
117
135
|
cursor: "ne-resize",
|
|
136
|
+
shape: "circle",
|
|
118
137
|
});
|
|
119
138
|
this.scaleBRHandle = this.createHandle({
|
|
120
139
|
name: "scaleBRHandle",
|
|
121
140
|
cursor: "se-resize",
|
|
141
|
+
shape: "circle",
|
|
122
142
|
});
|
|
123
143
|
this.scaleBLHandle = this.createHandle({
|
|
124
144
|
name: "scaleBLHandle",
|
|
125
145
|
cursor: "sw-resize",
|
|
146
|
+
shape: "circle",
|
|
126
147
|
});
|
|
127
148
|
// rotation handle
|
|
128
149
|
this.rotateHandle = this.createHandle({
|
|
129
150
|
name: "Rotate",
|
|
130
151
|
cursor: "pointer",
|
|
131
152
|
shape: "circle",
|
|
153
|
+
width: Math.round(this.controlsSize * 0.9),
|
|
154
|
+
height: Math.round(this.controlsSize * 0.9),
|
|
132
155
|
});
|
|
133
156
|
this.addChild(this.scaleTHandle, this.scaleRHandle, this.scaleBHandle, this.scaleLHandle, this.scaleTLHandle, this.scaleTRHandle, this.scaleBRHandle, this.scaleBLHandle, this.rotateHandle);
|
|
134
157
|
// ------------<MoveTool>---------------
|
|
@@ -455,21 +478,34 @@ export class Transformer extends Pixi.Container {
|
|
|
455
478
|
that[property] = false;
|
|
456
479
|
});
|
|
457
480
|
}
|
|
458
|
-
createHandle({ cursor, name, shape = "square", }) {
|
|
481
|
+
createHandle({ cursor, name, shape = "square", width, height, radius, }) {
|
|
482
|
+
const w = width ?? this.controlsSize;
|
|
483
|
+
const h = height ?? this.controlsSize;
|
|
484
|
+
const r = radius ?? Math.max(4, Math.round(Math.min(w, h) * 0.22));
|
|
459
485
|
const handle = new Pixi.Graphics();
|
|
460
486
|
handle.label = this.id;
|
|
461
487
|
handle.eventMode = "dynamic";
|
|
462
488
|
handle.alpha = this.handleOpacity;
|
|
463
489
|
this.addToolTip(handle, name, cursor);
|
|
464
490
|
if (shape === "circle") {
|
|
465
|
-
|
|
491
|
+
const radius = Math.min(w, h) / 2;
|
|
492
|
+
handle.ellipse(w / 2, h / 2, radius, radius);
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
handle.roundRect(0, 0, w, h, r);
|
|
466
496
|
}
|
|
467
|
-
else
|
|
468
|
-
handle.rect(0, 0, this.controlsSize, this.controlsSize);
|
|
469
497
|
handle
|
|
470
498
|
.stroke({ width: this.controlsStrokeThickness, color: this.lineColor })
|
|
471
499
|
.fill(this.handleColor);
|
|
472
|
-
handle.pivot.set(
|
|
500
|
+
handle.pivot.set(w / 2, h / 2);
|
|
501
|
+
const hitW = w * this.handleHitAreaScale;
|
|
502
|
+
const hitH = h * this.handleHitAreaScale;
|
|
503
|
+
if (shape === "circle") {
|
|
504
|
+
handle.hitArea = new Pixi.Circle(0, 0, Math.max(hitW, hitH) / 2);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
handle.hitArea = new Pixi.Rectangle(-hitW / 2, -hitH / 2, hitW, hitH);
|
|
508
|
+
}
|
|
473
509
|
this.handleHandleEvents(handle, this);
|
|
474
510
|
return handle;
|
|
475
511
|
}
|