Compare commits

...

2 Commits

Author SHA1 Message Date
5356e59088
load fonts from conf and merge
Some checks failed
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
ContinuousDelivery / linux-ubuntu (push) Failing after 13m18s
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 5m25s
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 5m37s
ContinuousIntegration / linux (push) Successful in 4m0s
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 5m13s
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 5m16s
2024-06-15 23:01:55 +02:00
2189c4c3cb
make tomato dpi aware (not dynamic) and fiddle around with fonts 2024-06-12 19:37:07 +02:00
4 changed files with 91 additions and 17 deletions

View File

@ -44,7 +44,7 @@ endif()
add_compile_definitions(ENTT_API_EXPORT) add_compile_definitions(ENTT_API_EXPORT)
# external libs # external libs
add_subdirectory(./external) # before increasing warn levels, sad :( add_subdirectory(./external EXCLUDE_FROM_ALL) # before increasing warn levels, sad :(
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)

View File

@ -18,6 +18,7 @@ add_library(imgui
imgui/misc/cpp/imgui_stdlib.cpp imgui/misc/cpp/imgui_stdlib.cpp
) )
target_compile_definitions(imgui PUBLIC IMGUI_USE_WCHAR32)
target_compile_features(imgui PUBLIC cxx_std_11) target_compile_features(imgui PUBLIC cxx_std_11)
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")

View File

@ -75,6 +75,14 @@ int main(int argc, char** argv) {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
// TODO: test android behaviour
float display_scale = SDL_GetWindowDisplayScale(window.get());
if (display_scale < 0.001f) {
// error?
display_scale = 1.f;
}
ImGui::GetStyle().ScaleAllSizes(display_scale);
Theme theme; Theme theme;
if (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_LIGHT) { if (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_LIGHT) {
ImGui::StyleColorsLight(); ImGui::StyleColorsLight();
@ -85,22 +93,6 @@ int main(int argc, char** argv) {
theme = getDefaultThemeDark(); theme = getDefaultThemeDark();
} }
{
ImGui::GetIO().Fonts->ClearFonts();
ImFontConfig fontcfg;
// upsampling to int looks almost ok
const float font_size_scale = 1.3f;
const float font_oversample = 4.f;
// default font is pixel perfect at 13
fontcfg.SizePixels = 13.f * font_size_scale;
fontcfg.RasterizerDensity = font_oversample/font_size_scale;
// normally density would be set to dpi scale of the display
ImGui::GetIO().Fonts->AddFontDefault(&fontcfg);
ImGui::GetIO().Fonts->Build();
}
ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get()); ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
ImGui_ImplSDLRenderer3_Init(renderer.get()); ImGui_ImplSDLRenderer3_Init(renderer.get());

View File

@ -50,6 +50,87 @@ StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer
} }
} }
float display_scale = SDL_GetWindowDisplayScale(SDL_GetRenderWindow(renderer));
if (display_scale < 0.001f) {
// error?
display_scale = 1.f;
}
{
auto* font_atlas = ImGui::GetIO().Fonts;
font_atlas->ClearFonts();
// for now we also always merge
//bool has_font {false};
ImFontGlyphRangesBuilder glyphbld;
ImVector<ImWchar> glyph_ranges;
{ // build ranges
glyphbld.AddRanges(font_atlas->GetGlyphRangesDefault());
glyphbld.AddRanges(font_atlas->GetGlyphRangesGreek());
glyphbld.AddRanges(font_atlas->GetGlyphRangesCyrillic());
glyphbld.AddRanges(font_atlas->GetGlyphRangesChineseSimplifiedCommon()); // contains CJK
glyphbld.AddText(""); // somehow missing
// popular emojies
glyphbld.AddText(u8"😂❤️🤣👍😭🙏😘🥰😍😊🎉😁💕🥺😅🔥☺️🤦♥️🤷🙄😆🤗😉🎂🤔👏🙂😳🥳😎👌💜😔💪✨💖👀😋😏😢👉💗😩💯🌹💞🎈💙😃😡💐😜🙈🤞😄🤤🙌🤪❣️😀💋💀👇💔😌💓🤩🙃😬😱😴🤭😐🌞😒😇🌸😈🎶✌️🎊🥵😞💚☀️🖤💰😚👑🎁💥🙋☹️😑🥴👈💩✅👋🤮😤🤢🌟❗😥🌈💛😝😫😲🖕‼️🔴🌻🤯💃👊🤬🏃😕👁️⚡☕🍀💦⭐🦋🤨🌺😹🤘🌷💝💤🤝🐰😓💘🍻😟😣🧐😠🤠😻🌙😛🤙🙊");
if (const auto sv_opt = _conf.get_string("ImGuiFonts", "atlas_extra_text"); sv_opt.has_value) {
glyphbld.AddText(sv_opt.s.start, sv_opt.s.start+sv_opt.s.extend);
}
glyphbld.BuildRanges(&glyph_ranges);
}
ImFontConfig fontcfg;
//fontcfg.SizePixels = 16.f*display_scale;
fontcfg.SizePixels = _conf.get_int("ImGuiFonts", "size").value_or(13) * display_scale;
fontcfg.RasterizerDensity = 1.f;
fontcfg.OversampleH = 2;
fontcfg.OversampleV = 1;
fontcfg.MergeMode = false;
for (const auto [font_path, should_load] : _conf.entries_bool("ImGuiFonts", "fonts")) {
if (!should_load) {
continue;
}
std::cout << "Font: loading '" << font_path << "'\n";
const auto* resulting_font = font_atlas->AddFontFromFileTTF(
font_path.c_str(),
_conf.get_int("ImGuiFonts", "size", font_path).value_or(0) * display_scale,
&fontcfg,
&(glyph_ranges[0])
);
if (resulting_font != nullptr) {
//has_font = true;
fontcfg.MergeMode = true;
} else {
std::cerr << "Font: failed to load '" << "path" << "' !\n";
}
}
// always append the default as a fallback (merge in)
{
#if 0
ImFontConfig fontcfg;
// upsampling to int looks almost ok
//const float font_size_scale = 1.3f * display_scale;
const float font_size_scale = 1.0f * display_scale;
const float font_oversample = 4.f;
// default font is pixel perfect at 13
fontcfg.SizePixels = 13.f * font_size_scale;
fontcfg.RasterizerDensity = font_oversample/font_size_scale;
// normally density would be set to dpi scale of the display
fontcfg.MergeMode = has_font;
#endif
font_atlas->AddFontDefault(&fontcfg);
}
font_atlas->Build();
}
} }
Screen* StartScreen::render(float, bool&) { Screen* StartScreen::render(float, bool&) {