-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyProgressBar.cpp
More file actions
92 lines (80 loc) · 1.7 KB
/
MyProgressBar.cpp
File metadata and controls
92 lines (80 loc) · 1.7 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 "MyProgressBar.h"
/*
* Constructor
*/
MyProgressBar::MyProgressBar(std::string path)
{
if (!texture.loadFromFile(path)) {};
sprite = sf::Sprite(texture);
if (!rectTexture.loadFromFile("images/settings/rect_bar.png")) {};
rectSprite = sf::Sprite(rectTexture);
_percentage = 50;
_start = 0;
_end = 100;
}
/*
* Advanced constructor
*/
MyProgressBar::MyProgressBar(int start, int end, std::string path) : MyProgressBar(path)
{
_start = start;
_end = end;
}
/*
* Destructor
*/
MyProgressBar::~MyProgressBar()
{
}
//Setters and getters
void MyProgressBar::setPosition(int x, int y)
{
rectSprite.setPosition(x, y);
}
void MyProgressBar::setPositionBar(int x, int y)
{
sprite.setPosition(x, y);
}
/*
* Return a percentage calculated with the coordinates
*/
bool MyProgressBar::setPercentage(int x, int y)
{
if (sprite.getGlobalBounds().contains(x, y)) {
rectSprite.setPosition(x, rectSprite.getPosition().y);
_percentage = ((float) x - sprite.getPosition().x) / texture.getSize().x;
return true;
}
return false;
}
/*
* Set the percentage
*/
bool MyProgressBar::setPercentage(int percentage) {
if (percentage>=0 && percentage<=100) {
_percentage = percentage / 100.;
rectSprite.setPosition((sprite.getPosition().x + texture.getSize().x*_percentage), rectSprite.getPosition().y);
return true;
}
return false;
}
sf::Sprite MyProgressBar::getSprite() const
{
return sf::Sprite(rectSprite);
}
sf::Sprite MyProgressBar::getSpriteBar() const
{
return sf::Sprite(sprite);
}
int MyProgressBar::getPercentage() const
{
return _start + ((_end - _start)*_percentage);
}
int MyProgressBar::getX() const
{
return sprite.getPosition().x;
}
int MyProgressBar::getY() const
{
return sprite.getPosition().y;
}