pushing for vavaas to debug

This commit is contained in:
2024-10-27 20:55:21 +01:00
parent 028cb57ff4
commit dbf4d3cc5b
7 changed files with 36 additions and 20 deletions

View File

@@ -148,20 +148,22 @@ namespace mlx
void Application::LoadFont(const std::filesystem::path& filepath, float scale)
{
MLX_PROFILE_FUNCTION();
std::shared_ptr<Font> font;
if(filepath.string() == "default")
font = std::make_shared<Font>("default", dogica_ttf, scale);
else
font = std::make_shared<Font>(filepath, scale);
std::shared_ptr<Font> font = m_font_registry.GetFont(filepath, scale);
if(!font)
{
if(filepath.string() == "default")
font = std::make_shared<Font>("default", dogica_ttf, scale);
else
font = std::make_shared<Font>(filepath, scale);
font->BuildFont();
m_font_registry.RegisterFont(font);
}
for(auto& gs : m_graphics)
{
if(gs)
gs->GetScene().BindFont(font);
}
if(m_font_registry.IsFontKnown(font))
return;
font->BuildFont();
m_font_registry.RegisterFont(font);
}
void Application::TexturePut(Handle win, Handle img, int x, int y)

View File

@@ -27,6 +27,9 @@ namespace mlx
void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str)
{
MLX_PROFILE_FUNCTION();
if(str.empty())
return;
Vec4f vec_color = {
static_cast<float>((color & 0x000000FF)) / 255.f,
static_cast<float>((color & 0x0000FF00) >> 8) / 255.f,

View File

@@ -38,7 +38,7 @@ namespace mlx
inline void RegisterFont(std::shared_ptr<Font> font);
inline void UnregisterFont(std::shared_ptr<Font> font);
inline bool IsFontKnown(std::shared_ptr<Font> font);
inline std::shared_ptr<Font> GetFont(const std::filesystem::path& name, float scale);
~FontRegistry() = default;

View File

@@ -13,11 +13,12 @@ namespace mlx
m_fonts_registry.erase(font);
}
bool FontRegistry::IsFontKnown(std::shared_ptr<Font> font)
std::shared_ptr<Font> FontRegistry::GetFont(const std::filesystem::path& name, float scale)
{
return std::find_if(m_fonts_registry.begin(), m_fonts_registry.end(), [&font](std::shared_ptr<Font> rhs)
auto it = std::find_if(m_fonts_registry.begin(), m_fonts_registry.end(), [&name, scale](std::shared_ptr<Font> rhs)
{
return font->GetName() == rhs->GetName() && font->GetScale() == rhs->GetScale();
}) != m_fonts_registry.end();
return name == rhs->GetName() && scale == rhs->GetScale();
});
return (it != m_fonts_registry.end() ? *it : nullptr);
}
}