ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
FontManager.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <unordered_map>
5#include <memory>
6#include <SDL3_ttf/SDL_ttf.h>
7
9
10namespace Shit {
16 class FontManager final {
17 friend class ResourceManager;
18 public:
19 FontManager(const FontManager&) = delete;
23 ~FontManager() { clearFont(); }
24
25 private:
26 FontManager() = default;
27
28 struct TTF_FontDeleter {
29 void operator()(TTF_Font* font) const {
30 if (font) TTF_CloseFont(font);
31 }
32 };
33
34 struct FontKey {
35 std::string path;
36 float size;
37 bool operator==(const FontKey& o) const { return path == o.path && size == o.size; }
38 };
39 struct FontKeyHash {
40 std::size_t operator()(const FontKey& k) const {
41 return std::hash<std::string>{}(k.path) ^ std::hash<float>{}(k.size);
42 }
43 };
44
45 TTF_Font* loadFont(const std::string& filePath, float fontSize);
46 TTF_Font* getFont(const std::string& filePath, float fontSize);
47 void unloadFont(const std::string& filePath, float fontSize);
48 void clearFont();
49
50 std::unordered_map<FontKey, std::unique_ptr<TTF_Font, TTF_FontDeleter>, FontKeyHash> m_fonts;
51 };
52}
FontManager(FontManager &&)=default
~FontManager()
定义 FontManager.h:23
FontManager & operator=(const FontManager &)=delete
friend class ResourceManager
定义 FontManager.h:17
FontManager(const FontManager &)=delete
FontManager & operator=(FontManager &&)=default
定义 AudioPlayer.h:10