diff --git a/client/src/gui/gui.h b/client/src/gui/gui.h index 73ddbcd..a48cb7e 100644 --- a/client/src/gui/gui.h +++ b/client/src/gui/gui.h @@ -52,6 +52,7 @@ enum MagicE { MAGIC_UPDOWN, //MAGIC_LISTBOX, //MAGIC_TERMINAL, + //MAGIC_DROPDOWN, MAGIC_COUNT }; diff --git a/client/src/gui/memory.c b/client/src/gui/memory.c index 37f6302..6009db9 100644 --- a/client/src/gui/memory.c +++ b/client/src/gui/memory.c @@ -23,7 +23,7 @@ #ifdef MEMWATCH_STDIO void memoryOutput(int c) { - putchar(c); + logWrite("%c", c); } #endif diff --git a/client/src/gui/memory.h b/client/src/gui/memory.h index 5ee7428..a9aa1b7 100644 --- a/client/src/gui/memory.h +++ b/client/src/gui/memory.h @@ -25,7 +25,7 @@ #include "os.h" -#ifdef __linux__ +#ifdef MEMORY_CHECK_ENABLED #define MEMWATCH #define MEMWATCH_STDIO #endif diff --git a/client/src/gui/os.h b/client/src/gui/os.h index ddd321b..0f73af5 100644 --- a/client/src/gui/os.h +++ b/client/src/gui/os.h @@ -50,7 +50,8 @@ long biostime(int cmd, long newtime); #endif -// Has to be after system headers in this file. +// Should be after system headers in this file. +#define MEMORY_CHECK_ENABLED #include "memory.h" // Now our headers. diff --git a/client/src/gui/updown.c b/client/src/gui/updown.c index 691cec2..64c95b5 100644 --- a/client/src/gui/updown.c +++ b/client/src/gui/updown.c @@ -19,6 +19,7 @@ #include "updown.h" +#include "timer.h" // 32 bit ranges from -2,147,483,648 to 2,147,483,647. @@ -35,7 +36,9 @@ static uint16_t _halfFont = 0; static void updownDel(WidgetT **widget); +static void updownFocusEvent(WidgetT *widget, uint8_t focused); static void updownMouseEvent(WidgetT *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event); +static void updownKeyboardEvent(WidgetT *widget, uint8_t ascii, uint8_t extended, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt); static void updownPaint(WidgetT *widget, RectT pos); static void updownSetVisible(UpdownT *updown); static void updownSizesRecalculate(UpdownT *updown); @@ -50,6 +53,14 @@ static void updownDel(WidgetT **widget) { } +static void updownFocusEvent(WidgetT *widget, uint8_t focused) { + // Make sure cursor disappears when we lose focus. + if (!focused) { + GUI_SET_FLAG(widget, WIDGET_FLAG_DIRTY); + } +} + + int32_t updownGetValue(UpdownT *updown) { return updown->value; } @@ -59,7 +70,9 @@ WidgetT *updownInit(WidgetT *widget, int32_t min, int32_t max, int32_t step, cha UpdownT *u = (UpdownT *)widget; u->base.delMethod = updownDel; + u->base.focusMethod = updownFocusEvent; u->base.paintMethod = updownPaint; + u->base.keyboardEventMethod = updownKeyboardEvent; u->base.mouseEventMethod = updownMouseEvent; u->maximum = INT32_MAX; u->minimum = INT32_MIN; @@ -75,6 +88,53 @@ WidgetT *updownInit(WidgetT *widget, int32_t min, int32_t max, int32_t step, cha } +static void updownKeyboardEvent(WidgetT *widget, uint8_t ascii, uint8_t extended, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt) { + + UpdownT *u = (UpdownT *)widget; + int32_t temp; + + (void)scancode; + (void)shift; + (void)control; + (void)alt; + + if (extended) { + + switch (ascii) { + case 72: // UP + if (u->value < u->maximum) u->value++; + break; + + case 80: // DOWN + if (u->value > u->minimum) u->value--; + break; + + case 83: // DELETE + u->value = (int)(u->value * 0.1); + break; + + } // switch + + } else { // extended + + switch (ascii) { + case 8: // BACKSPACE + u->value = (int)(u->value * 0.1); + break; + + default: // Number keys + if (ascii >= '0' && ascii <= '9') { + temp = u->value * 10 + (ascii - '0'); + if (temp <= u->maximum) u->value = temp; + } + break; + + } // switch + + } // extended +} + + static void updownMouseEvent(WidgetT *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event) { UpdownT *u = (UpdownT *)widget; uint16_t o; @@ -150,8 +210,9 @@ static void updownPaint(WidgetT *widget, RectT pos) { uint16_t o; ColorT color; char draw[UPDOWN_MAX_DIGITS + 1]; + char cursor[2] = { 0xb1, 0 }; - if (GUI_GET_FLAG(widget, WIDGET_FLAG_DIRTY)) { + if (GUI_GET_FLAG(widget, WIDGET_FLAG_DIRTY) || guiFocusGet() == widget) { updownSizesRecalculate(u); _arrowStart += pos.x; // This method expects the start in screen space, not widget space. @@ -203,6 +264,12 @@ static void updownPaint(WidgetT *widget, RectT pos) { textX += (u->visible - strlen(draw)) * fontWidthGet(_guiFont); fontRender(_guiFont, draw, _guiColor[COLOR_UPDOWN_TEXT], _guiColor[COLOR_UPDOWN_BACKGROUND], textX, textY); + // Draw cursor. + if (guiFocusGet() == widget && timerQuarterSecondOn) { + textX += (strlen(draw) - 1) * fontWidthGet(_guiFont); + fontRender(_guiFont, cursor, _guiColor[COLOR_TEXTBOX_TEXT], _guiColor[COLOR_TEXTBOX_BACKGROUND], textX, textY); + } + GUI_CLEAR_FLAG(widget, WIDGET_FLAG_DIRTY); } } diff --git a/client/src/main.c b/client/src/main.c index 7de18fd..4eb5a63 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -27,6 +27,7 @@ * - Move setup math for paint events inside the dirty check * - Methods that can change the width of a widget (such as setTitle) need to repaint the parent window as well * - Metrics, colors, etc. should be defined in each widget and not in GUI + * - UpDown is kinda lame * */