From 4f115f4f5885a5da741eff58b3f06935c6f48534 Mon Sep 17 00:00:00 2001 From: fan Date: Tue, 8 Aug 2023 14:47:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA=E7=A2=B0=E6=92=9E?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/graphics/SignalInteraction.ts | 2 ++ src/graphics/signal/SignalDrawAssistant.ts | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/drawApp/graphics/SignalInteraction.ts b/src/drawApp/graphics/SignalInteraction.ts index 5ceee84..72b327e 100644 --- a/src/drawApp/graphics/SignalInteraction.ts +++ b/src/drawApp/graphics/SignalInteraction.ts @@ -18,6 +18,7 @@ import { FederatedMouseEvent, DisplayObject } from 'pixi.js'; import { state } from 'src/protos/device_status'; import { mockSignalApi } from 'src/api/PlatformApi'; import { useLineStore } from 'src/stores/line-store'; +import { SignalGraphicHitArea } from 'src/graphics/signal/SignalDrawAssistant'; export class SignalData extends GraphicDataBase implements ISignalData { constructor(data?: graphicData.Signal) { @@ -331,6 +332,7 @@ export class SignalOperateInteraction extends GraphicInteractionPlugin { g.eventMode = 'static'; g.cursor = 'pointer'; g.selectable = true; + g.lampMainBody.hitArea = new SignalGraphicHitArea(g); g.on('_rightclick', this.onContextMenu, this); } diff --git a/src/graphics/signal/SignalDrawAssistant.ts b/src/graphics/signal/SignalDrawAssistant.ts index 09e4dd8..7971b55 100644 --- a/src/graphics/signal/SignalDrawAssistant.ts +++ b/src/graphics/signal/SignalDrawAssistant.ts @@ -1,4 +1,4 @@ -import { DisplayObject, FederatedPointerEvent, Point } from 'pixi.js'; +import { DisplayObject, FederatedPointerEvent, IHitArea, Point } from 'pixi.js'; import { AbsorbableLine, AbsorbablePosition, @@ -58,6 +58,22 @@ export class SignalDraw extends GraphicDrawAssistant< return true; } } + +export class SignalGraphicHitArea implements IHitArea { + signal: Signal; + constructor(signal: Signal) { + this.signal = signal; + } + contains(x: number, y: number): boolean { + const bound = this.signal.getLocalBounds(); + const maxX = bound.x + bound.width; + const minX = bound.x; + const maxY = bound.y + bound.height; + const minY = bound.y; + return maxX >= x && x >= minX && maxY >= y && y >= minY; + } +} + /** * 构建吸附线 * @param signal @@ -129,6 +145,7 @@ export class signalInteraction extends GraphicInteractionPlugin { g.cursor = 'pointer'; g.scalable = true; g.rotatable = true; + g.lampMainBody.hitArea = new SignalGraphicHitArea(g); g.on('transformstart', this.transformstart, this); g.signalCode.on('transformstart', this.codetransformstart, this); g.signalCode.draggable = true;