From 1da04b7ad7b404bf42e9e781100393f73cb59df0 Mon Sep 17 00:00:00 2001 From: kdx Date: Mon, 27 Nov 2023 09:01:12 +0100 Subject: ratio setting --- headers/TZR.h | 1 + headers/TZR_types.h | 1 + sources/TZR_DrawEnd.c | 7 ++++--- sources/TZR_Init.c | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/headers/TZR.h b/headers/TZR.h index b091233..7d55471 100644 --- a/headers/TZR.h +++ b/headers/TZR.h @@ -15,6 +15,7 @@ .height=224, \ .scale=1.0f, \ .target_fps=60, \ + .ratio=1.0f, \ .pixel_perfect=true, \ .hd_render=false, \ .scale_linear=false, \ diff --git a/headers/TZR_types.h b/headers/TZR_types.h index 105ac38..cd0baad 100644 --- a/headers/TZR_types.h +++ b/headers/TZR_types.h @@ -57,6 +57,7 @@ struct TZR_Config { int height; float scale; int target_fps; + float ratio; bool pixel_perfect; bool hd_render; bool scale_linear; diff --git a/sources/TZR_DrawEnd.c b/sources/TZR_DrawEnd.c index c5449e1..a1d09da 100644 --- a/sources/TZR_DrawEnd.c +++ b/sources/TZR_DrawEnd.c @@ -20,17 +20,18 @@ pixel_draw_end(void) win_w = win_w ? win_w : 1; win_h = win_h ? win_h : 1; - const float ratio_w = win_w / (float)___tzr_config.width; + const int width = ___tzr_config.width * ___tzr_config.ratio; + const float ratio_w = win_w / (float)(width); const float ratio_h = win_h / (float)___tzr_config.height; ___tzr_scale = (ratio_w < ratio_h) ? ratio_w : ratio_h; if (___tzr_scale > 1.0f && ___tzr_config.pixel_perfect) ___tzr_scale = (int)___tzr_scale; - ___tzr_off_x = (win_w - ___tzr_config.width * ___tzr_scale) / 2; + ___tzr_off_x = (win_w - width * ___tzr_scale) / 2; ___tzr_off_y = (win_h - ___tzr_config.height * ___tzr_scale) / 2; const SDL_Rect dest = { ___tzr_off_x, ___tzr_off_y, - ___tzr_config.width * ___tzr_scale, + width * ___tzr_scale, ___tzr_config.height * ___tzr_scale }; diff --git a/sources/TZR_Init.c b/sources/TZR_Init.c index a80880e..1fd23ee 100644 --- a/sources/TZR_Init.c +++ b/sources/TZR_Init.c @@ -45,7 +45,8 @@ _TZR_Init(const TZR_Config *config) SDL_CreateWindow(config->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - ___tzr_config.width * ___tzr_config.scale, + ___tzr_config.width * ___tzr_config.ratio + * ___tzr_config.scale, ___tzr_config.height * ___tzr_config.scale, SDL_WINDOW_RESIZABLE); if (___tzr_window == NULL) -- cgit v1.2.3