UNPKG

medsurf-draw

Version:

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

175 lines 7.82 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 { Design } from "../../config/design"; import { BaseContainer, BaseContainerImageModel } from "../../bases/elements/BaseContainer"; var SelftestPointModel = (function (_super) { __extends(SelftestPointModel, _super); function SelftestPointModel() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.options = { hasLine: true, lineColor: 0xFFFFFF, lineAlpha: 1, hasFill: false }; return _this; } return SelftestPointModel; }(BaseContainerImageModel)); export { SelftestPointModel }; var SelftestPoint = (function (_super) { __extends(SelftestPoint, _super); function SelftestPoint(model) { var _this = _super.call(this, model) || this; _this.zIndex = Design.wedgePoint.zIndex; _this.modeInteraction.on("default", _this._modeDefault, _this); _this.modeInteraction.on("remove-default", _this._removeModeDefault, _this); _this.modeInteraction.on("selftest", _this._modeSelftest, _this); _this.modeInteraction.on("remove-selftest", _this._removeModeSelftest, _this); _this.selectInteraction = new MedsurfDraw.SelectInteraction(_this); _this.selectInteraction.on("onHover", _this.onHover, _this); _this.selectInteraction.on("onOut", _this.onOut, _this); _this.selectInteraction.on("onSelftest", _this.onSelftest, _this); _this.on("added", function () { _this.image.moveInteraction.on("onMove", _this.onMove, _this); _this.image.zoomInteraction.on("onZoom", _this.onZoom, _this); }); _this.on("removed", function () { _this.image.moveInteraction.off("onMove", _this.onMove, _this); _this.image.zoomInteraction.off("onZoom", _this.onZoom, _this); }); return _this; } SelftestPoint.prototype.init = function () { this.position.set(this.image.position.x + this.selftestPoint.x * this.imageScale.x, this.image.position.y + this.selftestPoint.y * this.imageScale.y); this._selftestPointElement = new MedsurfDraw.Circle({ circle: new PIXI.Circle(0, 0, Design.selftest.selftestRadius), options: Object.assign({}, this.options), lineWidth: Design.selftest.lineWidth }); this.addChild(this._selftestPointElement); this.sortChildren(); this.emit("debounceDraw"); }; SelftestPoint.prototype.draw = function () { this._selftestPointElement.draw(); }; SelftestPoint.prototype.destroy = function (options) { if (this._selftestPointElement) { this._selftestPointElement.destroy(options); } _super.prototype.destroy.call(this, options); }; SelftestPoint.prototype._modeDefault = function () { this.hideItem(); }; SelftestPoint.prototype._removeModeDefault = function () { }; SelftestPoint.prototype._modeSelftest = function () { if (this.data.isSelftest) { this.interactive = true; this.cursor = "select"; this.selectInteraction.reset(); this.on("pointerover", this.selectInteraction.onHover, this.selectInteraction); this.on("pointerout", this.selectInteraction.onOut, this.selectInteraction); this.on("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction); this.on("mouseup", this.selectInteraction.onSelftest, this.selectInteraction); this.showItem(); } else { this.hideItem(); } }; SelftestPoint.prototype._removeModeSelftest = function (parent, mode) { this.interactive = false; this.off("pointerover", this.selectInteraction.onHover, this.selectInteraction); this.off("pointerout", this.selectInteraction.onOut, this.selectInteraction); this.off("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction); this.off("mouseup", this.selectInteraction.onSelftest, this.selectInteraction); if (mode !== 'selftest') { this._selftestPointElement.circle.radius = Design.selftest.selftestRadius; } this.hideItem(); }; SelftestPoint.prototype.onMove = function () { if (!this.selftestPoint) { return; } this.position.set(this.image.position.x + this.selftestPoint.x * this.imageScale.x, this.image.position.y + this.selftestPoint.y * this.imageScale.y); }; SelftestPoint.prototype.onSelftest = function () { this._selftestPointElement.circle.radius = Design.selftest.selftestRadiusSelected; this.emit("debounceDraw"); }; SelftestPoint.prototype.onZoom = function () { if (!this.selftestPoint) { return; } this.position.set(this.image.position.x + this.selftestPoint.x * this.imageScale.x, this.image.position.y + this.selftestPoint.y * this.imageScale.y); }; SelftestPoint.prototype.onHover = function () { this._selftestPointElement.options.lineColor = Design.primitive.lineColorHover; this._selftestPointElement.options.fillColor = Design.primitive.fillColorHover; this.emit("debounceDraw"); }; SelftestPoint.prototype.onOut = function () { this._selftestPointElement.options = Object.assign({}, this.options); this.emit("debounceDraw"); }; Object.defineProperty(SelftestPoint.prototype, "isSelftest", { get: function () { return this.data.isSelftest; }, set: function (value) { this.data.isSelftest = value; }, enumerable: false, configurable: true }); Object.defineProperty(SelftestPoint.prototype, "selftestPoint", { get: function () { return this.data.selftestPoint; }, set: function (value) { this.data.selftestPoint = value; this.position.set(this.image.position.x + this.selftestPoint.x * this.imageScale.x, this.image.position.y + this.selftestPoint.y * this.imageScale.y); }, enumerable: false, configurable: true }); Object.defineProperty(SelftestPoint.prototype, "options", { get: function () { return this.data.options; }, set: function (value) { this.data.options = value; this._selftestPointElement.options = Object.assign({}, this.data.options); this.emit("debounceDraw"); }, enumerable: false, configurable: true }); Object.defineProperty(SelftestPoint.prototype, "selectInteraction", { get: function () { return this._selectInteraction; }, set: function (value) { this._selectInteraction = value; }, enumerable: false, configurable: true }); return SelftestPoint; }(BaseContainer)); export { SelftestPoint }; //# sourceMappingURL=SelftestPoint.js.map