@quinninc/pixi-transformer 0.1.6 → 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.
@@ -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;
@@ -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,9 +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.6);
97
- const edgeShort = Math.round(this.controlsSize * 0.7);
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));
101
+ const cornerSize = Math.round(this.controlsSize * 1.4);
99
102
  // scaling handles
100
103
  this.scaleTHandle = this.createHandle({
101
104
  name: "scaleTHandle",
@@ -129,29 +132,47 @@ export class Transformer extends Pixi.Container {
129
132
  name: "scaleTLHandle",
130
133
  cursor: "nw-resize",
131
134
  shape: "circle",
135
+ width: cornerSize,
136
+ height: cornerSize,
137
+ fillColor: this.lineColor,
138
+ strokeColor: 0xffffff,
132
139
  });
133
140
  this.scaleTRHandle = this.createHandle({
134
141
  name: "scaleTRHandle",
135
142
  cursor: "ne-resize",
136
143
  shape: "circle",
144
+ width: cornerSize,
145
+ height: cornerSize,
146
+ fillColor: this.lineColor,
147
+ strokeColor: 0xffffff,
137
148
  });
138
149
  this.scaleBRHandle = this.createHandle({
139
150
  name: "scaleBRHandle",
140
151
  cursor: "se-resize",
141
152
  shape: "circle",
153
+ width: cornerSize,
154
+ height: cornerSize,
155
+ fillColor: this.lineColor,
156
+ strokeColor: 0xffffff,
142
157
  });
143
158
  this.scaleBLHandle = this.createHandle({
144
159
  name: "scaleBLHandle",
145
160
  cursor: "sw-resize",
146
161
  shape: "circle",
162
+ width: cornerSize,
163
+ height: cornerSize,
164
+ fillColor: this.lineColor,
165
+ strokeColor: 0xffffff,
147
166
  });
148
167
  // rotation handle
149
168
  this.rotateHandle = this.createHandle({
150
169
  name: "Rotate",
151
170
  cursor: "pointer",
152
171
  shape: "circle",
153
- width: Math.round(this.controlsSize * 0.9),
154
- height: Math.round(this.controlsSize * 0.9),
172
+ width: Math.round(this.controlsSize * 0.8),
173
+ height: Math.round(this.controlsSize * 0.8),
174
+ fillColor: 0xffffff,
175
+ strokeColor: this.lineColor,
155
176
  });
156
177
  this.addChild(this.scaleTHandle, this.scaleRHandle, this.scaleBHandle, this.scaleLHandle, this.scaleTLHandle, this.scaleTRHandle, this.scaleBRHandle, this.scaleBLHandle, this.rotateHandle);
157
178
  // ------------<MoveTool>---------------
@@ -165,6 +186,7 @@ export class Transformer extends Pixi.Container {
165
186
  this.handleHandleEvents(this.moveHandle, this);
166
187
  this.moveHandle.hitArea = new Pixi.Rectangle(0, 0, this.controlsSize, this.controlsSize);
167
188
  this.addChild(this.moveHandle);
189
+ this.setChildIndex(this.moveHandle, 0);
168
190
  function changeAnchorPoint(ev) {
169
191
  if (!that.pivotKey)
170
192
  return;
@@ -478,7 +500,7 @@ export class Transformer extends Pixi.Container {
478
500
  that[property] = false;
479
501
  });
480
502
  }
481
- createHandle({ cursor, name, shape = "square", width, height, radius, }) {
503
+ createHandle({ cursor, name, shape = "square", width, height, radius, fillColor, strokeColor, }) {
482
504
  const w = width ?? this.controlsSize;
483
505
  const h = height ?? this.controlsSize;
484
506
  const r = radius ?? Math.max(4, Math.round(Math.min(w, h) * 0.22));
@@ -495,17 +517,14 @@ export class Transformer extends Pixi.Container {
495
517
  handle.roundRect(0, 0, w, h, r);
496
518
  }
497
519
  handle
498
- .stroke({ width: this.controlsStrokeThickness, color: this.lineColor })
499
- .fill(this.handleColor);
520
+ .stroke({
521
+ width: this.controlsStrokeThickness,
522
+ color: strokeColor ?? this.lineColor,
523
+ })
524
+ .fill(fillColor ?? this.handleColor);
500
525
  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
- }
526
+ handle._handleSize = { w, h, shape };
527
+ this.updateHandleHitArea(handle);
509
528
  this.handleHandleEvents(handle, this);
510
529
  return handle;
511
530
  }
@@ -530,6 +549,13 @@ export class Transformer extends Pixi.Container {
530
549
  deScale(target) {
531
550
  target.scale.set(1 / this.scale.x, 1 / this.scale.y);
532
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
+ }
533
559
  // public methods:
534
560
  select(target) {
535
561
  if (!target) {
@@ -661,6 +687,7 @@ export class Transformer extends Pixi.Container {
661
687
  // descale all handles
662
688
  allHandles.forEach((handle) => {
663
689
  this.deScale(handle);
690
+ this.updateHandleHitArea(handle);
664
691
  });
665
692
  for (const cb of this.updateCallbacks) {
666
693
  cb(this);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quinninc/pixi-transformer",
3
3
  "private": false,
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "repository": {
6
6
  "url": "https://github.com/Quinn-Care-Private-Limited/pixi-transformer"
7
7
  },