From 9d6f07f98c2d942bb062f8cdcb99faf6e2e225fd Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sat, 11 Mar 2017 15:20:49 +0900 Subject: [PATCH] Add zoom support --- docs/xsystem35.html | 12 ++++++++++-- src/sdl_mode.c | 6 ++++++ web/shell/shell.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/docs/xsystem35.html b/docs/xsystem35.html index b19745e..ef3a375 100644 --- a/docs/xsystem35.html +++ b/docs/xsystem35.html @@ -26,8 +26,16 @@
-
diff --git a/src/sdl_mode.c b/src/sdl_mode.c index 1d05626..3cbe6e3 100644 --- a/src/sdl_mode.c +++ b/src/sdl_mode.c @@ -25,6 +25,9 @@ #include #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif #include "portab.h" #include "system.h" @@ -64,4 +67,7 @@ void sdl_setWindowSize(int x, int y, int w, int h) { SDL_TEXTUREACCESS_STATIC, w, h); //ms_active = (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ? TRUE : FALSE; +#ifdef __EMSCRIPTEN__ + EM_ASM( xsystem35.shell.windowSizeChanged(); ); +#endif } diff --git a/web/shell/shell.ts b/web/shell/shell.ts index 0d1a349..a3c0f27 100644 --- a/web/shell/shell.ts +++ b/web/shell/shell.ts @@ -28,6 +28,7 @@ namespace xsystem35 { class System35Shell { private imageLoader: ImageLoader; status: HTMLElement = document.getElementById('status'); + private zoom:ZoomManager; constructor() { this.imageLoader = new ImageLoader(this); @@ -56,6 +57,7 @@ class System35Shell { } ]; xsystem35.cdPlayer = new CDPlayer(this.imageLoader); + this.zoom = new ZoomManager(); } setStatus(text: string) { @@ -63,6 +65,10 @@ class System35Shell { this.status.innerHTML = text; } + windowSizeChanged() { + this.zoom.handleZoom(); + } + private fsyncTimer: number; syncfs(fname: string) { window.clearTimeout(this.fsyncTimer); @@ -116,4 +122,45 @@ class CDPlayer { } } +class ZoomManager { + private canvas: HTMLCanvasElement; + private zoomSelect: HTMLInputElement; + private smoothingCheckbox: HTMLInputElement; + + constructor() { + this.canvas = $('#canvas'); + this.zoomSelect = $('#zoom'); + this.zoomSelect.addEventListener('change', this.handleZoom.bind(this)); + this.zoomSelect.value = localStorage.getItem('zoom'); + this.smoothingCheckbox = $('#smoothing'); + this.smoothingCheckbox.addEventListener('change', this.handleSmoothing.bind(this)); + if (localStorage.getItem('smoothing') == 'false') { + this.smoothingCheckbox.checked = false; + this.handleSmoothing(); + } + } + + handleZoom() { + var value = this.zoomSelect.value; + localStorage.setItem('zoom', value); + var contentsStyle = $('.contents').style; + if (value == 'fit') { + contentsStyle.maxWidth = 'none'; + contentsStyle.width = this.canvas.style.width = '100%'; + } else { + var ratio = Number(value); + contentsStyle.maxWidth = 'none'; + contentsStyle.width = this.canvas.style.width = this.canvas.width * ratio + 'px'; + } + } + + private handleSmoothing() { + localStorage.setItem('smoothing', String(this.smoothingCheckbox.checked)); + if (this.smoothingCheckbox.checked) + this.canvas.classList.remove('pixelated'); + else + this.canvas.classList.add('pixelated'); + } +} + xsystem35.shell = new System35Shell();