EquipItem.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2020. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { SGraphyItem } from "@saga-web/graphy/lib";
  21. import { SColor, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
  22. import { SMouseEvent } from "@saga-web/base/lib";
  23. import { Equip } from "../types/Equip";
  24. import { Point } from "../types/Point";
  25. import { ItemOrder } from "../types/ItemOrder";
  26. /**
  27. * 设备item
  28. *
  29. * @author 郝建龙
  30. */
  31. export class EquipItem extends SGraphyItem {
  32. /** 宽度 */
  33. _width: number = 400;
  34. /** X轴坐标 */
  35. get width(): number {
  36. return this._width;
  37. } // Get width
  38. set width(v: number) {
  39. this._width = v;
  40. if (this.data) {
  41. this.data.Size.Width = v;
  42. }
  43. // this.minX = this.pos.x - v / 2;
  44. // this.maxX = this.pos.x + v / 2;
  45. this.update();
  46. } // Set width
  47. /** 高度 */
  48. _height: number = 300;
  49. /** X轴坐标 */
  50. get height(): number {
  51. return this._height;
  52. } // Get width
  53. set height(v: number) {
  54. this._height = v;
  55. if (this.data) {
  56. this.data.Size.Height = v;
  57. }
  58. this.update();
  59. } // Set width
  60. /** 设备数据 */
  61. data: Equip | null = null;
  62. /** 位置 */
  63. pos: SPoint = new SPoint(0, 0);
  64. /** X轴坐标 */
  65. get x(): number {
  66. return this.pos.x;
  67. } // Get x
  68. set x(v: number) {
  69. this.pos.x = v;
  70. this.$emit("changePos");
  71. this.update();
  72. } // Set x
  73. /** Y轴坐标 */
  74. get y(): number {
  75. return this.pos.y;
  76. } // Get y
  77. set y(v: number) {
  78. this.pos.y = v;
  79. this.$emit("changePos");
  80. this.update();
  81. } // Set y
  82. /** 展示的图片路径 */
  83. Img: CanvasImageSource | undefined;
  84. constructor(parent: SGraphyItem | null, data: Equip) {
  85. super(parent);
  86. if (data.Size.Width) {
  87. this.width = data.Size.Width;
  88. }
  89. if (data.Size.Height) {
  90. this.height = data.Size.Height;
  91. }
  92. if (data.ImgSource) {
  93. this.Img = new Image();
  94. this.Img.src = data.ImgSource;
  95. }
  96. this.data = data;
  97. this.name = data.Name || "";
  98. this.moveable = true;
  99. this.zOrder = ItemOrder.EquipOrder;
  100. this.update();
  101. } // Constructor
  102. /**
  103. * Item对象边界区域
  104. *
  105. * @return SRect
  106. */
  107. boundingRect(): SRect {
  108. return new SRect(
  109. -this.width / 2,
  110. -this.height / 2,
  111. this.width,
  112. this.height
  113. );
  114. } // Function boundingRect()
  115. /**
  116. * 鼠标按下事件
  117. *
  118. */
  119. onMouseDown(event: SMouseEvent): boolean {
  120. if (this.selectable) {
  121. this.selected = !this.selected;
  122. }
  123. this.$emit("click", event);
  124. super.onMouseDown(event);
  125. return true;
  126. } // Function onMouseDown
  127. /**
  128. * 鼠标右键事件
  129. *
  130. * @param event 事件参数
  131. * @return boolean
  132. */
  133. onContextMenu(event: SMouseEvent): boolean {
  134. this.$emit("ContextMenu", event);
  135. return true;
  136. } // Function onContextMenu()
  137. /**
  138. * Item绘制操作
  139. *
  140. * @param painter painter对象
  141. */
  142. onDraw(painter: SPainter): void {
  143. painter.brush.color = SColor.White;
  144. if (this.Img) {
  145. painter.drawImage(
  146. this.Img,
  147. -this.width / 2,
  148. -this.height / 2,
  149. this.width,
  150. this.height
  151. );
  152. } else {
  153. painter.drawRect(
  154. -this.width / 2,
  155. -this.height / 2,
  156. this.width,
  157. this.height
  158. );
  159. }
  160. if (this.name) {
  161. painter.brush.color = SColor.Black;
  162. painter.font.size = 12;
  163. painter.drawText(this.name, -20, this.height / 2 + 15);
  164. }
  165. } // Function onDraw()
  166. } // Class EquipItem