diff options
Diffstat (limited to 'game/client/gui')
| -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 |
8 files changed, 65 insertions, 26 deletions
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]); } } |
