From b5f2a9c1dfd9b2088c0c42bcbc23c5be0fa5a163 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Mon, 15 Jan 2024 13:45:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E6=8F=92=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=92=88=E5=AF=B9=E7=89=B9=E5=AE=9A=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E7=9A=84KeyListener?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/plugins/CopyPlugin.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0f30181..5863d3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "graphic-pixi", - "version": "0.1.3", + "version": "0.1.4", "description": "基于pixijs的图形应用、绘制应用框架", "productName": "Graphic-pixi", "author": "walker ", diff --git a/src/plugins/CopyPlugin.ts b/src/plugins/CopyPlugin.ts index 381d875..19af628 100644 --- a/src/plugins/CopyPlugin.ts +++ b/src/plugins/CopyPlugin.ts @@ -10,6 +10,7 @@ export class GraphicCopyPlugin { container: Container; scene: IGraphicScene; keyListeners: KeyListener[]; + graphicKeyListenercMap: Map; copys: JlGraphic[]; start?: Point; running = false; @@ -17,6 +18,7 @@ export class GraphicCopyPlugin { constructor(scene: IGraphicScene) { this.scene = scene; this.container = new Container(); + this.graphicKeyListenercMap = new Map(); this.copys = []; this.keyListeners = []; this.keyListeners.push( @@ -76,6 +78,12 @@ export class GraphicCopyPlugin { this.container.addChild(clone); 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('mouseup', this.onFinish, this); this.scene.canvas.on('rightup', this.cancle, this); @@ -97,6 +105,7 @@ export class GraphicCopyPlugin { this.keyListeners.forEach((kl) => { this.scene.app.removeKeyboardListener(kl); }); + this.keyListeners = this.keyListeners.splice(0, 3); } onPointerMove(e: FederatedPointerEvent): void { @@ -128,10 +137,14 @@ export class GraphicCopyPlugin { g.position.x += this.container.position.x; g.position.y += this.container.position.y; }); + this.saveCopyGraphic(); + this.clear(); + } + + saveCopyGraphic() { this.scene.app.addGraphicAndRecord(...this.copys); this.scene.detectRelations(); this.scene.updateSelected(...this.copys); - this.clear(); } cancle(): void {