From a5e690d2a062804df22cc6e181102d26d30e1864 Mon Sep 17 00:00:00 2001 From: Shaoxing Wang Date: Wed, 5 Sep 2018 23:26:13 +0800 Subject: [PATCH] Turn scale factor into float for better precision --- app/src/screen.c | 12 ++++++------ app/src/screen.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/screen.c b/app/src/screen.c index af9cc58c..9f8cff51 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -65,23 +65,23 @@ static void set_window_size(struct screen *screen, struct size new_size) { } } -void get_window_scale(SDL_Window *window, int *scale_x, int *scale_y) { +void get_window_scale(SDL_Window *window, float *scale_x, float *scale_y) { int win_w, win_h; SDL_GetWindowSize(window, &win_w, &win_h); int output_w, output_h; SDL_GL_GetDrawableSize(window, &output_w, &output_h); - *scale_x = output_w / win_w; - *scale_y = output_h / win_h; + *scale_x = (float)output_w / win_w; + *scale_y = (float)output_h / win_h; } SDL_bool screen_update_logical_size_if_needed(struct screen *screen) { - int scale_x, scale_y; + float scale_x, scale_y; get_window_scale(screen->window, &scale_x, &scale_y); if (scale_x != screen->scale_x || scale_y != screen->scale_y) { int logical_width, logical_height; SDL_RenderGetLogicalSize(screen->renderer, &logical_width, &logical_height); - logical_width *= (float)scale_x / screen->scale_x; - logical_height *= (float)scale_y / screen->scale_y; + logical_width *= scale_x / screen->scale_x; + logical_height *= scale_y / screen->scale_y; screen->scale_x = scale_x; screen->scale_y = scale_y; if (SDL_RenderSetLogicalSize(screen->renderer, logical_width, logical_height)) { diff --git a/app/src/screen.h b/app/src/screen.h index 32a854b8..41b96aee 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -12,8 +12,8 @@ struct screen { SDL_Renderer *renderer; SDL_Texture *texture; struct size frame_size; - int scale_x; - int scale_y; + float scale_x; + float scale_y; //used only in fullscreen mode to know the windowed window size struct size windowed_window_size; SDL_bool has_frame; @@ -68,7 +68,7 @@ void screen_resize_to_fit(struct screen *screen); // resize window to 1:1 (pixel-perfect) void screen_resize_to_pixel_perfect(struct screen *screen); -void get_window_scale(SDL_Window *window, int *scale_x, int *scale_y); +void get_window_scale(SDL_Window *window, float *scale_x, float *scale_y); SDL_bool screen_update_logical_size_if_needed(struct screen *screen);