mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Emscripten: use a fake size for external sizing check
The check would fail if the canvas happened to be the correct size already. (#66, mentioned in #58)
This commit is contained in:
parent
80d690a2a0
commit
1767d09187
@ -206,21 +206,22 @@ Emscripten_CreateWindow(_THIS, SDL_Window * window)
|
|||||||
scaled_w = SDL_floor(window->w * wdata->pixel_ratio);
|
scaled_w = SDL_floor(window->w * wdata->pixel_ratio);
|
||||||
scaled_h = SDL_floor(window->h * wdata->pixel_ratio);
|
scaled_h = SDL_floor(window->h * wdata->pixel_ratio);
|
||||||
|
|
||||||
emscripten_set_canvas_size(scaled_w, scaled_h);
|
/* set a fake size to check if there is any CSS sizing the canvas */
|
||||||
|
emscripten_set_canvas_size(1, 1);
|
||||||
emscripten_get_element_css_size(NULL, &css_w, &css_h);
|
emscripten_get_element_css_size(NULL, &css_w, &css_h);
|
||||||
|
|
||||||
wdata->external_size = SDL_floor(css_w) != scaled_w || SDL_floor(css_h) != scaled_h;
|
wdata->external_size = SDL_floor(css_w) != 1 || SDL_floor(css_h) != 1;
|
||||||
|
|
||||||
if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) {
|
if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) {
|
||||||
/* external css has resized us */
|
/* external css has resized us */
|
||||||
scaled_w = css_w * wdata->pixel_ratio;
|
scaled_w = css_w * wdata->pixel_ratio;
|
||||||
scaled_h = css_h * wdata->pixel_ratio;
|
scaled_h = css_h * wdata->pixel_ratio;
|
||||||
|
|
||||||
emscripten_set_canvas_size(scaled_w, scaled_h);
|
|
||||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
|
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emscripten_set_canvas_size(scaled_w, scaled_h);
|
||||||
|
|
||||||
/* if the size is not being controlled by css, we need to scale down for hidpi */
|
/* if the size is not being controlled by css, we need to scale down for hidpi */
|
||||||
if (!wdata->external_size) {
|
if (!wdata->external_size) {
|
||||||
if (wdata->pixel_ratio != 1.0f) {
|
if (wdata->pixel_ratio != 1.0f) {
|
||||||
|
Loading…
Reference in New Issue
Block a user