diff options
author | inmarket <andrewh@inmarket.com.au> | 2013-05-26 02:06:55 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2013-05-26 02:06:55 +1000 |
commit | 8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a (patch) | |
tree | c52d7733525727320d2de00acedb42bc18124471 /src/gwin | |
parent | 7fbfde42aabbcd30cffba2fba35158236c0a6c6c (diff) | |
download | uGFX-8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a.tar.gz uGFX-8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a.tar.bz2 uGFX-8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a.zip |
More GOS module changes
GQUEUE as a seperate module
GOS changes including basic Win32 O/S support
Diffstat (limited to 'src/gwin')
-rw-r--r-- | src/gwin/button.c | 4 | ||||
-rw-r--r-- | src/gwin/console.c | 201 |
2 files changed, 201 insertions, 4 deletions
diff --git a/src/gwin/button.c b/src/gwin/button.c index 19301698..cf5babc5 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -54,7 +54,7 @@ static void gwinButtonCallback(void *param, GEvent *pe) { #define pbe ((GEventGWinButton *)pe) // check if button is disabled - if (gh->enabled == false) + if (!gh->enabled) return; switch (pe->type) { @@ -150,7 +150,7 @@ GHandle gwinCreateButton(GButtonObject *gb, coord_t x, coord_t y, coord_t width, geventRegisterCallback(&gb->listener, gwinButtonCallback, gb); // buttons are enabled by default - gb->gwin.enabled = true; + gb->gwin.enabled = TRUE; return (GHandle)gb; } diff --git a/src/gwin/console.c b/src/gwin/console.c index a01ed79d..32e4f35a 100644 --- a/src/gwin/console.c +++ b/src/gwin/console.c @@ -30,7 +30,7 @@ * Stream interface implementation. The interface is write only */ -#if GFX_USE_OS_CHIBIOS +#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM #define Stream2GWindow(ip) ((GHandle)(((char *)(ip)) - (size_t)(&(((GConsoleObject *)0)->stream)))) static size_t GWinStreamWrite(void *ip, const uint8_t *bp, size_t n) { gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; } @@ -71,7 +71,7 @@ GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t widt return (GHandle)gc; } -#if GFX_USE_OS_CHIBIOS +#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM BaseSequentialStream *gwinGetConsoleStream(GHandle gh) { if (gh->type != GW_CONSOLE) return 0; @@ -145,6 +145,203 @@ void gwinPutCharArray(GHandle gh, const char *str, size_t n) { gwinPutChar(gh, *str++); } +#include <stdarg.h> + +#define MAX_FILLER 11 +#define FLOAT_PRECISION 100000 + +static char *ltoa_wd(char *p, long num, unsigned radix, long divisor) { + int i; + char *q; + + if (!divisor) divisor = num; + + q = p + MAX_FILLER; + do { + i = (int)(num % radix); + i += '0'; + if (i > '9') + i += 'A' - '0' - 10; + *--q = i; + num /= radix; + } while ((divisor /= radix) != 0); + + i = (int)(p + MAX_FILLER - q); + do { + *p++ = *q++; + } while (--i); + + return p; +} + +#if GWIN_CONSOLE_USE_FLOAT + static char *ftoa(char *p, double num) { + long l; + unsigned long precision = FLOAT_PRECISION; + + l = num; + p = ltoa_wd(p, l, 10, 0); + *p++ = '.'; + l = (num - l) * precision; + return ltoa_wd(p, l, 10, precision / 10); + } +#endif + +void gwinPrintf(GHandle gh, const char *fmt, ...) { + va_list ap; + char *p, *s, c, filler; + int i, precision, width; + bool_t is_long, left_align; + long l; + #if CHPRINTF_USE_FLOAT + float f; + char tmpbuf[2*MAX_FILLER + 1]; + #else + char tmpbuf[MAX_FILLER + 1]; + #endif + + if (gh->type != GW_CONSOLE || !gh->font) return; + + va_start(ap, fmt); + while (TRUE) { + c = *fmt++; + if (c == 0) { + va_end(ap); + return; + } + if (c != '%') { + gwinPutChar(gh, c); + continue; + } + + p = tmpbuf; + s = tmpbuf; + left_align = FALSE; + if (*fmt == '-') { + fmt++; + left_align = TRUE; + } + filler = ' '; + if (*fmt == '.') { + fmt++; + filler = '0'; + } + width = 0; + + while (TRUE) { + c = *fmt++; + if (c >= '0' && c <= '9') + c -= '0'; + else if (c == '*') + c = va_arg(ap, int); + else + break; + width = width * 10 + c; + } + precision = 0; + if (c == '.') { + while (TRUE) { + c = *fmt++; + if (c >= '0' && c <= '9') + c -= '0'; + else if (c == '*') + c = va_arg(ap, int); + else + break; + precision = precision * 10 + c; + } + } + /* Long modifier.*/ + if (c == 'l' || c == 'L') { + is_long = TRUE; + if (*fmt) + c = *fmt++; + } + else + is_long = (c >= 'A') && (c <= 'Z'); + + /* Command decoding.*/ + switch (c) { + case 'c': + filler = ' '; + *p++ = va_arg(ap, int); + break; + case 's': + filler = ' '; + if ((s = va_arg(ap, char *)) == 0) + s = "(null)"; + if (precision == 0) + precision = 32767; + for (p = s; *p && (--precision >= 0); p++); + break; + case 'D': + case 'd': + if (is_long) + l = va_arg(ap, long); + else + l = va_arg(ap, int); + if (l < 0) { + *p++ = '-'; + l = -l; + } + p = ltoa_wd(p, l, 10, 0); + break; + #if CHPRINTF_USE_FLOAT + case 'f': + f = (float) va_arg(ap, double); + if (f < 0) { + *p++ = '-'; + f = -f; + } + p = ftoa(p, f); + break; + #endif + case 'X': + case 'x': + c = 16; + goto unsigned_common; + case 'U': + case 'u': + c = 10; + goto unsigned_common; + case 'O': + case 'o': + c = 8; + unsigned_common: + if (is_long) + l = va_arg(ap, long); + else + l = va_arg(ap, int); + p = ltoa_wd(p, l, c, 0); + break; + default: + *p++ = c; + break; + } + + i = (int)(p - s); + if ((width -= i) < 0) + width = 0; + if (left_align == FALSE) + width = -width; + if (width < 0) { + if (*s == '-' && filler == '0') { + gwinPutChar(gh, *s++); + i--; + } + do { + gwinPutChar(gh, filler); + } while (++width != 0); + } + while (--i >= 0) + gwinPutChar(gh, *s++); + while (width) { + gwinPutChar(gh, filler); + width--; + } + } +} + #endif /* GFX_USE_GWIN && GWIN_NEED_CONSOLE */ /** @} */ |