diff options
author | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-06-20 22:29:15 +0900 |
---|---|---|
committer | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-06-20 22:29:15 +0900 |
commit | 06f6d9501f43af7a9b1c4f1e9e92a75ce15c1acf (patch) | |
tree | 530a09495b306e8ac4d0de5a77007d5a20dde5c1 /src | |
parent | eb333cc30568a732942a62dcb953387acb0195f5 (diff) |
Improve position of calculation
Diffstat (limited to 'src')
-rw-r--r-- | src/ray.c | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -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(); } |