mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 10:13:42 +00:00
technically a text_cache but maps throw segfaults for some reason
This commit is contained in:
parent
639c3bb38a
commit
dc2e54eea3
@ -48,16 +48,16 @@ public:
|
|||||||
TextManager(TextManager const&) = delete;
|
TextManager(TextManager const&) = delete;
|
||||||
void operator=(TextManager const&) = delete;
|
void operator=(TextManager const&) = delete;
|
||||||
|
|
||||||
|
std::map<const char*, TTF_Font*> font_cache;
|
||||||
|
std::map<std::string, SDL_Texture*> text_cache;
|
||||||
|
|
||||||
bool isTextRendered = false;
|
bool isTextRendered = false;
|
||||||
|
|
||||||
TTF_Font* loadFont(const char* filepath);
|
TTF_Font* loadFont(const char* filepath);
|
||||||
|
|
||||||
// TODO: probably gotta change sdl surface since this is a wrapper func for the dev
|
|
||||||
void RenderText(GameInternal* game, std::string font, std::string text, DisplayOptions displayOptions, Color fg, Color bg, int wrapWidth, Rect src, Rect dst);
|
void RenderText(GameInternal* game, std::string font, std::string text, DisplayOptions displayOptions, Color fg, Color bg, int wrapWidth, Rect src, Rect dst);
|
||||||
void RenderTextFromFile(GameInternal* game, std::string font, std::string filepath, int id, DisplayOptions displayOptions, Color fg, Color bg, int wrapWidth, Rect src, Rect dst);
|
void RenderTextFromFile(GameInternal* game, std::string font, std::string filepath, int id, DisplayOptions displayOptions, Color fg, Color bg, int wrapWidth, Rect src, Rect dst);
|
||||||
|
|
||||||
std::map<const char*, TTF_Font*> font_cache;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Texture* CreateRenderedTexture(GameInternal* game, TTF_Font* font, std::string text, DisplayOptions displayOptions, SDL_Color fg, SDL_Color bg, int wrapWidth);
|
SDL_Texture* CreateRenderedTexture(GameInternal* game, TTF_Font* font, std::string text, DisplayOptions displayOptions, SDL_Color fg, SDL_Color bg, int wrapWidth);
|
||||||
SDL_Surface* RenderSolid(TTF_Font* font, std::string text, SDL_Color fg, int wrapWidth);
|
SDL_Surface* RenderSolid(TTF_Font* font, std::string text, SDL_Color fg, int wrapWidth);
|
||||||
|
|||||||
@ -69,7 +69,6 @@ void TextManager::RenderTextFromFile(GameInternal* game, std::string font, std::
|
|||||||
std::string text;
|
std::string text;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto it = data.begin(); it != data.end(); ++it) {
|
for (auto it = data.begin(); it != data.end(); ++it) {
|
||||||
std::cout << "Key: " << it.key() << ", Value: " << it.value() << std::endl;
|
|
||||||
if (it.key() == std::to_string(id)) {
|
if (it.key() == std::to_string(id)) {
|
||||||
text = it.value();
|
text = it.value();
|
||||||
found = true;
|
found = true;
|
||||||
@ -89,6 +88,12 @@ void TextManager::RenderTextFromFile(GameInternal* game, std::string font, std::
|
|||||||
|
|
||||||
SDL_Texture* TextManager::CreateRenderedTexture(GameInternal* game, TTF_Font* font, std::string text, DisplayOptions displayOptions, SDL_Color fg, SDL_Color bg, int wrapWidth)
|
SDL_Texture* TextManager::CreateRenderedTexture(GameInternal* game, TTF_Font* font, std::string text, DisplayOptions displayOptions, SDL_Color fg, SDL_Color bg, int wrapWidth)
|
||||||
{
|
{
|
||||||
|
// auto it = this->text_cache.find(text);
|
||||||
|
//
|
||||||
|
// if (it != this->text_cache.end()) {
|
||||||
|
// return it->second;
|
||||||
|
// }
|
||||||
|
|
||||||
SDL_Surface* surface = nullptr;
|
SDL_Surface* surface = nullptr;
|
||||||
|
|
||||||
switch(displayOptions)
|
switch(displayOptions)
|
||||||
@ -113,7 +118,11 @@ SDL_Texture* TextManager::CreateRenderedTexture(GameInternal* game, TTF_Font* fo
|
|||||||
if(!surface)
|
if(!surface)
|
||||||
std::cerr << "Error when rendering text!" << std::endl;
|
std::cerr << "Error when rendering text!" << std::endl;
|
||||||
|
|
||||||
return SDL_CreateTextureFromSurface(game->renderer, surface);
|
auto texture = SDL_CreateTextureFromSurface(game->renderer, surface);
|
||||||
|
|
||||||
|
// text_cache[text] = texture;
|
||||||
|
|
||||||
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface* TextManager::RenderSolid(TTF_Font* font, std::string text, SDL_Color fg, int wrapWidth)
|
SDL_Surface* TextManager::RenderSolid(TTF_Font* font, std::string text, SDL_Color fg, int wrapWidth)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user