import { Render } from '../index'; import { Handler } from '../types'; import { LinkDraw } from '../draws'; // 临时连接线 export class LinkHandlers implements Handler { static readonly NAME = 'LinkHandlers'; private render: Render; constructor(render: Render) { this.render = render; } handlers = { stage: { mouseup: () => { const linkDrawState = (this.render.draws[LinkDraw.NAME] as LinkDraw)?.state; if (linkDrawState) { // 临时 连接线 移除 linkDrawState.linkingLine?.line.destroy(); linkDrawState.linkingLine = null; } }, mousemove: () => { const linkDrawState = (this.render.draws[LinkDraw.NAME] as LinkDraw)?.state; if (linkDrawState) { const pos = this.render.stage.getPointerPosition(); if (pos) { const stageState = this.render.getStageState(); if (linkDrawState.linkingLine) { // 临时 连接线 画 const { circle, line } = linkDrawState.linkingLine; line.points( [ [circle.x(), circle.y()], [ this.render.toStageValue(pos.x - stageState.x), this.render.toStageValue(pos.y - stageState.y) ] ].flat() ); } } } } } } }