-
Notifications
You must be signed in to change notification settings - Fork 0
/
barra.cpp
59 lines (54 loc) · 1.15 KB
/
barra.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
#include "barra.h"
const int Barra::STANDARD_CARACHTERS;
Barra::Barra(int max){
if(max > 0){
this->max = max;
}
else{
this->max = max * (-1);
}
this->num_states_bar = 74;
this->state_bar = 0;
}
bool Barra::change_state(int val){
int tmp = (val * this->num_states_bar)/this->max;
if(tmp > this->max){
return false;
}
if(tmp < 0){
return false;
}
if(tmp < this->state_bar || (val*100/this->max) < (this->val*100/this->max)){
this->state_bar = tmp;
this->val = val;
this->clear_bar();
this->print_bar();
}
else if(tmp > this->state_bar || (val*100/this->max) < (this->val*100/this->max)){
this->state_bar = tmp;
this->val = val;
this->print_bar();
}
return true;
}
void Barra::clear_bar(){
cout << "\r";
for(int i = 0; i < (this->num_states_bar + Barra::STANDARD_CARACHTERS); i++){
cout << " ";
}
}
void Barra::print_bar(){
cout << "\r";
cout << "[";
for(int i = 0; i < (this->state_bar - 1); i++){
cout << "=";
}
if(this->state_bar > 0){
cout << ">";
}
for(int i = 0; i < (this->num_states_bar - this->state_bar); i++){
cout << " ";
}
int percentuale = this->val*100/this->max;
cout << "]"<< percentuale << "%";
}