import type { fdOutgoingPosition } from '../fd'; export class Dimensions { public width : number; public height : number; constructor (width : number, height : number) { this.width = width; this.height = height; } public getRatio () : number { return this.width / this.height; } } interface Offset { x : number; y : number; } export class Display { private screen : Dimensions; private source : Dimensions; private display : Dimensions; private offset : Offset; constructor (width : number, height : number) { this.screen = new Dimensions(width, height); this.offset = { x: 0, y : 0 } } public setOffsetX (x : number) { this.offset.x = x; } public setOffsetY (y : number) { this.offset.y = y; } public setWidth (width : number) { this.display.width = width; } public setHeight (height : number) { this.display.height = height; } public setSource (width : number, height : number) { let offset : number; 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 }; } } public getOutgoingPosition () : fdOutgoingPosition { return { w : this.display.width, h : this.display.height, x : this.offset.x, y : this.offset.y } } public getDimensions () : Dimensions { return this.display; } public getOffset () : Offset { return this.offset; } public getScreen () : Dimensions { return this.screen; } public getSource () : Dimensions { return this.source; } } module.exports = { Display, Dimensions }; export type { Offset };