diff options
-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(); } |