]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/windows/gamecontroller_platform.h
Implement game controllers on Windows through XInput
[libs/gui.git] / source / input / windows / gamecontroller_platform.h
diff --git a/source/input/windows/gamecontroller_platform.h b/source/input/windows/gamecontroller_platform.h
new file mode 100644 (file)
index 0000000..46c2dd8
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef MSP_INPUT_GAMECONTROLLER_PLATFORM_H_
+#define MSP_INPUT_GAMECONTROLLER_PLATFORM_H_
+
+#include <windows.h>
+#include <xinput.h>
+#include <msp/core/thread.h>
+#include <msp/io/pipe.h>
+#include <msp/time/timer.h>
+
+namespace Msp {
+namespace Input {
+
+class GameControllerTimerThread: public Msp::Thread
+{
+private:
+       Time::Timer timer;
+       unsigned n_users;
+
+       static GameControllerTimerThread *thread;
+
+       GameControllerTimerThread();
+       ~GameControllerTimerThread();
+public:
+       static Time::Timer::Slot &add_slot();
+       static void remove_slot(Time::Timer::Slot &);
+
+private:
+       virtual void main();
+};
+
+
+struct GameController::Private
+{
+       unsigned index;
+       unsigned last_packet_number;
+       IO::Pipe *event_pipe;
+       Time::Timer::Slot *timer_slot;
+
+       static std::vector<unsigned> detected_controllers;
+
+       Private();
+
+       bool generate_event();
+
+       void update_state(GameController &, const XINPUT_STATE &, bool);
+
+};
+
+} // namespace Input
+} // namespace Msp
+
+#endif