static void USL_XORICursor(uint16_t x, uint16_t y, char *s, uint16_t cursor) { //static bool status; // VGA doesn't XOR... static char cursorStr[2] = {0x80, 0}; char buf[128]; uint16_t w, h; strcpy(buf, s); buf[cursor] = '\0'; VH_MeasurePropString(buf, &w, &h, us_printFont); // TODO: More changes to do here? US_SetPrintX(x + w - 1); US_SetPrintY(y); VH_DrawPropString(cursorStr, US_GetPrintX(), US_GetPrintY(), US_GetPrintFont(), US_GetPrintColour()); #if 0 if (status^=true) VH_DrawPropString("\x80", US_GetPrintX(), US_GetPrintY(), US_GetPrintFont(), US_GetPrintColour()); else { temp = us_printColour; us_printColour = us_backColour; VH_DrawPropString("\x80", US_GetPrintX(), US_GetPrintY(), US_GetPrintFont(), US_GetPrintColour()); us_printColour = temp; } #endif }
/* * Measure the containing box size of a string that spans multiple lines */ void CK_MeasureMultiline(const char *str, uint16_t *w, uint16_t *h) { char c; uint16_t x, y; char buf[80] = {0}; char *p; *h = *w = (uint16_t) 0; p = buf; /* must be a local buffer */ while ( (c = *str++) != 0 ) { *p++ = c; if ( c == '\n' || *str == 0 ) { VH_MeasurePropString( buf, &x, &y, US_GetPrintFont() ); *h += y; if ( *w < x ) *w = x; p = (char *) buf; // Shouldn't buf be cleared so that a newline is not read over by // VH_MeasurePropString? } } }
bool US_LineInput(uint16_t x, uint16_t y, char *buf, char *def, bool escok, uint16_t maxchars, uint16_t maxwidth) { bool redraw, cursorvis, cursormoved, done, result; IN_ScanCode sc; char c, s[128], olds[128]; uint16_t i, cursor, w, h, len/*, temp*/; uint32_t lasttime; if (def) strcpy(s, def); else *s = '\0'; *olds = '\0'; cursor = strlen(s); cursormoved = redraw = true; cursorvis = done = false; lasttime = SD_GetTimeCount(); IN_SetLastASCII(IN_KP_None); IN_SetLastScan(IN_SC_None); while (!done) { // TODO/FIXME: Handle this in a possibly better way // (no busy loop, updating gfx if required, etc..) IN_PumpEvents(); //CK_SetTicsPerFrame(); if (cursorvis) USL_XORICursor(x, y, s, cursor); sc = IN_GetLastScan(); IN_SetLastScan(IN_SC_None); c = IN_GetLastASCII(); IN_SetLastASCII(IN_KP_None); switch (sc) { case IN_SC_LeftArrow: if (cursor) cursor--; c = 0; cursormoved = true; break; case IN_SC_RightArrow: if (s[cursor]) cursor++; c = 0; cursormoved = true; break; case IN_SC_Home: cursor = 0; c = 0; cursormoved = true; break; case IN_SC_End: cursor = strlen(s); c = 0; cursormoved = true; break; case IN_SC_Enter: strcpy(buf, s); done = true; result = true; c = 0; break; case IN_SC_Escape: if (escok) { done = true; result = false; } c = 0; break; case IN_SC_Backspace: if (cursor) { strcpy(s + cursor - 1, s + cursor); cursor--; redraw = true; } c = 0; cursormoved = true; break; case IN_SC_Delete: if (s[cursor]) { strcpy(s + cursor, s + cursor + 1); redraw = true; } c = 0; cursormoved = true; break; case 0x4c: // Keypad 5 case IN_SC_UpArrow: case IN_SC_DownArrow: case IN_SC_PgUp: case IN_SC_PgDown: case IN_SC_Insert: c = 0; break; } if (c) { len = strlen(s); VH_MeasurePropString(s, &w, &h, US_GetPrintFont()); if ( isprint(c) && (len < 128 - 1) && ((!maxchars) || (len < maxchars)) && ((!maxwidth) || (w < maxwidth)) ) { for (i = len + 1; i > cursor; i--) s[i] = s[i - 1]; s[cursor++] = c; redraw = true; } } if (redraw) { /* px = x; py = y; */ //temp = us_printColour; //us_printColour = us_backColour; VH_DrawPropString(olds, x, y, us_printFont, us_printColour); //us_printColour = temp; strcpy(olds, s); /* px = x; py = y; */ VH_DrawPropString(s, x, y, us_printFont, us_printColour); redraw = false; } if (cursormoved) { cursorvis = false; lasttime = SD_GetTimeCount() - 70 /*TimeCount - TickBase*/; cursormoved = false; } if (SD_GetTimeCount()-lasttime > 35 /*TimeCount - lasttime > TickBase / 2*/) { lasttime = SD_GetTimeCount();//TimeCount; cursorvis ^= true; } if (cursorvis) USL_XORICursor(x, y, s, cursor); //VW_UpdateScreen(); VL_Present(); } if (cursorvis) USL_XORICursor(x, y, s, cursor); if (!result) { /* px = x; py = y; */ VH_DrawPropString(olds, x, y, us_printFont, us_printColour); } //VW_UpdateScreen(); VL_Present(); IN_ClearKeysDown(); return (result); }