From 06f6d9501f43af7a9b1c4f1e9e92a75ce15c1acf Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Thu, 20 Jun 2024 22:29:15 +0900 Subject: Improve position of calculation --- src/ray.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/ray.c b/src/ray.c index ad312f4..cf5d179 100644 --- a/src/ray.c +++ b/src/ray.c @@ -45,14 +45,41 @@ window\n"); EndDrawing(); } +static int +min(int x, int y) +{ + if (x < y) + return x; + else + return y; +} + void display_calc(int x, int y) { - char text[32] = {0}; - sprintf(text, "%d + %d", x, y); + char txt[32] = {0}; + int win_width, win_height; + int txt_width; + int font_size; + + sprintf(txt, "%d + %d", x, y); + + win_width = GetScreenWidth(); + win_height = GetScreenHeight(); + + font_size = min(win_height/3, 40); + txt_width = MeasureText(txt, font_size); + + if (txt_width > win_width) + { + float scale = txt_width/win_width; + font_size = font_size/scale; + txt_width = MeasureText(txt, font_size); + } + BeginDrawing(); ClearBackground(RAYWHITE); - DrawText(text, DEFAULT_WIDTH/2, DEFAULT_HEIGHT/2, 40, LIGHTGRAY); + DrawText(txt, (win_width-txt_width)/2, win_height/6, font_size, LIGHTGRAY); EndDrawing(); } -- cgit v1.2.3