-
Notifications
You must be signed in to change notification settings - Fork 5
/
Text.hpp
101 lines (82 loc) · 2.82 KB
/
Text.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Text.hpp
*
* Created on: 2014/11/23
* Author: Dimitri Kourkoulis
* http://dimitros.be
* License: BSD 3-Clause License (see LICENSE file)
*/
// bii://dimitrikourk/small3d/samplegame/resources/fonts/CrusoeText/CrusoeText-Regular.ttf
#include <string>
#include "Renderer.hpp"
#include <memory>
#include <miguel/sdl2_ttf/SDL_ttf.h>
using namespace std;
#pragma once
extern bool ttfInitialised;
namespace small3d {
string intToStr(int number);
/**
* @struct Text
*
* @brief Structure for rendering text
*
*/
struct Text {
private:
shared_ptr<Renderer> renderer;
TTF_Font *font;
int size;
public:
/**
* @fn Text( shared_ptr<Renderer> renderer,
* const string &ttfFontPath="dimitrikourk/small3d/samplegame/resources/fonts/CrusoeText/CrusoeText-Regular.ttf",
* const int &size = 48);
*
* @brief Constructor.
*
* @param renderer The renderer to be used.
* @param ttfFontPath (optional) The path to the TrueType font to be used by the Renderer,
* including its filename. It defaults to the font provided
* by the engine but, even if the same one is used for an
* game, most probably the path to where it is placed
* will need to be specified here. Only one font can be used
* by the engine at present but that will change in the near
* future.
* @param size (optional) the size of the font in the created images. It defaults
* to 48.
*/
Text(
shared_ptr<Renderer> renderer,
const string &ttfFontPath="dimitrikourk/small3d/samplegame/resources/fonts/CrusoeText/CrusoeText-Regular.ttf",
const int &size = 48);
/**
* @fn ~Text();
*
* @brief Destructor.
*
*/
~Text();
/**
* Render some text on the screen. A texture will be generated, containing the given
* text and it will be rendered at a depth z of 0.5 in an orthographic coordinate space.
* @param text The text to be rendered
* @param colour The colour in which the text will be rendered
* @param topX The top x coordinate of the text rectangle
* @param topY The top y coordinate of the text rectangle
* @param bottomX The bottom x coordinate of the text rectangle
* @param bottomY The bottom y coordinate of the text rectangle
*/
void renderText(const string &text, const SDL_Color &colour,
const float &topX, const float &topY, const float &bottomX, const float &bottomY);
/**
* @fn void deleteTextTexture(const string &text);
*
* @brief Deletes a texture, generated for text rendering, from the GPU and
* from the renderer's map of textures
*
* @param text The text for which the texture has been generated.
*/
void deleteTextTexture(const string &text);
};
}