UNPKG

medsurf-draw

Version:

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

122 lines 5.35 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 ScaleSideTypes; (function (ScaleSideTypes) { ScaleSideTypes[ScaleSideTypes["X"] = 0] = "X"; ScaleSideTypes[ScaleSideTypes["Y"] = 1] = "Y"; ScaleSideTypes[ScaleSideTypes["WIDTH"] = 2] = "WIDTH"; ScaleSideTypes[ScaleSideTypes["HEIGHT"] = 3] = "HEIGHT"; ScaleSideTypes[ScaleSideTypes["X_Y"] = 4] = "X_Y"; ScaleSideTypes[ScaleSideTypes["X_HEIGHT"] = 5] = "X_HEIGHT"; ScaleSideTypes[ScaleSideTypes["WIDTH_Y"] = 6] = "WIDTH_Y"; ScaleSideTypes[ScaleSideTypes["WIDTH_HEIGHT"] = 7] = "WIDTH_HEIGHT"; })(ScaleSideTypes || (ScaleSideTypes = {})); var ScaleInteraction = (function (_super) { __extends(ScaleInteraction, _super); function ScaleInteraction(element, pivotCenter) { if (pivotCenter === void 0) { pivotCenter = false; } var _this = _super.call(this, element) || this; _this._pivotCenter = pivotCenter; return _this; } ScaleInteraction.prototype.reset = function () { this._scaleX = 0; this._scaleY = 0; this._isScaling = false; }; ScaleInteraction.prototype.startScale = function (event, scaleSide) { if (scaleSide === void 0) { scaleSide = ScaleSideTypes.WIDTH_HEIGHT; } event.stopPropagation(); this.emit("startScaleStart", event); if (this._isScaling) { return; } this._scaleSide = scaleSide; var scale = this.element.imageScale; this._scaleX = event.data.global.x / scale.x; this._scaleY = event.data.global.y / scale.y; this._isScaling = true; this.emit("startScale", event); }; ScaleInteraction.prototype.onScale = function (event) { if (!this._isScaling) { return; } var scale = this.element.imageScale; var dX = 0; var dY = 0; var dW = 0; var dH = 0; var pW = 1; var pH = 1; if (this._pivotCenter) { pW = 2; pH = 2; } var cosR = Math.cos(this.element.rotation); if (cosR === 0) cosR = 1; var sinR = Math.sin(this.element.rotation); if (sinR === 0) sinR = 1; if (this._scaleSide == ScaleSideTypes.X || this._scaleSide == ScaleSideTypes.X_Y || this._scaleSide == ScaleSideTypes.X_HEIGHT) { dX = (event.data.global.x / scale.x - this._scaleX) / cosR; dW = -1 * dX * pW; this._scaleX = event.data.global.x / scale.x; } if (this._scaleSide == ScaleSideTypes.Y || this._scaleSide == ScaleSideTypes.X_Y || this._scaleSide == ScaleSideTypes.WIDTH_Y) { dY = (event.data.global.y / scale.y - this._scaleY) / sinR; dH = -1 * dY * pH; this._scaleY = event.data.global.y / scale.y; } if (this._scaleSide == ScaleSideTypes.WIDTH || this._scaleSide == ScaleSideTypes.WIDTH_Y || this._scaleSide == ScaleSideTypes.WIDTH_HEIGHT) { dW = (event.data.global.x / scale.x - this._scaleX) * pW / cosR; this._scaleX = event.data.global.x / scale.x; } if (this._scaleSide == ScaleSideTypes.HEIGHT || this._scaleSide == ScaleSideTypes.X_HEIGHT || this._scaleSide == ScaleSideTypes.WIDTH_HEIGHT) { dH = (event.data.global.y / scale.y - this._scaleY) * pH / sinR; this._scaleY = event.data.global.y / scale.y; } if (!(MedsurfDraw.Keyboard.isKeyDown("ShiftLeft") || MedsurfDraw.Keyboard.isKeyDown("ShiftRight"))) { var rectangle = this.element.getRectangle(); if (this._scaleSide == ScaleSideTypes.X_Y || this._scaleSide == ScaleSideTypes.WIDTH_Y) { dH = rectangle.height / rectangle.width * dW; } if (this._scaleSide == ScaleSideTypes.X_HEIGHT || this._scaleSide == ScaleSideTypes.WIDTH_HEIGHT) { dW = rectangle.width / rectangle.height * dH; } } this.emit("onScale", this._scaleSide, dX, dY, dW, dH); }; ScaleInteraction.prototype.endScale = function (event) { event.stopPropagation(); this.emit("endScaleStart", event); if (!this._isScaling) { return; } this._isScaling = false; this.emit("endScale", event); }; return ScaleInteraction; }(BaseElementInteraction)); export { ScaleInteraction }; //# sourceMappingURL=ScaleInteraction.js.map