Fix web simulator

This commit is contained in:
lolocomotive
2021-12-24 16:58:16 +01:00
committed by M4x1m3
parent fc3941511f
commit bf8f8bcb27
2 changed files with 5 additions and 42 deletions

View File

@@ -587,24 +587,13 @@ Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *u
double w = window_data->window->w; double w = window_data->window->w;
double h = window_data->window->h; double h = window_data->window->h;
if(window_data->external_size) {
emscripten_get_element_css_size(window_data->canvas_id, &w, &h);
}
emscripten_set_canvas_element_size(window_data->canvas_id, w * window_data->pixel_ratio, h * window_data->pixel_ratio);
/* set_canvas_size unsets this */
if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
emscripten_set_element_css_size(window_data->canvas_id, w, h);
}
if (force) { if (force) {
/* force the event to trigger, so pixel ratio changes can be handled */ /* force the event to trigger, so pixel ratio changes can be handled */
window_data->window->w = 0; window_data->window->w = 0;
window_data->window->h = 0; window_data->window->h = 0;
} }
SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, w, h); SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, 320, 240);
} }
} }

View File

@@ -197,38 +197,12 @@ Emscripten_CreateWindow(_THIS, SDL_Window * window)
} }
wdata->canvas_id = SDL_strdup("#canvas"); wdata->canvas_id = SDL_strdup("#canvas");
wdata->pixel_ratio = 320 / 240;
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { window->w = 320;
wdata->pixel_ratio = emscripten_get_device_pixel_ratio(); window->h = 240;
} else {
wdata->pixel_ratio = 1.0f;
}
scaled_w = SDL_floor(window->w * wdata->pixel_ratio); emscripten_set_canvas_element_size(wdata->canvas_id, 320, 240);
scaled_h = SDL_floor(window->h * wdata->pixel_ratio);
/* set a fake size to check if there is any CSS sizing the canvas */
emscripten_set_canvas_element_size(wdata->canvas_id, 1, 1);
emscripten_get_element_css_size(wdata->canvas_id, &css_w, &css_h);
wdata->external_size = SDL_floor(css_w) != 1 || SDL_floor(css_h) != 1;
if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) {
/* external css has resized us */
scaled_w = css_w * wdata->pixel_ratio;
scaled_h = css_h * wdata->pixel_ratio;
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
}
emscripten_set_canvas_element_size(wdata->canvas_id, scaled_w, scaled_h);
/* if the size is not being controlled by css, we need to scale down for hidpi */
if (!wdata->external_size) {
if (wdata->pixel_ratio != 1.0f) {
/*scale canvas down*/
emscripten_set_element_css_size(wdata->canvas_id, window->w, window->h);
}
}
#if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_EGL
if (window->flags & SDL_WINDOW_OPENGL) { if (window->flags & SDL_WINDOW_OPENGL) {