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 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);
|
||||
|
||||
|
||||
|
@ -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) {
|
||||
return (WidgetT *)_guiDesktop;
|
||||
}
|
||||
|
|
|
@ -142,6 +142,7 @@ void guiFocusSet(WidgetT *widget);
|
|||
void guiMousePositionOnWidgetGet(WidgetT *widget, MouseT *mouse, uint16_t *x, uint16_t *y);
|
||||
void guiPaint(WidgetT *widget);
|
||||
void guiProcessMouse(MouseT *mouse);
|
||||
void guiProcessKeyboard(uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt);
|
||||
WidgetT *guiRootGet(void);
|
||||
void guiSetWidgetAndChildrenDirty(WidgetT *widget);
|
||||
DesktopT *guiStartup(void);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
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 textboxKeyboardEvent(WidgetT *widget, uint8_t ascii, uint8_t scancode, uint8_t shift, uint8_t control, uint8_t alt);
|
||||
static void textboxPaint(WidgetT *widget);
|
||||
|
||||
|
||||
|
@ -49,19 +50,20 @@ char *textboxGetValue(TextboxT *textbox) {
|
|||
WidgetT *textboxInit(WidgetT *widget, uint16_t x, uint16_t y, uint16_t w, char *title) {
|
||||
TextboxT *t = (TextboxT *)widget;
|
||||
|
||||
t->base.magic = MAGIC_TEXTBOX;
|
||||
t->base.x = x;
|
||||
t->base.y = y;
|
||||
t->base.w = w;
|
||||
t->base.h = fontHeightGet(_guiFont) + 4 + (_guiMetric[METRIC_TEXTBOX_VERTICAL_PADDING] * 2);
|
||||
t->base.delMethod = textboxDel;
|
||||
t->base.focusMethod = textboxFocusEvent;
|
||||
t->base.paintMethod = textboxPaint;
|
||||
t->base.mouseEventMethod = textboxMouseEvent;
|
||||
t->title = NULL;
|
||||
t->maxLength = 256;
|
||||
t->value = (char *)malloc(t->maxLength);
|
||||
t->caret = 0;
|
||||
t->base.magic = MAGIC_TEXTBOX;
|
||||
t->base.x = x;
|
||||
t->base.y = y;
|
||||
t->base.w = w;
|
||||
t->base.h = fontHeightGet(_guiFont) + 4 + (_guiMetric[METRIC_TEXTBOX_VERTICAL_PADDING] * 2);
|
||||
t->base.delMethod = textboxDel;
|
||||
t->base.focusMethod = textboxFocusEvent;
|
||||
t->base.keyboardEventMethod = textboxKeyboardEvent;
|
||||
t->base.paintMethod = textboxPaint;
|
||||
t->base.mouseEventMethod = textboxMouseEvent;
|
||||
t->title = NULL;
|
||||
t->maxLength = 256;
|
||||
t->value = (char *)malloc(t->maxLength);
|
||||
t->caret = 0;
|
||||
|
||||
if (!t->value) return NULL;
|
||||
t->value[0] = 0;
|
||||
|
@ -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) {
|
||||
TextboxT *t = (TextboxT *)widget;
|
||||
|
||||
|
|
|
@ -32,22 +32,23 @@ uint16_t widgetGetWidth(WidgetT *widget) {
|
|||
|
||||
|
||||
WidgetT *widgetInit(WidgetT *widget) {
|
||||
widget->magic = MAGIC_UNKNOWN;
|
||||
widget->flags = 0;
|
||||
widget->x = 0;
|
||||
widget->y = 0;
|
||||
widget->w = 0;
|
||||
widget->h = 0;
|
||||
widget->marginX = 0;
|
||||
widget->marginY = 0;
|
||||
widget->surface = NULL;
|
||||
widget->children = NULL;
|
||||
widget->parent = NULL;
|
||||
widget->delMethod = NULL;
|
||||
widget->focusMethod = NULL;
|
||||
widget->paintMethod = NULL;
|
||||
widget->mouseEventMethod = NULL;
|
||||
widget->userData = NULL;
|
||||
widget->magic = MAGIC_UNKNOWN;
|
||||
widget->flags = 0;
|
||||
widget->x = 0;
|
||||
widget->y = 0;
|
||||
widget->w = 0;
|
||||
widget->h = 0;
|
||||
widget->marginX = 0;
|
||||
widget->marginY = 0;
|
||||
widget->surface = NULL;
|
||||
widget->children = NULL;
|
||||
widget->parent = NULL;
|
||||
widget->delMethod = NULL;
|
||||
widget->focusMethod = NULL;
|
||||
widget->keyboardEventMethod = NULL;
|
||||
widget->paintMethod = NULL;
|
||||
widget->mouseEventMethod = NULL;
|
||||
widget->userData = NULL;
|
||||
|
||||
GUI_SET_FLAG(widget, WIDGET_FLAG_DIRTY);
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
enum WidgetE {
|
||||
WIDGET_FLAG_DIRTY = 0,
|
||||
WIDGET_FLAG_ACTIVE,
|
||||
WIDGET_FLAG_OWNS_SURFACE
|
||||
WIDGET_FLAG_OWNS_SURFACE,
|
||||
WIDGET_FLAG_ALWAYS_RECEIVE_KEYBOARD_EVENTS
|
||||
};
|
||||
|
||||
|
||||
|
@ -39,28 +40,30 @@ typedef struct WindowS WindowT;
|
|||
typedef void (*widgetCallback)(struct WidgetS *widget);
|
||||
typedef void (*widgetDelMethod)(struct WidgetS **widget);
|
||||
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 (*widgetMouseEventMethod)(struct WidgetS *widget, MouseT *mouse, uint16_t x, uint16_t y, uint8_t event);
|
||||
|
||||
|
||||
typedef struct WidgetS {
|
||||
uint8_t magic; // Widget identifier constant
|
||||
uint8_t flags; // See above enum
|
||||
SurfaceT *surface; // Pointer to compositable surface or NULL
|
||||
WindowT *window; // The window holding this widget or NULL
|
||||
int16_t x; // Position of widget on parent
|
||||
int16_t y; // Position of widget on parent
|
||||
uint16_t w; // Width of widget
|
||||
uint16_t h; // Height of widget
|
||||
uint16_t marginX; // Pixels to skip when placing child widgets
|
||||
uint16_t marginY; // Pixels to skip when placing child widgets
|
||||
WidgetT **children; // List of children
|
||||
WidgetT *parent; // Parent of this widget
|
||||
widgetDelMethod delMethod; // Delete method
|
||||
widgetFocusMethod focusMethod; // Focus changed method
|
||||
widgetPaintMethod paintMethod; // Paint method
|
||||
widgetMouseEventMethod mouseEventMethod; // Mouse event handler
|
||||
void *userData; // Anything the user wants to store
|
||||
uint8_t magic; // Widget identifier constant
|
||||
uint8_t flags; // See above enum
|
||||
SurfaceT *surface; // Pointer to compositable surface or NULL
|
||||
WindowT *window; // The window holding this widget or NULL
|
||||
int16_t x; // Position of widget on parent
|
||||
int16_t y; // Position of widget on parent
|
||||
uint16_t w; // Width of widget
|
||||
uint16_t h; // Height of widget
|
||||
uint16_t marginX; // Pixels to skip when placing child widgets
|
||||
uint16_t marginY; // Pixels to skip when placing child widgets
|
||||
WidgetT **children; // List of children
|
||||
WidgetT *parent; // Parent of this widget
|
||||
widgetDelMethod delMethod; // Delete method
|
||||
widgetFocusMethod focusMethod; // Focus changed method
|
||||
widgetKeyboardEventMethod keyboardEventMethod; // Keyboard event handler
|
||||
widgetPaintMethod paintMethod; // Paint method
|
||||
widgetMouseEventMethod mouseEventMethod; // Mouse event handler
|
||||
void *userData; // Anything the user wants to store
|
||||
} WidgetT;
|
||||
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ void test(void *data) {
|
|||
mouse = mouseRead();
|
||||
if (keyHit()) {
|
||||
key = keyASCII();
|
||||
guiProcessKeyboard(keyASCII(), keyScanCode(), keyShift(), keyControl(), keyAlt());
|
||||
} else {
|
||||
key = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue