medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
142 lines • 5.83 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 NumberElementModel = (function (_super) {
__extends(NumberElementModel, _super);
function NumberElementModel() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.rectangle = new PIXI.Rectangle(0, 0, 20, 20);
return _this;
}
return NumberElementModel;
}(BaseContainerImageModel));
export { NumberElementModel };
var NumberElement = (function (_super) {
__extends(NumberElement, _super);
function NumberElement(model) {
var _this = _super.call(this, model) || this;
_this.zIndex = Design.numberElement.zIndex;
_this.position.set(_this.data.rectangle.x, _this.data.rectangle.y);
return _this;
}
NumberElement.prototype.init = function (parent) {
this._backgroundElement = new PIXI.Graphics();
this._backgroundElement.cursor = "select";
this._backgroundElement.interactive = true;
this.addChild(this._backgroundElement);
this._valueElement = new MedsurfDraw.Text({
text: (this.value || 'NAN').toString(),
style: new PIXI.TextStyle({ fill: Design.numberElement.textFillColor, fontSize: Design.numberElement.textFontSize, fontFamily: Design.numberElement.fontFamilyDefault, align: Design.numberElement.alignDefault, wordWrap: Design.numberElement.wordWrapDefault })
});
this.addChild(this._valueElement);
this._numberSliderElement = new MedsurfDraw.NumberSliderElement({
image: this.image,
value: this.value,
minValue: this.minValue,
maxValue: this.maxValue,
squareWidth: Design.numberElement.buttonWidth * Design.numberSliderElement.squareWidthAspect,
squareHeight: Design.numberElement.buttonWidth,
gab: this.gab
});
this._numberSliderElement.on("number", this.onNumber, this);
this.addChild(this._numberSliderElement);
this.sortChildren();
this.emit("debounceDraw");
};
NumberElement.prototype.draw = function () {
this._valueElement.position.set(this.rectangle.x + this.rectangle.width, this.rectangle.y - this.rectangle.height / 2);
this._numberSliderElement.position.set(this._valueElement.x + this._valueElement.width + 5, this._valueElement.y);
this._numberSliderElement.draw();
};
NumberElement.prototype.destroy = function (options) {
if (this._backgroundElement) {
this._backgroundElement.destroy(options);
}
if (this._valueElement) {
this._valueElement.destroy(options);
}
if (this._numberSliderElement) {
this._numberSliderElement.off("number", this.onNumber, this);
this._numberSliderElement.destroy(options);
}
_super.prototype.destroy.call(this, options);
};
NumberElement.prototype.onNumber = function (number) {
this._valueElement.text = number.toString();
this.emit("number", number);
};
Object.defineProperty(NumberElement.prototype, "rectangle", {
get: function () {
return this.data.rectangle;
},
set: function (value) {
this.data.rectangle = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NumberElement.prototype, "value", {
get: function () {
return this.data.value;
},
set: function (value) {
this.data.value = value;
this._valueElement.text = (this.value || "N/A").toString();
this._numberSliderElement.value = this.value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NumberElement.prototype, "minValue", {
get: function () {
return this.data.minValue;
},
set: function (value) {
this.data.minValue = value;
this._numberSliderElement.minValue = this.minValue;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NumberElement.prototype, "maxValue", {
get: function () {
return this.data.maxValue;
},
set: function (value) {
this.data.maxValue = value;
this._numberSliderElement.maxValue = this.maxValue;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NumberElement.prototype, "gab", {
get: function () {
return this.data.gab;
},
set: function (value) {
this.data.gab = value;
this._numberSliderElement.gab = this.gab;
},
enumerable: false,
configurable: true
});
return NumberElement;
}(BaseContainer));
export { NumberElement };
//# sourceMappingURL=NumberElement.js.map