SDL SPOOKY PLATFORMER ENGINE  0.2.0
An implementation of a platformer using sdl, implemented using an entity component system and efficient collision management.
TextManager.hpp
Go to the documentation of this file.
1 #ifndef TEXT_MANAGER_HPP
2 #define TEXT_MANAGER_HPP
3 
4 #include <SDL2/SDL.h>
5 #include <SDL2/SDL_ttf.h>
6 #include <ResourceManager.hpp>
7 
9 static void CloseFont(TTF_Font *ttf_font)
10 {
11  std::cout << "calling ttf font destructor" << std::endl
12  << std::flush;
13  // TTF_CloseFont(ttf_font); // seg faults right now... even though font exists
14 }
15 
19 class TextManager : public ResourceManager<TextManager, TTF_Font>
20 {
21 public:
26  {
27  static TextManager *instance = new TextManager();
28  return *instance;
29  }
30 
36  int startUp(SDL_Renderer *in)
37  {
38  if (TTF_Init() == -1)
39  {
40  printf("failed to initialize ttf library\n");
41  }
42  ren = in;
43  fileMap.emplace("DejaVuSansMono", "./Assets/fonts/DejaVuSansMono.ttf");
44  return 1;
45  }
46 
50  int shutDown()
51  {
53  TTF_Quit();
54  return 1;
55  }
56 
60  std::shared_ptr<TTF_Font> Load(const std::string &path)
61  {
62 
63  TTF_Font *font = TTF_OpenFont(path.c_str(), 20);
64 
65  if (font == NULL)
66  {
67  printf("%s\n", TTF_GetError());
68  SDL_Log("Failed to allocate surface");
69  return NULL;
70  }
71  else
72  {
73  wchar_t wc = '\u0045';
74  if (!TTF_GlyphIsProvided(font, wc))
75  {
76  printf("Warning: some characters may not be available in the font: %s", path.c_str());
77  }
78  SDL_Log("Allocated font memory for %s", path.c_str());
79  return std::shared_ptr<TTF_Font>(font, CloseFont);
80  }
81  }
82 
83  TextManager(TextManager const &) = delete;
84  void operator=(TextManager const &) = delete;
85 protected:
86  SDL_Renderer *ren;
87 private:
88  TextManager()
89  {
90  printf("Constructing text manager\n");
91  }
92 };
93 
94 #endif
void operator=(TextManager const &) = delete
Forbidden.
std::shared_ptr< TTF_Font > Load(const std::string &path)
Definition: TextManager.hpp:60
int shutDown()
Definition: ResourceManager.hpp:69
int shutDown()
Definition: TextManager.hpp:50
std::map< std::string, std::string > fileMap
stores location of resources
Definition: ResourceManager.hpp:156
SDL_Renderer * ren
The renderer.
Definition: TextManager.hpp:86
int startUp(SDL_Renderer *in)
Definition: TextManager.hpp:36
static TextManager & instance()
Definition: TextManager.hpp:25
Definition: ResourceManager.hpp:62
Definition: TextManager.hpp:19
static void CloseFont(TTF_Font *ttf_font)
<
Definition: TextManager.hpp:9