UNPKG

medsurf-draw

Version:

Draw annotations on jpg/zoomify images, based on PIXI.js

138 lines 5.69 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as MedsurfDraw from "../public-api"; import { BaseElementInteraction } from "../bases/interactions/BaseElementInteraction"; export var StickMode; (function (StickMode) { StickMode[StickMode["NOELEMENTS"] = 0] = "NOELEMENTS"; StickMode[StickMode["POSITIONPOINTS"] = 1] = "POSITIONPOINTS"; StickMode[StickMode["POSITIONPOINTS_FILLCOLLECTIONS"] = 2] = "POSITIONPOINTS_FILLCOLLECTIONS"; })(StickMode || (StickMode = {})); var DrawInteraction = (function (_super) { __extends(DrawInteraction, _super); function DrawInteraction(element, stickMode) { var _this = _super.call(this, element) || this; _this.stickMode = stickMode; return _this; } DrawInteraction.prototype.reset = function () { this._isScaling = false; }; DrawInteraction.prototype.startDraw = function (event) { event.stopPropagation(); this.emit("startDrawStart", event); if (this.element.moveInteraction.isMoving) { return; } this.emit("startMove", event); this._isScaling = false; this.emit("startDraw", event); }; DrawInteraction.prototype.resetDraw = function (event) { event.stopPropagation(); this.emit("resetDrawStart", event); if (!this.element.moveInteraction.isMoving) { return; } this.emit("resetMove", event); this.emit("resetDraw", event); }; DrawInteraction.prototype.startDrawScale = function (event) { event.stopPropagation(); this.emit("startDrawScaleStart", event); if (this._isScaling) { return; } this.emit("startScale", event); this._isScaling = true; this.emit("startDrawScale", event); }; DrawInteraction.prototype.onDraw = function (event) { this.emit("onDrawStart", event); if (this._isScaling) { this.emit("onScale", event); } else if (this.element.moveInteraction.isMoving) { this.emit("onMove", event); } this.emit("onDraw", event); }; DrawInteraction.prototype.endDraw = function (event) { event.stopPropagation(); this.emit("endDrawStart", event); if (this.element.moveInteraction.isMoving) { this.emit("endMove", event); } if (this._isScaling) { this._isScaling = false; this.emit("endScale", event); } var renderer = this.element.image.renderer; if (renderer) { var globalPoint = renderer.plugins.interaction.mouse.global; var element = renderer.plugins.interaction.hitTest(globalPoint, this.element.image); if ((this.stickMode === StickMode.POSITIONPOINTS || this.stickMode === StickMode.POSITIONPOINTS_FILLCOLLECTIONS) && element instanceof MedsurfDraw.PositionPoint) { if (element.modeInteraction.lastMode.startsWith('draw')) { this.emit("updatePoint", event, element); } else { this.emit("startMove", event); } } else if ((this.stickMode === StickMode.POSITIONPOINTS || this.stickMode === StickMode.POSITIONPOINTS_FILLCOLLECTIONS) && (element instanceof MedsurfDraw.ArrowPrimitive || element instanceof MedsurfDraw.EllipsePrimitive || element instanceof MedsurfDraw.RectanglePrimitive || element instanceof MedsurfDraw.TextPrimitive) && element.parent !== this.element) { if (element.parent.modeInteraction.lastMode.startsWith('draw')) { this.emit("updatePoint", event, element.parent); } else { this.emit("startMove", event); } } else if (this.stickMode === StickMode.POSITIONPOINTS_FILLCOLLECTIONS && element instanceof MedsurfDraw.FillCollection) { if (element.modeInteraction.lastMode.startsWith('draw')) { this.emit("updateFill", event, element); } else { this.emit("startMove", event); } } else { this.emit("endDraw", event); } } }; DrawInteraction.prototype.abortDraw = function (event) { event.stopPropagation(); this.emit("abortDrawStart", event); this.emit("abortDraw", event); }; Object.defineProperty(DrawInteraction.prototype, "stickMode", { get: function () { return this._stickMode; }, set: function (value) { this._stickMode = value; }, enumerable: false, configurable: true }); return DrawInteraction; }(BaseElementInteraction)); export { DrawInteraction }; //# sourceMappingURL=DrawInteraction.js.map