Advertisement
NickG

Dbar - dbar.cpp

Mar 20th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #ifndef _GLIBCXX_IOSTREAM
  2. #include <iostream>
  3. using namespace std;
  4. #endif
  5.  
  6. #ifdef __WIN32__
  7. #include <windows.h>
  8. #endif
  9.  
  10. #include "dbar.hpp"
  11.  
  12. Dbar::Dbar(int _max, int _min, int _value, int _length) {
  13. max=_max;
  14. min=_min;
  15. value=_value;
  16. length=_length;
  17. }
  18.  
  19. void Dbar::setColor(int nColor)
  20. {color=nColor;}
  21.  
  22. void Dbar::setMax(int nMax)
  23. {max = nMax;}
  24.  
  25. void Dbar::setMin(int nMin)
  26. {min = nMin;}
  27.  
  28. void Dbar::setVal(int nVal)
  29. {value = nVal;}
  30.  
  31. void Dbar::setLng(int nLng)
  32. {length = nLng;}
  33.  
  34. void Dbar::drawBar() {
  35. #ifdef __WIN32__
  36.      //We will need this handle to get the current background attribute
  37.      HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  38.      CONSOLE_SCREEN_BUFFER_INFO csbi;
  39.      
  40.      //We use csbi for the wAttributes word.
  41.      if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
  42.      {
  43.         //Mask out all but the background attribute, and add in the forground color
  44.           color+=7;
  45.           SetConsoleTextAttribute(hStdOut, color);    
  46.      }
  47. #endif
  48.  
  49. #ifdef __linux__
  50.      color+=30;
  51.      cout << "\E[1;" << color << "m";
  52. #endif
  53.  
  54. cout << "[";
  55. for (int print=((value*length)/max), total=length;total>0;print--, total--) {
  56.    if (print>0)
  57.    {cout << "#";}
  58.    else
  59.    {cout << " ";}
  60.    }
  61. cout << "]";
  62.  
  63. #ifdef __WIN32__
  64.      //Fix this
  65. #endif
  66.  
  67. #ifdef __linux__
  68.      cout << "\E[0m";
  69. #endif
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement