-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI_FullButton.cpp
65 lines (48 loc) · 1.81 KB
/
GUI_FullButton.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
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "GUI_FullButton.h"
//--------------------------------------------------------------------------------
GUI_FullButton::GUI_FullButton(int _x, int _y, int _width, int _height, SDL_Surface *_theme, TTF_Font *_font, SDL_Color _color, std::string _str, GFX_SpriteManager *_mng, int _icon, int _iconSize)
: GUI_Button(_x, _y, _width, _height, _theme)
{
sprMng = _mng;
icon = _icon;
iconSize = _iconSize;
font = _font;
color = _color;
txtSurface = NULL;
SetText(_str);
}
//--------------------------------------------------------------------------------
GUI_FullButton::~GUI_FullButton(void)
{
SDL_FreeSurface(txtSurface);
}
//--------------------------------------------------------------------------------
void GUI_FullButton::Render(SDL_Surface *dest)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(clicked ? container2 : container, &(container->clip_rect), dest, &offset);
int ww = (txtSurface->clip_rect.w + iconSize)/2;
int hh = txtSurface->clip_rect.h/2;
offset.x = x+width/2-ww+iconSize+(clicked ? 1 : 0);
offset.y = y+height/2-hh+(clicked ? 1 : 0);
SDL_BlitSurface(txtSurface, &(txtSurface->clip_rect), dest, &offset);
sprMng->DrawSprite(icon, offset.x-iconSize, y+4+(clicked ? 1 : 0), dest);
}
//--------------------------------------------------------------------------------
void GUI_FullButton::SetText(std::string str)
{
text = str;
if(NULL != txtSurface)
SDL_FreeSurface(txtSurface);
txtSurface = TTF_RenderText_Solid(font, text.c_str(), color);
}
//--------------------------------------------------------------------------------
void GUI_FullButton::SetColor(SDL_Color _color)
{
color = _color;
if(NULL != txtSurface)
SDL_FreeSurface(txtSurface);
txtSurface = TTF_RenderText_Solid(font, text.c_str(), color);
}