diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cRender.cpp | 40 | ||||
-rw-r--r-- | src/cRender.h | 52 |
2 files changed, 68 insertions, 24 deletions
diff --git a/src/cRender.cpp b/src/cRender.cpp index cb3305d..57b06a7 100644 --- a/src/cRender.cpp +++ b/src/cRender.cpp @@ -80,11 +80,20 @@ int cRender::drawPoint(char _c, sPos _pos, WORD _color) return _ERR_COORDINATES_INVALID_; cScreen[_pos.x][_pos.y] = _c; + + #ifdef _WIN32 + if (_color == _COL_DEFAULT) //_COL_DEFAULT is NOT a proper colorcode! wColor[_pos.x][_pos.y] = wDefColor; else wColor[_pos.x][_pos.y] = _color; + #elif __linux__ + + wColor[_pos.x][_pos.y] = _color; + + #endif + if(!bBlockRender) //Changemap is not allocated in inherited Classes bChanged[_pos.x][_pos.y] = true; @@ -190,15 +199,36 @@ int cRender::render(void) gotoxy(o,i); SetConsoleTextAttribute(hstdout, wColor[o][i] | _COL_INTENSITY); - //cout << cScreen[o][i]; + printf("%c", cScreen[o][i]); #elif __linux__ - //gotoxy(x,y) now included!! + char buffer[20]; - //int cbuf = sprintf(buffer,"\e[%u;%uH\e[%im%c", i + 1, o + 1, wColor[o][i], cScreen[o][i]); - // Position Color Origin is at 1,1 - int cbuf = sprintf(buffer,"\e[%u;%uH%c", i + 1, o + 1, cScreen[o][i]); + char colorstr[20]; + uint8_t color[3] = {(uint8_t) (0x0000ff & wColor[o][i]), //Color + (uint8_t)((0x00ff00 & wColor[o][i]) >> 8), //Background + (uint8_t)((0xff0000 & wColor[o][i]) >> 16)};//Modifier + + {//// + int cc = 0; + cc = cc + sprintf(&colorstr[cc], "%u", color[0]); + if(color[1]) + { + colorstr[cc] = ';'; + colorstr[cc + 1] = color[1]; + cc += 1 + sprintf(&colorstr[cc + 1], "%u", color[1]); + } + if(color[2]) + { + colorstr[cc] = ';'; + cc += 1 + sprintf(&colorstr[cc + 1], "%u", color[2]); + } + }//// + + int cbuf = sprintf(buffer,"\e[%u;%uH\e[%sm%c\e[0m", i + 1, o + 1, colorstr, cScreen[o][i]); + // Position Color Origin is at 1,1 + //int cbuf = sprintf(buffer,"\e[%u;%uH%c", i + 1, o + 1, cScreen[o][i]); write (STDOUT_FILENO, buffer, cbuf); #endif //__linux__ diff --git a/src/cRender.h b/src/cRender.h index 6dd75fb..42c3388 100644 --- a/src/cRender.h +++ b/src/cRender.h @@ -9,8 +9,9 @@ #ifdef __linux__ #include <unistd.h> #include <sys/ioctl.h> + #include <stdint.h> - typedef int WORD; + typedef uint32_t WORD; #elif _WIN32 #include <Windows.h> #else @@ -27,6 +28,7 @@ //Colors #ifdef _WIN32 + #define _COL_BLACK 0x00 #define _COL_BLUE 0x01 #define _COL_GREEN 0x02 @@ -36,23 +38,37 @@ #define _COL_DARK_WHITE 0x07 #define _COL_INTENSITY 0x08 #define _COL_DEFAULT 0xFF + #elif __linux__ - #define _COL_BLACK 30 - #define _COL_BLUE 34 - #define _COL_GREEN 32 - #define _COL_YELLOW 33 - #define _COL_RED 31 - #define _COL_WHITE 37 - #define _COL_DEFAULT 0 - - //Linux Specific - #define _COL_BOLD 1 - #define _COL_BOLD_OFF 21 - #define _COL_UNDERLINE 4 + + //FG + #define _COL_DEFAULT 0x00 + #define _COL_BLACK 0x1e//30 + #define _COL_RED 0x1f//31 + #define _COL_GREEN 0x20//32 + #define _COL_YELLOW 0x21//33 + #define _COL_BLUE 0x22//34 + #define _COL_WHITE 0x25//37 + + //BG + #define _COL_BLACK_BG 0x1e00 + 0x0a00//30 + #define _COL_RED_BG 0x1f00 + 0x0a00//31 + #define _COL_GREEN_BG 0x2000 + 0x0a00//32 + #define _COL_YELLOW_BG 0x2100 + 0x0a00//33 + #define _COL_BLUE_BG 0x2200 + 0x0a00//34 + #define _COL_WHITE_BG 0x2500 + 0x0a00//37 + + //MOD + #define _COL_BOLD 0x010000 + #define _COL_UNDERLINE 0x040000 + #define _COL_INVERSE 0x070000 + + //Not needed + #define _COL_BOLD_OFF 21 #define _COL_UNDERLINE_OFF 24 - #define _COL_INVERSE 7 - #define _COL_INVERSE_OFF 27 -#endif + #define _COL_INVERSE_OFF 27 + +#endif // __linux__ using namespace std; @@ -78,12 +94,11 @@ public: virtual ~cRender(); /** Draws _c @ _pos in screenbuffer - * Returns _COLLOSION_ if _pos is already set to !cBackround + * _color can be combined by OR: (FG | BG | MOD). Anyone can be left out. */ int drawPoint(char _c, sPos _pos, WORD _color); /** draws Line from _pos1 to _pos2 in screenbuffer - * x Value of pos1 MUSTNT exceed the x value of pos2! */ int drawLine(char _c, sPos _pos1, sPos _pos2, WORD _color); @@ -93,7 +108,6 @@ public: int drawText(string _s, sPos _pos, WORD _color); /** writes rectangle to screenbuffer - * x Value of pos1 MUSTNT exceed the x value of pos2! */ int drawRectangle(char _border, char _fill, sPos _pos1, sPos _pos2, WORD _borderColor, WORD _fillColor); |