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
|
||||
@ -43,6 +45,8 @@ private:
|
||||
|
||||
FaceTTF* m_digit_ttf;
|
||||
|
||||
std::unordered_map<std::type_index, int> m_font_type_map;
|
||||
|
||||
public:
|
||||
LEAK_CHECK()
|
||||
// ------------------------------------------------------------------------
|
||||
@ -53,10 +57,10 @@ public:
|
||||
template <typename T> T* getFont()
|
||||
{
|
||||
T* out = NULL;
|
||||
for (unsigned int i = 0; i < m_fonts.size(); i++)
|
||||
{
|
||||
out = dynamic_cast<T*>(m_fonts.get(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)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
Log::fatal("FontManager", "Can't get a font!");
|
||||
|
Loading…
Reference in New Issue
Block a user