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
|
#ifndef TEXT_HPP
#define TEXT_HPP
#include "framework.hpp"
using namespace std;
class Ctext
{
public:
Ctext();
void quit();
void write_text(int size,int R,int G,int B,const char text[]);
void write_int(int size,int R,int G,int B,int integer);
void Render (int xpos,int ypos);
private:
SDL_Surface *m_pScreen;
SDL_Surface *m_pText;
SDL_Rect m_Rect;
SDL_Color mcolor;
TTF_Font* mfont;
int msize;
stringstream mssinteger;
};
#endif
//text.cpp
#include "text.hpp"
Ctext::Ctext()
{
// Zeiger auf Screen holen
m_pScreen = g_pFramework->m_pScreen;
mfont = g_pFramework->m_pFont;
}
void Ctext::quit()
{
TTF_CloseFont (mfont);
// Surface freigeben
SDL_FreeSurface (m_pText);
m_pText = NULL;
}
void Ctext::write_text(int size,int R,int G,int B,const char text[])
{
msize = size;
mcolor.r = R;
mcolor.g = G;
mcolor.b = B;
m_pText = TTF_RenderText_Solid(mfont,text,mcolor);
}
void Ctext::write_int(int size,int R,int G,int B,int integer)
{
msize = size;
mcolor.r = R;
mcolor.g = G;
mcolor.b = B;
mssinteger.clear();
mssinteger.str ("");
mssinteger << integer;
m_pText = TTF_RenderText_Solid(mfont,mssinteger.str().c_str(),mcolor);
}
void Ctext::Render (int xpos,int ypos)
{
m_Rect.x = xpos;
m_Rect.y = ypos;
// Text rendern
SDL_BlitSurface (m_pText, NULL, m_pScreen, &m_Rect);
}
|