SRectSelectItem.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { SGraphItem } from "@saga-web/graph/lib";
  2. import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
  3. import { SMouseEvent } from "@saga-web/base/lib";
  4. import { ItemColor, ItemOrder } from "..";
  5. /**
  6. * 矩形选择item
  7. *
  8. * @author 郝建龙
  9. */
  10. export class SRectSelectItem extends SGraphItem {
  11. /** 起点 */
  12. startPoint: SPoint = new SPoint();
  13. /** 终点 */
  14. endPoint: SPoint = new SPoint();
  15. /**
  16. * 构造函数
  17. *
  18. * @param parent 指向父对象
  19. * @param point 起点数据
  20. */
  21. constructor(parent: SGraphItem | null, point: SPoint) {
  22. super(parent);
  23. this.startPoint = point;
  24. this.endPoint = new SPoint(point.x, point.y);
  25. this.update();
  26. this.zOrder = ItemOrder.rectSelectOrder;
  27. } // Constructor
  28. /**
  29. * Item对象边界区域
  30. *
  31. * @return SRect
  32. */
  33. boundingRect(): SRect {
  34. return new SRect(this.startPoint, this.endPoint);
  35. } // Function boundingRect()
  36. /**
  37. * 鼠标移动事件
  38. *
  39. * @param event 事件参数
  40. * @return boolean
  41. */
  42. onMouseMove(event: SMouseEvent): boolean {
  43. this.endPoint.x = event.x;
  44. this.endPoint.y = event.y;
  45. this.update();
  46. return true;
  47. } // Function onMouseMove()
  48. /**
  49. * Item绘制操作
  50. *
  51. * @param painter painter对象
  52. */
  53. onDraw(painter: SPainter): void {
  54. painter.pen.lineWidth = painter.toPx(2);
  55. painter.pen.color = ItemColor.rectSelectOutColor;
  56. painter.brush.color = ItemColor.rectSelectInColor;
  57. painter.drawRect(this.startPoint, this.endPoint);
  58. } // Function onDraw()
  59. } // SRectSelectItem