2024-07-12 13:51:39 +00:00
|
|
|
"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 };
|
|
|
|
}
|
2024-08-09 20:20:07 +00:00
|
|
|
setOffsetX(x) {
|
|
|
|
this.offset.x = x;
|
|
|
|
}
|
|
|
|
setOffsetY(y) {
|
|
|
|
this.offset.y = y;
|
|
|
|
}
|
2024-07-12 13:51:39 +00:00
|
|
|
setSource(width, height) {
|
2024-08-15 02:43:02 +00:00
|
|
|
let offset;
|
2024-07-12 13:51:39 +00:00
|
|
|
this.source = new Dimensions(width, height);
|
|
|
|
if (this.source.getRatio() > this.screen.getRatio()) {
|
2024-08-15 02:43:02 +00:00
|
|
|
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) };
|
2024-07-12 13:51:39 +00:00
|
|
|
}
|
|
|
|
else {
|
2024-08-15 02:43:02 +00:00
|
|
|
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 };
|
2024-07-12 13:51:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
getDimensions() {
|
|
|
|
return {
|
|
|
|
w: this.display.width,
|
|
|
|
h: this.display.height,
|
|
|
|
x: this.offset.x,
|
|
|
|
y: this.offset.y
|
|
|
|
};
|
|
|
|
}
|
2024-08-15 02:43:02 +00:00
|
|
|
getScreen() {
|
|
|
|
return this.screen;
|
|
|
|
}
|
2024-08-16 04:52:46 +00:00
|
|
|
getSource() {
|
|
|
|
return this.source;
|
|
|
|
}
|
2024-07-12 13:51:39 +00:00
|
|
|
}
|
|
|
|
exports.Display = Display;
|
|
|
|
module.exports = { Display };
|
|
|
|
//# sourceMappingURL=index.js.map
|