复制插件增加针对特定图形的KeyListener
This commit is contained in:
parent
100ddafc75
commit
b5f2a9c1df
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "graphic-pixi",
|
"name": "graphic-pixi",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"description": "基于pixijs的图形应用、绘制应用框架",
|
"description": "基于pixijs的图形应用、绘制应用框架",
|
||||||
"productName": "Graphic-pixi",
|
"productName": "Graphic-pixi",
|
||||||
"author": "walker <shengxuqiang@joylink.club>",
|
"author": "walker <shengxuqiang@joylink.club>",
|
||||||
|
@ -10,6 +10,7 @@ export class GraphicCopyPlugin {
|
|||||||
container: Container;
|
container: Container;
|
||||||
scene: IGraphicScene;
|
scene: IGraphicScene;
|
||||||
keyListeners: KeyListener[];
|
keyListeners: KeyListener[];
|
||||||
|
graphicKeyListenercMap: Map<string, KeyListener[]>;
|
||||||
copys: JlGraphic[];
|
copys: JlGraphic[];
|
||||||
start?: Point;
|
start?: Point;
|
||||||
running = false;
|
running = false;
|
||||||
@ -17,6 +18,7 @@ export class GraphicCopyPlugin {
|
|||||||
constructor(scene: IGraphicScene) {
|
constructor(scene: IGraphicScene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.container = new Container();
|
this.container = new Container();
|
||||||
|
this.graphicKeyListenercMap = new Map<string, KeyListener[]>();
|
||||||
this.copys = [];
|
this.copys = [];
|
||||||
this.keyListeners = [];
|
this.keyListeners = [];
|
||||||
this.keyListeners.push(
|
this.keyListeners.push(
|
||||||
@ -76,6 +78,12 @@ export class GraphicCopyPlugin {
|
|||||||
this.container.addChild(clone);
|
this.container.addChild(clone);
|
||||||
clone.repaint();
|
clone.repaint();
|
||||||
});
|
});
|
||||||
|
const addGraphicTypeKeyListener = this.graphicKeyListenercMap.get(
|
||||||
|
app.selectedGraphics[0].type,
|
||||||
|
);
|
||||||
|
if (addGraphicTypeKeyListener) {
|
||||||
|
this.keyListeners.push(...addGraphicTypeKeyListener);
|
||||||
|
}
|
||||||
this.scene.canvas.on('mousemove', this.onPointerMove, this);
|
this.scene.canvas.on('mousemove', this.onPointerMove, this);
|
||||||
this.scene.canvas.on('mouseup', this.onFinish, this);
|
this.scene.canvas.on('mouseup', this.onFinish, this);
|
||||||
this.scene.canvas.on('rightup', this.cancle, this);
|
this.scene.canvas.on('rightup', this.cancle, this);
|
||||||
@ -97,6 +105,7 @@ export class GraphicCopyPlugin {
|
|||||||
this.keyListeners.forEach((kl) => {
|
this.keyListeners.forEach((kl) => {
|
||||||
this.scene.app.removeKeyboardListener(kl);
|
this.scene.app.removeKeyboardListener(kl);
|
||||||
});
|
});
|
||||||
|
this.keyListeners = this.keyListeners.splice(0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
onPointerMove(e: FederatedPointerEvent): void {
|
onPointerMove(e: FederatedPointerEvent): void {
|
||||||
@ -128,10 +137,14 @@ export class GraphicCopyPlugin {
|
|||||||
g.position.x += this.container.position.x;
|
g.position.x += this.container.position.x;
|
||||||
g.position.y += this.container.position.y;
|
g.position.y += this.container.position.y;
|
||||||
});
|
});
|
||||||
|
this.saveCopyGraphic();
|
||||||
|
this.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
saveCopyGraphic() {
|
||||||
this.scene.app.addGraphicAndRecord(...this.copys);
|
this.scene.app.addGraphicAndRecord(...this.copys);
|
||||||
this.scene.detectRelations();
|
this.scene.detectRelations();
|
||||||
this.scene.updateSelected(...this.copys);
|
this.scene.updateSelected(...this.copys);
|
||||||
this.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cancle(): void {
|
cancle(): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user