Fix the issues found while reviewing the engine frame

Use util::str2wstr_utf8 for the window title instead of the deprecated
codecvt conversion, choose the bar control icon with a switch, and keep
the frontend layout in sync when a frame is drawn from the refresh
callback the platform calls while it blocks the main loop.

The frame forgets its interaction state when the window mode changes or
the cursor gets locked, a bar click that only moved the window is no
longer a double click, and one frame per size is drawn per resize.

The tooltips of the two window settings were only present in the Russian
locale and under a key the settings page never asks for: they are named
display.<id>.tooltip now and translated in both locales. The version label
of the debug build moves below the bar that covers the menu screen.
This commit is contained in:
alexei-zebra 2026-10-11 20:06:11 +03:00
parent c635549892
commit fbedfad478
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
10 changed files with 173 additions and 153 deletions

View file

@ -11,27 +11,15 @@
#include "graphics/ui/GUI.hpp"
#include "window/Window.hpp"
#include "assets/Assets.hpp"
#include "util/stringutil.hpp"
#include <algorithm>
#include <string_view>
#include <codecvt>
#include <locale>
namespace {
std::wstring to_wide(const std::string& text) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.from_bytes(text);
}
const std::string BAR_FONT = FONT_DEFAULT;
}
/// @brief Draws the window bar the backend cannot draw itself.
///
/// The bar lives in window coordinates while the GUI container is shifted
/// down by its height in game, so the GUI camera cannot be reused here: the
/// bar sets its own viewport and projection. It borrows the GUI batch only
/// because the ui shader it needs is the one the GUI already loads.
/// The bar lives in window coordinates, so it sets the shader and projection
/// itself instead of depending on the state the GUI left behind.
void draw_window_bar(Engine& engine) {
auto& window = engine.getWindow();
const int height = window.getDecorationHeight();
@ -39,7 +27,7 @@ void draw_window_bar(Engine& engine) {
return;
}
auto* batch = engine.getGUI().getBatch2D();
auto font = engine.requireAssets().getShared<Font>(BAR_FONT);
auto font = engine.requireAssets().getShared<Font>(FONT_DEFAULT);
const auto size = window.getSize();
const float barHeight = static_cast<float>(height);
@ -80,7 +68,7 @@ void draw_window_bar(Engine& engine) {
}
// the bar and its controls do not need the font, only the title does
if (font != nullptr) {
const std::wstring title = to_wide(window.getTitle());
const std::wstring title = util::str2wstr_utf8(window.getTitle());
const float available = std::max(0.0f, titleRight - titleLeft);
size_t titleLength = title.size();
while (titleLength > 0 &&
@ -124,13 +112,20 @@ void draw_window_bar(Engine& engine) {
}
const float ink = isHovered ? 1.0f : 0.8f;
batch->setColor(glm::vec4(1.0f, 1.0f, 1.0f, ink));
const char* iconName =
item.button == DecorationButton::CLOSE
? "gui/cross"
: item.button == DecorationButton::MINIMIZE
? "gui/minimize_w"
: window.isMaximized() ? "gui/restore_w"
: "gui/maximize_w";
const char* iconName = nullptr;
switch (item.button) {
case DecorationButton::CLOSE:
iconName = "gui/cross";
break;
case DecorationButton::MINIMIZE:
iconName = "gui/minimize_w";
break;
case DecorationButton::MAXIMIZE:
default:
iconName = window.isMaximized() ? "gui/restore_w"
: "gui/maximize_w";
break;
}
auto icon = engine.requireAssets().getShared<Texture>(iconName);
if (icon != nullptr) {
const float iconSize = std::min(