diff options
| author | untodesu <kirill@untode.su> | 2025-09-11 15:10:18 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-09-11 15:10:18 +0500 |
| commit | a6ea7b7bbc66327cc2a957496f65dcfab5361cee (patch) | |
| tree | a4fda8a1a490bf1d88afe4e8d2f8814afdcc0de1 /game | |
| parent | 8784cbfebcb8a0220fb947a6070032e20b80fc2f (diff) | |
| download | voxelius-a6ea7b7bbc66327cc2a957496f65dcfab5361cee.tar.bz2 voxelius-a6ea7b7bbc66327cc2a957496f65dcfab5361cee.zip | |
Update ImGui to a newer version with font scaling
Diffstat (limited to 'game')
| -rw-r--r-- | game/client/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | game/client/game.cc | 116 | ||||
| -rw-r--r-- | game/client/globals.cc | 5 | ||||
| -rw-r--r-- | game/client/globals.hh | 5 | ||||
| -rw-r--r-- | game/client/gui/chat.cc | 10 | ||||
| -rw-r--r-- | game/client/gui/imdraw_ext.cc | 25 | ||||
| -rw-r--r-- | game/client/gui/imdraw_ext.hh | 10 | ||||
| -rw-r--r-- | game/client/gui/main_menu.cc | 4 | ||||
| -rw-r--r-- | game/client/gui/metrics.cc | 19 | ||||
| -rw-r--r-- | game/client/gui/scoreboard.cc | 9 | ||||
| -rw-r--r-- | game/client/gui/splash.cc | 2 | ||||
| -rw-r--r-- | game/client/gui/status_lines.cc | 12 | ||||
| -rw-r--r-- | game/client/main.cc | 2 | ||||
| -rw-r--r-- | game/server/main.cc | 2 |
14 files changed, 123 insertions, 100 deletions
diff --git a/game/client/CMakeLists.txt b/game/client/CMakeLists.txt index 8fbc48d..633e486 100644 --- a/game/client/CMakeLists.txt +++ b/game/client/CMakeLists.txt @@ -23,7 +23,7 @@ target_compile_definitions(vclient PUBLIC GLFW_INCLUDE_NONE) target_include_directories(vclient PRIVATE "${PROJECT_SOURCE_DIR}") target_include_directories(vclient PRIVATE "${PROJECT_SOURCE_DIR}/game") target_precompile_headers(vclient PRIVATE "${CMAKE_CURRENT_LIST_DIR}/pch.hh") -target_link_libraries(vclient PUBLIC shared dr_libs glad glfw imgui imgui_glfw imgui_opengl3 salad) +target_link_libraries(vclient PUBLIC shared dr_libs glad glfw imgui imgui-glfw imgui-opengl3 salad) add_subdirectory(config) add_subdirectory(entity) diff --git a/game/client/game.cc b/game/client/game.cc index d5820f4..428e6a3 100644 --- a/game/client/game.cc +++ b/game/client/game.cc @@ -7,8 +7,8 @@ #include "core/config/string.hh" #include "core/io/config_map.hh" #include "core/math/angles.hh" -#include "core/resource/binfile.hh" #include "core/resource/resource.hh" +#include "core/utils/physfs.hh" #include "shared/entity/collision.hh" #include "shared/entity/gravity.hh" @@ -84,62 +84,29 @@ bool client_game::hide_hud = false; static config::KeyBind hide_hud_toggle(GLFW_KEY_F1); -static resource_ptr<BinFile> bin_unscii16; -static resource_ptr<BinFile> bin_unscii8; - -static void on_glfw_framebuffer_size(const io::GlfwFramebufferSizeEvent& event) +static ImFont* load_font(std::string_view path, float size, ImFontConfig& font_config, ImVector<ImWchar>& ranges) { - auto width_float = static_cast<float>(event.size.x); - auto height_float = static_cast<float>(event.size.y); - auto wscale = math::max(1U, math::floor<unsigned int>(width_float / static_cast<float>(BASE_WIDTH))); - auto hscale = math::max(1U, math::floor<unsigned int>(height_float / static_cast<float>(BASE_HEIGHT))); - auto scale = math::min(wscale, hscale); - - if(globals::gui_scale != scale) { - auto& io = ImGui::GetIO(); - auto& style = ImGui::GetStyle(); - - ImFontConfig font_config; - font_config.FontDataOwnedByAtlas = false; - - io.Fonts->Clear(); - - ImFontGlyphRangesBuilder builder; - - // This should cover a hefty range of glyph ranges. - // UNDONE: just slap the whole UNICODE Plane-0 here? - builder.AddRanges(io.Fonts->GetGlyphRangesDefault()); - builder.AddRanges(io.Fonts->GetGlyphRangesCyrillic()); - builder.AddRanges(io.Fonts->GetGlyphRangesGreek()); - builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); - - ImVector<ImWchar> ranges = {}; - builder.BuildRanges(&ranges); - - globals::font_default = io.Fonts->AddFontFromMemoryTTF( - bin_unscii16->buffer, bin_unscii16->size, 16.0f * scale, &font_config, ranges.Data); - globals::font_chat = io.Fonts->AddFontFromMemoryTTF( - bin_unscii16->buffer, bin_unscii16->size, 8.0f * scale, &font_config, ranges.Data); - globals::font_debug = io.Fonts->AddFontFromMemoryTTF(bin_unscii8->buffer, bin_unscii8->size, 4.0f * scale, &font_config); - - // Re-assign the default font - io.FontDefault = globals::font_default; - - // This should be here!!! Just calling Build() - // on the font atlas does not invalidate internal - // device objects defined by the implementation!!! - ImGui_ImplOpenGL3_CreateDeviceObjects(); - - if(globals::gui_scale) { - // Well, ImGuiStyle::ScaleAllSizes indeed takes - // the scale values as a RELATIVE scaling, not as - // absolute. So I have to make a special crutch - style.ScaleAllSizes(static_cast<float>(scale) / static_cast<float>(globals::gui_scale)); - } + bool font_load_success; + std::vector<std::byte> font; - globals::gui_scale = scale; + if(!utils::read_file(path, font)) { + spdlog::error("{}: utils::read_file failed", path); + std::terminate(); } + auto& io = ImGui::GetIO(); + auto font_ptr = io.Fonts->AddFontFromMemoryTTF(font.data(), font.size(), size, &font_config, ranges.Data); + + if(font_ptr == nullptr) { + spdlog::error("{}: AddFontFromMemoryTTF failed", path); + std::terminate(); + } + + return font_ptr; +} + +static void on_glfw_framebuffer_size(const io::GlfwFramebufferSizeEvent& event) +{ if(globals::world_fbo) { glDeleteRenderbuffers(1, &globals::world_fbo_depth); glDeleteTextures(1, &globals::world_fbo_color); @@ -178,13 +145,24 @@ static void on_glfw_key(const io::GlfwKeyEvent& event) void client_game::init(void) { - bin_unscii16 = resource::load<BinFile>("fonts/unscii-16.ttf"); - bin_unscii8 = resource::load<BinFile>("fonts/unscii-8.ttf"); + auto& io = ImGui::GetIO(); + io.ConfigFlags &= ~ImGuiConfigFlags_NavEnableGamepad; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + io.IniFilename = nullptr; + io.Fonts->Clear(); - if((bin_unscii16 == nullptr) || (bin_unscii8 == nullptr)) { - spdlog::critical("client_game: font loading failed"); - std::terminate(); - } + ImFontConfig font_config; + font_config.FontDataOwnedByAtlas = false; + + ImFontGlyphRangesBuilder builder; + builder.AddRanges(io.Fonts->GetGlyphRangesDefault()); + builder.AddRanges(io.Fonts->GetGlyphRangesCyrillic()); + + ImVector<ImWchar> ranges; + builder.BuildRanges(&ranges); + + globals::font_unscii16 = load_font("fonts/unscii-16.ttf", 16.0f, font_config, ranges); + globals::font_unscii8 = load_font("fonts/unscii-8.ttf", 8.0f, font_config, ranges); gui::client_splash::init(); gui::client_splash::render(); @@ -314,7 +292,7 @@ void client_game::init(void) // taught me one important thing: dimensions // of UI elements must be calculated at semi-runtime // so there's simply no point for an INI file. - ImGui::GetIO().IniFilename = nullptr; + io.IniFilename = nullptr; toggles::init(); @@ -459,9 +437,6 @@ void client_game::shutdown(void) world::chunk_mesher::shutdown(); enet_host_destroy(globals::client_host); - - bin_unscii8 = nullptr; - bin_unscii16 = nullptr; } void client_game::fixed_update(void) @@ -539,6 +514,21 @@ void client_game::update(void) gui::client_chat::update(); experiments::update(); + + constexpr auto half_base_width = 0.5f * static_cast<float>(BASE_WIDTH); + constexpr auto half_base_height = 0.5f * static_cast<float>(BASE_HEIGHT); + + auto twice_scale_x = static_cast<float>(globals::width) / half_base_width; + auto twice_scale_y = static_cast<float>(globals::height) / half_base_height; + + auto scale_x = math::max(1.0f, 0.5f * glm::floor(twice_scale_x)); + auto scale_y = math::max(1.0f, 0.5f * glm::floor(twice_scale_y)); + auto scale_min = math::ceil<unsigned int>(math::min(scale_x, scale_y)); + auto scale_int = math::max(1U, (scale_min / 2U) * 2U); + + auto& io = ImGui::GetIO(); + io.FontGlobalScale = scale_int; + globals::gui_scale = scale_int; } void client_game::update_late(void) diff --git a/game/client/globals.cc b/game/client/globals.cc index 5f5b3c9..1932675 100644 --- a/game/client/globals.cc +++ b/game/client/globals.cc @@ -33,9 +33,8 @@ ENetHost* globals::client_host; world::Dimension* globals::dimension = nullptr; entt::entity globals::player; -ImFont* globals::font_debug; -ImFont* globals::font_default; -ImFont* globals::font_chat; +ImFont* globals::font_unscii16; +ImFont* globals::font_unscii8; config::KeyBind* globals::gui_keybind_ptr = nullptr; config::GamepadAxis* globals::gui_gamepad_axis_ptr = nullptr; diff --git a/game/client/globals.hh b/game/client/globals.hh index 0ed98ac..69ce29c 100644 --- a/game/client/globals.hh +++ b/game/client/globals.hh @@ -58,9 +58,8 @@ extern ENetHost* client_host; extern world::Dimension* dimension; extern entt::entity player; -extern ImFont* font_debug; -extern ImFont* font_default; -extern ImFont* font_chat; +extern ImFont* font_unscii16; +extern ImFont* font_unscii8; extern config::KeyBind* gui_keybind_ptr; extern config::GamepadAxis* gui_gamepad_axis_ptr; diff --git a/game/client/gui/chat.cc b/game/client/gui/chat.cc index 8c4ac26..855c892 100644 --- a/game/client/gui/chat.cc +++ b/game/client/gui/chat.cc @@ -12,6 +12,7 @@ #include "client/config/keybind.hh" #include "client/gui/gui_screen.hh" +#include "client/gui/imdraw_ext.hh" #include "client/gui/language.hh" #include "client/gui/settings.hh" #include "client/io/glfw.hh" @@ -169,7 +170,7 @@ void gui::client_chat::layout(void) ImGui::SetNextWindowPos(window_start); ImGui::SetNextWindowSize(window_size); - ImGui::PushFont(globals::font_chat); + ImGui::PushFont(globals::font_unscii16, 8.0f); if(!ImGui::Begin("###chat", nullptr, WINDOW_FLAGS)) { ImGui::End(); @@ -184,7 +185,7 @@ void gui::client_chat::layout(void) // The text input widget occupies the bottom part // of the chat window, we need to reserve some space for it - auto ypos = window_size.y - 2.5f * font->FontSize - 2.0f * padding.y - 2.0f * spacing.y; + auto ypos = window_size.y - 2.5f * ImGui::GetFontSize() - 2.0f * padding.y - 2.0f * spacing.y; if(globals::gui_screen == GUI_CHAT) { if(needs_focus) { @@ -223,10 +224,11 @@ void gui::client_chat::layout(void) auto rect_col = ImGui::GetColorU32(ImGuiCol_FrameBg, rect_alpha); auto text_col = ImGui::GetColorU32(ImVec4(it->color.x, it->color.y, it->color.z, it->color.w * text_alpha)); + auto shadow_col = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, text_alpha)); draw_list->AddRectFilled(rect_pos, rect_end, rect_col); - draw_list->AddText( - font, font->FontSize, text_pos, text_col, it->text.c_str(), it->text.c_str() + it->text.size(), window_size.x); + + imdraw_ext::text_shadow_w(it->text, text_pos, text_col, shadow_col, font, draw_list, 8.0f, window_size.x); ypos -= rect_size.y; } diff --git a/game/client/gui/imdraw_ext.cc b/game/client/gui/imdraw_ext.cc index e6db148..832f284 100644 --- a/game/client/gui/imdraw_ext.cc +++ b/game/client/gui/imdraw_ext.cc @@ -7,7 +7,28 @@ void gui::imdraw_ext::text_shadow( const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, ImDrawList* draw_list) { + imdraw_ext::text_shadow(text, position, text_color, shadow_color, font, draw_list, font->LegacySize); +} + +void gui::imdraw_ext::text_shadow(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, + ImDrawList* draw_list, float font_size) +{ + const auto shadow_position = ImVec2(position.x + 0.5f * globals::gui_scale, position.y + 0.5f * globals::gui_scale); + draw_list->AddText(font, globals::gui_scale * font_size, shadow_position, shadow_color, text.c_str(), text.c_str() + text.size()); + draw_list->AddText(font, globals::gui_scale * font_size, position, text_color, text.c_str(), text.c_str() + text.size()); +} + +void gui::imdraw_ext::text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, + ImDrawList* draw_list, float wrap_width) +{ + imdraw_ext::text_shadow_w(text, position, text_color, shadow_color, font, draw_list, font->LegacySize, wrap_width); +} + +void gui::imdraw_ext::text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, + ImDrawList* draw_list, float font_size, float wrap_width) +{ const auto shadow_position = ImVec2(position.x + 0.5f * globals::gui_scale, position.y + 0.5f * globals::gui_scale); - draw_list->AddText(font, font->FontSize, shadow_position, shadow_color, text.c_str(), text.c_str() + text.size()); - draw_list->AddText(font, font->FontSize, position, text_color, text.c_str(), text.c_str() + text.size()); + draw_list->AddText( + font, globals::gui_scale * font_size, shadow_position, shadow_color, text.c_str(), text.c_str() + text.size(), wrap_width); + draw_list->AddText(font, globals::gui_scale * font_size, position, text_color, text.c_str(), text.c_str() + text.size(), wrap_width); } diff --git a/game/client/gui/imdraw_ext.hh b/game/client/gui/imdraw_ext.hh index 7f0abfb..35ee37e 100644 --- a/game/client/gui/imdraw_ext.hh +++ b/game/client/gui/imdraw_ext.hh @@ -6,6 +6,16 @@ namespace gui::imdraw_ext { void text_shadow( const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, ImDrawList* draw_list); +void text_shadow(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, ImDrawList* draw_list, + float font_size); +} // namespace gui::imdraw_ext + +namespace gui::imdraw_ext +{ +void text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, + ImDrawList* draw_list, float wrap_width); +void text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, + ImDrawList* draw_list, float font_size, float wrap_width); } // namespace gui::imdraw_ext #endif // CLIENT_IMDRAW_EXT_HH diff --git a/game/client/gui/main_menu.cc b/game/client/gui/main_menu.cc index 62802a8..5395335 100644 --- a/game/client/gui/main_menu.cc +++ b/game/client/gui/main_menu.cc @@ -156,8 +156,8 @@ void gui::main_menu::layout(void) const auto& padding = ImGui::GetStyle().FramePadding; const auto& spacing = ImGui::GetStyle().ItemSpacing; - ImGui::PushFont(globals::font_debug); - ImGui::SetCursorScreenPos(ImVec2(padding.x + spacing.x, window_size.y - globals::font_debug->FontSize - padding.y - spacing.y)); + ImGui::PushFont(globals::font_unscii8, 4.0f); + ImGui::SetCursorScreenPos(ImVec2(padding.x + spacing.x, window_size.y - ImGui::GetFontSize() - padding.y - spacing.y)); ImGui::Text("Voxelius %*s", version::semver.size(), version::semver.data()); // string_view is not always null-terminated ImGui::PopFont(); } diff --git a/game/client/gui/metrics.cc b/game/client/gui/metrics.cc index f439fd0..234d3b5 100644 --- a/game/client/gui/metrics.cc +++ b/game/client/gui/metrics.cc @@ -46,34 +46,35 @@ void gui::metrics::layout(void) auto text_color = ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); auto shadow_color = ImGui::GetColorU32(ImVec4(0.1f, 0.1f, 0.1f, 1.0f)); + auto font_size = 4.0f; auto position = ImVec2(8.0f, 8.0f); - auto y_step = 1.5f * globals::font_debug->FontSize; + auto y_step = 1.5f * globals::gui_scale * font_size; // Draw version auto version_line = std::format("Voxelius {} [{}]", version::semver, version::commit); - gui::imdraw_ext::text_shadow(version_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(version_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += 1.5f * y_step; // Draw client-side window framerate metrics auto window_framerate = 1.0f / globals::window_frametime_avg; auto window_frametime = 1000.0f * globals::window_frametime_avg; auto window_fps_line = std::format("{:.02f} FPS [{:.02f} ms]", window_framerate, window_frametime); - gui::imdraw_ext::text_shadow(window_fps_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(window_fps_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += y_step; // Draw world rendering metrics auto drawcall_line = std::format("World: {} DC / {} TRI", globals::num_drawcalls, globals::num_triangles); - gui::imdraw_ext::text_shadow(drawcall_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(drawcall_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += y_step; // Draw OpenGL version string auto r_version_line = std::format("GL_VERSION: {}", reinterpret_cast<const char*>(r_version.c_str())); - gui::imdraw_ext::text_shadow(r_version_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(r_version_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += y_step; // Draw OpenGL renderer string auto r_renderer_line = std::format("GL_RENDERER: {}", reinterpret_cast<const char*>(r_renderer.c_str())); - gui::imdraw_ext::text_shadow(r_renderer_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(r_renderer_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += 1.5f * y_step; const auto& head = globals::dimension->entities.get<entity::Head>(globals::player); @@ -83,18 +84,18 @@ void gui::metrics::layout(void) // Draw player voxel position auto voxel_position = coord::to_voxel(transform.chunk, transform.local); auto voxel_line = std::format("voxel: [{} {} {}]", voxel_position.x, voxel_position.y, voxel_position.z); - gui::imdraw_ext::text_shadow(voxel_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(voxel_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += y_step; // Draw player world position auto world_line = std::format("world: [{} {} {}] [{:.03f} {:.03f} {:.03f}]", transform.chunk.x, transform.chunk.y, transform.chunk.z, transform.local.x, transform.local.y, transform.local.z); - gui::imdraw_ext::text_shadow(world_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(world_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += y_step; // Draw player look angles auto angles = glm::degrees(transform.angles + head.angles); auto angle_line = std::format("angle: [{: .03f} {: .03f} {: .03f}]", angles[0], angles[1], angles[2]); - gui::imdraw_ext::text_shadow(angle_line, position, text_color, shadow_color, globals::font_debug, draw_list); + gui::imdraw_ext::text_shadow(angle_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size); position.y += y_step; } diff --git a/game/client/gui/scoreboard.cc b/game/client/gui/scoreboard.cc index 85a982f..ad49a69 100644 --- a/game/client/gui/scoreboard.cc +++ b/game/client/gui/scoreboard.cc @@ -51,11 +51,11 @@ void gui::scoreboard::layout(void) return; } - ImGui::PushFont(globals::font_chat); + ImGui::PushFont(globals::font_unscii16, 8.0f); const auto& padding = ImGui::GetStyle().FramePadding; const auto& spacing = ImGui::GetStyle().ItemSpacing; - auto font = globals::font_chat; + auto font = globals::font_unscii8; // Figure out the maximum username size for(const auto& username : usernames) { @@ -74,7 +74,7 @@ void gui::scoreboard::layout(void) const float rect_start_x = 0.5f * window_size.x - 0.5f * true_size; const float rect_start_y = 0.15f * window_size.y; const float rect_size_x = 2.0f * padding.x + true_size; - const float rect_size_y = 2.0f * padding.y + font->FontSize; + const float rect_size_y = 2.0f * padding.y + 0.5f * ImGui::GetFontSize(); // const ImU32 border_col = ImGui::GetColorU32(ImGuiCol_Border, 1.00f); const ImU32 rect_col = ImGui::GetColorU32(ImGuiCol_FrameBg, 0.80f); @@ -92,7 +92,8 @@ void gui::scoreboard::layout(void) // draw_list->AddRect(rect_a, rect_b, border_col, 0.0f, ImDrawFlags_None, globals::gui_scale); draw_list->AddRectFilled(rect_a, rect_b, rect_col, 0.0f, ImDrawFlags_None); - draw_list->AddText(font, font->FontSize, text_pos, text_col, usernames[i].c_str(), usernames[i].c_str() + usernames[i].size()); + draw_list->AddText( + font, 0.5f * ImGui::GetFontSize(), text_pos, text_col, usernames[i].c_str(), usernames[i].c_str() + usernames[i].size()); } ImGui::PopFont(); diff --git a/game/client/gui/splash.cc b/game/client/gui/splash.cc index 9eed8d3..887e209 100644 --- a/game/client/gui/splash.cc +++ b/game/client/gui/splash.cc @@ -148,7 +148,7 @@ void gui::client_splash::render(void) const ImVec2 image_pos = ImVec2(image_x, image_y); if(!current_text.empty()) { - ImGui::PushFont(globals::font_chat); + ImGui::PushFont(globals::font_unscii8, 16.0f); ImGui::SetCursorPos(ImVec2(16.0f, 16.0f)); ImGui::TextDisabled("%s", current_text.c_str()); ImGui::PopFont(); diff --git a/game/client/gui/status_lines.cc b/game/client/gui/status_lines.cc index 054f971..9d9ac4c 100644 --- a/game/client/gui/status_lines.cc +++ b/game/client/gui/status_lines.cc @@ -8,6 +8,7 @@ static float line_offsets[gui::STATUS_COUNT]; static ImFont* line_fonts[gui::STATUS_COUNT]; +static float line_sizes[gui::STATUS_COUNT]; static ImVec4 line_text_colors[gui::STATUS_COUNT]; static ImVec4 line_shadow_colors[gui::STATUS_COUNT]; @@ -34,8 +35,11 @@ void gui::status_lines::init_late(void) void gui::status_lines::layout(void) { - line_fonts[STATUS_DEBUG] = globals::font_debug; - line_fonts[STATUS_HOTBAR] = globals::font_chat; + line_fonts[STATUS_DEBUG] = globals::font_unscii8; + line_sizes[STATUS_DEBUG] = 4.0f; + + line_fonts[STATUS_HOTBAR] = globals::font_unscii16; + line_sizes[STATUS_HOTBAR] = 8.0f; auto viewport = ImGui::GetMainViewport(); auto draw_list = ImGui::GetForegroundDrawList(); @@ -45,7 +49,7 @@ void gui::status_lines::layout(void) auto& text = line_strings[i]; auto* font = line_fonts[i]; - auto size = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, text.c_str(), text.c_str() + text.size()); + auto size = font->CalcTextSizeA(line_sizes[i] * globals::gui_scale, FLT_MAX, 0.0f, text.c_str(), text.c_str() + text.size()); auto pos = ImVec2(0.5f * (viewport->Size.x - size.x), viewport->Size.y - offset); auto spawn = line_spawns[i]; @@ -57,7 +61,7 @@ void gui::status_lines::layout(void) auto color_U32 = ImGui::GetColorU32(ImVec4(color.x, color.y, color.z, color.w * alpha)); auto shadow_U32 = ImGui::GetColorU32(ImVec4(shadow.x, shadow.y, shadow.z, color.w * alpha)); - gui::imdraw_ext::text_shadow(text, pos, color_U32, shadow_U32, font, draw_list); + gui::imdraw_ext::text_shadow(text, pos, color_U32, shadow_U32, font, draw_list, line_sizes[i]); } } diff --git a/game/client/main.cc b/game/client/main.cc index 72c116e..d7fcb1e 100644 --- a/game/client/main.cc +++ b/game/client/main.cc @@ -2,7 +2,6 @@ #include "core/io/cmdline.hh" #include "core/io/config_map.hh" -#include "core/resource/binfile.hh" #include "core/resource/image.hh" #include "core/resource/resource.hh" #include "core/utils/epoch.hh" @@ -221,7 +220,6 @@ int main(int argc, char** argv) spdlog::info("opengl: version: {}", reinterpret_cast<const char*>(glGetString(GL_VERSION))); spdlog::info("opengl: renderer: {}", reinterpret_cast<const char*>(glGetString(GL_RENDERER))); - BinFile::register_resource(); Image::register_resource(); TextureGUI::register_resource(); SoundEffect::register_resource(); diff --git a/game/server/main.cc b/game/server/main.cc index e25a457..b3caf36 100644 --- a/game/server/main.cc +++ b/game/server/main.cc @@ -4,7 +4,6 @@ #include "core/io/cmdline.hh" #include "core/io/config_map.hh" #include "core/math/constexpr.hh" -#include "core/resource/binfile.hh" #include "core/resource/image.hh" #include "core/resource/resource.hh" #include "core/utils/epoch.hh" @@ -46,7 +45,6 @@ int main(int argc, char** argv) std::signal(SIGINT, &on_termination_signal); std::signal(SIGTERM, &on_termination_signal); - BinFile::register_resource(); Image::register_resource(); server_game::init(); |
