CheatMenuSA/src/fontmgr.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

2021-11-05 05:59:11 -04:00
#include "fontmgr.h"
#include "pch.h"
ImFont* FontMgr::GetFont(const char* fontName)
{
for (auto &data : m_vecFonts)
{
2022-01-07 03:18:00 -05:00
if (data.m_path == std::string(fontName))
{
return data.m_pFont;
}
2021-11-05 05:59:11 -04:00
}
return nullptr;
}
ImFont* FontMgr::LoadFont(const char* fontName, float fontMul)
{
ImGuiIO& io = ImGui::GetIO();
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * fontMul;
std::string fullPath = std::string(PLUGIN_PATH((char*)"CheatMenu/fonts/")) + fontName + ".ttf";
2021-12-24 05:36:07 -05:00
m_vecFonts.push_back({io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize), fontSize, fontMul,
2022-01-07 03:18:00 -05:00
std::string(fontName)});
2021-11-05 05:59:11 -04:00
io.Fonts->Build();
return m_vecFonts.back().m_pFont;
}
2021-12-24 05:36:07 -05:00
void FontMgr::UnloadFonts()
2021-11-05 05:59:11 -04:00
{
2021-12-24 05:36:07 -05:00
ImGui::GetIO().Fonts->Clear();
}
2021-11-05 05:59:11 -04:00
2021-12-24 05:36:07 -05:00
void FontMgr::ReloadFonts()
{
UnloadFonts();
ImGuiIO& io = ImGui::GetIO();
2021-11-05 05:59:11 -04:00
for (auto &data : m_vecFonts)
{
2021-12-24 05:36:07 -05:00
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * data.m_fMul;
2021-11-05 05:59:11 -04:00
std::string fullPath = PLUGIN_PATH((char*)"CheatMenu/fonts/") + data.m_path + ".ttf";
2021-12-24 05:36:07 -05:00
data.m_pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), data.m_nSize);
2021-11-05 05:59:11 -04:00
}
io.FontDefault = GetFont("text");
io.Fonts->Build();
}