Keyboard event added.
This commit is contained in:
parent
148a6b4f9f
commit
70f944d416
6 changed files with 93 additions and 47 deletions
|
@ -42,6 +42,7 @@ static uint8_t _guiLastWidgetLeftEvent = MOUSE_EVENT_NONE;
|
||||||
static WidgetT *_guiFocused = NULL;
|
static WidgetT *_guiFocused = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
static void guiProcessKeyboardChildren(WidgetT *widget, uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt);
|
||||||
static uint8_t guiProcessMouseChildren(WidgetT *widget, MouseT *mouse);
|
static uint8_t guiProcessMouseChildren(WidgetT *widget, MouseT *mouse);
|
||||||
|
|
||||||
|
|
||||||
|
@ -358,6 +359,38 @@ static uint8_t guiProcessMouseChildren(WidgetT *widget, MouseT *mouse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void guiProcessKeyboard(uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt) {
|
||||||
|
// Does the focused widget want events? Check for global keyboard so it doesn't get double events.
|
||||||
|
if (_guiFocused) {
|
||||||
|
if (_guiFocused->keyboardEventMethod && !GUI_GET_FLAG(_guiFocused, WIDGET_FLAG_ALWAYS_RECEIVE_KEYBOARD_EVENTS)) {
|
||||||
|
_guiFocused->keyboardEventMethod(_guiFocused, ascii, scancode, shift, control, alt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check everyone for global keyboard handling.
|
||||||
|
guiProcessKeyboardChildren((WidgetT *)_guiDesktop, ascii, scancode, shift, control, alt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void guiProcessKeyboardChildren(WidgetT *widget, uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt) {
|
||||||
|
size_t len;
|
||||||
|
size_t x;
|
||||||
|
|
||||||
|
// Process children of this widget.
|
||||||
|
len = arrlenu(widget->children);
|
||||||
|
for (x=0; x<len; x++) {
|
||||||
|
guiProcessKeyboardChildren(widget->children[x], ascii, scancode, shift, control, alt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Does this widget want events? Check for global keyboard so it doesn't get double events.
|
||||||
|
if (widget) {
|
||||||
|
if (widget->keyboardEventMethod && GUI_GET_FLAG(widget, WIDGET_FLAG_ALWAYS_RECEIVE_KEYBOARD_EVENTS)) {
|
||||||
|
widget->keyboardEventMethod(widget, ascii, scancode, shift, control, alt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WidgetT *guiRootGet(void) {
|
WidgetT *guiRootGet(void) {
|
||||||
return (WidgetT *)_guiDesktop;
|
return (WidgetT *)_guiDesktop;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,7 @@ void guiFocusSet(WidgetT *widget);
|
||||||
void guiMousePositionOnWidgetGet(WidgetT *widget, MouseT *mouse, uint16_t *x, uint16_t *y);
|
void guiMousePositionOnWidgetGet(WidgetT *widget, MouseT *mouse, uint16_t *x, uint16_t *y);
|
||||||
void guiPaint(WidgetT *widget);
|
void guiPaint(WidgetT *widget);
|
||||||
void guiProcessMouse(MouseT *mouse);
|
void guiProcessMouse(MouseT *mouse);
|
||||||
|
void guiProcessKeyboard(uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt);
|
||||||
WidgetT *guiRootGet(void);
|
WidgetT *guiRootGet(void);
|
||||||
void guiSetWidgetAndChildrenDirty(WidgetT *widget);
|
void guiSetWidgetAndChildrenDirty(WidgetT *widget);
|
||||||
DesktopT *guiStartup(void);
|
DesktopT *guiStartup(void);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
static void textboxFocusEvent(WidgetT *widget, uint8_t focused);
|
static void textboxFocusEvent(WidgetT *widget, uint8_t focused);
|
||||||
static void textboxMouseEvent(WidgetT *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event);
|
static void textboxMouseEvent(WidgetT *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event);
|
||||||
|
static void textboxKeyboardEvent(WidgetT *widget, uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt);
|
||||||
static void textboxPaint(WidgetT *widget);
|
static void textboxPaint(WidgetT *widget);
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ WidgetT *textboxInit(WidgetT *widget, uint16_t x, uint16_t y, uint16_t w, char *
|
||||||
t->base.h = fontHeightGet(_guiFont) + 4 + (_guiMetric[METRIC_TEXTBOX_VERTICAL_PADDING] * 2);
|
t->base.h = fontHeightGet(_guiFont) + 4 + (_guiMetric[METRIC_TEXTBOX_VERTICAL_PADDING] * 2);
|
||||||
t->base.delMethod = textboxDel;
|
t->base.delMethod = textboxDel;
|
||||||
t->base.focusMethod = textboxFocusEvent;
|
t->base.focusMethod = textboxFocusEvent;
|
||||||
|
t->base.keyboardEventMethod = textboxKeyboardEvent;
|
||||||
t->base.paintMethod = textboxPaint;
|
t->base.paintMethod = textboxPaint;
|
||||||
t->base.mouseEventMethod = textboxMouseEvent;
|
t->base.mouseEventMethod = textboxMouseEvent;
|
||||||
t->title = NULL;
|
t->title = NULL;
|
||||||
|
@ -73,6 +75,11 @@ WidgetT *textboxInit(WidgetT *widget, uint16_t x, uint16_t y, uint16_t w, char *
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void textboxKeyboardEvent(WidgetT *widget, uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void textboxMouseEvent(WidgetT *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event) {
|
static void textboxMouseEvent(WidgetT *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event) {
|
||||||
TextboxT *t = (TextboxT *)widget;
|
TextboxT *t = (TextboxT *)widget;
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ WidgetT *widgetInit(WidgetT *widget) {
|
||||||
widget->parent = NULL;
|
widget->parent = NULL;
|
||||||
widget->delMethod = NULL;
|
widget->delMethod = NULL;
|
||||||
widget->focusMethod = NULL;
|
widget->focusMethod = NULL;
|
||||||
|
widget->keyboardEventMethod = NULL;
|
||||||
widget->paintMethod = NULL;
|
widget->paintMethod = NULL;
|
||||||
widget->mouseEventMethod = NULL;
|
widget->mouseEventMethod = NULL;
|
||||||
widget->userData = NULL;
|
widget->userData = NULL;
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
enum WidgetE {
|
enum WidgetE {
|
||||||
WIDGET_FLAG_DIRTY = 0,
|
WIDGET_FLAG_DIRTY = 0,
|
||||||
WIDGET_FLAG_ACTIVE,
|
WIDGET_FLAG_ACTIVE,
|
||||||
WIDGET_FLAG_OWNS_SURFACE
|
WIDGET_FLAG_OWNS_SURFACE,
|
||||||
|
WIDGET_FLAG_ALWAYS_RECEIVE_KEYBOARD_EVENTS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ typedef struct WindowS WindowT;
|
||||||
typedef void (*widgetCallback)(struct WidgetS *widget);
|
typedef void (*widgetCallback)(struct WidgetS *widget);
|
||||||
typedef void (*widgetDelMethod)(struct WidgetS **widget);
|
typedef void (*widgetDelMethod)(struct WidgetS **widget);
|
||||||
typedef void (*widgetFocusMethod)(struct WidgetS *widget, uint8_t focused);
|
typedef void (*widgetFocusMethod)(struct WidgetS *widget, uint8_t focused);
|
||||||
|
typedef void (*widgetKeyboardEventMethod)(struct WidgetS *widget, uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt);
|
||||||
typedef void (*widgetPaintMethod)(struct WidgetS *widget);
|
typedef void (*widgetPaintMethod)(struct WidgetS *widget);
|
||||||
typedef void (*widgetMouseEventMethod)(struct WidgetS *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event);
|
typedef void (*widgetMouseEventMethod)(struct WidgetS *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event);
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ typedef struct WidgetS {
|
||||||
WidgetT *parent; // Parent of this widget
|
WidgetT *parent; // Parent of this widget
|
||||||
widgetDelMethod delMethod; // Delete method
|
widgetDelMethod delMethod; // Delete method
|
||||||
widgetFocusMethod focusMethod; // Focus changed method
|
widgetFocusMethod focusMethod; // Focus changed method
|
||||||
|
widgetKeyboardEventMethod keyboardEventMethod; // Keyboard event handler
|
||||||
widgetPaintMethod paintMethod; // Paint method
|
widgetPaintMethod paintMethod; // Paint method
|
||||||
widgetMouseEventMethod mouseEventMethod; // Mouse event handler
|
widgetMouseEventMethod mouseEventMethod; // Mouse event handler
|
||||||
void *userData; // Anything the user wants to store
|
void *userData; // Anything the user wants to store
|
||||||
|
|
|
@ -128,6 +128,7 @@ void test(void *data) {
|
||||||
mouse = mouseRead();
|
mouse = mouseRead();
|
||||||
if (keyHit()) {
|
if (keyHit()) {
|
||||||
key = keyASCII();
|
key = keyASCII();
|
||||||
|
guiProcessKeyboard(keyASCII(), keyScanCode(), keyShift(), keyControl(), keyAlt());
|
||||||
} else {
|
} else {
|
||||||
key = 0;
|
key = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue