summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-11-09 19:15:36 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-11-09 19:15:36 +0100
commit0bd58d53437969264a0c217f9048baa71a4ef698 (patch)
treec7f13d8fee4e24314b5d01e19deba06fae508b22 /src
parent92489617eec44b913515404143baf5b094a16473 (diff)
font scaling
Diffstat (limited to 'src')
-rw-r--r--src/asset_defs.c37
-rw-r--r--src/overlay.c16
2 files changed, 46 insertions, 7 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c
index 566a49b..4fe621d 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -1,9 +1,17 @@
#include "../include/asset_defs.h"
void load_assets() {
+ fnt_52 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 52);
+ fnt_48 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 48);
+ fnt_44 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 44);
+ fnt_40 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 40);
+ fnt_36 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 36);
fnt_32 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 32);
+ fnt_28 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 28);
fnt_24 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 24);
fnt_20 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 20);
+ fnt_16 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 16);
+ fnt_12 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 12);
// Icons
img_icon_bullets = assets_load_image_from_file("data/imgs/bullets.png");
@@ -54,4 +62,33 @@ void load_assets() {
wav_error = Mix_LoadWAV("data/sounds/error.wav");
wav_impact_zombie = Mix_LoadWAV("data/sounds/impact_zombie.wav");
wav_collect = Mix_LoadWAV("data/sounds/collect.wav");
+}
+
+font* get_font(platform_window* window, float scale) {
+ log_assert(scale >= 0.2f && scale <= 2.2f, "scale must be a multiple of 0.2");
+ float window_scale = window->width / 800.0f;
+ float diff = window_scale - 1.0f;
+
+ int index_of_original = (int)(scale / 0.2f);
+ int index_to_return = index_of_original + (int)(diff/0.2f);
+
+ if (index_to_return < 0) index_to_return = 0;
+ if (index_to_return > 10) index_to_return = 10;
+
+ log_infox("%d %d", (int)(diff/0.2f), index_to_return);
+ font* arr[] = {
+ fnt_12, // scale = 0.2
+ fnt_16,
+ fnt_20,
+ fnt_24,
+ fnt_28, // scale = 1.0
+ fnt_32,
+ fnt_36,
+ fnt_40,
+ fnt_44,
+ fnt_48, // scale = 2.0
+ fnt_52,
+ };
+
+ return arr[index_to_return];
} \ No newline at end of file
diff --git a/src/overlay.c b/src/overlay.c
index 6aad6d4..942b580 100644
--- a/src/overlay.c
+++ b/src/overlay.c
@@ -126,28 +126,30 @@ void draw_points(platform_window* window) {
int y = (int)_global_camera.y + window->height - EDGE_PADDING;
char points_txt[20];
+ font* score_font = get_font(window, 1.0f);
+ font* sub_score_font = get_font(window, 0.2f);
for (int i = 0; i < MAX_PLAYERS; i++) {
if (!players[i].active) continue;
sprintf(points_txt, "%d", players[i].points);
- y -= fnt_20->px_h;
- int x1 = renderer->calculate_text_width(fnt_24, points_txt);
- renderer->render_text(fnt_24, x - x1+1, y+1, points_txt, rgba(0,0,0,120));
- renderer->render_text(fnt_24, x - x1, y, points_txt, get_color_tint_by_player_index(i));
+ y -= score_font->px_h;
+ int x1 = renderer->calculate_text_width(score_font, points_txt);
+ renderer->render_text(score_font, x - x1+1, y+1, points_txt, rgba(0,0,0,120));
+ renderer->render_text(score_font, x - x1, y, points_txt, get_color_tint_by_player_index(i));
for (int t = 0; t < MAX_POINT_ANIMATIONS; t++) {
if (!players[i].point_animations[t].active) continue;
point_animation animation = players[i].point_animations[t];
sprintf(points_txt, "%d", animation.points);
- int textw = renderer->calculate_text_width(fnt_20, points_txt);
+ int textw = renderer->calculate_text_width(sub_score_font, points_txt);
int py = y - animation.position.y;
int px = x1 - animation.position.x;
px += textw+2;
color c = get_color_tint_by_player_index(i);
c.a = 255*animation.opacity;
- renderer->render_text(fnt_20, x - px+1, py+1, points_txt, rgba(0,0,0,120*animation.opacity));
- renderer->render_text(fnt_20, x - px, py, points_txt, c);
+ renderer->render_text(sub_score_font, x - px+1, py+1, points_txt, rgba(0,0,0,120*animation.opacity));
+ renderer->render_text(sub_score_font, x - px, py, points_txt, c);
}
y -= 8;