68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Display = exports.Dimensions = void 0;
|
|
class Dimensions {
|
|
constructor(width, height) {
|
|
this.width = width;
|
|
this.height = height;
|
|
}
|
|
getRatio() {
|
|
return this.width / this.height;
|
|
}
|
|
}
|
|
exports.Dimensions = Dimensions;
|
|
class Display {
|
|
constructor(width, height) {
|
|
this.screen = new Dimensions(width, height);
|
|
this.offset = { x: 0, y: 0 };
|
|
}
|
|
setOffsetX(x) {
|
|
this.offset.x = x;
|
|
}
|
|
setOffsetY(y) {
|
|
this.offset.y = y;
|
|
}
|
|
setWidth(width) {
|
|
this.display.width = width;
|
|
}
|
|
setHeight(height) {
|
|
this.display.height = height;
|
|
}
|
|
setSource(width, height) {
|
|
let offset;
|
|
this.source = new Dimensions(width, height);
|
|
if (this.source.getRatio() > this.screen.getRatio()) {
|
|
this.display = new Dimensions(this.screen.width, Math.floor(this.screen.width / this.source.getRatio()));
|
|
offset = this.screen.height - this.display.height;
|
|
this.offset = { x: 0, y: Math.round(offset / 2) };
|
|
}
|
|
else {
|
|
this.display = new Dimensions(Math.floor(this.source.getRatio() * this.screen.height), this.screen.height);
|
|
offset = this.screen.width - this.display.width;
|
|
this.offset = { x: Math.round(offset / 2), y: 0 };
|
|
}
|
|
}
|
|
getOutgoingPosition() {
|
|
return {
|
|
w: this.display.width,
|
|
h: this.display.height,
|
|
x: this.offset.x,
|
|
y: this.offset.y
|
|
};
|
|
}
|
|
getDimensions() {
|
|
return this.display;
|
|
}
|
|
getOffset() {
|
|
return this.offset;
|
|
}
|
|
getScreen() {
|
|
return this.screen;
|
|
}
|
|
getSource() {
|
|
return this.source;
|
|
}
|
|
}
|
|
exports.Display = Display;
|
|
module.exports = { Display, Dimensions };
|
|
//# sourceMappingURL=index.js.map
|