From 60ffab4350810f65f164a1e341de4a802bb5977c Mon Sep 17 00:00:00 2001 From: jackun Date: Wed, 23 Sep 2020 14:02:27 +0300 Subject: [PATCH] Add `no_small_font` option for unified font size --- README.md | 1 + bin/MangoHud.conf | 1 + src/font.cpp | 10 ++++++++-- src/overlay_params.cpp | 4 ++++ src/overlay_params.h | 2 ++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f18f3c7..e4da54ec 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ Parameters that are enabled by default have to be explicitly disabled. These (cu | `font_file` | Change default font (set location to .TTF/.OTF file ) | | `font_file_text` | Change text font. Otherwise `font_file` is used | | `font_glyph_ranges` | Specify extra font glyph ranges, comma separated: `korean`, `chinese`, `chinese_simplified`, `japanese`, `cyrillic`, `thai`, `vietnamese`, `latin_ext_a`, `latin_ext_b`. If you experience crashes or text is just squares, reduce font size or glyph ranges. | +| `no_small_font` | Use primary font size for smaller text like units | | `width=`
`height=` | Customizeable hud dimensions (in pixels) | | `position=` | Location of the hud: `top-left` (default), `top-right`, `bottom-left`, `bottom-right`, `top-center` | | `offset_x` `offset_y` | Hud position offsets | diff --git a/bin/MangoHud.conf b/bin/MangoHud.conf index a897c3e9..5e0e9a43 100644 --- a/bin/MangoHud.conf +++ b/bin/MangoHud.conf @@ -58,6 +58,7 @@ font_size=24 # font_scale=1.0 # font_size_text=24 # font_scale_media_player = 0.55 +# no_small_font ### Change default font (set location to .TTF/.OTF file ) ## Set font for the whole hud diff --git a/src/font.cpp b/src/font.cpp index a5abb5d9..ff51de87 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -56,11 +56,17 @@ void create_fonts(const overlay_params& params, ImFont*& small_font, ImFont*& te // ImGui takes ownership of the data, no need to free it if (!params.font_file.empty() && file_exists(params.font_file)) { io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size, nullptr, same_font && same_size ? glyph_ranges.Data : default_range); - small_font = io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size * 0.55f, nullptr, default_range); + if (params.no_small_font) + small_font = io.Fonts->Fonts[0]; + else + small_font = io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size * 0.55f, nullptr, default_range); } else { const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85(); io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size, nullptr, default_range); - small_font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size * 0.55f, nullptr, default_range); + if (params.no_small_font) + small_font = io.Fonts->Fonts[0]; + else + small_font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size * 0.55f, nullptr, default_range); } auto font_file_text = params.font_file_text; diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 6a8a3fb4..5b22c8b6 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -343,6 +343,7 @@ parse_font_glyph_ranges(const char *str) #define parse_background_alpha(s) parse_float(s) #define parse_alpha(s) parse_float(s) #define parse_permit_upload(s) parse_unsigned(s) +#define parse_no_small_font(s) parse_unsigned(s) != 0 #define parse_cpu_color(s) parse_color(s) #define parse_gpu_color(s) parse_color(s) @@ -651,6 +652,9 @@ parse_overlay_config(struct overlay_params *params, } else { params->width = params->font_size * params->font_scale * 11.7; } + // Treat it like hud would need to be ~7 characters wider with default font. + if (params->no_small_font) + params->width += 7 * params->font_size * params->font_scale; } // set frametime limit diff --git a/src/overlay_params.h b/src/overlay_params.h index d3da03d1..798ddc76 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -62,6 +62,7 @@ typedef unsigned long KeySym; OVERLAY_PARAM_CUSTOM(font_file) \ OVERLAY_PARAM_CUSTOM(font_file_text) \ OVERLAY_PARAM_CUSTOM(font_glyph_ranges) \ + OVERLAY_PARAM_CUSTOM(no_small_font) \ OVERLAY_PARAM_CUSTOM(font_size) \ OVERLAY_PARAM_CUSTOM(font_size_text) \ OVERLAY_PARAM_CUSTOM(font_scale) \ @@ -176,6 +177,7 @@ struct overlay_params { std::vector cpu_load_value; unsigned media_player_color; unsigned tableCols; + bool no_small_font; float font_size, font_scale; float font_size_text; float font_scale_media_player;