ajout de la gestion évènementielle du clavier avec callbacks
This commit is contained in:
parent
3e210cb232
commit
625dcb6a8d
1320
build-fx/map
1320
build-fx/map
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,4 @@
|
|||
build-fx/src/FxEngine/keyboard.o: src/FxEngine/keyboard.c \
|
||||
src/FxEngine/keyboard.h
|
||||
|
||||
src/FxEngine/keyboard.h:
|
Binary file not shown.
|
@ -0,0 +1,33 @@
|
|||
#include "keyboard.h"
|
||||
|
||||
static callback callbacks[3][6][10]={0};
|
||||
|
||||
static inline uint32_t get_x(const uint32_t matrix_code)
|
||||
{
|
||||
return (matrix_code-1) % 0x10;
|
||||
}
|
||||
|
||||
static inline uint32_t get_y(const uint32_t matrix_code)
|
||||
{
|
||||
return (matrix_code-1) / 0x10;
|
||||
}
|
||||
|
||||
void FE_keyboard_reload()
|
||||
{
|
||||
key_event_t event;
|
||||
while (1)
|
||||
{
|
||||
event=pollevent();
|
||||
event.type--;
|
||||
if (event.type==-1)
|
||||
break;
|
||||
callback action = callbacks[event.type][get_x(event.key)][get_y(event.key)];
|
||||
if (action)
|
||||
action();
|
||||
}
|
||||
}
|
||||
|
||||
void FE_keyboard_set_key(uint32_t matrix_code, uint32_t ev_type, callback function)
|
||||
{
|
||||
callbacks[ev_type-1][get_x(matrix_code)][get_y(matrix_code)]=function;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef FE_KEYBOARD
|
||||
#define FE_KEYBOARD
|
||||
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/keycodes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* FE_keyboard: gestion evenementielle du clavier
|
||||
on peut assigner des callbacks à certains evènements définis dans gint
|
||||
les arguments envoyés sont le code de la touche en question (event.key)
|
||||
le type d'evenement (event.type)
|
||||
void (*callback)(void)
|
||||
la fonction à exécuter en cas de pression sur une touche
|
||||
la fonction reload est appelée à la demande de l'utilisateur et appelle tous les callbacks dans l'ordre */
|
||||
|
||||
typedef void (*callback)(void);
|
||||
|
||||
void FE_keyboard_set_key(uint32_t matrix_code, uint32_t ev_type, callback function);
|
||||
|
||||
void FE_keyboard_reload();
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue