Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui to respect fonts.json #75920

Merged
merged 5 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,21 @@ static int GetFallbackCharWidth( ImWchar c, const float scale )
return fontwidth * mk_wcwidth( c ) * scale;
}

void cataimgui::client::load_fonts( const std::unique_ptr<Font> &cata_font,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette )
void cataimgui::client::load_fonts( const Font_Ptr &cata_font,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette,
const std::vector<std::string> &typefaces )
{
ImGuiIO &io = ImGui::GetIO();
if( ImGui::GetIO().FontDefault == nullptr ) {
std::vector<std::string> typefaces;
ensure_unifont_loaded( typefaces );
std::vector<std::string> io_typefaces{ typefaces };
ensure_unifont_loaded( io_typefaces );

for( size_t index = 0; index < color_loader<SDL_Color>::COLOR_NAMES_COUNT; index++ ) {
SDL_Color sdlCol = windowsPalette[index];
ImU32 rgb = sdlCol.b << 16 | sdlCol.g << 8 | sdlCol.r;
sdlColorsToCata[rgb] = index;
}
io.FontDefault = io.Fonts->AddFontFromFileTTF( typefaces[0].c_str(), fontheight, nullptr,
io.FontDefault = io.Fonts->AddFontFromFileTTF( io_typefaces[0].c_str(), fontheight, nullptr,
io.Fonts->GetGlyphRangesDefault() );
io.Fonts->Fonts[0]->SetFallbackStrSizeCallback( GetFallbackStrWidth );
io.Fonts->Fonts[0]->SetFallbackCharSizeCallback( GetFallbackCharWidth );
Expand Down
5 changes: 3 additions & 2 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class client
#else
client( const SDL_Renderer_Ptr &sdl_renderer, const SDL_Window_Ptr &sdl_window,
const GeometryRenderer_Ptr &sdl_geometry );
void load_fonts( const std::unique_ptr<Font> &cata_font,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette );
void load_fonts( const std::unique_ptr<Font> &cata_fonts,
const std::array<SDL_Color, color_loader<SDL_Color>::COLOR_NAMES_COUNT> &windowsPalette,
const std::vector<std::string> &typeface );
#endif
~client();

Expand Down
2 changes: 1 addition & 1 deletion src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3728,7 +3728,7 @@ void catacurses::init_interface()
windowsPalette, fl.overmap_typeface, fl.overmap_fontsize, fl.fontblending );
stdscr = newwin( get_terminal_height(), get_terminal_width(), point_zero );
//newwin calls `new WINDOW`, and that will throw, but not return nullptr.
imclient->load_fonts( font, windowsPalette );
imclient->load_fonts( font, windowsPalette, fl.typeface );
#if defined(__ANDROID__)
// Make sure we initialize preview_terminal_width/height to sensible values
preview_terminal_width = TERMINAL_WIDTH * fontwidth;
Expand Down
Loading