From fb8e5cb3e603ed0b680c70d59e9e4db78ca2b2fb Mon Sep 17 00:00:00 2001 From: JessYan <52144974+JessYan0913@users.noreply.github.com> Date: Mon, 24 Jul 2023 22:48:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E7=BB=98=E5=9B=BE?= =?UTF-8?q?=E7=9B=B8=E4=BA=92=E5=BD=B1=E5=93=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/tools/ellipse-tool.ts | 17 +++++++++++++++++ packages/core/src/tools/rect-tool.ts | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/core/src/tools/ellipse-tool.ts b/packages/core/src/tools/ellipse-tool.ts index ab9d3507..75aad922 100644 --- a/packages/core/src/tools/ellipse-tool.ts +++ b/packages/core/src/tools/ellipse-tool.ts @@ -10,6 +10,7 @@ class EllipseTool implements ToolStrategy { private ellipse: Ellipse | null = null; public onMouseDown({ app }: AppMouseEvent): void { + app.canvas.discardActiveObject(); app.canvas.selection = false; this.startPointer = app.pointer; this.ellipse = new Ellipse({ @@ -25,6 +26,17 @@ class EllipseTool implements ToolStrategy { } public onMouseMove({ app }: AppMouseEvent): void { + const activeObject = app.canvas.getActiveObject(); + + app.canvas.forEachObject((obj) => { + if (obj !== activeObject) { + obj.set({ + evented: false, + }); + } + }); + + app.canvas.renderAll(); if (!this.ellipse) { return; } @@ -46,6 +58,11 @@ class EllipseTool implements ToolStrategy { } public onMouseUp({ app }: AppMouseEvent): void { + app.canvas.forEachObject((obj) => { + obj.set({ + evented: true, + }); + }); app.setTool(selectTool); this.startPointer.setXY(0, 0); this.ellipse && app.canvas.setActiveObject(this.ellipse); diff --git a/packages/core/src/tools/rect-tool.ts b/packages/core/src/tools/rect-tool.ts index 6c39862b..e90441b3 100644 --- a/packages/core/src/tools/rect-tool.ts +++ b/packages/core/src/tools/rect-tool.ts @@ -10,6 +10,7 @@ class RectTool implements ToolStrategy { private rectangle: Rect | null = null; public onMouseDown({ app }: AppMouseEvent): void { + app.canvas.discardActiveObject(); app.canvas.selection = false; this.startPointer = app.pointer; this.rectangle = new Rect({ @@ -25,6 +26,17 @@ class RectTool implements ToolStrategy { } public onMouseMove({ app }: AppMouseEvent): void { + const activeObject = app.canvas.getActiveObject(); + + app.canvas.forEachObject((obj) => { + if (obj !== activeObject) { + obj.set({ + evented: false, + }); + } + }); + + app.canvas.renderAll(); if (!this.rectangle) { return; } @@ -35,6 +47,11 @@ class RectTool implements ToolStrategy { } public onMouseUp({ app }: AppMouseEvent): void { + app.canvas.forEachObject((obj) => { + obj.set({ + evented: true, + }); + }); app.setTool(selectTool); this.startPointer.setXY(0, 0); this.rectangle && app.canvas.setActiveObject(this.rectangle);