Skip to content

Commit

Permalink
Fonts now properly reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankata453 committed Aug 7, 2024
1 parent 0fb68f7 commit 5c236f2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/supertux/menu/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "util/gettext.hpp"
#include "util/log.hpp"
#include "video/texture_manager.hpp"
#include "video/ttf_surface_manager.hpp"

DebugMenu::DebugMenu() :
next_game_speed(0)
Expand Down Expand Up @@ -78,9 +79,10 @@ DebugMenu::DebugMenu() :
add_toggle(-1, _("Show Tile IDs in Editor Toolbox"), &g_debug.show_toolbox_tile_ids);

add_entry(_("Reload Resources"), []{
Resources::load();
TextureManager::current()->reload();
TTFSurfaceManager::current()->clear_cache();

Resources::load(true);
SpriteManager::current()->reload();
TileManager::current()->reload();
})
Expand Down
4 changes: 2 additions & 2 deletions src/supertux/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SurfacePtr Resources::no_tile;
std::string Resources::current_font;

void
Resources::load()
Resources::load(bool reload)
{
// Load the mouse-cursor
mouse_cursor.reset(new MouseCursor(SpriteManager::current()->create("images/engine/menu/mousecursor.sprite")));
Expand All @@ -69,7 +69,7 @@ Resources::load()
console_font.reset(new TTFFont("fonts/SourceCodePro-Medium.ttf", 12, 1.25f, 0, 1));

auto font = get_font_for_locale(g_dictionary_manager->get_language());
if(font != current_font)
if(reload || font != current_font)
{
current_font = font;
fixed_font.reset(new TTFFont(font, 18, 1.25f, 2, 1));
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Resources final
static SurfacePtr no_tile;

public:
static void load();
static void load(bool reload = false);
static void unload();
static bool needs_custom_font(const tinygettext::Language& locale);
static std::string get_font_for_locale(const tinygettext::Language& locale);
Expand Down
7 changes: 7 additions & 0 deletions src/video/ttf_surface_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ TTFSurfaceManager::get_cached_surface_width(const TTFFont& font,
return entry.ttf_surface->get_width();
}

void
TTFSurfaceManager::clear_cache()
{
m_cache.clear();
m_cache_iter = m_cache.begin();
}

void
TTFSurfaceManager::cache_cleanup_step()
{
Expand Down
2 changes: 2 additions & 0 deletions src/video/ttf_surface_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class TTFSurfaceManager final : public Currenton<TTFSurfaceManager>
// Returns -1 if there is no cached text surface
int get_cached_surface_width(const TTFFont& font, const std::string& text);

void clear_cache();

void print_debug_info(std::ostream& out);

private:
Expand Down

0 comments on commit 5c236f2

Please sign in to comment.