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 | * SDL mouse driver header |
||
10 | * |
||
11 | */ |
||
12 | |||
13 | #pragma once |
||
14 | |||
15 | #include "pstypes.h" |
||
16 | #include "maths.h" |
||
17 | |||
18 | #ifdef __cplusplus |
||
19 | #include <SDL_version.h> |
||
20 | #include <cassert> |
||
21 | #include "fwd-window.h" |
||
22 | #include "event.h" |
||
23 | |||
24 | struct SDL_MouseButtonEvent; |
||
25 | struct SDL_MouseMotionEvent; |
||
26 | |||
27 | namespace dcx { |
||
28 | |||
29 | #define MOUSE_MAX_BUTTONS 16 |
||
30 | #define Z_SENSITIVITY 100 |
||
31 | #define MBTN_LEFT 0 |
||
32 | #define MBTN_RIGHT 1 |
||
33 | #define MBTN_MIDDLE 2 |
||
34 | #define MBTN_Z_UP 3 |
||
35 | #define MBTN_Z_DOWN 4 |
||
36 | #define MBTN_PITCH_BACKWARD 5 |
||
37 | #define MBTN_PITCH_FORWARD 6 |
||
38 | #define MBTN_BANK_LEFT 7 |
||
39 | #define MBTN_BANK_RIGHT 8 |
||
40 | #define MBTN_HEAD_LEFT 9 |
||
41 | #define MBTN_HEAD_RIGHT 10 |
||
42 | #define MBTN_11 11 |
||
43 | #define MBTN_12 12 |
||
44 | #define MBTN_13 13 |
||
45 | #define MBTN_14 14 |
||
46 | #define MBTN_15 15 |
||
47 | #define MBTN_16 16 |
||
48 | #define MOUSE_LBTN 1 |
||
49 | #define MOUSE_RBTN 2 |
||
50 | #define MOUSE_MBTN 4 |
||
51 | |||
52 | extern void mouse_flush(); // clears all mice events... |
||
53 | extern void mouse_init(void); |
||
54 | extern void mouse_close(void); |
||
55 | extern void mouse_get_pos( int *x, int *y, int *z ); |
||
56 | window_event_result mouse_in_window(class window *wind); |
||
57 | extern void mouse_get_delta( int *dx, int *dy, int *dz ); |
||
58 | void mouse_enable_cursor(); |
||
59 | void mouse_disable_cursor(); |
||
60 | window_event_result mouse_button_handler(const SDL_MouseButtonEvent *mbe); |
||
61 | window_event_result mouse_motion_handler(const SDL_MouseMotionEvent *mme); |
||
62 | void mouse_cursor_autohide(); |
||
63 | |||
64 | class d_event_mousebutton : public d_event |
||
65 | { |
||
66 | public: |
||
67 | d_event_mousebutton(event_type type, unsigned b); |
||
68 | const unsigned button; |
||
69 | }; |
||
70 | |||
71 | class d_event_mouse_moved : public d_event |
||
72 | { |
||
73 | public: |
||
74 | #if SDL_MAJOR_VERSION == 1 |
||
75 | #define SDL_MOUSE_MOVE_INT_TYPE Sint16 |
||
76 | #elif SDL_MAJOR_VERSION == 2 |
||
77 | #define SDL_MOUSE_MOVE_INT_TYPE Sint32 |
||
78 | #endif |
||
79 | const SDL_MOUSE_MOVE_INT_TYPE dx, dy; |
||
80 | const int16_t dz; |
||
81 | 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) : |
||
82 | d_event(t), dx(x), dy(y), dz(z) |
||
83 | { |
||
84 | } |
||
85 | #undef SDL_MOUSE_MOVE_INT_TYPE |
||
86 | }; |
||
87 | |||
88 | static inline int event_mouse_get_button(const d_event &event) |
||
89 | { |
||
90 | auto &e = static_cast<const d_event_mousebutton &>(event); |
||
91 | assert(e.type == EVENT_MOUSE_BUTTON_DOWN || e.type == EVENT_MOUSE_BUTTON_UP); |
||
92 | return e.button; |
||
93 | } |
||
94 | |||
95 | static inline void event_mouse_get_delta(const d_event &event, int *dx, int *dy, int *dz) |
||
96 | { |
||
97 | auto &e = static_cast<const d_event_mouse_moved &>(event); |
||
98 | assert(e.type == EVENT_MOUSE_MOVED); |
||
99 | *dx = e.dx; |
||
100 | *dy = e.dy; |
||
101 | *dz = e.dz; |
||
102 | } |
||
103 | |||
104 | } |
||
105 | |||
106 | #endif |