medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
180 lines • 8.06 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 { BaseContainer, BaseContainerImageModel } from "../../bases/elements/BaseContainer";
import { Design } from "../../config/design";
var MultiSelectItemModel = (function (_super) {
__extends(MultiSelectItemModel, _super);
function MultiSelectItemModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return MultiSelectItemModel;
}(BaseContainerImageModel));
export { MultiSelectItemModel };
var MultiSelectItemElement = (function (_super) {
__extends(MultiSelectItemElement, _super);
function MultiSelectItemElement(model) {
var _this = this;
throw 'not implemented';
_this = _super.call(this, model) || this;
_this.displayObjects = [];
_this.zIndex = Design.selectElement.zIndex;
_this.on("added", function () {
_this.image.modeInteraction.on("default", _this._modeDefault, _this);
_this.image.modeInteraction.on("remove-default", _this._removeModeDefault, _this);
_this.image.modeInteraction.on("author", _this._modeAuthor, _this);
_this.image.modeInteraction.on("remove-author", _this._removeModeAuthor, _this);
_this.image.modeInteraction.on("setDefaultMode", _this.controlSetDefaultMode, _this);
});
_this.on("removed", function () {
_this.image.modeInteraction.off("default", _this._modeDefault, _this);
_this.image.modeInteraction.off("remove-default", _this._removeModeDefault, _this);
_this.image.modeInteraction.off("author", _this._modeAuthor, _this);
_this.image.modeInteraction.off("remove-author", _this._removeModeAuthor, _this);
_this.image.modeInteraction.off("setDefaultMode", _this.controlSetDefaultMode, _this);
});
return _this;
}
MultiSelectItemElement.prototype.init = function () {
this.hideItem();
this.position.set(0, 0);
this._selectElement = new MedsurfDraw.Rectangle({
rectangle: new PIXI.Rectangle(0, 0, 0, 0),
options: { hasLine: true, lineColor: Design.selectElement.lineColor, lineAlpha: Design.selectElement.lineAlpha, hasFill: true, fillColor: Design.selectElement.fillColor, fillAlpha: Design.selectElement.fillAlpha },
lineWidth: Design.selectElement.lineWidth
});
this.addChild(this._selectElement);
this.sortChildren();
this.draw();
};
MultiSelectItemElement.prototype.draw = function () {
this.hideItem();
var displayObjects = this._getSelectedDisplayObjects();
var rectangle = this._getSelectedItemsRectangle(displayObjects);
if (rectangle) {
rectangle.pad(Design.selectElement.groupPad, Design.selectElement.groupPad);
this._selectElement.rectangle = rectangle;
this.showItem();
this.displayObjects = displayObjects;
}
else {
this.displayObjects = [];
}
this._selectElement.draw();
};
MultiSelectItemElement.prototype.destroy = function (options) {
this.modeInteraction.off("default", this._modeDefault, this);
this.modeInteraction.off("remove-default", this._removeModeDefault, this);
if (this._selectElement) {
this._selectElement.destroy(options);
}
_super.prototype.destroy.call(this, options);
};
MultiSelectItemElement.prototype._getSelectedDisplayObjects = function () {
return this.image.getImageObjects()
.filter(function (displayObject) { return displayObject.modeInteraction && displayObject.modeInteraction.lastMode === 'select_layer_group'; });
};
MultiSelectItemElement.prototype._getSelectedItemsRectangle = function (displayObjects) {
if (displayObjects.length > 0) {
var topLeft_1;
var topRight_1;
var bottomLeft_1;
displayObjects.forEach(function (displayObject) {
var position = displayObject.position;
var rect = displayObject.getRectangle();
if (!topLeft_1) {
topLeft_1 = new PIXI.Point(rect.x, rect.y);
}
else {
if (rect.x < topLeft_1.x) {
topLeft_1.x = rect.x;
}
if (rect.y < topLeft_1.y) {
topLeft_1.y = rect.y;
}
}
if (!topRight_1) {
topRight_1 = new PIXI.Point(rect.x + rect.width);
}
else {
if (rect.x + rect.width > topRight_1.x) {
topRight_1.x = rect.x + rect.width;
}
}
if (!bottomLeft_1) {
bottomLeft_1 = new PIXI.Point(undefined, rect.y + rect.height);
}
else {
if (rect.y + rect.height > bottomLeft_1.y) {
bottomLeft_1.y = rect.y + rect.height;
}
}
});
return new PIXI.Rectangle(topLeft_1.x, topLeft_1.y, topRight_1.x - topLeft_1.x, bottomLeft_1.y - topLeft_1.y);
}
else {
return undefined;
}
};
MultiSelectItemElement.prototype._setEventsForDisplayObjects = function (displayObjects) {
var _this = this;
displayObjects.forEach(function (displayObject) {
if (displayObject.moveInteraction) {
displayObject.moveInteraction.on("endMove", _this.controlSetDefaultMode, _this);
_this._displayObjects.push(displayObject);
}
});
};
MultiSelectItemElement.prototype._unsetEventsForDisplayObjects = function (displayObjects) {
var _this = this;
displayObjects.forEach(function (displayObject) {
if (displayObject.moveInteraction) {
displayObject.moveInteraction.off("endMove", _this.controlSetDefaultMode, _this);
}
});
};
MultiSelectItemElement.prototype._modeDefault = function () {
this.hideItem();
};
MultiSelectItemElement.prototype._removeModeDefault = function () {
this.hideItem();
};
MultiSelectItemElement.prototype._modeAuthor = function () {
this.hideItem();
};
MultiSelectItemElement.prototype._removeModeAuthor = function () {
this.hideItem();
};
MultiSelectItemElement.prototype.controlSetDefaultMode = function () {
this.emit("debounceDraw");
};
Object.defineProperty(MultiSelectItemElement.prototype, "displayObjects", {
get: function () {
return this._displayObjects;
},
set: function (value) {
this._unsetEventsForDisplayObjects(this.displayObjects || []);
this._displayObjects = value;
this._setEventsForDisplayObjects(this.displayObjects);
},
enumerable: false,
configurable: true
});
return MultiSelectItemElement;
}(BaseContainer));
export { MultiSelectItemElement };
//# sourceMappingURL=MultiSelectItemElement.js.map