import { STextItem, SLineStyle } from "@saga-web/graph/lib"; import { SColor, SFont } from "@saga-web/draw"; import { ItemOrder } from '@saga-web/big/lib'; /** * 标识对象Item(文本类型) * * * @author 张宇(taohuzy@163.com) */ export class STextMarkerItem extends STextItem { /** * 构造函数 * * @param parent 指向父对象 * @param data 标识对象数据 */ constructor(parent, data) { super(parent); /** 边框宽度 */ this._lineWidth = 1; /** 边框样式 */ this._borderStyle = SLineStyle.None; this.zOrder = ItemOrder.textOrder; 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; } if (data.Properties && data.Properties.Color) { this.color = data.Properties.Color; } if (data.Properties && data.Properties.Font) { this.font = new SFont("sans-serif", data.Properties.Font); ; } if (data.Properties && data.Properties.BackgroundColor) { this.backgroundColor = data.Properties.BackgroundColor; } } // Constructor get lineWidth() { return this._lineWidth; } set lineWidth(v) { this._lineWidth = v; this.update(); } get borderStyle() { return this._borderStyle; } set borderStyle(v) { this._borderStyle = v; this.update(); } toData() { this.data.Pos = { X: this.x, Y: this.y }; this.data.Size = { Width: this.width, Height: this.height }; this.data.Properties.Text = this.text; this.data.Properties.Color = this.color; this.data.Properties.Font = this.font.size; this.data.Properties.BackgroundColor = this.backgroundColor; return this.data; } /** * Item绘制操作 * * @param painter 绘画类 */ onDraw(painter) { // 绘制文本 painter.brush.color = new SColor(this.color); painter.font = this.font; this.drawFormatText(painter); if (this.selected) { this.borderStyle = SLineStyle.Dashed; } else { this.borderStyle = SLineStyle.None; } if (this.borderStyle == SLineStyle.Dashed) { painter.pen.lineDash = [ painter.toPx(this.lineWidth * 3), painter.toPx(this.lineWidth * 7) ]; painter.brush.color = SColor.Transparent; painter.drawRect(this.boundingRect()); } else if (this.borderStyle == SLineStyle.Dotted) { painter.pen.lineDash = [ painter.toPx(this.lineWidth), painter.toPx(this.lineWidth) ]; painter.brush.color = SColor.Transparent; painter.drawRect(this.boundingRect()); } else if (this.borderStyle == SLineStyle.Soild) { painter.brush.color = SColor.Transparent; painter.drawRect(this.boundingRect()); } } // Function onDraw() } // Class STextMarkerItem