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
|
#include "Text.hpp"
// Constructor
// Task: Set the pointers
CText::CText()
{
m_pScreen = g_pFramework->GetScreen();
m_pText = NULL;
m_pFont = NULL;
}
// Destructor
// Task: Free the surfaces
CText::~CText()
{
SDL_FreeSurface(m_pText);
}
// Init
// Task: Initialize the Text, setting color, font and position
void CText::Init(char sText[], char sTTF[], short size, float fXPos, float fYPos, short r, short g, short b)
{
m_Size = size;
m_sTTF = sTTF;
m_sText = sText;
m_pFont = TTF_OpenFont(m_sTTF, m_Size);
if (m_pFont != NULL)
{
m_Color.r = r;
m_Color.g = g;
m_Color.b = b;
m_Color.unused = 0;
m_pText = TTF_RenderText_Solid(m_pFont, m_sText, m_Color);
m_Rect.x = static_cast<int>(fXPos);
m_Rect.y = static_cast<int>(fYPos);
m_Rect.w = 0;
m_Rect.h = 0;
}
}
// Render
// Task: Render the text into the screen
void CText::Render()
{
SDL_BlitSurface(m_pText, NULL, m_pScreen, &m_Rect);
}
// SetPos
// Task: Set new Positon of the text
void CText::SetPos(float fXPos, float fYPos)
{
m_Rect.x = static_cast<int>(fXPos);
m_Rect.y = static_cast<int>(fYPos);
}
// SetColor
// Task: Set new Color
void CText::SetColor(short r, short g, short b)
{
m_Color.r = r;
m_Color.g = g;
m_Color.b = b;
m_pText = TTF_RenderText_Solid(m_pFont, m_sText, m_Color);
}
// SetText
// Task: Set new Text
void CText::SetText(char sText[])
{
m_sText = sText;
m_pText = TTF_RenderText_Solid(m_pFont, m_sText, m_Color);
}
|