medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
107 lines • 5.21 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 { Design } from "../../config/design";
import { BaseContainer, BaseContainerImageModel } from "../../bases/elements/BaseContainer";
var RotateElementModel = (function (_super) {
__extends(RotateElementModel, _super);
function RotateElementModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return RotateElementModel;
}(BaseContainerImageModel));
export { RotateElementModel };
var RotateElement = (function (_super) {
__extends(RotateElement, _super);
function RotateElement(model) {
var _this = _super.call(this, model) || this;
_this.zIndex = Design.rotate.zIndex;
_this._rotateInteraction = new MedsurfDraw.RotateInteraction(_this);
return _this;
}
RotateElement.prototype.init = function () {
var scale = this.imageScale.x * Design.positionPoint.scaleAspect;
var radius = Design.positionPoint.radius;
radius = Math.floor(radius / scale);
var lineWidth = Design.rotate.lineWidth / scale;
var cornerRadius = Design.rotate.cornerRadius / scale / 2;
this._rotateCircleElement = new MedsurfDraw.Circle({
circle: new PIXI.Circle(this.rectangle.x, this.rectangle.y, cornerRadius),
options: { hasLine: true, lineColor: Design.rotate.lineColor, lineAlpha: Design.rotate.lineAlpha, hasFill: true, fillColor: Design.rotate.fillColor, fillAlpha: Design.rotate.fillAlpha },
lineWidth: lineWidth
});
this._rotateCircleElement.interactive = true;
this._rotateCircleElement.cursor = "rotate";
this._rotateCircleElement.on("mousedown", this._rotateInteraction.startRotate, this._rotateInteraction);
this._rotateCircleElement.on("pointermove", this._rotateInteraction.onRotate, this._rotateInteraction);
this._rotateCircleElement.on("mouseup", this._rotateInteraction.endRotate, this._rotateInteraction);
this._rotateCircleElement.on("pointerupoutside", this._rotateInteraction.endRotate, this._rotateInteraction);
this.addChild(this._rotateCircleElement);
this.sortChildren();
this.emit("debounceDraw");
};
RotateElement.prototype.draw = function () {
var scale = this.imageScale.x * Design.rotate.scaleAspect;
if (scale > 1) {
scale = 1;
}
var lineWidth = Design.rotate.lineWidth / scale;
var cornerRadius = Design.rotate.cornerRadius / scale / 2;
this._rotateCircleElement.lineWidth = lineWidth;
this._rotateCircleElement.circle = new PIXI.Circle(this.rectangle.x, this.rectangle.y - this.rectangle.height / 2 - Design.rotate.rotationDY, cornerRadius);
this._rotateCircleElement.draw();
};
RotateElement.prototype.destroy = function (options) {
if (this.rotateInteraction) {
this.rotateInteraction.removeAllListeners();
}
if (this._rotateCircleElement) {
this._rotateCircleElement.off("mousedown", this._rotateInteraction.startRotate, this._rotateInteraction);
this._rotateCircleElement.off("pointermove", this._rotateInteraction.onRotate, this._rotateInteraction);
this._rotateCircleElement.off("mouseup", this._rotateInteraction.endRotate, this._rotateInteraction);
this._rotateCircleElement.off("pointerupoutside", this._rotateInteraction.endRotate, this._rotateInteraction);
this._rotateCircleElement.destroy(options);
}
_super.prototype.destroy.call(this, options);
};
RotateElement.prototype.onImageZoom = function (scaleX, scaleY) {
this.emit("debounceDraw");
};
Object.defineProperty(RotateElement.prototype, "rotateInteraction", {
get: function () {
return this._rotateInteraction;
},
set: function (value) {
this._rotateInteraction = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RotateElement.prototype, "rectangle", {
get: function () {
return this.data.rectangle;
},
set: function (value) {
this.data.rectangle = value;
},
enumerable: false,
configurable: true
});
return RotateElement;
}(BaseContainer));
export { RotateElement };
//# sourceMappingURL=RotateElement.js.map