@quinninc/pixi-transformer 0.0.8 → 0.1.0
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 +2 -1
- package/dist/Transformer.js +29 -8
- package/package.json +1 -1
package/dist/Transformer.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class Transformer extends Pixi.Container {
|
|
|
18
18
|
private toPoint;
|
|
19
19
|
private target;
|
|
20
20
|
private movedThreshold;
|
|
21
|
+
private updateCallbacks;
|
|
21
22
|
private handleOpacity;
|
|
22
23
|
private controlsSize;
|
|
23
24
|
private controlsDimOpacity;
|
|
@@ -77,7 +78,7 @@ export declare class Transformer extends Pixi.Container {
|
|
|
77
78
|
private deScale;
|
|
78
79
|
select(target: Pixi.Container): void;
|
|
79
80
|
unselect(): void;
|
|
80
|
-
onUpdate: () => void;
|
|
81
|
+
onUpdate: (cb: (t?: Transformer) => void) => () => void;
|
|
81
82
|
update(): void;
|
|
82
83
|
setTitle(title: string): void;
|
|
83
84
|
setCursor(cursor: string): void;
|
package/dist/Transformer.js
CHANGED
|
@@ -32,6 +32,7 @@ export class Transformer extends Pixi.Container {
|
|
|
32
32
|
super();
|
|
33
33
|
// target Pixi.Container
|
|
34
34
|
this.target = null;
|
|
35
|
+
this.updateCallbacks = [];
|
|
35
36
|
// position state
|
|
36
37
|
this.left = 0;
|
|
37
38
|
this.top = 0;
|
|
@@ -41,7 +42,15 @@ export class Transformer extends Pixi.Container {
|
|
|
41
42
|
this.dragging = false;
|
|
42
43
|
this.snapKey = false;
|
|
43
44
|
this.pivotKey = false;
|
|
44
|
-
this.onUpdate = () => {
|
|
45
|
+
this.onUpdate = (cb) => {
|
|
46
|
+
this.updateCallbacks.push(cb);
|
|
47
|
+
return () => {
|
|
48
|
+
const index = this.updateCallbacks.indexOf(cb);
|
|
49
|
+
if (index > -1) {
|
|
50
|
+
this.updateCallbacks.splice(index, 1);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
45
54
|
const that = this;
|
|
46
55
|
this._id = id;
|
|
47
56
|
this.debug = debug;
|
|
@@ -140,10 +149,18 @@ export class Transformer extends Pixi.Container {
|
|
|
140
149
|
if (!that.target)
|
|
141
150
|
return;
|
|
142
151
|
const eventPoint = that.convertToLocal(ev.global);
|
|
143
|
-
console.log("Prev anchor - ", that._anchor);
|
|
144
|
-
console.log("ev.position - ", eventPoint.x, eventPoint.y);
|
|
145
|
-
console.log(
|
|
146
|
-
|
|
152
|
+
// console.log("Prev anchor - ", that._anchor);
|
|
153
|
+
// console.log("ev.position - ", eventPoint.x, eventPoint.y);
|
|
154
|
+
// console.log(
|
|
155
|
+
// "that.target.position - ",
|
|
156
|
+
// that.target.position.x,
|
|
157
|
+
// that.target.position.y,
|
|
158
|
+
// );
|
|
159
|
+
// console.log(
|
|
160
|
+
// "that.target.pivot - ",
|
|
161
|
+
// that.target.pivot.x,
|
|
162
|
+
// that.target.pivot.y,
|
|
163
|
+
// );
|
|
147
164
|
let dx, dy;
|
|
148
165
|
// calc new pivot point
|
|
149
166
|
// step 1 - translate to origin
|
|
@@ -532,14 +549,15 @@ export class Transformer extends Pixi.Container {
|
|
|
532
549
|
this.pivotKey = false;
|
|
533
550
|
this.snapKey = false;
|
|
534
551
|
this.dragging = false;
|
|
535
|
-
this.
|
|
552
|
+
for (const cb of this.updateCallbacks) {
|
|
553
|
+
cb(this);
|
|
554
|
+
}
|
|
536
555
|
}
|
|
537
556
|
update() {
|
|
538
557
|
if (!this.target) {
|
|
539
|
-
console.log("no target, returning...");
|
|
558
|
+
// console.log("no target, returning...");
|
|
540
559
|
return;
|
|
541
560
|
}
|
|
542
|
-
this.onUpdate();
|
|
543
561
|
// copy object translation/transformation
|
|
544
562
|
const bounds = this.target.getLocalBounds();
|
|
545
563
|
this.width = bounds.width;
|
|
@@ -636,6 +654,9 @@ export class Transformer extends Pixi.Container {
|
|
|
636
654
|
allHandles.forEach((handle) => {
|
|
637
655
|
this.deScale(handle);
|
|
638
656
|
});
|
|
657
|
+
for (const cb of this.updateCallbacks) {
|
|
658
|
+
cb(this);
|
|
659
|
+
}
|
|
639
660
|
}
|
|
640
661
|
setTitle(title) {
|
|
641
662
|
title = title || "";
|