-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdjustBar.cpp
75 lines (64 loc) · 1.66 KB
/
AdjustBar.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
70
71
72
73
74
75
#include "AdjustBar.h"
AdjustBar::AdjustBar(Vector2f size)
:size{ size }
, base{ size }
, bar{ {0, size.y} }
{
//this->turn_count = turn_count;
//this->turn_width = static_cast<double>(size.x) / turn_count;
base.setFillColor(Color(100, 100, 100, 100));
base.setOutlineThickness(2);
base.setOutlineColor(Color::Black);
bar.setSize(Vector2f(0, size.y));
bar.setFillColor(Color(220, 220, 220, 170));
}
void AdjustBar::setTurnCount(int turnCount)
{
this->turn_count = turnCount;
this->turn_width = static_cast<double>(size.x) / turn_count;
bar.setSize(Vector2f(0, size.y));
}
void AdjustBar::setProgress(float mouseX)
{
mouseX = mouseX - this->getPosition().x + turn_width / 3;
if (mouseX < 0) {
mouseX = 0;
}
else if (mouseX > size.x) {
mouseX = size.x;
}
mouseX = static_cast<int>(mouseX / turn_width) * turn_width;
bar.setSize(Vector2f(mouseX, size.y));
}
double AdjustBar::getProgress()
{
return static_cast<double>(bar.getSize().x) / size.x;
}
void AdjustBar::setValue(int value)
{
bar.setSize(Vector2f(turn_width * value, size.y));
}
int AdjustBar::getValue()
{
return (bar.getSize().x + 0.5) / turn_width;
}
void AdjustBar::advance(double turns)
{
bar.setSize(Vector2f(bar.getSize().x + turns * turn_width, size.y));
if (bar.getSize().x < 0) {
bar.setSize(Vector2f(0, size.y));
}
else if (bar.getSize().x > size.x) {
bar.setSize(size);
}
}
bool AdjustBar::contains(Vector2f point)
{
return base.getGlobalBounds().contains(this->getTransform().getInverse() * point);
}
void AdjustBar::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= this->getTransform();
target.draw(base, states);
target.draw(bar , states);
}