medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
188 lines • 8.15 kB
JavaScript
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 { debounce } from 'debounce';
var BaseContainerModel = (function () {
function BaseContainerModel() {
}
return BaseContainerModel;
}());
export { BaseContainerModel };
var BaseContainerImageModel = (function (_super) {
__extends(BaseContainerImageModel, _super);
function BaseContainerImageModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BaseContainerImageModel;
}(BaseContainerModel));
export { BaseContainerImageModel };
var BaseContainer = (function (_super) {
__extends(BaseContainer, _super);
function BaseContainer(data) {
var _this = _super.call(this) || this;
_this.data = data;
_this.modeInteraction = new MedsurfDraw.ModeInteraction(_this);
_this.modeInteraction.on("init", _this.init, _this);
_this._debounceStartDrawingMethod = debounce(_this.startDrawing.bind(_this), 500).bind(_this);
_this._debounceDrawMethod = debounce(_this.draw.bind(_this), 20).bind(_this);
_this.on("added", function (parent) {
if (_this instanceof MedsurfDraw.Image || _this instanceof MedsurfDraw.NavigatorElement
|| _this instanceof MedsurfDraw.VirtualPointerElement) {
parent.on("setDefaultMode", _this.modeInteraction.setDefaultMode, _this.modeInteraction);
parent.on("setMode", _this.modeInteraction.setMode, _this.modeInteraction);
}
else if (_this instanceof MedsurfDraw.MenuElement || _this instanceof MedsurfDraw.SelftestPoint) {
_this.image.on('imageZoom', _this.onImageZoom, _this);
_this.image.modeInteraction.on("setDefaultMode", _this.modeInteraction.setDefaultMode, _this.modeInteraction);
_this.image.modeInteraction.on("setMode", _this.modeInteraction.setMode, _this.modeInteraction);
}
else {
_this.image.on('imageZoom', _this.onImageZoom, _this);
parent.modeInteraction.on("setDefaultMode", _this.modeInteraction.setDefaultMode, _this.modeInteraction);
parent.modeInteraction.on("setMode", _this.modeInteraction.setMode, _this.modeInteraction);
}
_this.on("debounceStart", _this._debounceStartDrawingMethod);
_this.on("debounceDraw", _this._debounceDrawMethod);
});
_this.on("removed", function (parent) {
if (_this instanceof MedsurfDraw.Image || _this instanceof MedsurfDraw.NavigatorElement || _this instanceof MedsurfDraw.VirtualPointerElement) {
parent.off("setDefaultMode", _this.modeInteraction.setDefaultMode, _this.modeInteraction);
parent.off("setMode", _this.modeInteraction.setMode, _this.modeInteraction);
}
else if (_this instanceof MedsurfDraw.MenuElement || _this instanceof MedsurfDraw.SelftestPoint) {
_this.image.off('imageZoom', _this.onImageZoom, _this);
_this.image.modeInteraction.off("setDefaultMode", _this.modeInteraction.setDefaultMode, _this.modeInteraction);
_this.image.modeInteraction.off("setMode", _this.modeInteraction.setMode, _this.modeInteraction);
}
else {
_this.image.off('imageZoom', _this.onImageZoom, _this);
parent.modeInteraction.off("setDefaultMode", _this.modeInteraction.setDefaultMode, _this.modeInteraction);
parent.modeInteraction.off("setMode", _this.modeInteraction.setMode, _this.modeInteraction);
}
_this.off("debounceStart", _this._debounceStartDrawingMethod);
_this.off("debounceDraw", _this._debounceDrawMethod);
});
return _this;
}
BaseContainer.prototype.startDrawing = function () {
this.on("debounceDraw", this._debounceDrawMethod);
};
BaseContainer.prototype.stopDrawing = function (selfheal_timeout) {
var _this = this;
this.off("debounceDraw", this._debounceDrawMethod);
setTimeout(function () {
_this.emit("debounceStart");
}, selfheal_timeout);
};
BaseContainer.prototype.destroy = function (options) {
if (this.modeInteraction) {
this.modeInteraction.removeAllListeners();
}
this.removeAllListeners();
_super.prototype.destroy.call(this, options);
};
BaseContainer.prototype.getRectangle = function () {
var position = this.position;
var bounds = this.getLocalBounds();
return new PIXI.Rectangle(position.x + bounds.x, position.y + bounds.y, bounds.width, bounds.height);
};
BaseContainer.prototype.getElementRectangle = function () {
return this.getRectangle();
};
BaseContainer.prototype.getRotation = function () {
return this.rotation;
};
BaseContainer.prototype.showItem = function () {
this.visible = true;
this.emit("debounceDraw");
};
BaseContainer.prototype.hideItem = function () {
this.visible = false;
};
BaseContainer.prototype.toggleItem = function (override) {
this.visible = override || !this.visible;
};
BaseContainer.prototype.onImageZoom = function (scaleX, scaleY) {
};
Object.defineProperty(BaseContainer.prototype, "data", {
get: function () {
return this._data;
},
set: function (value) {
this._data = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseContainer.prototype, "image", {
get: function () {
if (this.data.hasOwnProperty("image")) {
return this.data.image;
}
debugger;
throw 'Not implemented';
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseContainer.prototype, "imageCanvas", {
get: function () {
if (this.data.hasOwnProperty("image")) {
return this.data.image.canvas;
}
debugger;
throw 'Not implemented';
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseContainer.prototype, "imageScale", {
get: function () {
if (this.data.hasOwnProperty("image")) {
return this.data.image.imageScale;
}
debugger;
throw 'Not implemented';
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseContainer.prototype, "imageDimensions", {
get: function () {
if (this.data.hasOwnProperty("image")) {
return this.data.image.imageDimensions;
}
debugger;
throw 'Not implemented';
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseContainer.prototype, "modeInteraction", {
get: function () {
return this._modeInteraction;
},
set: function (value) {
this._modeInteraction = value;
},
enumerable: false,
configurable: true
});
return BaseContainer;
}(PIXI.Container));
export { BaseContainer };
//# sourceMappingURL=BaseContainer.js.map