Нема описа

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 RectangularMarkerGrips_1 = require("./RectangularMarkerGrips");
  17. var BaseMarker_1 = require("../BaseMarker");
  18. var ResizeGrip_1 = require("../BaseMarker/ResizeGrip");
  19. var SvgHelper_1 = require("../../renderer/SvgHelper");
  20. var RectangularMarker = (function (_super) {
  21. __extends(RectangularMarker, _super);
  22. function RectangularMarker() {
  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-whiteboard-rect-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-whiteboard-rect-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. RectangularMarker.prototype.endManipulation = function () {
  107. _super.prototype.endManipulation.call(this);
  108. this.isResizing = false;
  109. this.activeGrip = null;
  110. };
  111. RectangularMarker.prototype.select = function () {
  112. _super.prototype.select.call(this);
  113. this.controlBox.style.display = '';
  114. };
  115. RectangularMarker.prototype.deselect = function () {
  116. _super.prototype.deselect.call(this);
  117. this.controlBox.style.display = 'none';
  118. };
  119. RectangularMarker.prototype.setup = function () {
  120. _super.prototype.setup.call(this);
  121. this.addControlBox();
  122. if (this.page && this.page.mode === 'mirror') {
  123. this.controlBox.style.display = 'none';
  124. }
  125. };
  126. RectangularMarker.prototype.resizeByEvent = function (x, y, pos) {
  127. this.activeGrip = this.controlGrips[pos];
  128. this.resize(x, y);
  129. };
  130. RectangularMarker.prototype.resize = function (x, y, onPosition) {
  131. var translateX = 0;
  132. var translateY = 0;
  133. switch (this.activeGrip) {
  134. case this.controlGrips.topLeft:
  135. this.width -= x;
  136. this.height -= y;
  137. translateX += x;
  138. translateY += y;
  139. if (onPosition) {
  140. onPosition('topLeft');
  141. }
  142. break;
  143. case this.controlGrips.bottomLeft:
  144. this.width -= x;
  145. this.height += y;
  146. translateX += x;
  147. if (onPosition) {
  148. onPosition('bottomLeft');
  149. }
  150. break;
  151. case this.controlGrips.topRight:
  152. this.width += x;
  153. this.height -= y;
  154. translateY += y;
  155. if (onPosition) {
  156. onPosition('topRight');
  157. }
  158. break;
  159. case this.controlGrips.bottomRight:
  160. this.width += x;
  161. this.height += y;
  162. if (onPosition) {
  163. onPosition('bottomRight');
  164. }
  165. break;
  166. case this.controlGrips.centerLeft:
  167. this.width -= x;
  168. translateX += x;
  169. if (onPosition) {
  170. onPosition('centerLeft');
  171. }
  172. break;
  173. case this.controlGrips.centerRight:
  174. this.width += x;
  175. if (onPosition) {
  176. onPosition('centerRight');
  177. }
  178. break;
  179. case this.controlGrips.topCenter:
  180. this.height -= y;
  181. translateY += y;
  182. if (onPosition) {
  183. onPosition('topCenter');
  184. }
  185. break;
  186. case this.controlGrips.bottomCenter:
  187. this.height += y;
  188. if (onPosition) {
  189. onPosition('bottomCenter');
  190. }
  191. break;
  192. default:
  193. break;
  194. }
  195. if (this.width < this.MIN_SIZE) {
  196. var offset = this.MIN_SIZE - this.width;
  197. this.width = this.MIN_SIZE;
  198. if (translateX !== 0) {
  199. translateX -= offset;
  200. }
  201. }
  202. if (this.height < this.MIN_SIZE) {
  203. var offset = this.MIN_SIZE - this.height;
  204. this.height = this.MIN_SIZE;
  205. if (translateY !== 0) {
  206. translateY -= offset;
  207. }
  208. }
  209. if (translateX !== 0 || translateY !== 0) {
  210. var translate = this.visual.transform.baseVal.getItem(0);
  211. translate.setMatrix(translate.matrix.translate(translateX, translateY));
  212. this.visual.transform.baseVal.replaceItem(translate, 0);
  213. }
  214. this.adjustControlBox();
  215. };
  216. RectangularMarker.prototype.onTouch = function (ev) {
  217. _super.prototype.onTouch.call(this, ev);
  218. };
  219. RectangularMarker.createMarker = function (page) {
  220. var marker = new RectangularMarker();
  221. marker.page = page;
  222. marker.setup();
  223. return marker;
  224. };
  225. return RectangularMarker;
  226. }(BaseMarker_1.BaseMarker));
  227. exports.RectangularMarker = RectangularMarker;