-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
92 lines (82 loc) · 1.77 KB
/
Copy pathButton.cpp
File metadata and controls
92 lines (82 loc) · 1.77 KB
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
#include "Button.h"
#include "SDL_ttf.h"
#include "FontFactory.h"
Button::Button(void)
{
setX(0);
setY(0);
setW(1);
setH(1);
SDL_Color fontC = {255,255,255};
SDL_Color black = {0,0,0};
SDL_Color some = {32, 43, 234};
this->fontClickedColor = fontC;
this->fontColor = black;
this->frontClicked = some;
front_text = "";
pressed = false;
enabled = true;
}
Button::Button(int x, int y, int w, int h, char* frontText)
{
setX(x);
setY(y);
setW(w);
setH(h);
SDL_Color fontC = {255,255,255};
SDL_Color black = {0,0,0};
SDL_Color some = {32, 43, 234};
this->fontClickedColor = fontC;
this->fontColor = black;
this->frontClicked = some;
front_text = frontText;
pressed = false;
enabled = true;
}
void Button::draw(int x, int y)
{
SDL_Color textColor;
Uint32 temp = this->backgroundColor;
if(pressed && enabled)
{
textColor = this->fontClickedColor;
this->backgroundColor = SDL_MapRGB(surface->format, frontClicked.r, frontClicked.g, frontClicked.b);
}
else
{
textColor = this->fontColor;
}
FramedRect::draw(x,y);
if(front_text != "")
{
TTF_Font* font = FontFactory::getFont(fontName);
SDL_Surface* newSurface;
newSurface = TTF_RenderText_Solid(font, this->front_text, textColor);
SDL_Rect cuts;
cuts.h = h; cuts.w = w;
cuts.x = this->x + x + w/2 - newSurface->w / 2; cuts.y = this->y + y + h/2 - newSurface->h/2;
SDL_BlitSurface(newSurface, NULL, surface, &cuts);
SDL_FreeSurface(newSurface);
}
this->backgroundColor = temp;
}
void Button::setFontName(char* fontName)
{
this->fontName = fontName;
}
void Button::setEnable(bool enabled)
{
this->enabled = enabled;
}
bool Button::isEnabled()
{
return this->enabled;
}
bool Button::spreadEvent(SDL_Event e)
{
if(enabled) return DrawableSDL::spreadEvent(e);
return false;
}
Button::~Button(void)
{
}