Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _GLIBCXX_IOSTREAM
- #include <iostream>
- using namespace std;
- #endif
- #ifdef __WIN32__
- #include <windows.h>
- #endif
- #include "dbar.hpp"
- Dbar::Dbar(int _max, int _min, int _value, int _length) {
- max=_max;
- min=_min;
- value=_value;
- length=_length;
- }
- void Dbar::setColor(int nColor)
- {color=nColor;}
- void Dbar::setMax(int nMax)
- {max = nMax;}
- void Dbar::setMin(int nMin)
- {min = nMin;}
- void Dbar::setVal(int nVal)
- {value = nVal;}
- void Dbar::setLng(int nLng)
- {length = nLng;}
- void Dbar::drawBar() {
- #ifdef __WIN32__
- //We will need this handle to get the current background attribute
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- //We use csbi for the wAttributes word.
- if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
- {
- //Mask out all but the background attribute, and add in the forground color
- color+=7;
- SetConsoleTextAttribute(hStdOut, color);
- }
- #endif
- #ifdef __linux__
- color+=30;
- cout << "\E[1;" << color << "m";
- #endif
- cout << "[";
- for (int print=((value*length)/max), total=length;total>0;print--, total--) {
- if (print>0)
- {cout << "#";}
- else
- {cout << " ";}
- }
- cout << "]";
- #ifdef __WIN32__
- //Fix this
- #endif
- #ifdef __linux__
- cout << "\E[0m";
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement