Keyboard support in UpDown.
This commit is contained in:
parent
9acf435c52
commit
1a5cc62422
6 changed files with 74 additions and 4 deletions
|
@ -52,6 +52,7 @@ enum MagicE {
|
||||||
MAGIC_UPDOWN,
|
MAGIC_UPDOWN,
|
||||||
//MAGIC_LISTBOX,
|
//MAGIC_LISTBOX,
|
||||||
//MAGIC_TERMINAL,
|
//MAGIC_TERMINAL,
|
||||||
|
//MAGIC_DROPDOWN,
|
||||||
MAGIC_COUNT
|
MAGIC_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#ifdef MEMWATCH_STDIO
|
#ifdef MEMWATCH_STDIO
|
||||||
void memoryOutput(int c) {
|
void memoryOutput(int c) {
|
||||||
putchar(c);
|
logWrite("%c", c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef MEMORY_CHECK_ENABLED
|
||||||
#define MEMWATCH
|
#define MEMWATCH
|
||||||
#define MEMWATCH_STDIO
|
#define MEMWATCH_STDIO
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,7 +50,8 @@ long biostime(int cmd, long newtime);
|
||||||
#endif
|
#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"
|
#include "memory.h"
|
||||||
|
|
||||||
// Now our headers.
|
// Now our headers.
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "updown.h"
|
#include "updown.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
|
|
||||||
// 32 bit ranges from -2,147,483,648 to 2,147,483,647.
|
// 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 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 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 updownPaint(WidgetT *widget, RectT pos);
|
||||||
static void updownSetVisible(UpdownT *updown);
|
static void updownSetVisible(UpdownT *updown);
|
||||||
static void updownSizesRecalculate(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) {
|
int32_t updownGetValue(UpdownT *updown) {
|
||||||
return updown->value;
|
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;
|
UpdownT *u = (UpdownT *)widget;
|
||||||
|
|
||||||
u->base.delMethod = updownDel;
|
u->base.delMethod = updownDel;
|
||||||
|
u->base.focusMethod = updownFocusEvent;
|
||||||
u->base.paintMethod = updownPaint;
|
u->base.paintMethod = updownPaint;
|
||||||
|
u->base.keyboardEventMethod = updownKeyboardEvent;
|
||||||
u->base.mouseEventMethod = updownMouseEvent;
|
u->base.mouseEventMethod = updownMouseEvent;
|
||||||
u->maximum = INT32_MAX;
|
u->maximum = INT32_MAX;
|
||||||
u->minimum = INT32_MIN;
|
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) {
|
static void updownMouseEvent(WidgetT *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event) {
|
||||||
UpdownT *u = (UpdownT *)widget;
|
UpdownT *u = (UpdownT *)widget;
|
||||||
uint16_t o;
|
uint16_t o;
|
||||||
|
@ -150,8 +210,9 @@ static void updownPaint(WidgetT *widget, RectT pos) {
|
||||||
uint16_t o;
|
uint16_t o;
|
||||||
ColorT color;
|
ColorT color;
|
||||||
char draw[UPDOWN_MAX_DIGITS + 1];
|
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);
|
updownSizesRecalculate(u);
|
||||||
|
|
||||||
_arrowStart += pos.x; // This method expects the start in screen space, not widget space.
|
_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);
|
textX += (u->visible - strlen(draw)) * fontWidthGet(_guiFont);
|
||||||
fontRender(_guiFont, draw, _guiColor[COLOR_UPDOWN_TEXT], _guiColor[COLOR_UPDOWN_BACKGROUND], textX, textY);
|
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);
|
GUI_CLEAR_FLAG(widget, WIDGET_FLAG_DIRTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* - Move setup math for paint events inside the dirty check
|
* - 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
|
* - 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
|
* - Metrics, colors, etc. should be defined in each widget and not in GUI
|
||||||
|
* - UpDown is kinda lame
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue