Source File Downloads Source Code /********************************************************************* * This library is a revised version of the original color library. * * This color library relieves the programmers use of having to toil * * around with assembly and/or interrupt routines and handles. This * * library includes some color consepts revised as well as some new * * additions to enhance the library itself. * **********************************************************************/ /* One final note, THIS LIBRARY IS ONLY COMPATIBLE FOR Microsoft Visual C++ 6.0 AND CAN ONLY WORK ON Win32 Consoles!!!!!!!! */ /*List of revisions: ($)Added a new class thanks to my C++ professor. A many thanks to you Mr. Irvine! The class enables to define a variable with whatever variables instead of having to type functions all over again that only clutter the workspace. ($)I took out the setdefaultcolor function since it seemed to had no possible purpose. ($)I also took out some unuseful functions such as the setbcolordesign. I will add however an msgbox-like function to it. That should come up in the next revision of this library. ($)I also made sure to add some error - checking of my own at the same time. ($)I fixed the background and foreground color constant for grey so if everythings correct then it should work. ($)I finally finished the status bar function so now it can be used for any future programming. */ #ifndef _COLOR_H #define _COLOR_H #include <iostream> #include <string> #include <iomanip> #include <windows.h> #include <cassert> using namespace std; #include "tools.h" //Foreground color constants const int fBLUE = FOREGROUND_BLUE; const int fGREEN = FOREGROUND_GREEN; const int fTEAL = FOREGROUND_BLUE | FOREGROUND_GREEN; const int fRED = FOREGROUND_RED; const int fPURPLE = FOREGROUND_RED | FOREGROUND_BLUE; const int fBROWN = FOREGROUND_RED | FOREGROUND_GREEN; const int fGREY = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN; const int fBRIGHT_BLUE = FOREGROUND_BLUE | FOREGROUND_INTENSITY; const int fBRIGHT_GREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY; const int fBRIGHT_TEAL = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY; const int fBRIGHT_RED = FOREGROUND_RED| FOREGROUND_INTENSITY; const int fBRIGHT_PURPLE = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; const int fYELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; const int fBRIGHT_WHITE = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY; //Background color constants const int bBLUE = BACKGROUND_BLUE; const int bGREEN = BACKGROUND_GREEN; const int bTEAL = BACKGROUND_BLUE | BACKGROUND_GREEN; const int bRED = BACKGROUND_RED; const int bPURPLE = BACKGROUND_RED | BACKGROUND_BLUE; const int bBROWN = BACKGROUND_RED | BACKGROUND_GREEN; const int bGREY = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN; const int bBRIGHT_BLUE = BACKGROUND_BLUE | BACKGROUND_INTENSITY; const int bBRIGHT_GREEN = BACKGROUND_GREEN | BACKGROUND_INTENSITY; const int bBRIGHT_TEAL = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY; const int bBRIGHT_RED = BACKGROUND_RED| BACKGROUND_INTENSITY; const int bBRIGHT_PURPLE = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY; const int bYELLOW = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY; const int bBRIGHT_WHITE = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY; class Color { //The class that's responsible for all the color display public: Color() //default constructor { set_Default(); //mutator } void set_Default()//mutator { m_BackGroundColor = 0; m_ForeGroundColor = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),m_BackGroundColor|m_ForeGroundColor); } void set_Background( int bcolor )//mutator { //assert(bcolor >= 1 && bcolor <= 15); m_BackGroundColor = bcolor; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),bcolor|m_ForeGroundColor); } void set_Foreground( int fcolor )//mutator { //assert(fcolor >= 1 && fcolor <= 15); m_ForeGroundColor = fcolor; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),fcolor|m_BackGroundColor); } void set_FullColor( int fcolor, int bcolor )//mutator { //assert(bcolor >= 1 && bcolor <= 15); //assert(fcolor >= 1 && fcolor <= 15); m_BackGroundColor = bcolor; m_ForeGroundColor = fcolor; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),m_ForeGroundColor|m_BackGroundColor); } private: int m_BackGroundColor; int m_ForeGroundColor; }; //Base functions that although arent in the class, they work with the Color class. void locate( int x, int y ) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } void StandardLocation() { COORD abc = {0, 0}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), abc); } void BackgroundDesign( char chardesign, WORD color, COORD locatefill, DWORD NumOfCellsToFill, DWORD NumOfCellsToFillColor) { /*[2nd parameter] = accepts either a color constant such as FOREGROUND_RED or the pore-defined const int's like fBLUE1 [4rd parameter] = must be pre-defined by using #define [5th parameter] = you can put in a regular numnber if you want*/ DWORD CharsWrittenTo; FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color, NumOfCellsToFillColor, locatefill, &CharsWrittenTo); FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), chardesign, NumOfCellsToFill, locatefill, &CharsWrittenTo); } void ProgressBar(int BarDesign, int BarX, int BarY, int incr) { /*[1st parameter] = denotes the design of the scroll bar [2nd parameter] = the x-coordinate location of the scroll bar [3rd parameter] = the y-coordinate location of the scroll bar [4th parameter] = the increment of the delay when the bar scrolls*/ int endbar = BarY + 38; assert(endbar <= 80); locate(BarX, BarY); cout << "1%"; //locate(BarX, endbar); cout << setw(endbar - 8) << "100%"; char design; assert(BarDesign <= 4 && BarDesign >= 1); if (BarDesign == 1) design = '°'; else if (BarDesign == 2) design = '±'; else if (BarDesign == 3) design = '²'; else if (BarDesign == 4) design = 'Û'; int i = BarX + 2; locate(i, BarY); int z; z = i; while (z < endbar) { sleep(incr); cout << design; z++; } StandardLocation(); } void StatusBar(int BorderStyle, int BarColor, string message = "Ready", bool ToggleTime = true) { /*[1st parameter] = enables the user to choose from 2 different border designs to be displayed. [2nd parameter] = the color of the status bar. This only works with either foreground or either background color settings, not both at the same time. [3rd parameter] = The message to be displayed at the status bar. The user is limited to a certain number of characters. [4th parameter] = enables the user to toggle whether to display the time or not. By default, it's enabled.*/ int MAX_X = 80; int MAX_Y = 25; if (BorderStyle == 1 || BorderStyle < 1 || BorderStyle > 2) { //****first line**** locate(21, 1); cout << char(201); for (int i = 2; i < 66; i++) cout << char(205); cout << char(203); for (int j = 67; j < 72; j++) cout << char(205); cout << char(187); //****second line**** locate(22, 1); cout << char(186); for (i = 0; i < 66; i++) cout << char(000); cout << char(186); if (ToggleTime == true) { cout << Time(1); } else if (ToggleTime == false) { cout << "#:##:##"; } cout << " " << char(186); //****third line**** locate(23, 1); cout << char(200); for (i = 2; i < 66; i++) cout << char(205); cout << char(202); for (j = 67; j < 72; j++) cout << char(205); cout << char(188); //msg locate(22, 2); cout << message; else if(BorderStyle == 2) { //****first line**** locate(21, 1); cout << char(218); for (int i = 2; i < 66; i++) cout << char(196); cout << char(194); for (int j = 67; j < 72; j++) cout << char(196); cout << char(191); //****second line**** locate(22, 1); cout << char(179); for (i = 0; i < 66; i++) cout << char(000); cout << char(179); if (ToggleTime == true) { cout << Time(1); } else if (ToggleTime == false) { cout << "#:##:##"; } cout << " " << char(179); //****third line**** locate(23, 1); cout << char(192); for (i = 2; i < 66; i++) cout << char(196); cout << char(193); for (j = 67; j < 72; j++) cout << char(196); cout << char(217); //msg locate(22, 2); cout << message; } } #endif |
HOME | OPEN SOURCE | ASSEMBLY | C/C++ | JAVA | SCRIPT | SUBMIT CODE | CONTACT US