Debian Codegraph @

common/include/mouse.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 * SDL mouse driver header
10 *
11 */
12
13 #pragma once
14
15 #include <array>
16 #include <tuple>
17 #include "pstypes.h"
18 #include "maths.h"
19 #include <SDL_version.h>
20 #include <cassert>
21 #include "event.h"
22
23 struct SDL_MouseButtonEvent;
24 struct SDL_MouseMotionEvent;
25
26 namespace dcx {
27
28 #define MOUSE_MAX_BUTTONS 17
29 #define Z_SENSITIVITY 100
30
31 enum class mbtn : uint8_t
32 {
33 left = 0,
34 right = 1,
35 middle = 2,
36 z_up = 3,
37 z_down = 4,
38 pitch_backward = 5,
39 pitch_forward = 6,
40 bank_left = 7,
41 bank_right = 8,
42 head_left = 9,
43 head_right = 10,
44 _11 = 11,
45 _12 = 12,
46 _13 = 13,
47 _14 = 14,
48 _15 = 15,
49 _16 = 16,
50 };
51
52 #define MOUSE_LBTN 1
53 #define MOUSE_RBTN 2
54 #define MOUSE_MBTN 4
55
56 extern void mouse_flush(); // clears all mice events...
57 extern void mouse_init(void);
58 extern void mouse_close(void);
59 [[nodiscard]]
60 std::tuple<int /* x */, int /* y */, int /* z */> mouse_get_pos();
61 window_event_result mouse_in_window(class window *wind);
62 #if 0
63 [[nodiscard]]
64 std::tuple<int /* x */, int /* y */, int /* z */> mouse_get_delta();
65 #endif
66 void mouse_enable_cursor();
67 void mouse_disable_cursor();
68 window_event_result mouse_button_handler(const SDL_MouseButtonEvent *mbe);
69 window_event_result mouse_motion_handler(const SDL_MouseMotionEvent *mme);
70 void mouse_cursor_autohide();
71
72 class d_event_mousebutton : public d_event
73 {
74 public:
75 d_event_mousebutton(event_type type, mbtn b);
76 const mbtn button;
77 };
78
79 class d_event_mouse_moved : public d_event
80 {
81 public:
82 #if SDL_MAJOR_VERSION == 1
83 #define SDL_MOUSE_MOVE_INT_TYPE Sint16
84 #elif SDL_MAJOR_VERSION == 2
85 #define SDL_MOUSE_MOVE_INT_TYPE Sint32
86 #endif
87 const SDL_MOUSE_MOVE_INT_TYPE dx, dy;
88 const int16_t dz;
89 constexpr d_event_mouse_moved(const event_type t, const SDL_MOUSE_MOVE_INT_TYPE x, const SDL_MOUSE_MOVE_INT_TYPE y, const int16_t z) :
90 d_event{t}, dx{x}, dy{y}, dz{z}
91 {
92 }
93 #undef SDL_MOUSE_MOVE_INT_TYPE
94 };
95
96 static inline mbtn event_mouse_get_button(const d_event &event)
97 {
98 auto &e = static_cast<const d_event_mousebutton &>(event);
99 assert(e.type == event_type::mouse_button_down || e.type == event_type::mouse_button_up);
100 return e.button;
101 }
102
103 [[nodiscard]]
104 static inline std::array<int, 3> event_mouse_get_delta(const d_event &event)
105 {
106 auto &e = static_cast<const d_event_mouse_moved &>(event);
107 assert(e.type == event_type::mouse_moved);
108 return {{
109 e.dx,
110 e.dy,
111 e.dz,
112 }};
113 }
114
115 }