Load GUI from XML
This commit is contained in:
42
FontProvider.hh
Normal file
42
FontProvider.hh
Normal file
@@ -0,0 +1,42 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user