-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.inl
More file actions
92 lines (77 loc) · 2.08 KB
/
interface.inl
File metadata and controls
92 lines (77 loc) · 2.08 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
void swap_flag(bool* pflag){
if (*pflag){
*pflag = false;
} else {
*pflag = true;
}
}
void HandleClose(sf::RenderWindow& window, sf::Event& event){
//if exit button was pressed
if (event.type == sf::Event::Closed)
//then close the main window
window.close();
}
//CONSTRUCTORS
Button::Button()
{
x = 0;
y = 0;
xsize = 10;
ysize = 10;
}
Button::Button(int x, int y, int xsize, int ysize, sf::Font& font, string name){
this -> x = x;
this -> y = y;
this -> xsize = xsize;
this -> ysize = ysize;
pressedStatus = false;
picture.setSize(sf::Vector2f(xsize, ysize));
picture.setFillColor(sf::Color::Red);
picture.setOutlineThickness(2);
picture.setOutlineColor(sf::Color::Black);
picture.setPosition(x, y);
label.setFont(font);
label.setColor(sf::Color::Black);
label.setPosition(x, y);
label.setString(name);
label.setCharacterSize(20);
}
///////////////////////////////////////////////////////////////////////////
Button::~Button(){
}
///////////////////////////////////////////////////////////////////////////
bool Button::HandlePressed(sf::Event event, int MouseX, int MouseY){
if (event.type == sf::Event::MouseButtonPressed){
if ((MouseX >= x) && (MouseY >= y) && (MouseX <= (x + xsize)) && (MouseY <= (y + ysize))) {
pressedStatus = !pressedStatus;
if (pressedStatus){
picture.setFillColor(sf::Color::White);
} else {
picture.setFillColor(sf::Color::Red);
}
return true;
}
}
return false;
}
bool Button::get_pressedStatus(){
return pressedStatus;
}
sf::RectangleShape Button::get_picture(){
if (pressedStatus){
picture.setFillColor(sf::Color::White);
} else {
picture.setFillColor(sf::Color::Red);
}
return picture;
}
sf::Text Button::get_label(){
return label;
}
void Button::setStatus(bool status){
pressedStatus = status;
}
void Button::setLabel(string& s)
{
label.setString(s);
}