Keine Beschreibung

RectangularMarkerBase.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var SvgHelper_1 = require("../../utils/SvgHelper");
  17. var MarkerBase_1 = require("./MarkerBase");
  18. var RectangularMarkerGrips_1 = require("./RectangularMarkerGrips");
  19. var ResizeGrip_1 = require("./ResizeGrip");
  20. var RectangularMarkerBase = (function (_super) {
  21. __extends(RectangularMarkerBase, _super);
  22. function RectangularMarkerBase() {
  23. var _this = _super !== null && _super.apply(this, arguments) || this;
  24. _this.MIN_SIZE = 5;
  25. _this.CB_DISTANCE = 10;
  26. _this.addControlBox = function () {
  27. _this.controlBox = SvgHelper_1.SvgHelper.createGroup([['class', 'fc-whiteboardrect-control-box']]);
  28. var translate = SvgHelper_1.SvgHelper.createTransform();
  29. translate.setTranslate(-_this.CB_DISTANCE / 2, -_this.CB_DISTANCE / 2);
  30. _this.controlBox.transform.baseVal.appendItem(translate);
  31. _this.addToVisual(_this.controlBox);
  32. _this.controlRect = SvgHelper_1.SvgHelper.createRect(_this.width + _this.CB_DISTANCE, _this.height + _this.CB_DISTANCE, [['class', 'fc-whiteboardrect-control-rect']]);
  33. _this.controlBox.appendChild(_this.controlRect);
  34. _this.controlGrips = new RectangularMarkerGrips_1.RectangularMarkerGrips();
  35. _this.addControlGrips();
  36. };
  37. _this.adjustControlBox = function () {
  38. _this.controlRect.setAttribute('width', (_this.width + _this.CB_DISTANCE).toString());
  39. _this.controlRect.setAttribute('height', (_this.height + _this.CB_DISTANCE).toString());
  40. _this.positionGrips();
  41. };
  42. _this.addControlGrips = function () {
  43. _this.controlGrips.topLeft = _this.createGrip();
  44. _this.controlGrips.topCenter = _this.createGrip();
  45. _this.controlGrips.topRight = _this.createGrip();
  46. _this.controlGrips.centerLeft = _this.createGrip();
  47. _this.controlGrips.centerRight = _this.createGrip();
  48. _this.controlGrips.bottomLeft = _this.createGrip();
  49. _this.controlGrips.bottomCenter = _this.createGrip();
  50. _this.controlGrips.bottomRight = _this.createGrip();
  51. _this.positionGrips();
  52. };
  53. _this.createGrip = function () {
  54. var grip = new ResizeGrip_1.ResizeGrip();
  55. grip.visual.transform.baseVal.appendItem(SvgHelper_1.SvgHelper.createTransform());
  56. _this.controlBox.appendChild(grip.visual);
  57. grip.visual.addEventListener('mousedown', _this.gripMouseDown);
  58. grip.visual.addEventListener('mousemove', _this.gripMouseMove);
  59. grip.visual.addEventListener('mouseup', _this.gripMouseUp);
  60. grip.visual.addEventListener('touchstart', _this.onTouch, { passive: false });
  61. grip.visual.addEventListener('touchend', _this.onTouch, { passive: false });
  62. grip.visual.addEventListener('touchmove', _this.onTouch, { passive: false });
  63. return grip;
  64. };
  65. _this.positionGrips = function () {
  66. var gripSize = _this.controlGrips.topLeft.GRIP_SIZE;
  67. var left = -gripSize / 2;
  68. var top = left;
  69. var cx = (_this.width + _this.CB_DISTANCE) / 2 - gripSize / 2;
  70. var cy = (_this.height + _this.CB_DISTANCE) / 2 - gripSize / 2;
  71. var bottom = _this.height + _this.CB_DISTANCE - gripSize / 2;
  72. var right = _this.width + _this.CB_DISTANCE - gripSize / 2;
  73. _this.positionGrip(_this.controlGrips.topLeft.visual, left, top);
  74. _this.positionGrip(_this.controlGrips.topCenter.visual, cx, top);
  75. _this.positionGrip(_this.controlGrips.topRight.visual, right, top);
  76. _this.positionGrip(_this.controlGrips.centerLeft.visual, left, cy);
  77. _this.positionGrip(_this.controlGrips.centerRight.visual, right, cy);
  78. _this.positionGrip(_this.controlGrips.bottomLeft.visual, left, bottom);
  79. _this.positionGrip(_this.controlGrips.bottomCenter.visual, cx, bottom);
  80. _this.positionGrip(_this.controlGrips.bottomRight.visual, right, bottom);
  81. };
  82. _this.positionGrip = function (grip, x, y) {
  83. var translate = grip.transform.baseVal.getItem(0);
  84. translate.setTranslate(x, y);
  85. grip.transform.baseVal.replaceItem(translate, 0);
  86. };
  87. _this.gripMouseDown = function (ev) {
  88. _this.isResizing = true;
  89. _this.activeGrip = _this.controlGrips.findGripByVisual(ev.target) || null;
  90. _this.previousMouseX = ev.screenX;
  91. _this.previousMouseY = ev.screenY;
  92. ev.stopPropagation();
  93. };
  94. _this.gripMouseUp = function (ev) {
  95. _this.isResizing = false;
  96. _this.activeGrip = null;
  97. ev.stopPropagation();
  98. };
  99. _this.gripMouseMove = function (ev) {
  100. if (_this.isResizing) {
  101. _this.manipulate(ev);
  102. }
  103. };
  104. return _this;
  105. }
  106. RectangularMarkerBase.prototype.endManipulation = function () {
  107. _super.prototype.endManipulation.call(this);
  108. this.isResizing = false;
  109. this.activeGrip = null;
  110. };
  111. RectangularMarkerBase.prototype.select = function () {
  112. _super.prototype.select.call(this);
  113. this.controlBox.style.display = '';
  114. };
  115. RectangularMarkerBase.prototype.deselect = function () {
  116. _super.prototype.deselect.call(this);
  117. this.controlBox.style.display = 'none';
  118. };
  119. RectangularMarkerBase.prototype.setup = function () {
  120. _super.prototype.setup.call(this);
  121. this.addControlBox();
  122. };
  123. RectangularMarkerBase.prototype.resize = function (x, y) {
  124. var translateX = 0;
  125. var translateY = 0;
  126. switch (this.activeGrip) {
  127. case this.controlGrips.topLeft:
  128. this.width -= x;
  129. this.height -= y;
  130. translateX += x;
  131. translateY += y;
  132. break;
  133. case this.controlGrips.bottomLeft:
  134. this.width -= x;
  135. this.height += y;
  136. translateX += x;
  137. break;
  138. case this.controlGrips.topRight:
  139. this.width += x;
  140. this.height -= y;
  141. translateY += y;
  142. break;
  143. case this.controlGrips.bottomRight:
  144. this.width += x;
  145. this.height += y;
  146. break;
  147. case this.controlGrips.centerLeft:
  148. this.width -= x;
  149. translateX += x;
  150. break;
  151. case this.controlGrips.centerRight:
  152. this.width += x;
  153. break;
  154. case this.controlGrips.topCenter:
  155. this.height -= y;
  156. translateY += y;
  157. break;
  158. case this.controlGrips.bottomCenter:
  159. this.height += y;
  160. break;
  161. }
  162. if (this.width < this.MIN_SIZE) {
  163. var offset = this.MIN_SIZE - this.width;
  164. this.width = this.MIN_SIZE;
  165. if (translateX !== 0) {
  166. translateX -= offset;
  167. }
  168. }
  169. if (this.height < this.MIN_SIZE) {
  170. var offset = this.MIN_SIZE - this.height;
  171. this.height = this.MIN_SIZE;
  172. if (translateY !== 0) {
  173. translateY -= offset;
  174. }
  175. }
  176. if (translateX !== 0 || translateY !== 0) {
  177. var translate = this.visual.transform.baseVal.getItem(0);
  178. translate.setMatrix(translate.matrix.translate(translateX, translateY));
  179. this.visual.transform.baseVal.replaceItem(translate, 0);
  180. }
  181. this.adjustControlBox();
  182. };
  183. RectangularMarkerBase.prototype.onTouch = function (ev) {
  184. _super.prototype.onTouch.call(this, ev);
  185. };
  186. RectangularMarkerBase.createMarker = function () {
  187. var marker = new RectangularMarkerBase();
  188. marker.setup();
  189. return marker;
  190. };
  191. return RectangularMarkerBase;
  192. }(MarkerBase_1.MarkerBase));
  193. exports.RectangularMarkerBase = RectangularMarkerBase;