import { SGraphyItem } from '@sybotan-web/graphy' import { SRect, SSize, SPoint } from "@sybotan-web/base"; import { SPen, SPainter, SColor } from "@sybotan-web/draw"; /** * 墙Item类 * */ export class SGraphyWallItem extends SGraphyItem { pointArr: SPoint[]; isVirtual: boolean = false; fillColor: SColor = SColor.White; color: SColor = SColor.Black; width: number = 1; /** * 构造函数 * * @param pointArr 点坐标list * @param isVirtual 墙类型(实体墙-虚拟墙) * @param color 墙的颜色 * @param fillColor 墙的填充颜色 * @param width 墙的宽度 * @param parent */ constructor( parent: SGraphyItem | null, pointArr: SPoint[], isVirtual: boolean = false, fillColor: SColor = SColor.White, color: SColor = SColor.Black, width: number = 1, ) { super(parent); this.isVirtual = isVirtual; this.pointArr = pointArr; this.color = color; this.fillColor = fillColor; this.width = width; } // Constructor() /** * Item对象边界区域 * * @return SRect */ boundingRect(): SRect { let minX = this.pointArr[0].x; let maxX = minX; let minY = this.pointArr[0].y; let maxY = minY; for (let i = 1; i < this.pointArr.length; i++) { if (this.pointArr[i].x < minX) { minX = this.pointArr[i].x } if (this.pointArr[i].y < minY) { minY = this.pointArr[i].y } if (this.pointArr[i].x > maxX) { maxX = this.pointArr[i].x } if (this.pointArr[i].y > maxY) { maxY = this.pointArr[i].y } } return new SRect( minX, minY, maxX - minX, maxY - minY ); } // Function boundingRect() /** * Item绘制操作 * * @param painter painter对象 * @param rect 绘制区域 */ onDraw(painter: SPainter, rect: SRect): void { if (this.pointArr.length) { // painter.pen = new SPen(this.color, this.width); painter.pen.color = this.color; painter.brush.color = this.fillColor; painter.drawPolyline(this.pointArr) } } } // Class SGraphyPolygonItem