import { SGraphItem } from "@saga-web/graph/lib"; import { SPainter, SPoint, SRect } from "@saga-web/draw/lib"; import { SMouseEvent } from "@saga-web/base/lib"; import { ItemColor, ItemOrder } from ".."; /** * 矩形选择item * * @author 郝建龙 */ export class SRectSelectItem extends SGraphItem { /** 起点 */ startPoint: SPoint = new SPoint(); /** 终点 */ endPoint: SPoint = new SPoint(); /** * 构造函数 * * @param parent 指向父对象 * @param point 起点数据 */ constructor(parent: SGraphItem | null, point: SPoint) { super(parent); this.startPoint = point; this.endPoint = new SPoint(point.x, point.y); this.update(); this.zOrder = ItemOrder.rectSelectOrder; } // Constructor /** * Item对象边界区域 * * @return SRect */ boundingRect(): SRect { return new SRect(this.startPoint, this.endPoint); } // Function boundingRect() /** * 鼠标移动事件 * * @param event 事件参数 * @return boolean */ onMouseMove(event: SMouseEvent): boolean { this.endPoint.x = event.x; this.endPoint.y = event.y; this.update(); return true; } // Function onMouseMove() /** * Item绘制操作 * * @param painter painter对象 */ onDraw(painter: SPainter): void { painter.pen.lineWidth = painter.toPx(2); painter.pen.color = ItemColor.rectSelectOutColor; painter.brush.color = ItemColor.rectSelectInColor; painter.drawRect(this.startPoint, this.endPoint); } // Function onDraw() } // SRectSelectItem