refactor display scaling again
- fix screen blanking bug - turns out the timeout wasn't needed (only added it because I thought writing so many times was causing the above bug)
This commit is contained in:
parent
3b4d6ce6df
commit
6fd6028a25
|
|
@ -416,15 +416,16 @@ export default class CollabVMClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onWindowResize(e: Event) {
|
private onWindowResize(e: Event) {
|
||||||
var t = setTimeout(() => {
|
if (!this.connectedToVM) return;
|
||||||
if (!this.connectedToVM) return;
|
// If the canvas is the same size as the screen, don't bother redrawing
|
||||||
var copyctx = (this.actualScreenSize.width !== this.canvasScale.width || this.actualScreenSize.height !== this.canvasScale.height) ? this.unscaledCanvas : this.canvas;
|
if (window.innerWidth >= this.actualScreenSize.width && this.canvas.width === this.actualScreenSize.width) return;
|
||||||
this.recalculateCanvasScale(this.actualScreenSize.width, this.actualScreenSize.height);
|
if (this.actualScreenSize.width === this.canvasScale.width && this.actualScreenSize.height === this.canvasScale.height) {
|
||||||
this.canvas.width = this.canvasScale.width;
|
this.unscaledCtx.drawImage(this.canvas, 0, 0);
|
||||||
this.canvas.height = this.canvasScale.height;
|
}
|
||||||
this.ctx.drawImage(copyctx, 0, 0, this.actualScreenSize.width, this.actualScreenSize.height, 0, 0, this.canvas.width, this.canvas.height);
|
this.recalculateCanvasScale(this.actualScreenSize.width, this.actualScreenSize.height);
|
||||||
}, 500);
|
this.canvas.width = this.canvasScale.width;
|
||||||
window.addEventListener('resize', () => clearTimeout(t), {once: true});
|
this.canvas.height = this.canvasScale.height;
|
||||||
|
this.ctx.drawImage(this.unscaledCanvas, 0, 0, this.actualScreenSize.width, this.actualScreenSize.height, 0, 0, this.canvas.width, this.canvas.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private recalculateCanvasScale(width: number, height: number) {
|
private recalculateCanvasScale(width: number, height: number) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user