Handle dpi scaling / zooming in the browser port.

This commit is contained in:
Shpoike 2024-05-25 02:03:33 +01:00
parent 44f97c2cc1
commit 5bc9626dd6
3 changed files with 16 additions and 6 deletions

View file

@ -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),

View file

@ -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();

View file

@ -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;