filmout_manager/dist/display/index.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Display = void 0;
class Dimensions {
constructor(width, height) {
this.width = width;
this.height = height;
}
getRatio() {
return this.width / this.height;
}
}
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;
}
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.source.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 };
}
}
getDimensions() {
return {
w: this.display.width,
h: this.display.height,
x: this.offset.x,
y: this.offset.y
};
}
getScreen() {
return this.screen;
}
getSource() {
return this.source;
}
}
exports.Display = Display;
module.exports = { Display };
//# sourceMappingURL=index.js.map