-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.h
More file actions
87 lines (71 loc) · 2.02 KB
/
Button.h
File metadata and controls
87 lines (71 loc) · 2.02 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
#pragma once
#include "StaticObject.h"
/// <summary>
/// Contains all the properties needed to create text
/// </summary>
struct TextProperties {
std::string text;
sf::Font font;
unsigned int fontSize;
sf::Color fill;
sf::Color outline;
float thickness;
public:
TextProperties() {
text = "";
fontSize = 10;
font = sf::Font("Fonts/Arial.TTF");
fill = sf::Color(255, 255, 255);
outline = sf::Color(255, 255, 255);
thickness = 1;
}
TextProperties(std::string str, sf::Font font, unsigned int fontSize,
sf::Color fill, sf::Color outline, float outlineThickness) {
text = str;
this->font = font;
this->fontSize = fontSize;
this->fill = fill;
this->outline = outline;
thickness = outlineThickness;
}
};
/// <summary>
/// Represents a clickable and drawable button
/// </summary>
class Button : public StaticObject
{
public:
Button(float x = 0, float y = 0, float radius = 1,
sf::Color fill = sf::Color(0, 0, 0), sf::Color pressed = sf::Color(0, 0, 0), sf::Color outline = sf::Color(0, 0, 0), float outlineThickness = 1);
bool ButtonPressed(const sf::Vector2f coords);
virtual void Render(sf::RenderWindow& screen) override;
void SetRadius(const float radius) {
this->radius = radius;
}
void SetColors(const sf::Color fill, const sf::Color clicked, const sf::Color outline) {
fillCol = fill;
pressedCol = clicked;
outlineCol = outline;
}
void SetOutlineThickness(const float outlineThickness) {
thickness = outlineThickness;
}
void SetText(std::string str, const sf::Font font, unsigned int fontSize,
sf::Color fill, sf::Color outline, float outlineThickness = 1) {
tp = TextProperties(str, font, fontSize, fill, outline, outlineThickness);
}
void SetClickedState(const bool clicked) {
pressed = clicked;
}
const bool GetClickedState() {
return pressed;
}
virtual PhysicsObject* GetObj() { return nullptr; }
protected:
// Properties of the button
float radius;
sf::Color fillCol, pressedCol, outlineCol;
float thickness;
bool pressed; // State of the button
TextProperties tp;
};