mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 14:24:10 +08:00
Improved font rendering interface
This commit is contained in:
@@ -3,13 +3,13 @@
|
||||
#include <unordered_map>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
|
||||
#include "Textstyle.h"
|
||||
#include "FontManager.h"
|
||||
|
||||
class TextRenderer {
|
||||
private:
|
||||
SDL_Renderer* m_renderer;
|
||||
FontManager& m_fontManager;
|
||||
FontManager* m_fontManager;
|
||||
|
||||
// 缓存文字纹理
|
||||
|
||||
@@ -20,23 +20,25 @@ private:
|
||||
int height;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, CachedText> m_cache;
|
||||
|
||||
|
||||
|
||||
std::unordered_map<size_t, CachedText> m_cache;
|
||||
// 创建材质
|
||||
SDL_Texture* createTextTexture(const std::string& text, const std::string& fontID, SDL_Color color);
|
||||
|
||||
// 创建一个唯一的缓存键:文本 + 字体 + 颜色
|
||||
std::string makeCacheKey(const std::string& text, const std::string& fontID, SDL_Color color);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
TextRenderer(FontManager& fontManager, SDL_Renderer* renderer);
|
||||
TextRenderer(SDL_Renderer* renderer, FontManager* fontManager);
|
||||
~TextRenderer();
|
||||
|
||||
|
||||
//渲染文本
|
||||
|
||||
void renderText(const std::string& text, const std::string& fontID, int x, int y, SDL_Color color);
|
||||
void renderText(const std::string& text, TextStyle style, int x, int y);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user