ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
FontManager.h
浏览该文件的文档.
1
#pragma once
2
3
#include <string>
4
#include <unordered_map>
5
#include <memory>
6
#include <SDL3_ttf/SDL_ttf.h>
7
8
#include "
ShitEngine/Core/Core.h
"
9
10
namespace
Shit
{
16
class
FontManager
final {
17
friend
class
ResourceManager
;
18
public
:
19
FontManager
(
const
FontManager
&) =
delete
;
20
FontManager
&
operator=
(
const
FontManager
&) =
delete
;
21
FontManager
(
FontManager
&&) =
default
;
22
FontManager
&
operator=
(
FontManager
&&) =
default
;
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
}
Core.h
Shit::FontManager::FontManager
FontManager(FontManager &&)=default
Shit::FontManager::~FontManager
~FontManager()
定义
FontManager.h:23
Shit::FontManager::operator=
FontManager & operator=(const FontManager &)=delete
Shit::FontManager::ResourceManager
friend class ResourceManager
定义
FontManager.h:17
Shit::FontManager::FontManager
FontManager(const FontManager &)=delete
Shit::FontManager::operator=
FontManager & operator=(FontManager &&)=default
Shit
定义
AudioPlayer.h:10
include
ShitEngine
Resource
FontManager.h
制作者
1.17.0