move mouse wakeup from SR to VG
[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 f32 hidden_mouse_travel;
51
52 struct vg_controller{
53 SDL_GameController *handle; /* handle for controller. NULL if unused */
54 SDL_JoystickID instance_id; /* uid used in events */
55
56 float axises[ SDL_CONTROLLER_AXIS_MAX ];
57 u32 buttons[ SDL_CONTROLLER_BUTTON_MAX ];
58 }
59 controllers[4];
60
61 int active_controller_index; /* most recent controller (by button press)
62 will be -1 if no controllers active */
63
64 /* what the user is currently using. the keyboard and controller are still
65 * active simultaneously, but this reflects what the UI should show */
66 enum input_method{
67 k_input_method_kbm,
68 k_input_method_controller
69 }
70 display_input_method;
71 SDL_GameControllerType display_input_type;
72 }
73 extern vg_input;
74
75 u8 vg_getkey( SDL_Keycode kc );
76 void vg_process_inputs(void);
77 void async_vg_input_init( void *payload, u32 size );
78 void vg_input_init(void);
79 void vg_input_free(void);
80 struct vg_controller *vg_active_controller(void);
81 u8 vg_controller_button( SDL_GameControllerButton button );
82 f32 vg_controller_axis( SDL_GameControllerAxis axis );
83 void vg_exec_input_program( enum vg_input_type type, vg_input_op *ops,
84 void *out_result );
85 const char *controller_button_str( SDL_GameControllerButton button );
86 void vg_keyboard_key_string( vg_str *str, u32 key, int special_glyphs );
87 void vg_mouse_button_string( vg_str *str, u32 button, int special_glyphs );
88 void vg_joy_axis_string( vg_str *str, SDL_GameControllerAxis axis,
89 int special_glyphs );
90 void vg_joy_string( vg_str *str, vg_input_op op, int special_glyphs );
91 void vg_input_string( vg_str *str, vg_input_op *ops, int glyphs );
92 void vg_input_device_event( SDL_Event *ev );
93 void vg_input_controller_event( SDL_Event *ev );