build system revision
[vg.git] / vg_input.h
1 #pragma once
2
3 /* Copyright (C) 2021-2024 Harry Godden (hgn) - All Rights Reserved */
4 #define VG_MAX_CONTROLLERS 4
5
6 #include "vg_platform.h"
7
8 extern f32 controller_deadzone;
9
10 typedef u32 vg_input_op;
11 typedef vg_input_op *vg_input_program;
12
13 enum vg_input_type
14 {
15 k_vg_input_type_button_u8,
16 k_vg_input_type_axis_f32,
17 k_vg_input_type_joy_v2f
18 };
19
20 enum vg_input_op
21 {
22 /* data source */
23 vg_keyboard,
24 vg_mouse,
25 vg_joy_button,
26 vg_joy_axis,
27 vg_joy_ls,
28 vg_joy_rs,
29
30 /* modes */
31 vg_mode_mul,
32 vg_mode_sub,
33 vg_mode_add,
34 vg_mode_absmax,
35 vg_mode_max,
36
37 /* control */
38 vg_index,
39 vg_end,
40 vg_gui_visible,
41
42 /* math */
43 vg_normalize
44 };
45
46 struct vg_input
47 {
48 const u8 *sdl_keys;
49 u32 sdl_mouse;
50
51 struct vg_controller{
52 SDL_GameController *handle; /* handle for controller. NULL if unused */
53 SDL_JoystickID instance_id; /* uid used in events */
54
55 float axises[ SDL_CONTROLLER_AXIS_MAX ];
56 u32 buttons[ SDL_CONTROLLER_BUTTON_MAX ];
57 }
58 controllers[4];
59
60 int active_controller_index; /* most recent controller (by button press)
61 will be -1 if no controllers active */
62
63 /* what the user is currently using. the keyboard and controller are still
64 * active simultaneously, but this reflects what the UI should show */
65 enum input_method{
66 k_input_method_kbm,
67 k_input_method_controller
68 }
69 display_input_method;
70 SDL_GameControllerType display_input_type;
71 }
72 extern vg_input;
73
74 u8 vg_getkey( SDL_Keycode kc );
75 void vg_process_inputs(void);
76 void async_vg_input_init( void *payload, u32 size );
77 void vg_input_init(void);
78 void vg_input_free(void);
79 struct vg_controller *vg_active_controller(void);
80 u8 vg_controller_button( SDL_GameControllerButton button );
81 f32 vg_controller_axis( SDL_GameControllerAxis axis );
82 void vg_exec_input_program( enum vg_input_type type, vg_input_op *ops,
83 void *out_result );
84 const char *controller_button_str( SDL_GameControllerButton button );
85 void vg_keyboard_key_string( vg_str *str, u32 key, int special_glyphs );
86 void vg_mouse_button_string( vg_str *str, u32 button, int special_glyphs );
87 void vg_joy_axis_string( vg_str *str, SDL_GameControllerAxis axis,
88 int special_glyphs );
89 void vg_joy_string( vg_str *str, vg_input_op op, int special_glyphs );
90 void vg_input_string( vg_str *str, vg_input_op *ops, int glyphs );
91 void vg_input_device_event( SDL_Event *ev );
92 void vg_input_controller_event( SDL_Event *ev );