#pragma once #ifdef _WIN32 #include #include #include #include #include #include #ifndef DIRECTINPUT_VERSION # define DIRECTINPUT_VERSION 0x800 #endif #include #include #include "opentrack-compat/timer.hpp" #include #include #include #include #include namespace std { template<> struct hash { inline std::size_t operator()(const QString& value) const { return qHash(value); } }; } #include "export.hpp" struct OPENTRACK_API_EXPORT win32_joy_ctx { using fn = std::function; enum { joy_axis_size = 65535 }; struct joy_info { QString name, guid; }; void poll(fn f); bool poll_axis(const QString& guid, int axes[8]); std::vector get_joy_info(); win32_joy_ctx(const win32_joy_ctx&) = delete; win32_joy_ctx& operator=(const win32_joy_ctx&) = delete; win32_joy_ctx(); ~win32_joy_ctx(); void refresh(); private: QMutex mtx; QMainWindow fake_main_window; LPDIRECTINPUT8 di; static QString guid_to_string(const GUID guid); void release(); struct joy { LPDIRECTINPUTDEVICE8 joy_handle; QString guid, name; bool pressed[128]; Timer first_timer; DIJOYSTATE2 js_old; joy(LPDIRECTINPUTDEVICE8 handle, const QString& guid, const QString& name); ~joy(); void release(); bool poll(fn f); }; std::unordered_map> joys; class enum_state { std::unordered_map> joys; QMainWindow& fake_main_window; LPDIRECTINPUT8 di; std::vector all; static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext); static BOOL CALLBACK EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* ctx); public: enum_state(std::unordered_map>& joys, QMainWindow& fake_main_window, LPDIRECTINPUT8 di); }; }; #endif