UNPKG

medsurf-draw

Version:

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

255 lines 11.9 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 PIXI from "pixi.js-legacy"; import * as MedsurfDraw from "../../public-api"; import { BaseGenerator } from "../../bases/generators/BaseGenerator"; import { PositionPointGeneratorModel } from "../positionings/PositionPointGenerator"; var TextPrimitiveGeneratorModel = (function (_super) { __extends(TextPrimitiveGeneratorModel, _super); function TextPrimitiveGeneratorModel() { return _super !== null && _super.apply(this, arguments) || this; } return TextPrimitiveGeneratorModel; }(PositionPointGeneratorModel)); export { TextPrimitiveGeneratorModel }; var TextPrimitiveGenerator = (function (_super) { __extends(TextPrimitiveGenerator, _super); function TextPrimitiveGenerator(model) { var _this = _super.call(this, model) || this; _this.target.modeInteraction.setModeItem("drawing"); if (!_this.startElement) { _this._positionPointGenerator = new MedsurfDraw.PositionPointGenerator({ target: _this.target, layerGroup: _this.data.layerGroup, image: _this.data.image, stickMode: _this.stickMode }); _this._positionPointGenerator.once("startGenerator", _this.start, _this); _this._positionPointGenerator.once("startGenerator", _this.startPositionPointGenerator, _this); _this._positionPointGenerator.once("updatePoint", _this.updatePositionPointGenerator, _this); if (_this.withScaling) { _this._positionPointGenerator.once("endGenerator", _this.endPositionPointGeneratorScale, _this); _this._positionPointGenerator.once("endGenerator", _this.startScale, _this); } else { _this._positionPointGenerator.once("endGenerator", _this.endPositionPointGenerator, _this); } _this._positionPointGenerator.once("abortGenerator", _this.abortPositionPointGenerator, _this); } else { _this.startPositionPointGenerator(); if (_this.withScaling) { _this.endPositionPointGeneratorScale(); var globalPoint = _this.target.renderer.plugins.interaction.mouse.global; var hitTest = _this.target.renderer.plugins.interaction.hitTest(globalPoint, _this.target); if (!hitTest) { _this.target.once("pointerover", _this.startScale, _this); } else { _this.startScale(); } } else { _this.endPositionPointGenerator(); } } return _this; } TextPrimitiveGenerator.prototype.start = function (event) { this.emit("startGenerator"); }; TextPrimitiveGenerator.prototype.end = function () { this.target.parent.off("mousedown", this.drawInteraction.startDrawScale, this.drawInteraction); this.target.parent.off("rightup", this.drawInteraction.abortDraw, this.drawInteraction); this.target.parent.off("pointermove", this.drawInteraction.onDraw, this.drawInteraction); this.target.parent.off("mouseup", this.drawInteraction.endDraw, this.drawInteraction); this.drawInteraction.removeAllListeners(); if (this._positionPointGenerator) { this._positionPointGenerator.removeAllListeners(); } _super.prototype.end.call(this); }; TextPrimitiveGenerator.prototype.destroy = function (options) { this.end(); if (this.textPrimitiveElement) { this.textPrimitiveElement.modeInteraction.setMode('delete_draw'); } if (this._positionPointGenerator) { this._positionPointGenerator.destroy(); } }; TextPrimitiveGenerator.prototype.endGenerator = function () { _super.prototype.endGenerator.call(this); this.target.sortChildren(); this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode); }; TextPrimitiveGenerator.prototype.abortGenerator = function () { _super.prototype.abortGenerator.call(this); this.target.getImageObjects() .filter(function (imageObject) { return imageObject.modeInteraction.lastMode.startsWith('draw_') && imageObject.modeInteraction.lastMode.endsWith('_new'); }) .forEach(function (imageObject) { imageObject.modeInteraction.setMode("delete_draw"); }); this.target.sortChildren(); this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode); }; TextPrimitiveGenerator.prototype.startPositionPointGenerator = function () { this._textPrimitiveElement = MedsurfDraw.TextPrimitive.getInstance(this.target, this.rotateWithLine, this.target.dimensions.width); this.positionPointElement.addChild(this.textPrimitiveElement); this.textPrimitiveElement.controlDrawItem(); this.textPrimitiveElement.showItem(); this._drawInteraction = new MedsurfDraw.DrawInteraction(this.textPrimitiveElement, MedsurfDraw.StickMode.NOELEMENTS); }; TextPrimitiveGenerator.prototype.updatePositionPointGenerator = function () { this.startPositionPointGenerator(); if (this.withScaling) { this.endPositionPointGeneratorScale(); this.startScale(); } else { this.endPositionPointGenerator(); } }; TextPrimitiveGenerator.prototype.endPositionPointGeneratorScale = function () { if (!this.positionPointElement.model.primitives) { this.positionPointElement.model.primitives = []; } this.positionPointElement.model.primitives.push(this.textPrimitiveElement.model); if (!this.withScaling && this.triggerImmediateEndDraw) { this.endTextPrimitiveDraw(); } else { this.target.parent.on("mousedown", this.drawInteraction.startDrawScale, this.drawInteraction); this.target.parent.on("rightup", this.drawInteraction.abortDraw, this.drawInteraction); this.target.parent.on("pointermove", this.drawInteraction.onDraw, this.drawInteraction); this.target.parent.on("mouseup", this.drawInteraction.endDraw, this.drawInteraction); this.drawInteraction.on("startScale", this.textPrimitiveElement.scaleInteraction.startScale, this.textPrimitiveElement.scaleInteraction); this.drawInteraction.on("onScale", this.textPrimitiveElement.scaleInteraction.onScale, this.textPrimitiveElement.scaleInteraction); this.drawInteraction.on("endScale", this.textPrimitiveElement.scaleInteraction.endScale, this.textPrimitiveElement.scaleInteraction); this.drawInteraction.on("endDraw", this.endTextPrimitiveDraw, this); this.drawInteraction.on("abortDraw", this.abortTextPrimitiveDraw, this); } }; TextPrimitiveGenerator.prototype.endPositionPointGenerator = function () { if (!this.positionPointElement.model.primitives) { this.positionPointElement.model.primitives = []; } this.positionPointElement.model.primitives.push(this.textPrimitiveElement.model); if (!this.withScaling && this.triggerImmediateEndDraw) { this.endTextPrimitiveDraw(); } else { this.target.parent.on("mousedown", this.drawInteraction.startDrawScale, this.drawInteraction); this.target.parent.on("rightup", this.drawInteraction.abortDraw, this.drawInteraction); this.target.parent.on("pointermove", this.drawInteraction.onDraw, this.drawInteraction); this.target.parent.on("mouseup", this.drawInteraction.endDraw, this.drawInteraction); this.drawInteraction.on("endDraw", this.endTextPrimitiveDraw, this); this.drawInteraction.on("abortDraw", this.abortTextPrimitiveDraw, this); } }; TextPrimitiveGenerator.prototype.startScale = function () { var event = new PIXI.InteractionEvent(); event.data = new PIXI.InteractionData(); event.data.global = this.target.renderer.plugins.interaction.mouse.global; this.drawInteraction.startDrawScale(event); }; TextPrimitiveGenerator.prototype.abortPositionPointGenerator = function () { this.emit("abortGenerator"); this.destroy(); }; TextPrimitiveGenerator.prototype.endTextPrimitiveDraw = function () { this.emit("endGenerator"); this.end(); }; TextPrimitiveGenerator.prototype.abortTextPrimitiveDraw = function () { this.emit("abortGenerator"); this.destroy(); }; Object.defineProperty(TextPrimitiveGenerator.prototype, "drawInteraction", { get: function () { return this._drawInteraction; }, enumerable: false, configurable: true }); Object.defineProperty(TextPrimitiveGenerator.prototype, "positionPointElement", { get: function () { return this.startElement ? this.startElement : this._positionPointGenerator.positionPointElement; }, enumerable: false, configurable: true }); Object.defineProperty(TextPrimitiveGenerator.prototype, "textPrimitiveElement", { get: function () { return this._textPrimitiveElement; }, enumerable: false, configurable: true }); Object.defineProperty(TextPrimitiveGenerator.prototype, "stickMode", { get: function () { return this.data.stickMode; }, set: function (value) { this.data.stickMode = value; }, enumerable: false, configurable: true }); Object.defineProperty(TextPrimitiveGenerator.prototype, "startElement", { get: function () { return this.data.startElement; }, set: function (value) { this.data.startElement = value; }, enumerable: false, configurable: true }); Object.defineProperty(TextPrimitiveGenerator.prototype, "rotateWithLine", { get: function () { return this.data.rotateWithLine; }, set: function (value) { this.data.rotateWithLine = value; }, enumerable: false, configurable: true }); Object.defineProperty(TextPrimitiveGenerator.prototype, "withScaling", { get: function () { return this.data.withScaling; }, set: function (value) { this.data.withScaling = value; }, enumerable: false, configurable: true }); Object.defineProperty(TextPrimitiveGenerator.prototype, "triggerImmediateEndDraw", { get: function () { return this.data.triggerImmediateEndDraw; }, set: function (value) { this.data.triggerImmediateEndDraw = value; }, enumerable: false, configurable: true }); return TextPrimitiveGenerator; }(BaseGenerator)); export { TextPrimitiveGenerator }; //# sourceMappingURL=TextPrimitiveGenerator.js.map