-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButton.cpp
More file actions
46 lines (37 loc) · 1.12 KB
/
Copy pathButton.cpp
File metadata and controls
46 lines (37 loc) · 1.12 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
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace sf;
using namespace std;
class Button{
private:
RectangleShape button;
Text text;
Color idleColor;
Color hoverColor;
public:
Button(){
idleColor = Color::White;
};
Button(Vector2f pos, float width, float height, Font& font, string mess){
idleColor = Color::White;
button.setPosition(pos);
button.setSize(Vector2f(width, height));
button.setFillColor(idleColor);
button.setOutlineThickness(2);
button.setOutlineColor(Color(100, 100, 100));
text.setFont(font);
text.setString(mess);
text.setFillColor(Color::Black);
float xPos = (pos.x + width / 2) - (text.getLocalBounds().width / 2);
float yPos = (pos.y + height / 2.5) - (text.getLocalBounds().height / 2);
text.setPosition(xPos, yPos);
}
void drawButton(RenderWindow &window){
window.draw(button);
window.draw(text);
}
bool isClicked(Vector2f mousePos){
FloatRect buttonBounds = button.getGlobalBounds();
return buttonBounds.contains(mousePos);
}
};