-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.cpp
65 lines (58 loc) · 1.45 KB
/
Button.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 "Button.h"
Button::Button()
{
}
Button::Button(int x1, int y1, int w1, std::string text1)
{
x = x1;
y = y1;
text = text1;
height = 35;
width = w1;
// = al_load_font("comic.ttf", 20, 0);
color = al_color_name("white");
img = NULL;
}
Button::Button(int x1, int y1, int w1, ALLEGRO_BITMAP *sprite, std::string title)
{
x = x1;
y = y1;
text = "";
height = w1;
width = w1;
img = sprite;
towerTitle = title;
//font = al_load_font("comic.ttf", 20, 0);
}
int Button::draw(ALLEGRO_MOUSE_STATE state)
{
int thickness = 1;
color = preferredcolor;
int checkedMouse = checkMouse(state);
ALLEGRO_COLOR fontcolor = al_color_name("white");
if(enabled){
thickness = checkedMouse;
}
else {
thickness = 1;
color = al_color_name("darkslategray");
fontcolor = al_color_name("gray");
}
al_draw_text(font, fontcolor, x + 20, y, ALLEGRO_ALIGN_LEFT, text.c_str());
if (img != NULL)
{
al_draw_filled_rectangle(x, y, x+ width, y + height, al_color_name("gray"));
al_draw_scaled_bitmap(img, 0, 0, al_get_bitmap_width(img), al_get_bitmap_height(img), x, y, width, height, 0);
}
al_draw_rectangle(x, y, x + width, y + height, color, thickness);
return checkedMouse;
}
int Button::checkMouse(ALLEGRO_MOUSE_STATE state)
{
if ((state.y >= y&& state.y <= y + height)
&& (state.x >= x && state.x <= x + width)) {
color = al_color_name("cyan");
return 2;
}
return 1;
}