diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-05-02 18:24:48 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-05-02 18:24:48 +0200 |
commit | 53382473b3ed8266a6355de0954f324efdc5192f (patch) | |
tree | b8c21206d88ab6bc0dc27e36bf1a34352badef3c /dinput | |
parent | 5ea61a6b6f2cc587cf3aeb0cf16f2f492b20b52f (diff) |
dinput: fix clang "non-constant-expression" error
Diffstat (limited to 'dinput')
-rw-r--r-- | dinput/win32-joystick.cpp | 22 | ||||
-rw-r--r-- | dinput/win32-joystick.hpp | 4 |
2 files changed, 18 insertions, 8 deletions
diff --git a/dinput/win32-joystick.cpp b/dinput/win32-joystick.cpp index c20aefce..d4ae0e8a 100644 --- a/dinput/win32-joystick.cpp +++ b/dinput/win32-joystick.cpp @@ -3,6 +3,8 @@ #undef NDEBUG #include "win32-joystick.hpp" #include "compat/sleep.hpp" + +#include <cstddef> #include <cassert> #include <cstring> #include <algorithm> @@ -180,18 +182,24 @@ bool win32_joy_ctx::joy::poll(fn f) bool is_pov = false; int i = -1; +#define POV_HAT_OFFSET(k) \ + (offsetof(DIJOYSTATE, rgdwPOV) + (k) * sizeof(DWORD)) + +#define BUTTON(k) \ + (offsetof(DIJOYSTATE, rgbButtons) + (k) * sizeof(BYTE)) + switch (event.dwOfs) { - case DIJOFS_POV(0): i = 0, is_pov = true; break; - case DIJOFS_POV(2): i = 1, is_pov = true; break; - case DIJOFS_POV(3): i = 2, is_pov = true; break; - case DIJOFS_POV(4): i = 3, is_pov = true; break; + case POV_HAT_OFFSET(0): i = 0; is_pov = true; break; + case POV_HAT_OFFSET(2): i = 1; is_pov = true; break; + case POV_HAT_OFFSET(3): i = 2; is_pov = true; break; + case POV_HAT_OFFSET(4): i = 3; is_pov = true; break; default: - if (event.dwOfs >= DIJOFS_BUTTON0 && event.dwOfs <= DIJOFS_BUTTON(127)) + if (event.dwOfs >= BUTTON(0) && event.dwOfs <= BUTTON(127)) { unsigned tmp = event.dwOfs; - tmp -= DIJOFS_BUTTON0; - tmp /= DIJOFS_BUTTON1 - DIJOFS_BUTTON0; + tmp -= BUTTON(0); + tmp /= BUTTON(1) - BUTTON(0); tmp &= 127; i = tmp; } diff --git a/dinput/win32-joystick.hpp b/dinput/win32-joystick.hpp index f7ea1302..8b71b8b7 100644 --- a/dinput/win32-joystick.hpp +++ b/dinput/win32-joystick.hpp @@ -35,7 +35,7 @@ struct hash<QString> }; } -struct OTR_DINPUT_EXPORT win32_joy_ctx +struct OTR_DINPUT_EXPORT win32_joy_ctx final { using fn = std::function<void(const QString& guid, int btn, bool held)>; @@ -97,6 +97,8 @@ private: ~enum_state(); void refresh(); const joys_t& get_joys() const; + + enum_state(enum_state const&) = delete; }; static enum_state enumerator; |