STextMarkerItem.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { STextItem, SLineStyle } from "@saga-web/graph/lib";
  2. import { SColor, SFont } from "@saga-web/draw";
  3. import { ItemOrder } from '@saga-web/big/lib';
  4. /**
  5. * 标识对象Item(文本类型)
  6. *
  7. * * @author 张宇(taohuzy@163.com)
  8. */
  9. export class STextMarkerItem extends STextItem {
  10. /**
  11. * 构造函数
  12. *
  13. * @param parent 指向父对象
  14. * @param data 标识对象数据
  15. */
  16. constructor(parent, data) {
  17. super(parent);
  18. /** 边框宽度 */
  19. this._lineWidth = 1;
  20. /** 边框样式 */
  21. this._borderStyle = SLineStyle.None;
  22. this.zOrder = ItemOrder.textOrder;
  23. this.data = data;
  24. this.id = data.ID;
  25. this.name = data.Name;
  26. this.moveTo(data.Pos.X, data.Pos.Y);
  27. if (data.Size) {
  28. this.width = data.Size.Width;
  29. this.height = data.Size.Height;
  30. }
  31. if (data.Properties && data.Properties.Text) {
  32. this.text = data.Properties.Text;
  33. }
  34. if (data.Properties && data.Properties.Color) {
  35. this.color = data.Properties.Color;
  36. }
  37. if (data.Properties && data.Properties.Font) {
  38. this.font = new SFont("sans-serif", data.Properties.Font);
  39. ;
  40. }
  41. if (data.Properties && data.Properties.BackgroundColor) {
  42. this.backgroundColor = data.Properties.BackgroundColor;
  43. }
  44. } // Constructor
  45. get lineWidth() {
  46. return this._lineWidth;
  47. }
  48. set lineWidth(v) {
  49. this._lineWidth = v;
  50. this.update();
  51. }
  52. get borderStyle() {
  53. return this._borderStyle;
  54. }
  55. set borderStyle(v) {
  56. this._borderStyle = v;
  57. this.update();
  58. }
  59. toData() {
  60. this.data.Pos = { X: this.x, Y: this.y };
  61. this.data.Size = { Width: this.width, Height: this.height };
  62. this.data.Properties.Text = this.text;
  63. this.data.Properties.Color = this.color;
  64. this.data.Properties.Font = this.font.size;
  65. this.data.Properties.BackgroundColor = this.backgroundColor;
  66. return this.data;
  67. }
  68. /**
  69. * Item绘制操作
  70. *
  71. * @param painter 绘画类
  72. */
  73. onDraw(painter) {
  74. // 绘制文本
  75. painter.brush.color = new SColor(this.color);
  76. painter.font = this.font;
  77. this.drawFormatText(painter);
  78. if (this.selected) {
  79. this.borderStyle = SLineStyle.Dashed;
  80. }
  81. else {
  82. this.borderStyle = SLineStyle.None;
  83. }
  84. if (this.borderStyle == SLineStyle.Dashed) {
  85. painter.pen.lineDash = [
  86. painter.toPx(this.lineWidth * 3),
  87. painter.toPx(this.lineWidth * 7)
  88. ];
  89. painter.brush.color = SColor.Transparent;
  90. painter.drawRect(this.boundingRect());
  91. }
  92. else if (this.borderStyle == SLineStyle.Dotted) {
  93. painter.pen.lineDash = [
  94. painter.toPx(this.lineWidth),
  95. painter.toPx(this.lineWidth)
  96. ];
  97. painter.brush.color = SColor.Transparent;
  98. painter.drawRect(this.boundingRect());
  99. }
  100. else if (this.borderStyle == SLineStyle.Soild) {
  101. painter.brush.color = SColor.Transparent;
  102. painter.drawRect(this.boundingRect());
  103. }
  104. } // Function onDraw()
  105. } // Class STextMarkerItem