CheatMenuSA/src/fontmgr.cpp

48 lines
1.2 KiB
C++
Raw Normal View History

2021-11-05 05:59:11 -04:00
#include "fontmgr.h"
#include "pch.h"
2022-06-12 14:01:43 -04:00
ImFont* FontMgr::Get(const char* fontName)
2021-11-05 05:59:11 -04:00
{
for (auto &data : m_vecFonts)
{
2022-06-12 14:01:43 -04:00
if (!strcmp(data.m_path.c_str(), fontName))
2022-01-07 03:18:00 -05:00
{
return data.m_pFont;
}
2021-11-05 05:59:11 -04:00
}
return nullptr;
}
2022-06-12 14:01:43 -04:00
ImFont* FontMgr::Load(const char* fontName, float fontMul)
2021-11-05 05:59:11 -04:00
{
ImGuiIO& io = ImGui::GetIO();
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * fontMul;
2022-06-12 14:01:43 -04:00
std::string fullPath = std::format("{}{}.ttf", PLUGIN_PATH((char*)"CheatMenu/fonts/"), fontName);
ImFont *pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize);
m_vecFonts.push_back({pFont, fontSize, fontMul, std::string(fontName)});
2021-11-05 05:59:11 -04:00
io.Fonts->Build();
2022-06-12 14:01:43 -04:00
return pFont;
2021-11-05 05:59:11 -04:00
}
2022-06-12 14:01:43 -04:00
void FontMgr::UnloadAll()
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
2022-06-12 14:01:43 -04:00
void FontMgr::ReloadAll()
2021-12-24 05:36:07 -05:00
{
2022-06-12 14:01:43 -04:00
UnloadAll();
2021-12-24 05:36:07 -05:00
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
}
2022-06-12 14:01:43 -04:00
io.FontDefault = Get("text");
2021-11-05 05:59:11 -04:00
io.Fonts->Build();
}