import { SGraphItem, STextItem } from "@saga-web/graph/lib"; import { SPainter, SColor } from "@saga-web/draw"; import { Marker } from '../types/Marker'; import { SLineStyle } from '../enums/SLineStyle'; /** * 标识对象Item(文本类型) * * * @author 张宇(taohuzy@163.com) */ export class STextMarkerItem extends STextItem { /** 标识对象数据 */ data: Marker; /** 边框宽度 */ private _lineWidth: number = 1; get lineWidth(): number { return this._lineWidth; } set lineWidth(v: number) { this._lineWidth = v; this.update(); } /** 边框样式 */ private _borderStyle: SLineStyle = SLineStyle.Soild; get borderStyle(): SLineStyle { return this._borderStyle; } set borderStyle(v: SLineStyle) { this._borderStyle = v; this.update(); } /** * 构造函数 * * @param parent 指向父对象 * @param data 标识对象数据 */ constructor(parent: SGraphItem | null, data: Marker) { super(parent); this.data = data; this.id = data.ID; this.name = data.Name; this.moveTo(data.Pos.X, data.Pos.Y); if (data.Size) { this.width = data.Size.Width; this.height = data.Size.Height; } if (data.Properties && data.Properties.Text) { this.text = data.Properties.Text; } } // Constructor toData(): Marker { this.data.Pos = {X: this.x, Y: this.y}; this.data.Size = {Width: this.width, Height: this.height}; this.data.Properties.Text = this.text; return this.data; } /** * Item绘制操作 * * @param painter 绘画类 */ onDraw(painter: SPainter): void { // 绘制文本 painter.brush.color = new SColor(this.color); painter.font = this.font; if (this.borderStyle == SLineStyle.Dashed) { painter.pen.lineDash = [ painter.toPx(this.lineWidth * 3), painter.toPx(this.lineWidth * 7) ]; } else if (this.borderStyle == SLineStyle.Dotted) { painter.pen.lineDash = [ painter.toPx(this.lineWidth), painter.toPx(this.lineWidth) ]; } this.drawFormatText(painter); } // Function onDraw() } // Class STextMarkerItem