Debian Codegraph @

common/include/joy.h

raw
1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7 /*
8 *
9 * Header for joystick functions
10 *
11 */
12
13 #pragma once
14
15 #include "dxxsconf.h"
16 #include "dsx-ns.h"
17 #include "fwd-event.h"
18
19 #if DXX_MAX_JOYSTICKS
20 #include "pstypes.h"
21 #include "maths.h"
22 #include <SDL.h>
23
24 namespace dcx {
25
26 constexpr std::integral_constant<unsigned, DXX_MAX_AXES_PER_JOYSTICK * DXX_MAX_JOYSTICKS> JOY_MAX_AXES{};
27 #define JOY_MAX_BUTTONS (DXX_MAX_BUTTONS_PER_JOYSTICK * DXX_MAX_JOYSTICKS)
28
29 struct d_event_joystick_axis_value
30 {
31 unsigned axis;
32 int value;
33 };
34
35 extern void joy_init();
36 extern void joy_close();
37 extern void joy_flush();
38 extern int apply_deadzone(int value, int deadzone);
39
40 }
41 #else
42 #define joy_init() static_cast<void>(0)
43 #define joy_flush()
44 #define joy_close() static_cast<void>(0)
45 #endif
46
47 namespace dcx {
48
49 #if DXX_MAX_BUTTONS_PER_JOYSTICK
50 bool joy_translate_menu_key(const d_event &event);
51 int event_joystick_get_button(const d_event &event);
52 window_event_result joy_button_handler(const SDL_JoyButtonEvent *jbe);
53 #else
54 #define joy_button_handler(jbe) (static_cast<const SDL_JoyButtonEvent *const &>(jbe), window_event_result::ignored)
55 #endif
56
57 #if DXX_MAX_HATS_PER_JOYSTICK
58 window_event_result joy_hat_handler(const SDL_JoyHatEvent *jhe);
59 #else
60 #define joy_hat_handler(jbe) (static_cast<const SDL_JoyHatEvent *const &>(jbe), window_event_result::ignored)
61 #endif
62
63 #if DXX_MAX_AXES_PER_JOYSTICK
64 const d_event_joystick_axis_value &event_joystick_get_axis(const d_event &event);
65 window_event_result joy_axis_handler(const SDL_JoyAxisEvent *jae);
66 #else
67 #define joy_axis_handler(jbe) (static_cast<const SDL_JoyAxisEvent *const &>(jbe), window_event_result::ignored)
68 #endif
69
70 #if DXX_MAX_AXES_PER_JOYSTICK && (DXX_MAX_BUTTONS_PER_JOYSTICK || DXX_MAX_HATS_PER_JOYSTICK)
71 window_event_result joy_axisbutton_handler(const SDL_JoyAxisEvent *jae);
72 #else
73 #define joy_axisbutton_handler(jbe) (static_cast<const SDL_JoyAxisEvent *const &>(jbe), window_event_result::ignored)
74 #endif
75
76 }