123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { SGraphItem, STextItem, SLineStyle } from "@saga-web/graph/lib";
- import { SPainter, SColor,SFont } from "@saga-web/draw";
- import { Marker } from '../types/Marker';
- import { ItemOrder } from '@saga-web/big/lib';
- /**
- * 标识对象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.None;
- 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.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
- 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;
- 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: SPainter): void {
- // 绘制文本
- 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
|