Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 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 "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 | const d_event_joystick_axis_value &event_joystick_get_axis(const d_event &event); |
||
38 | extern void joy_flush(); |
||
39 | bool joy_translate_menu_key(const d_event &event); |
||
40 | extern int event_joystick_get_button(const d_event &event); |
||
41 | extern int apply_deadzone(int value, int deadzone); |
||
42 | |||
43 | } |
||
44 | #else |
||
45 | #define joy_init() static_cast<void>(0) |
||
46 | #define joy_flush() |
||
47 | #define joy_close() static_cast<void>(0) |
||
48 | #endif |
||
49 | |||
50 | namespace dcx { |
||
51 | |||
52 | #if DXX_MAX_BUTTONS_PER_JOYSTICK |
||
53 | window_event_result joy_button_handler(const SDL_JoyButtonEvent *jbe); |
||
54 | #else |
||
55 | #define joy_button_handler(jbe) (static_cast<const SDL_JoyButtonEvent *const &>(jbe), window_event_result::ignored) |
||
56 | #endif |
||
57 | |||
58 | #if DXX_MAX_HATS_PER_JOYSTICK |
||
59 | window_event_result joy_hat_handler(const SDL_JoyHatEvent *jhe); |
||
60 | #else |
||
61 | #define joy_hat_handler(jbe) (static_cast<const SDL_JoyHatEvent *const &>(jbe), window_event_result::ignored) |
||
62 | #endif |
||
63 | |||
64 | #if DXX_MAX_AXES_PER_JOYSTICK |
||
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 | } |