From 5bc9626dd60f9092337e94b497a0bbe0540b3be2 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Sat, 25 May 2024 02:03:33 +0100 Subject: [PATCH] Handle dpi scaling / zooming in the browser port. --- engine/web/ftejslib.h | 2 +- engine/web/ftejslib.js | 9 ++++++--- engine/web/gl_vidweb.c | 11 +++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/engine/web/ftejslib.h b/engine/web/ftejslib.h index 3ea93069d..0f020037b 100644 --- a/engine/web/ftejslib.h +++ b/engine/web/ftejslib.h @@ -52,7 +52,7 @@ void emscriptenfte_settitle(const char *text); int emscriptenfte_setupcanvas( int width, int height, - void(*Resized)(int newwidth, int newheight), + void(*Resized)(int newwidth, int newheight, float scale), void(*Mouse)(unsigned int devid,int abs,float x,float y,float z,float size), void(*Button)(unsigned int devid, int down, int mbutton), int(*Keyboard)(unsigned int devid, int down, int keycode, int unicode), diff --git a/engine/web/ftejslib.js b/engine/web/ftejslib.js index 09fd7d3f4..f00fe34d3 100644 --- a/engine/web/ftejslib.js +++ b/engine/web/ftejslib.js @@ -634,6 +634,9 @@ console.log("jaxis dev:" + idx + " axis:"+j+" val:"+gp.axes[j]+" mapping:"+gp.ma window.onresize = function() { + let scale = window.devicePixelRatio; //urgh. haxx. + if (scale <= 0) + scale = 1; //emscripten's browser library will revert sizes wrongly or something when we're fullscreen, so make sure that doesn't happen. // if (Browser.isFullScreen) // { @@ -642,11 +645,11 @@ console.log("jaxis dev:" + idx + " axis:"+j+" val:"+gp.axes[j]+" mapping:"+gp.ma // } // else { - var rect = Module['canvas'].getBoundingClientRect(); - Browser.setCanvasSize(rect.width, rect.height, false); + let rect = Module['canvas'].getBoundingClientRect(); + Browser.setCanvasSize(rect.width*scale, rect.height*scale, false); } if (FTEC.evcb.resize != 0) - {{{makeDynCall('vii','FTEC.evcb.resize')}}}(Module['canvas'].width, Module['canvas'].height); + {{{makeDynCall('viif','FTEC.evcb.resize')}}}(Module['canvas'].width, Module['canvas'].height, scale); }; window.onresize(); diff --git a/engine/web/gl_vidweb.c b/engine/web/gl_vidweb.c index 2063b1627..3df611100 100644 --- a/engine/web/gl_vidweb.c +++ b/engine/web/gl_vidweb.c @@ -334,13 +334,20 @@ static void IN_GamePadOrientationEvent(int joydevid, float px,float py,float pz, IN_SetHandPosition(dev, org, ang, NULL, NULL); } -static void VID_Resized(int width, int height) +static void VID_Resized(int width, int height, float scale) { extern cvar_t vid_conautoscale, vid_conwidth; + extern cvar_t vid_dpi_x, vid_dpi_y; vid.pixelwidth = width; vid.pixelheight = height; //Con_Printf("Resized: %i %i\n", vid.pixelwidth, vid.pixelheight); + //if you're zooming in, it should stay looking like its zoomed. + vid.dpi_x = 96*scale; + vid.dpi_y = 96*scale; + Cvar_ForceSetValue(&vid_dpi_x, vid.dpi_x); + Cvar_ForceSetValue(&vid_dpi_y, vid.dpi_y); + Cvar_ForceCallback(&vid_conautoscale); Cvar_ForceCallback(&vid_conwidth); } @@ -544,7 +551,7 @@ qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette) qglViewport (0, 0, vid.pixelwidth, vid.pixelheight); - VID_Resized(vid.pixelwidth, vid.pixelheight); + VID_Resized(vid.pixelwidth, vid.pixelheight, 1); mouseactive = false;