From 25d7a0decd62f3cc5a1812896dcb03348fd866e6 Mon Sep 17 00:00:00 2001 From: Levent Kaya Date: Sun, 24 Nov 2024 12:33:22 +0300 Subject: [feature] keyboard event tracking definitions --- fbgl.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'fbgl.h') diff --git a/fbgl.h b/fbgl.h index 75fb4b8..b91dfd6 100644 --- a/fbgl.h +++ b/fbgl.h @@ -26,6 +26,7 @@ #define VERSION "0.1.0" #define NAME "FBGL" #define DEFAULT_FB "/dev/fb0" +#define #define FBGL_MAX_KEYS 256 // Maximum number of keys to track #include #include @@ -46,8 +47,6 @@ #include FT_FREETYPE_H #endif //FBGL_USE_FREETYPE -static struct termios orig_termios; - /** * Structs */ @@ -92,6 +91,20 @@ typedef struct fbgl_tga_texture { uint32_t *data; } fbgl_tga_texture_t; +typedef struct fbgl_keyboard { + bool keys[FBGL_MAX_KEYS]; // Current state of each key + bool prev_keys[FBGL_MAX_KEYS]; // Previous state of each key + bool is_initialized; // Track if keyboard is initialized +} fbgl_keyboard_t; + + +/** + * Key state function and variables + * + */ +static struct termios orig_termios; +static fbgl_keyboard_t keyboard = {0}; + #ifdef FBGL_HIDE_CURSOR #include int fbgl_hide_cursor(int fd) @@ -172,12 +185,22 @@ void fbgl_draw_rectangle_filled(fbgl_point_t top_left, fbgl_t *fb); /** - * texture - */ +* texture +*/ fbgl_tga_texture_t *fbgl_load_tga_texture(const char *path); void fbgl_destroy_texture(fbgl_tga_texture_t *texture); void fbgl_draw_texture(fbgl_t *fb, fbgl_tga_texture_t *texture, int x, int y); +/** + * Keyboard + */ +int fbgl_keyboard_init(); +void fbgl_keyboard_clean(); +void fbgl_keyboard_update(); +bool fbgl_key_pressed(unsigned char key); +bool fbgl_key_released(unsigned char key); +bool fbgl_key_down(unsigned char key); + #ifdef FBGL_IMPLEMENTATION char const *fbgl_name_info(void) -- cgit v1.2.3