medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
154 lines • 5.97 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 { BaseElementInteraction } from "../bases/interactions/BaseElementInteraction";
import { debounce } from 'debounce';
export var MOVE_HITTEST_EXTENSION = 200;
var MoveInteraction = (function (_super) {
__extends(MoveInteraction, _super);
function MoveInteraction(element, isImage) {
if (isImage === void 0) { isImage = false; }
var _this = _super.call(this, element) || this;
_this._moveDelta = 0.1;
_this._moveDeltaScaleCounterLimit = 5;
_this._isMoving = false;
_this._isMoveLock = false;
_this._isImage = isImage;
_this._moveDeltaScaleCounter = 0;
_this._moveDeltaScale = 1;
return _this;
}
MoveInteraction.prototype.reset = function () {
this._moveX = 0;
this._moveY = 0;
this._isMoving = false;
this._isMoveLock = false;
};
MoveInteraction.prototype.onMoveHover = function (event) {
event.stopPropagation();
this.element.cursor = "move";
this.emit("onMoveHover", event);
};
MoveInteraction.prototype.startMove = function (event) {
event.stopPropagation();
this.element.cursor = "move";
this.emit("startMoveStart", event);
if (this.isMoving) {
return;
}
var scale = (this._isImage) ? { x: 1, y: 1 } : this.element.imageScale;
this._moveX = event.data.global.x / scale.x;
this._moveY = event.data.global.y / scale.y;
this._isMoving = true;
this._isMoveLock = false;
this.emit("startMove", event);
};
MoveInteraction.prototype.resetMove = function (event) {
event.stopPropagation();
this.emit("resetMoveStart", event);
if (!this.isMoving) {
return;
}
var scale = (this._isImage) ? { x: 1, y: 1 } : this.element.imageScale;
this._moveX = event.data.global.x / scale.x;
this._moveY = event.data.global.y / scale.y;
this.emit("resetMove", event);
};
MoveInteraction.prototype.onMove = function (event) {
if (!this.isMoving) {
return;
}
this._isMoveLock = true;
var scale = (this._isImage) ? { x: 1, y: 1 } : this.element.imageScale;
var dX = event.data.global.x / scale.x - this._moveX;
var dY = event.data.global.y / scale.y - this._moveY;
this._moveX = event.data.global.x / scale.x;
this._moveY = event.data.global.y / scale.y;
this.emit("onMove", event, dX, dY);
};
MoveInteraction.prototype.endMove = function (event) {
event.stopPropagation();
this.element.cursor = "default";
this.emit("endMoveStart", event);
if (!this.isMoving) {
return;
}
this._isMoving = false;
this.emit("endMove", event);
if (!this._isMoveLock) {
this.emit("endMoveLock", event);
}
else {
this._isMoveLock = false;
}
};
MoveInteraction.prototype.moveUp = function (event) {
if (!this._isMoving) {
this.emit("startMove", event);
this._isMoving = true;
}
if (this._moveDeltaScaleCounter++ % this._moveDeltaScaleCounterLimit == 0) {
this._moveDeltaScale++;
}
this.emit("onMove", event, 0, -1 * this._moveDelta * this._moveDeltaScale);
};
MoveInteraction.prototype.moveRight = function (event) {
if (!this._isMoving) {
this.emit("startMove", event);
this._isMoving = true;
}
if (this._moveDeltaScaleCounter++ % this._moveDeltaScaleCounterLimit == 0) {
this._moveDeltaScale++;
}
this.emit("onMove", event, this._moveDelta * this._moveDeltaScale, 0);
};
MoveInteraction.prototype.moveDown = function (event) {
if (!this._isMoving) {
this.emit("startMove", event);
this._isMoving = true;
}
if (this._moveDeltaScaleCounter++ % this._moveDeltaScaleCounterLimit == 0) {
this._moveDeltaScale++;
}
this.emit("onMove", event, 0, this._moveDelta * this._moveDeltaScale);
};
MoveInteraction.prototype.moveLeft = function (event) {
if (!this._isMoving) {
this.emit("startMove", event);
this._isMoving = true;
}
if (this._moveDeltaScaleCounter++ % this._moveDeltaScaleCounterLimit == 0) {
this._moveDeltaScale++;
}
this.emit("onMove", event, -1 * this._moveDelta * this._moveDeltaScale, 0);
};
MoveInteraction.prototype.moveRelease = function () {
this._moveDeltaScaleCounter = 0;
this._moveDeltaScale = 1;
this._isMoving = false;
debounce(this.endMove.bind(this, new PIXI.InteractionEvent()), 50).bind(this)();
};
Object.defineProperty(MoveInteraction.prototype, "isMoving", {
get: function () {
return this._isMoving;
},
enumerable: false,
configurable: true
});
return MoveInteraction;
}(BaseElementInteraction));
export { MoveInteraction };
//# sourceMappingURL=MoveInteraction.js.map