-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressBar.cpp
69 lines (50 loc) · 1.82 KB
/
ProgressBar.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
66
67
68
69
#include <utility>
#include "ProgressBar.h"
ProgressBar::ProgressBar(FileTransfer *s, sf::RenderWindow *w, std::string type,
unsigned int x, unsigned int y, sf::Color color) :
window(w), subject(s), type(std::move(type)), maxWidth(300), maxHeight(10) {
subject->addObserver(this);
rectangleShape.setPosition(sf::Vector2f(x, y));
rectangleShape.setFillColor(color);
}
ProgressBar::~ProgressBar() {
subject->removeObserver(this);
}
void ProgressBar::update() {
if (type == "overall") {
rectangleShape.setSize(sf::Vector2f((maxWidth * subject->getNumFilesTransferred()) /
subject->getFilesSize(), maxHeight));
}
if (type == "single") {
rectangleShape.setPosition(sf::Vector2f(0, 30));
rectangleShape.setSize(sf::Vector2f(300, 40));
rectangleShape.setFillColor(sf::Color::Black);
window->draw(rectangleShape);
rectangleShape.setFillColor(sf::Color::Green);
rectangleShape.setSize(sf::Vector2f((maxWidth * subject->getBytesTransferred())
/ subject->getFileTransferring()->second, maxHeight));
}
window->draw(rectangleShape);
window->display();
}
const sf::RectangleShape &ProgressBar::getRectangleShape() const {
return rectangleShape;
}
const std::string &ProgressBar::getType() const {
return type;
}
void ProgressBar::setType(const std::string &type) {
ProgressBar::type = type;
}
unsigned int ProgressBar::getMaxWidth() const {
return maxWidth;
}
void ProgressBar::setMaxWidth(unsigned int maxWidth) {
ProgressBar::maxWidth = maxWidth;
}
unsigned int ProgressBar::getMaxHeight() const {
return maxHeight;
}
void ProgressBar::setMaxHeight(unsigned int maxHeight) {
ProgressBar::maxHeight = maxHeight;
}