-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI_TextField.cpp
52 lines (38 loc) · 1.3 KB
/
GUI_TextField.cpp
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
#include "GUI_TextField.h"
//--------------------------------------------------------------------------------
GUI_TextField::GUI_TextField(int _x, int _y, int _width, int _height, TTF_Font *_font, SDL_Color _color, std::string _str) : GUI_Widget(_x, _y, _width, _height)
{
font = _font;
color = _color;
txtSurface = NULL;
SetText(_str);
}
//--------------------------------------------------------------------------------
GUI_TextField::~GUI_TextField(void)
{
SDL_FreeSurface(txtSurface);
}
//--------------------------------------------------------------------------------
void GUI_TextField::SetText(std::string str)
{
text = str;
if(NULL != txtSurface)
SDL_FreeSurface(txtSurface);
txtSurface = TTF_RenderText_Solid(font, text.c_str(), color);
}
//--------------------------------------------------------------------------------
void GUI_TextField::SetColor(SDL_Color _color)
{
color = _color;
if(NULL != txtSurface)
SDL_FreeSurface(txtSurface);
txtSurface = TTF_RenderText_Solid(font, text.c_str(), color);
}
//--------------------------------------------------------------------------------
void GUI_TextField::Render(SDL_Surface *dest)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(txtSurface, &(container->clip_rect), dest, &offset);
}