2D_Game_Engine
Loading...
Searching...
No Matches
fontmanager.cpp
Go to the documentation of this file.
1#include <pch.hpp>
2#include <fontmanager.hpp>
3
4std::pair<uint32_t,std::shared_ptr<TextRenderer>> FontManager::GetFont(const std::string &path,int glyph_size,bool fixed){
5 for(auto &[id,font]:m_Fonts){
6 TextRenderer &f=*font.font;
7
8 if(f.m_LoadedGlyphSize==glyph_size && f.m_Fixed==fixed && f.m_LoadedFontPath==path){
9 font.copies++;
10 return {id,font.font};
11 }
12 }
13
14 uint32_t id=m_NextID++;
15 std::shared_ptr<TextRenderer> f=std::make_shared<TextRenderer>(path,glyph_size,fixed,id);
16
17 m_Fonts[id]=FontInfo(f);
18 return {id,f};
19}
20
21std::shared_ptr<TextRenderer> FontManager::GetFont(uint32_t id){
22 auto it=m_Fonts.find(id);
23
24 if(it==m_Fonts.end())
25 return nullptr;
26
27 return it->second.font;
28}
29
30void FontManager::ReleaseFont(uint32_t font_id){
31 auto it=m_Fonts.find(font_id);
32
33 if(it==m_Fonts.end())
34 return;
35
36 if(--(it->second.copies)==0)
37 m_Fonts.erase(it);
38}
39
40std::pair<uint32_t,std::shared_ptr<TextRenderer>> FontManager::UpdateFont(uint32_t font_id,const std::string &path,int glyph_size,bool fixed){
41 ReleaseFont(font_id);
42
43 return GetFont(path,glyph_size,fixed);
44}
std::pair< uint32_t, std::shared_ptr< TextRenderer > > UpdateFont(uint32_t font_id, const std::string &path, int glyph_size, bool fixed)
std::pair< uint32_t, std::shared_ptr< TextRenderer > > GetFont(const std::string &path, int glyph_size, bool fixed)
void ReleaseFont(uint32_t font_id)