SGraphRectItem.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SGraphShape } from "./SGraphShape";
  27. import { SGraphItem } from "../SGraphItem";
  28. import { SPainter, SRect } from "@persagy-web/draw";
  29. import { SGraphRect } from "..";
  30. /**
  31. * 矩形(包含圆角矩形)item
  32. *
  33. * @author 郝建龙
  34. * */
  35. export class SGraphRectItem extends SGraphShape {
  36. /** item左上角X坐标 */
  37. private _leftTopY: number = 0;
  38. get leftTopY(): number {
  39. return this._leftTopY;
  40. } // Get leftTopY
  41. set leftTopY(v: number) {
  42. if (v == this._leftTopY) {
  43. return;
  44. }
  45. this._leftTopY = v;
  46. this.update();
  47. } // Set leftTopY
  48. /** item左上角Y坐标 */
  49. private _leftTopX: number = 0;
  50. get leftTopX(): number {
  51. return this._leftTopX;
  52. } // Get leftTopX
  53. set leftTopX(v: number) {
  54. if (v == this._leftTopX) {
  55. return;
  56. }
  57. this._leftTopX = v;
  58. this.update();
  59. } // Set leftTopX
  60. /** item宽 */
  61. private _width: number = 0;
  62. get width(): number {
  63. return this._width;
  64. } // Get width
  65. set width(v: number) {
  66. if (v == this._width) {
  67. return;
  68. }
  69. this._width = v;
  70. this.update();
  71. } // Set width
  72. /** item高 */
  73. private _height: number = 0;
  74. get height(): number {
  75. return this._height;
  76. } // Get height
  77. set height(v: number) {
  78. if (v == this._height) {
  79. return;
  80. }
  81. this._height = v;
  82. this.update();
  83. } // Set height
  84. /** 绘制矩形的圆角半径 */
  85. private _radius: number = 0;
  86. get radius(): number {
  87. return this._radius;
  88. } // Get radius
  89. set radius(v: number) {
  90. if (v == this._radius) {
  91. return;
  92. }
  93. this._radius = v;
  94. this.update();
  95. } // Set radius
  96. /**
  97. * 构造函数
  98. *
  99. * @param parent 指向父对象
  100. * @param data 矩形数据
  101. */
  102. constructor(parent: SGraphItem | null, data: SGraphRect) {
  103. super(parent, data.Style);
  104. this.leftTopX = data.X;
  105. this.leftTopY = data.Y;
  106. this.width = data.Width;
  107. this.height = data.Height;
  108. if (data.Radius && !isNaN(data.Radius)) {
  109. this.radius = Number(data.Radius);
  110. }
  111. } // Constructor
  112. /**
  113. * Item对象边界区域
  114. *
  115. * @return SRect
  116. */
  117. boundingRect(): SRect {
  118. return new SRect(this.leftTopX, this.leftTopY, this.width, this.height);
  119. } // Function boundingRect()
  120. /**
  121. * 绘制
  122. *
  123. * @param painter painter对象
  124. * */
  125. onDraw(painter: SPainter): void {
  126. super.onDraw(painter);
  127. if (this.radius != 0) {
  128. painter.drawRoundRect(
  129. this.leftTopX,
  130. this.leftTopY,
  131. this.width,
  132. this.height,
  133. this.radius
  134. );
  135. } else {
  136. painter.drawRect(
  137. this.leftTopX,
  138. this.leftTopY,
  139. this.width,
  140. this.height
  141. );
  142. }
  143. } // Function onDraw()
  144. } // Class SGraphRectItem