SIconTextItem.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SIconTextItem = void 0;
  4. const lib_1 = require("@persagy-web/graph/lib");
  5. const __1 = require("..");
  6. const draw_1 = require("@persagy-web/draw");
  7. class SIconTextItem extends lib_1.SObjectItem {
  8. constructor(parent, data) {
  9. super(parent);
  10. this._status = __1.SItemStatus.Normal;
  11. this._showText = true;
  12. this._isActive = false;
  13. this._activeColor = new draw_1.SColor("#00000033");
  14. this._showAnchor = false;
  15. this.img = new lib_1.SImageItem(this);
  16. this.textItem = new lib_1.STextItem(this);
  17. this.img.width = 32;
  18. this.img.height = 32;
  19. this.img.origin = new draw_1.SPoint(this.img.width * 0.5, this.img.height * 0.5);
  20. this.img.connect("onMove", this, this.changeAhchorPoint.bind(this));
  21. let anchorPoint;
  22. if (data && data.length) {
  23. anchorPoint = data.map(t => {
  24. return {
  25. x: t.Pos.X,
  26. y: t.Pos.Y,
  27. id: t.ID
  28. };
  29. });
  30. }
  31. else {
  32. anchorPoint = [
  33. { x: this.img.x, y: this.img.y, id: "" },
  34. { x: this.img.x, y: this.img.y, id: "" },
  35. { x: this.img.x, y: this.img.y, id: "" },
  36. { x: this.img.x, y: this.img.y, id: "" }
  37. ];
  38. }
  39. this.anchorList = anchorPoint.map(t => {
  40. let item = new lib_1.SAnchorItem(this);
  41. if (t.id) {
  42. item.id = t.id;
  43. }
  44. item.moveTo(t.x, t.y);
  45. return item;
  46. });
  47. this.showAnchor = false;
  48. this.textItem.text = "";
  49. this.textItem.font.size = 12;
  50. this.textItem.moveTo((this.img.width * 0.5), -(this.font.size * 1.25 * 0.5));
  51. this.moveable = true;
  52. this.selectable = true;
  53. }
  54. get status() {
  55. return this._status;
  56. }
  57. set status(v) {
  58. this._status = v;
  59. if (v == __1.SItemStatus.Normal) {
  60. this.moveable = true;
  61. this.textItem.moveable = false;
  62. this.img.moveable = false;
  63. }
  64. else if (v == __1.SItemStatus.Edit) {
  65. this.moveable = false;
  66. this.textItem.moveable = true;
  67. this.img.moveable = true;
  68. }
  69. else if (v == __1.SItemStatus.Create) {
  70. this.moveable = true;
  71. this.textItem.moveable = false;
  72. this.img.moveable = false;
  73. }
  74. this.update();
  75. }
  76. get showText() {
  77. return this._showText;
  78. }
  79. set showText(v) {
  80. if (v === this._showText) {
  81. return;
  82. }
  83. this._showText = v;
  84. if (v) {
  85. this.textItem.show();
  86. }
  87. else {
  88. this.textItem.hide();
  89. }
  90. }
  91. get selected() {
  92. return this._selected && this.selectable && this.enabled;
  93. }
  94. set selected(value) {
  95. if (this.selected == value) {
  96. return;
  97. }
  98. this._selected = value;
  99. if (value) {
  100. this.img.scale = 1.25;
  101. this.zOrder = __1.ItemOrder.highLightOrder;
  102. }
  103. else {
  104. this.img.scale = 1;
  105. this.zOrder = __1.ItemOrder.markOrder;
  106. }
  107. this.update();
  108. }
  109. get isActive() {
  110. return this._isActive;
  111. }
  112. set isActive(v) {
  113. this._isActive = v;
  114. if (v) {
  115. this.cursor = "pointer";
  116. this.textItem.cursor = "pointer";
  117. this.img.cursor = "pointer";
  118. }
  119. else {
  120. this.cursor = "auto";
  121. this.textItem.cursor = "auto";
  122. this.img.cursor = "auto";
  123. }
  124. this.update();
  125. }
  126. get activeColor() {
  127. return this._activeColor;
  128. }
  129. set activeColor(v) {
  130. this._activeColor = v;
  131. this.update();
  132. }
  133. get x() {
  134. return this.pos.x;
  135. }
  136. set x(v) {
  137. this.pos.x = v;
  138. this.$emit("changePos");
  139. this.update();
  140. }
  141. get y() {
  142. return this.pos.y;
  143. }
  144. set y(v) {
  145. this.pos.y = v;
  146. this.$emit("changePos");
  147. this.update();
  148. }
  149. get sWidth() {
  150. return this.img.width;
  151. }
  152. set sWidth(v) {
  153. this.img.width = v;
  154. this.img.origin = new draw_1.SPoint(this.img.width * 0.5, this.img.height * 0.5);
  155. this.changeAhchorPoint();
  156. this.update();
  157. }
  158. get sHeight() {
  159. return this.img.height;
  160. }
  161. set sHeight(v) {
  162. this.img.height = v;
  163. this.img.origin = new draw_1.SPoint(this.img.width * 0.5, this.img.height * 0.5);
  164. this.changeAhchorPoint();
  165. this.update();
  166. }
  167. get showAnchor() {
  168. return this._showAnchor;
  169. }
  170. set showAnchor(v) {
  171. this._showAnchor = v;
  172. this.anchorList.forEach(t => {
  173. t.visible = v;
  174. });
  175. }
  176. get text() {
  177. return this.textItem.text;
  178. }
  179. set text(v) {
  180. this.textItem.text = v;
  181. this.update();
  182. }
  183. get color() {
  184. return this.textItem.color;
  185. }
  186. set color(v) {
  187. this.textItem.color = v;
  188. this.update();
  189. }
  190. get font() {
  191. return this.textItem.font;
  192. }
  193. set font(v) {
  194. this.textItem.font = v;
  195. this.update();
  196. }
  197. changeAhchorPoint() {
  198. if (this.anchorList.length) {
  199. let anchorPoint = [
  200. { x: this.img.x, y: this.img.y },
  201. { x: this.img.x, y: this.img.y },
  202. { x: this.img.x, y: this.img.y },
  203. { x: this.img.x, y: this.img.y }
  204. ];
  205. this.anchorList.forEach((item, index) => {
  206. item.moveTo(anchorPoint[index].x, anchorPoint[index].y);
  207. });
  208. }
  209. }
  210. onMouseDown(event) {
  211. if (this.status == __1.SItemStatus.Normal) {
  212. return super.onMouseDown(event);
  213. }
  214. else if (this.status == __1.SItemStatus.Edit) {
  215. return super.onMouseDown(event);
  216. }
  217. return true;
  218. }
  219. onResize(oldSize, newSize) {
  220. console.log(arguments);
  221. }
  222. onDoubleClick(event) {
  223. if (__1.SItemStatus.Normal == this.status) {
  224. this.status = __1.SItemStatus.Edit;
  225. this.grabItem(this);
  226. }
  227. else if (__1.SItemStatus.Edit == this.status) {
  228. this.status = __1.SItemStatus.Normal;
  229. this.releaseItem();
  230. }
  231. this.update();
  232. return true;
  233. }
  234. boundingRect() {
  235. let rect = this.img
  236. .boundingRect()
  237. .adjusted(this.img.pos.x, this.img.pos.y, 0, 0);
  238. if (this.showText) {
  239. rect = rect.unioned(this.textItem
  240. .boundingRect()
  241. .adjusted(this.textItem.pos.x, this.textItem.pos.y, 0, 0));
  242. }
  243. return rect.adjusted(-5, -5, 10, 10);
  244. }
  245. onDraw(painter) {
  246. if (this.status == __1.SItemStatus.Edit) {
  247. painter.pen.lineWidth = painter.toPx(1);
  248. painter.pen.lineDash = [painter.toPx(3), painter.toPx(7)];
  249. painter.pen.color = draw_1.SColor.Black;
  250. painter.brush.color = draw_1.SColor.Transparent;
  251. painter.drawRect(this.boundingRect());
  252. }
  253. if (this.isActive) {
  254. painter.pen.color = draw_1.SColor.Transparent;
  255. painter.brush.color = this.activeColor;
  256. if (this.selected) {
  257. painter.shadow.shadowBlur = 10;
  258. painter.shadow.shadowColor = this.activeColor;
  259. painter.shadow.shadowOffsetX = 5;
  260. painter.shadow.shadowOffsetY = 5;
  261. painter.drawCircle(this.img.x, this.img.y, (this.sWidth / 2.0 + 3) * 1.25);
  262. }
  263. else {
  264. painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0 + 3);
  265. }
  266. }
  267. else {
  268. if (this.selected) {
  269. painter.pen.color = draw_1.SColor.Transparent;
  270. painter.brush.color = draw_1.SColor.Transparent;
  271. painter.shadow.shadowBlur = 10;
  272. painter.shadow.shadowColor = new draw_1.SColor(`#00000033`);
  273. painter.shadow.shadowOffsetX = 5;
  274. painter.shadow.shadowOffsetY = 5;
  275. painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0);
  276. }
  277. }
  278. }
  279. }
  280. exports.SIconTextItem = SIconTextItem;