void gwinPutChar(GHandle gh, char c) { #define gcw ((GConsoleObject *)gh) uint8_t width, fy, fp; if (gh->vmt != &consoleVMT || !gh->font) return; fy = gdispGetFontMetric(gh->font, fontHeight); fp = gdispGetFontMetric(gh->font, fontCharPadding); #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif if (c == '\n') { gcw->cx = 0; gcw->cy += fy; // We use lazy scrolling here and only scroll when the next char arrives } else if (c == '\r') { // gcw->cx = 0; } else { width = gdispGetCharWidth(c, gh->font) + fp; if (gcw->cx + width >= gh->width) { gcw->cx = 0; gcw->cy += fy; } if (gcw->cy + fy > gh->height) { #if GDISP_NEED_SCROLL /* scroll the console */ gdispVerticalScroll(gh->x, gh->y, gh->width, gh->height, fy, gh->bgcolor); /* reset the cursor to the start of the last line */ gcw->cx = 0; gcw->cy = (((coord_t)(gh->height/fy))-1)*fy; #else /* clear the console */ gdispFillArea(gh->x, gh->y, gh->width, gh->height, gh->bgcolor); /* reset the cursor to the top of the window */ gcw->cx = 0; gcw->cy = 0; #endif } #if GWIN_CONSOLE_USE_CLEAR_LINES /* clear to the end of the line */ if (gcw->cx == 0) gdispFillArea(gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor); #endif #if GWIN_CONSOLE_USE_FILLED_CHARS gdispFillChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color, gh->bgcolor); #else gdispDrawChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color); #endif /* update cursor */ gcw->cx += width; } #undef gcw }
msg_t lcdConsolePut(GConsole *console, char c) { uint8_t width; if(c == '\n') { /* clear the text at the end of the line */ if(console->cx < console->sx) gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, console->sx - console->cx, console->fy, console->bkcolor); console->cx = 0; console->cy += console->fy; } else if(c == '\r') { /* TODO: work backwards through the buffer to the start of the current line */ //console->cx = 0; } else { width = gdispGetCharWidth(c, console->font) + console->fp; if((console->cx + width) >= console->sx) { /* clear the text at the end of the line */ if (console->cy <= console->sy) gdispFillArea(console->x0 + console->cx, console->y0 + console->cy, console->sx - (console->cx + width), console->fy, console->bkcolor); console->cx = 0; console->cy += console->fy; } if((console->cy > console->sy)) { #if GDISP_NEED_SCROLL /* scroll the console */ gdispVerticalScroll(console->x0, console->y0, console->sx, console->sy + console->fy, console->fy, console->bkcolor); /* reset the cursor to the start of the line */ console->cx = 0; console->cy = console->sy; #else /* clear the console */ gdispFillArea(console->x0, console->y0, console->sx, console->sy + console->fy, console->bkcolor); /* reset the cursor to the top of the console */ console->cx = 0; console->cy = 0; #endif } gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c, console->font, console->color); /* update cursor */ console->cx += width; } return RDY_OK; }
void gwinPutChar(GHandle gh, char c) { #define gcw ((GConsoleObject *)gh) uint8_t width, fy; if (gh->vmt != &consoleVMT || !gh->font) return; fy = gdispGetFontMetric(gh->font, fontHeight); #if GWIN_CONSOLE_ESCSEQ /** * Handle escape sequences * ESC color Change subsequent text color * color: "0" = black, "1" = red, "2" = green, "3" = yellow, "4" = blue, * "5" = magenta, "6" = cyan, "7" = white * ESC C Revert subsequent text color to the window default * ESC u Turn on underline * ESC U Turn off underline * ESC b Turn on bold * ESC B Turn off bold * ESC J Clear the window */ switch (gcw->escstate) { case 1: gcw->escstate = 0; if (ESCtoAttr(c, &gcw->currattr)) { if (gcw->cx == 0 && gcw->cy == 0) gcw->startattr = gcw->currattr; else { putCharInBuffer(gcw, 27); putCharInBuffer(gcw, c); } } else { switch(c) { case 'J': // Clear the console and reset the cursor clearBuffer(gcw); if (DrawStart(gh)) { gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor); DrawEnd(gh); } gcw->cx = 0; gcw->cy = 0; gcw->startattr = gcw->currattr; break; } } return; } #endif /** * Special Characters: * * Carriage returns and line feeds (\r & \n) are handled in unix terminal cooked mode; that is, * line feeds perform both actions and carriage-returns are ignored. * * if GWIN_CONSOLE_ESCSEQ is turned on then ESC is trapped ready for the escape command. * * All other characters are treated as printable. */ switch (c) { case '\n': // clear to the end of the line #if GWIN_CONSOLE_USE_CLEAR_LINES if (gcw->cx == 0 && gcw->cy+fy < gh->height && DrawStart(gh)) { gdispGFillArea(gh->display, gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor); DrawEnd(gh); } #endif // update the cursor gcw->cx = 0; gcw->cy += fy; putCharInBuffer(gcw, '\n'); // We use lazy scrolling here and only scroll when the next char arrives return; case '\r': // gcw->cx = 0; return; #if GWIN_CONSOLE_ESCSEQ case 27: // ESC gcw->escstate = 1; return; #endif } // Characters with no width are ignored if (!(width = gdispGetCharWidth(c, gh->font))) return; // Allow space for (very crude) bold #if GWIN_CONSOLE_ESCSEQ if ((gcw->currattr & ESC_BOLD)) width++; #endif // Do we need to go to the next line to fit this character? if (gcw->cx + width >= gh->width) { gcw->cx = 0; gcw->cy += fy; putCharInBuffer(gcw, '\n'); } // Do we need to scroll to fit this character? if (gcw->cy + fy > gh->height) { #if GWIN_CONSOLE_USE_HISTORY && GWIN_CONSOLE_BUFFER_SCROLLING if (gcw->buffer) { // Scroll the buffer and then redraw using the buffer scrollBuffer(gcw); if (DrawStart(gh)) { HistoryuRedraw(gh); DrawEnd(gh); } } else #endif #if GDISP_NEED_SCROLL { // Scroll the console using hardware scrollBuffer(gcw); if (DrawStart(gh)) { gdispGVerticalScroll(gh->display, gh->x, gh->y, gh->width, gh->height, fy, gh->bgcolor); DrawEnd(gh); } // Set the cursor to the start of the last line gcw->cx = 0; gcw->cy = (((coord_t)(gh->height/fy))-1)*fy; } #else { // Clear the console and reset the cursor clearBuffer(gcw); if (DrawStart(gh)) { gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor); DrawEnd(gh); } gcw->cx = 0; gcw->cy = 0; #if GWIN_CONSOLE_ESCSEQ gcw->startattr = gcw->currattr; #endif } #endif } // Save the char putCharInBuffer(gcw, c); // Draw the character if (DrawStart(gh)) { // If we are at the beginning of a new line clear the line #if GWIN_CONSOLE_USE_CLEAR_LINES if (gcw->cx == 0) gdispGFillArea(gh->display, gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor); #endif #if GWIN_CONSOLE_USE_FILLED_CHARS gdispGFillChar(gh->display, gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw), gh->bgcolor); #else gdispGDrawChar(gh->display, gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw)); #endif #if GWIN_CONSOLE_ESCSEQ // Draw the underline if ((gcw->currattr & ESC_UNDERLINE)) gdispGDrawLine(gh->display, gh->x + gcw->cx, gh->y + gcw->cy + fy - gdispGetFontMetric(gh->font, fontDescendersHeight), gh->x + gcw->cx + width + gdispGetFontMetric(gh->font, fontCharPadding), gh->y + gcw->cy + fy - gdispGetFontMetric(gh->font, fontDescendersHeight), ESCPrintColor(gcw)); // Bold (very crude) if ((gcw->currattr & ESC_BOLD)) gdispGDrawChar(gh->display, gh->x + gcw->cx + 1, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw)); #endif DrawEnd(gh); } // Update the cursor gcw->cx += width + gdispGetFontMetric(gh->font, fontCharPadding); #undef gcw }