Try to use c++11 typeid for getFont
This commit is contained in:
parent
29185f679b
commit
cefead119a
@ -52,17 +52,21 @@ void FontManager::loadFonts()
|
||||
m_digit_ttf = new FaceTTF(stk_config->m_digit_ttf);
|
||||
|
||||
// Now load fonts with settings of ttf file
|
||||
unsigned int font_loaded = 0;
|
||||
RegularFace* regular = new RegularFace(m_normal_ttf);
|
||||
regular->init();
|
||||
m_fonts.push_back(regular);
|
||||
m_font_type_map[std::type_index(typeid(RegularFace))] = font_loaded++;
|
||||
|
||||
BoldFace* bold = new BoldFace(m_normal_ttf);
|
||||
bold->init();
|
||||
m_fonts.push_back(bold);
|
||||
m_font_type_map[std::type_index(typeid(BoldFace))] = font_loaded++;
|
||||
|
||||
DigitFace* digit = new DigitFace(m_digit_ttf);
|
||||
digit->init();
|
||||
m_fonts.push_back(digit);
|
||||
m_font_type_map[std::type_index(typeid(DigitFace))] = font_loaded++;
|
||||
} // loadFonts
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
@ -35,13 +37,15 @@ class FontWithFace;
|
||||
class FontManager : public NoCopy
|
||||
{
|
||||
private:
|
||||
PtrVector<FontWithFace> m_fonts;
|
||||
PtrVector<FontWithFace> m_fonts;
|
||||
|
||||
FT_Library m_ft_library;
|
||||
FT_Library m_ft_library;
|
||||
|
||||
FaceTTF* m_normal_ttf;
|
||||
FaceTTF* m_normal_ttf;
|
||||
|
||||
FaceTTF* m_digit_ttf;
|
||||
FaceTTF* m_digit_ttf;
|
||||
|
||||
std::unordered_map<std::type_index, int> m_font_type_map;
|
||||
|
||||
public:
|
||||
LEAK_CHECK()
|
||||
@ -53,11 +57,11 @@ public:
|
||||
template <typename T> T* getFont()
|
||||
{
|
||||
T* out = NULL;
|
||||
for (unsigned int i = 0; i < m_fonts.size(); i++)
|
||||
const unsigned int n = m_font_type_map[std::type_index(typeid(T))];
|
||||
out = dynamic_cast<T*>(m_fonts.get(n));
|
||||
if (out != NULL)
|
||||
{
|
||||
out = dynamic_cast<T*>(m_fonts.get(i));
|
||||
if (out != NULL)
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
Log::fatal("FontManager", "Can't get a font!");
|
||||
return out;
|
||||
|
Loading…
Reference in New Issue
Block a user