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?