4.2 Data Structures
/* Button states */
typedef enum {
D3TUI_BUTTON_UP = 0,
D3TUI_BUTTON_DOWN = 1,
D3TUI_BUTTON_HELD = 2
} d3tui_button_state_t;
/* Controller buttons */
typedef enum {
D3TUI_BUTTON_A = 0,
D3TUI_BUTTON_B,
D3TUI_BUTTON_X,
D3TUI_BUTTON_Y,
D3TUI_BUTTON_START,
D3TUI_BUTTON_DPAD_UP,
D3TUI_BUTTON_DPAD_DOWN,
D3TUI_BUTTON_DPAD_LEFT,
D3TUI_BUTTON_DPAD_RIGHT,
D3TUI_BUTTON_L_TRIGGER,
D3TUI_BUTTON_R_TRIGGER,
D3TUI_BUTTON_MAX
} d3tui_controller_button_t;
/* Controller state */
typedef struct {
d3tui_button_state_t buttons[D3TUI_BUTTON_MAX];
int16_t left_stick_x; /* -128 to 127 */
int16_t left_stick_y; /* -128 to 127 */
int16_t right_stick_x; /* -128 to 127 */
int16_t right_stick_y; /* -128 to 127 */
uint8_t left_trigger; /* 0-255 */
uint8_t right_trigger; /* 0-255 */
} d3tui_controller_state_t;
/* Keyboard modifiers */
typedef enum {
D3TUI_MOD_SHIFT = 1 << 0,
D3TUI_MOD_CTRL = 1 << 1,
D3TUI_MOD_ALT = 1 << 2,
D3TUI_MOD_META = 1 << 3
} d3tui_modifier_t;
/* Key event */
typedef struct {
uint32_t codepoint; /* Unicode codepoint or special key code */
uint8_t modifiers; /* Modifier flags */
bool pressed; /* true = press, false = release */
uint32_t timestamp; /* When the event occurred */
} d3tui_key_event_t;
/* Input buffer */
typedef struct {
d3tui_key_event_t *events; /* Array of events */
size_t count; /* Number of events */
size_t capacity; /* Maximum capacity */
size_t read_pos; /* Read position */
size_t write_pos; /* Write position */
} d3tui_input_buffer_t;
/* Key binding */
typedef struct {
uint32_t key; /* Key code or button */
uint8_t modifiers; /* Required modifiers */
const char *sequence; /* Output sequence */
} d3tui_key_binding_t;
/* Input handler */
typedef struct {
maple_device_t *controller_dev; /* Controller device */
maple_device_t *keyboard_dev; /* Keyboard device */
d3tui_controller_state_t controller; /* Current controller state */
d3tui_input_buffer_t buffer; /* Input event buffer */
d3tui_key_binding_t *bindings; /* Key bindings */
size_t binding_count; /* Number of bindings */
} d3tui_input_handler_t;