input.h (1410B)
1 /* input.h - teclas abstractas, eventos y zonas clickeables, comunes a todos los 2 * frontends (TUI, GUI SDL, PicoCalc). */ 3 #ifndef COMUN_INPUT_H 4 #define COMUN_INPUT_H 5 #include <stdint.h> 6 #include <stdbool.h> 7 8 /* Teclas especiales; el resto son caracteres (Latin-1). */ 9 enum Key { 10 K_UP = 0x100, K_DOWN, K_LEFT, K_RIGHT, K_OK, K_BACK, K_TAB, K_PLUS, K_MINUS, K_BKSP 11 }; 12 13 /* Eventos de los frontends de PC. */ 14 enum { EV_NONE, EV_KEY, EV_CLICK, EV_RESIZE, EV_QUIT }; 15 typedef struct { int type, key, x, y; } InEvent; 16 17 /* Zonas clickeables que registra el frontend al dibujar. kind lo define cada 18 * juego (0..HIT_APP-1); HIT_APP son las de la app (formularios, dialogos). */ 19 enum { HIT_APP = 7 }; 20 typedef struct { int16_t x, y, w, h; uint8_t kind; int16_t id; } Hit; 21 typedef struct { Hit h[96]; int n; } HitList; 22 23 static inline void hit_add(HitList *l, int x, int y, int w, int h, int kind, int id) 24 { 25 if (l && l->n < 96) { Hit *t = &l->h[l->n++]; t->x = (int16_t)x; t->y = (int16_t)y; t->w = (int16_t)w; t->h = (int16_t)h; t->kind = (uint8_t)kind; t->id = (int16_t)id; } 26 } 27 28 static inline const Hit *hit_find(const HitList *l, int x, int y) 29 { 30 for (int i = l->n - 1; i >= 0; i--) { 31 const Hit *t = &l->h[i]; 32 if (x >= t->x && x < t->x + t->w && y >= t->y && y < t->y + t->h) return t; 33 } 34 return 0; 35 } 36 37 /* Layouts de pantalla en pixeles. */ 38 enum { LAYOUT_COMPACT, LAYOUT_WIDE }; 39 40 #endif