SGraphyWallItem.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { SGraphyItem } from '@sybotan-web/graphy'
  2. import { SRect, SSize, SPoint } from "@sybotan-web/base";
  3. import { SPen, SPainter, SColor } from "@sybotan-web/draw";
  4. /**
  5. * 墙Item类
  6. *
  7. */
  8. export class SGraphyWallItem extends SGraphyItem {
  9. pointArr: SPoint[];
  10. isVirtual: boolean = false;
  11. fillColor: SColor = SColor.White;
  12. color: SColor = SColor.Black;
  13. width: number = 1;
  14. /**
  15. * 构造函数
  16. *
  17. * @param pointArr 点坐标list
  18. * @param isVirtual 墙类型(实体墙-虚拟墙)
  19. * @param color 墙的颜色
  20. * @param fillColor 墙的填充颜色
  21. * @param width 墙的宽度
  22. * @param parent
  23. */
  24. constructor(
  25. parent: SGraphyItem | null,
  26. pointArr: SPoint[],
  27. isVirtual: boolean = false,
  28. fillColor: SColor = SColor.White,
  29. color: SColor = SColor.Black,
  30. width: number = 1,
  31. ) {
  32. super(parent);
  33. this.isVirtual = isVirtual;
  34. this.pointArr = pointArr;
  35. this.color = color;
  36. this.fillColor = fillColor;
  37. this.width = width;
  38. } // Constructor()
  39. /**
  40. * Item对象边界区域
  41. *
  42. * @return SRect
  43. */
  44. boundingRect(): SRect {
  45. let minX = this.pointArr[0].x;
  46. let maxX = minX;
  47. let minY = this.pointArr[0].y;
  48. let maxY = minY;
  49. for (let i = 1; i < this.pointArr.length; i++) {
  50. if (this.pointArr[i].x < minX) {
  51. minX = this.pointArr[i].x
  52. }
  53. if (this.pointArr[i].y < minY) {
  54. minY = this.pointArr[i].y
  55. }
  56. if (this.pointArr[i].x > maxX) {
  57. maxX = this.pointArr[i].x
  58. }
  59. if (this.pointArr[i].y > maxY) {
  60. maxY = this.pointArr[i].y
  61. }
  62. }
  63. return new SRect(
  64. minX,
  65. minY,
  66. maxX - minX,
  67. maxY - minY
  68. );
  69. } // Function boundingRect()
  70. /**
  71. * Item绘制操作
  72. *
  73. * @param painter painter对象
  74. * @param rect 绘制区域
  75. */
  76. onDraw(painter: SPainter, rect: SRect): void {
  77. if (this.pointArr.length) {
  78. // painter.pen = new SPen(this.color, this.width);
  79. painter.pen.color = this.color;
  80. painter.brush.color = this.fillColor;
  81. painter.drawPolyline(this.pointArr)
  82. }
  83. }
  84. } // Class SGraphyPolygonItem