HighlightItem.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { SGraphItem } from "@saga-web/graph/lib";
  21. import { SColor, SLine, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
  22. import { ItemOrder, ItemColor } from '@saga-web/big/lib';
  23. /**
  24. * 吸附时高亮对象
  25. *
  26. * @author 郝建龙
  27. */
  28. export class HighlightItem extends SGraphItem {
  29. /** 对象与鼠标位置距离 */
  30. distance: number = 0;
  31. /** 对象类型 */
  32. private type: number = 1;
  33. /** 点对象数据-当吸附的为线时,此点为垂线与线段的交点 */
  34. _point: SPoint = new SPoint();
  35. get point(): SPoint {
  36. return this._point;
  37. } // Get point
  38. set point(v: SPoint) {
  39. this._point = v;
  40. this.type = 1;
  41. this.update();
  42. } // Set point
  43. /** 点对象数据 */
  44. _line: SLine = new SLine();
  45. get line(): SLine {
  46. return this._line;
  47. } // Get line
  48. set line(v: SLine) {
  49. this._line = v;
  50. this.type = 2;
  51. this.update();
  52. } // Set line
  53. /**
  54. * 构造函数
  55. *
  56. * @param parent 指向父对象
  57. */
  58. constructor(parent: SGraphItem | null) {
  59. super(parent);
  60. this.visible = false;
  61. this.zOrder = ItemOrder.highLightOrder;
  62. } // Constructor
  63. /**
  64. * Item对象边界区域
  65. *
  66. * @return SRect
  67. */
  68. boundingRect(): SRect {
  69. return new SRect(this.point.x, this.point.y, 10, 10);
  70. } // Function boundingRect()
  71. /**
  72. * Item绘制操作
  73. *
  74. * @param painter painter对象
  75. */
  76. onDraw(painter: SPainter): void {
  77. if (this.type == 2) {
  78. painter.pen.color = ItemColor.highLightLineColor;
  79. painter.pen.lineWidth = painter.toPx(6);
  80. painter.drawLine(this.line);
  81. }
  82. painter.pen.color = SColor.Transparent;
  83. painter.brush.color = ItemColor.highLightPointColor;
  84. painter.drawCircle(this.point.x, this.point.y, painter.toPx(5));
  85. } // Function onDraw()
  86. } // Class HighlightItem