From bf6e399ce91de1a4a8de3d596c23cb102bf6cabd Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Wed, 7 Oct 2020 15:56:38 -0500 Subject: [PATCH] vcs: resize screen --- src/ide/ui.ts | 7 +++++-- src/platform/vcs.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ide/ui.ts b/src/ide/ui.ts index 18373d5e..39f6d757 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -1958,7 +1958,7 @@ function replaceURLState() { function addPageFocusHandlers() { var hidden = false; document.addEventListener("visibilitychange", () => { - if (document.visibilityState == 'hidden' && platform.isRunning()) { + if (document.visibilityState == 'hidden' && platform && platform.isRunning()) { _pause(); hidden = true; } else if (document.visibilityState == 'visible' && hidden) { @@ -1973,11 +1973,14 @@ function addPageFocusHandlers() { } }); $(window).on("blur", () => { - if (platform.isRunning()) { + if (platform && platform.isRunning()) { _pause(); hidden = true; } }); + $(window).on("orientationchange", () => { + if (platform) setTimeout(platform.resize.bind(platform), 200); + }); } // TODO: merge w/ embed.html somehow? diff --git a/src/platform/vcs.ts b/src/platform/vcs.ts index 0a86c15e..83736372 100644 --- a/src/platform/vcs.ts +++ b/src/platform/vcs.ts @@ -108,6 +108,7 @@ class VCSPlatform extends BasePlatform { }; var jacanvas = $("#javatari-screen").find("canvas"); jacanvas.mousedown(rasterPosBreakFn); + this.resize(); } loadROM(title, data) { @@ -389,6 +390,13 @@ class VCSPlatform extends BasePlatform { connectProbe(probe:ProbeAll) { this.probe = probe || this.nullProbe; } + + // resizing + resize() { + var scale = Math.min(1, ($('#emulator').width() - 24) / 640); + var xt = (1 - scale) * 50; + $('#javatari-div').css('transform', `translateX(-${xt}%) translateY(-${xt}%) scale(${scale})`); + } }; // TODO: mixin for Base6502Platform?