Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef COMPUTERCRAFT_H
- #define COMPUTERCRAFT_H
- class Color
- {
- public:
- int black = 0;
- int blue = 1;
- int green = 2;
- int cyan = 3;
- int red = 4;
- int purple = 5;
- int brown = 6;
- int lightGray = 7;
- int gray = 8;
- int lightBlue = 9;
- int lime = 10;
- int neonBlue = 11;
- int neonRed = 12;
- int neonPurple = 13;
- int yellow = 14;
- int white = 15;
- };
- class Term
- {
- public:
- WORD curTextColor = 0x0F;
- WORD curBackColor = 0x00;
- WORD colorbit = curBackColor + curTextColor;
- int printx = 1;
- int printy = 1;
- const WORD textcolors[20]
- {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
- 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
- 0x0C, 0x0D, 0x0E, 0x0F
- };
- const WORD backcolors[20]
- {
- 0x00, 0x10, 0x20, 0x30, 0x40, 0x50,
- 0x60, 0x70, 0x80, 0x90, 0xA0, 0xB0,
- 0xC0, 0xD0, 0xE0, 0xF0
- };
- // Color Setting \\
- void setTextColor(WORD newtextcolor)
- {
- curTextColor = textcolors[newtextcolor];
- WORD colorbit = curBackColor + curTextColor;
- SetConsoleTextAttribute(GetStdHandle( STD_OUTPUT_HANDLE ), colorbit);
- };
- void setCursorBlink(bool showFlag)
- {
- HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO cursorInfo;
- GetConsoleCursorInfo(out, &cursorInfo);
- cursorInfo.bVisible = showFlag; // set the cursor visibility
- SetConsoleCursorInfo(out, &cursorInfo);
- }
- void setBackgroundColor(WORD newbackcolor)
- {
- curBackColor = backcolors[newbackcolor];
- WORD colorbit = curBackColor + curTextColor;
- SetConsoleTextAttribute(GetStdHandle( STD_OUTPUT_HANDLE ), colorbit);
- };
- void setColorFromBit(WORD bit)
- {
- SetConsoleTextAttribute(GetStdHandle( STD_OUTPUT_HANDLE ), bit);
- WORD colorbit = bit;
- };
- void Clear()
- {
- system("cls");
- };
- void setCursorPos(int x, int y)
- {
- COORD pos = {x, y};
- printx = x;
- printy = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
- };
- void write(char* text)
- {
- DWORD dwBytesWritten = 0;
- WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), text, strlen(text), &dwBytesWritten, NULL);
- };
- protected:
- private:
- };
- class Paintutils: public Term
- {
- public:
- Term *trm;
- void initialize(Term *nterm)
- {
- trm = nterm;
- };
- void drawBox(int sx, int sy, int ex, int ey, int color)
- {
- int prevTextColor = trm->curTextColor;
- int prevBackColor = trm->curBackColor;
- trm->setCursorPos(sx,sy);
- trm->setBackgroundColor(color);
- for(int xx = sx; xx < ex; xx++)
- {
- trm->setCursorPos(xx,sy);
- trm->write(" ");
- };
- for(int yy = sy; yy < ey; yy++)
- {
- trm->setCursorPos(sx,yy);
- trm->write(" ");
- };
- for(int yy = sy; yy < ey; yy++)
- {
- trm->setCursorPos(ex,yy);
- trm->write(" ");
- };
- for(int xx = sx; xx < ex+1; xx++)
- {
- trm->setCursorPos(xx,ey);
- trm->write(" ");
- };
- };
- void drawBoxFilled(int sx, int sy, int ex, int ey, int colorborder, int color)
- {
- int prevTextColor = trm->curTextColor;
- int prevBackColor = trm->curBackColor;
- trm->setCursorPos(sx,sy);
- trm->setBackgroundColor(colorborder);
- for(int xx = sx; xx < ex; xx++)
- {
- trm->setCursorPos(xx,sy);
- trm->write(" ");
- };
- for(int yy = sy; yy < ey; yy++)
- {
- trm->setCursorPos(sx,yy);
- trm->write(" ");
- };
- for(int yy = sy; yy < ey; yy++)
- {
- trm->setCursorPos(ex,yy);
- trm->write(" ");
- };
- for(int xx = sx; xx < ex+1; xx++)
- {
- trm->setCursorPos(xx,ey);
- trm->write(" ");
- };
- // fill inner rectangle.
- trm->setBackgroundColor(color);
- for(int yy = sy+1; yy < ey; yy++)
- {
- for(int xx = sx+1; xx < ex; xx++)
- {
- trm->setCursorPos(xx,yy);
- trm->write(" ");
- };
- };
- };
- };
- #endif // CONSOLECOLOR_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement