43 lines
979 B
C++
43 lines
979 B
C++
#ifndef __OPENGLPLAYGROUND_FONTPROVIDER_HH__
|
|
#define __OPENGLPLAYGROUND_FONTPROVIDER_HH__
|
|
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <tuple>
|
|
#include <string>
|
|
|
|
#include "common.hh"
|
|
#include "Singleton.hh"
|
|
|
|
using FontProviderKeyType = std::tuple<std::string, unsigned>;
|
|
|
|
namespace std
|
|
{
|
|
template<>
|
|
struct hash<FontProviderKeyType> {
|
|
typedef FontProviderKeyType argument_type;
|
|
typedef std::size_t result_type;
|
|
|
|
result_type operator()(argument_type const& s) const {
|
|
const result_type h1{std::hash<std::string>()(std::get<0>(s))};
|
|
const result_type h2{std::hash<unsigned>()(std::get<1>(s))};
|
|
return h1 ^ h2;
|
|
}
|
|
};
|
|
}
|
|
|
|
class FontProvider : public Singleton<FontProvider> {
|
|
private:
|
|
FontProvider();
|
|
friend class Singleton<FontProvider>;
|
|
|
|
public:
|
|
TTF_Font *getFont(std::string const& name, unsigned ptsize);
|
|
|
|
void cleanup();
|
|
|
|
private:
|
|
std::unordered_map<std::tuple<std::string, unsigned>, TTFFontUPtr> fontCache_;
|
|
};
|
|
#endif
|