libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextRenderer.hpp
Go to the documentation of this file.
1 #ifndef TEXTRENDERER_HPP
2 #define TEXTRENDERER_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <memory>
22 #include <string>
23 #include <map>
24 #include "SDLHandle.hpp"
25 #include "Color.hpp"
26 
27 struct _TTF_Font;
28 typedef _TTF_Font TTF_Font;
29 struct SDL_Color;
30 
31 namespace AlgAudio{
32 
33 class SDLTexture;
34 class SDLTextTexture;
35 class Window;
36 
37 struct FontParams{
38  FontParams(std::string n, int s) : name(n), size(s) {}
39  std::string name;
40  int size;
41  bool operator<(const FontParams& other) const{ return name<other.name || (name==other.name && size < other.size);}
42 };
43 
44 // TODO: Instantiable class, SDLHandle tracking, font unloading on destruction
48  TextRenderer() = delete; // static class
49 public:
50  static std::shared_ptr<SDLTextTexture> Render(std::weak_ptr<Window>, FontParams, std::string);
51 private:
52  static TTF_Font* GetFont(FontParams);
53  static TTF_Font* Preload(FontParams);
54  // Temporarily it is assumed that any rendering will be performed only if
55  // at least one window exists, thus it should be safe to assume that SDL
56  // is always initialised.
57  // SDLHandle handle;
58  static std::map<FontParams, TTF_Font*> fontbank;
59 };
60 
61 
62 } // namespace AlgAudio
63 
64 #endif // TEXTRENDERER_HPP
int size
Definition: TextRenderer.hpp:40
Definition: TextRenderer.hpp:47
FontParams(std::string n, int s)
Definition: TextRenderer.hpp:38
Definition: TextRenderer.hpp:37
static std::shared_ptr< SDLTextTexture > Render(std::weak_ptr< Window >, FontParams, std::string)
bool operator<(const FontParams &other) const
Definition: TextRenderer.hpp:41
Definition: Alertable.hpp:26
_TTF_Font TTF_Font
Definition: TextRenderer.hpp:27
std::string name
Definition: TextRenderer.hpp:39