From 14df82ee4db71509f4ec4968df439d4659ca1ac3 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 20 Sep 2022 12:34:35 +0200 Subject: Implement input component It is required to redirect keyboard input (both physical or not) when a GUI line edit is focused. This means other components cannot be activated on key presses. Therefore, this new component is meant as a higher-level abstraction compared to the `keyboard`/`pad`/`mouse` components, which: - Implements the same APIs provided by `keyboard`, `mouse` and `pad`. - Returns the same results as the APIs above if no GUI element is focused, no input otherwise. Note: replacing calls to `keyboard`/`pad`/`mouse` with `input` will be implemented in a future commit. --- src/input/inc/input.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/input/inc/input.h (limited to 'src/input/inc/input.h') diff --git a/src/input/inc/input.h b/src/input/inc/input.h new file mode 100644 index 0000000..2dd401b --- /dev/null +++ b/src/input/inc/input.h @@ -0,0 +1,56 @@ +#ifndef INPUT_H +#define INPUT_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef void (*input_ch)(char ch, void *user); +typedef void (*input_erase)(void *user); + +struct input +{ + input_ch cb; + input_erase erase; + void *user; + unsigned char t; + bool repeat; + struct keyboard_combo prev; +}; + +void input_update(struct input *in, const union peripheral *p); +int input_render(const struct input *in, const union peripheral *p); +bool input_keyboard_justpressed(const struct input *in, + const struct keyboard *k, + const struct keyboard_combo *c); +bool input_keyboard_pressed(const struct input *in, + const struct keyboard *k, + const struct keyboard_combo *c); +bool input_keyboard_justreleased(const struct input *in, + const struct keyboard *k, + const struct keyboard_combo *c); +bool input_pad_pressed(const struct input *in, const struct pad *p, + enum pad_key k); +bool input_pad_justpressed(const struct input *in, const struct pad *p, + enum pad_key k); +bool input_pad_released(const struct input *in, const struct pad *p, + enum pad_key k); +bool input_mouse_pressed(const struct input *in, const struct mouse *m, + enum mouse_button b); +bool input_mouse_justpressed(const struct input *in, const struct mouse *m, + enum mouse_button b); +bool input_mouse_justreleased(const struct input *in, const struct mouse *m, + enum mouse_button b); + +#ifdef __cplusplus +} +#endif + +#endif /* INPUT_H */ -- cgit v1.2.3