www.pudn.com > f_graph_h.zip > f_graph.cpp
#include "f_graph.h" #include#include #include // an instance of our class - to access member functions f_graph gf; // to save where our cursor on the screen int countLine=7; // f_graph class constructor f_graph::f_graph(void): std::basic_ostream >(std::cout.rdbuf()) { consoleHandler = GetStdHandle(STD_OUTPUT_HANDLE); } // to set cursor mode int f_graph::setCursor(CursorMode _cursorMode) { if (consoleHandler == INVALID_HANDLE_VALUE) return 0; CONSOLE_CURSOR_INFO cursorInfo; switch (_cursorMode) { case CURSOR_OFF: cursorInfo.bVisible = FALSE; cursorInfo.dwSize = 10; break; case CURSOR_ON: cursorInfo.bVisible = TRUE; cursorInfo.dwSize = 10; break; case CURSOR_BIG: cursorInfo.bVisible = TRUE; cursorInfo.dwSize = 100; break; } SetConsoleCursorInfo(consoleHandler, &cursorInfo); } // to get current screen x dimension int f_graph::getDimensionX(void) { if (consoleHandler == INVALID_HANDLE_VALUE) return 0; CONSOLE_SCREEN_BUFFER_INFO screenInfo; GetConsoleScreenBufferInfo(consoleHandler, &screenInfo); return screenInfo.dwMaximumWindowSize.X; } // to get current screen y dimension int f_graph::getDimensionY(void) { if (consoleHandler == INVALID_HANDLE_VALUE) return 0; CONSOLE_SCREEN_BUFFER_INFO screenInfo; GetConsoleScreenBufferInfo(consoleHandler, &screenInfo); return screenInfo.dwMaximumWindowSize.Y; } // to set cursor to given position // (1, 1) means upper left corner int f_graph::gotoxy(const int _x, const int _y) { if (consoleHandler == INVALID_HANDLE_VALUE) return 0; COORD coords = {static_cast (_x - 1), static_cast (_y - 1)}; SetConsoleCursorPosition(consoleHandler, coords); } // to get current cursor position on x dimension int f_graph::whereX(void) { if (consoleHandler == INVALID_HANDLE_VALUE) return 0; CONSOLE_SCREEN_BUFFER_INFO screenInfo; GetConsoleScreenBufferInfo(consoleHandler, &screenInfo); return screenInfo.dwCursorPosition.X + 1; } // to get current cursor position on y dimension int f_graph::whereY(void) { if (consoleHandler == INVALID_HANDLE_VALUE) return 0; CONSOLE_SCREEN_BUFFER_INFO screenInfo; GetConsoleScreenBufferInfo(consoleHandler, &screenInfo); return screenInfo.dwCursorPosition.Y + 1; } // to set the cursor position to the left pixel void f_graph::goRight(void) { int x; int y; x = whereX(); y = whereY(); gotoxy(x+1,y); }; // to set the cursor position to the left pixel void f_graph::goLeft(void) { int x; int y; x = whereX(); y = whereY(); gotoxy(x-1,y); }; // to set the cursor position to the left pixel void f_graph::goUp(void) { int x; int y; x = whereX(); y = whereY(); gotoxy(x,y-1); }; // to set the cursor position to the left pixel void f_graph::goDown(void) { int x; int y; x = whereX(); y = whereY(); gotoxy(x,y+1); }; // to set color for output on console window void f_graph::setColor(const WORD _newColorToSet) { if (consoleHandler == INVALID_HANDLE_VALUE) return; SetConsoleTextAttribute(consoleHandler, _newColorToSet); } // to clear console window with special color void f_graph::clrscr(const WORD _newColorToClr) { if (consoleHandler == INVALID_HANDLE_VALUE) return; static const COORD topLeftCorner = {0, 0}; CONSOLE_SCREEN_BUFFER_INFO screenInfo; GetConsoleScreenBufferInfo(consoleHandler, &screenInfo); SMALL_RECT screenSize; screenSize.Left = 0; screenSize.Top = 0; screenSize.Right = screenInfo.dwSize.X - 1; screenSize.Bottom = screenInfo.dwSize.Y - 1; _CHAR_INFO* buffer = new _CHAR_INFO[screenInfo.dwSize.X * screenInfo.dwSize.Y]; _CHAR_INFO charInfo = {' ', _newColorToClr}; for (int i = 0; i < screenInfo.dwSize.X * screenInfo.dwSize.Y; i++) { buffer[i] = charInfo; } COORD bufferSize = {screenInfo.dwSize.X, screenInfo.dwSize.Y}; WriteConsoleOutput(consoleHandler, buffer, bufferSize, topLeftCorner, &screenSize); delete[] buffer; goBeginPixels(); setColor(screenInfo.wAttributes); } // to clear console window (white text on black background) void f_graph::clrscr(void) { clrscr(FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN ); } // to set title of console window void f_graph::setTitle(const char* _title) { SetConsoleTitle(_title); } // waits as much as given value void f_graph::wait(int _value) { Sleep(_value); }; // to clear the area in given directions void f_graph::clearArea(int _x1,int _y1,int _x2,int _y2) { int i,j; int x = whereX(); int y = whereY(); gotoxy(_x1,_y1); for(j = _y1; j<=_y2 ; j++) { for(i = _x1;i<=_x2;i++) { gotoxy(i,j); cout<<(" "); } }; gotoxy(x,y); } // to make a box with given directions void f_graph::box(int _x1,int _y1,int _x2,int _y2) { char topLeft = 201; char horizontalLines = 205; char topRight = 187; char verticalLines = 186; char bottomLeft = 200; char bottomRight = 188; int i; int xBegin = whereX(); int yBegin = whereY(); gotoxy(_x1,_y1); cout< = (_x2 - xPixel))) { countLine = _y1+1; clearArea(_x1+1,_y1+1,_x2-1,_y2-1); gotoxy(_x1+1,countLine); } if(countLine == _y2-1 && _controlKey == 1 && ((letterCounterBegin - placeHolder) >= (_x2 - xPixel))) { countLine = _y1+1; setColor(FOREGROUND_RED | FOREGROUND_INTENSITY); rightBottomText("Press any key to go to the next page"); getch(); clearArea(_x1+1,_y1+1,_x2-1,_y2-1); setColor(FOREGROUND_GREEN); clearArea(1,24,80,24); gotoxy(_x1+2,countLine+1); } if((letterCounterBegin - placeHolder) < (_x2 - xPixel)) { for(;placeHolder