InputSDL.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // InputSDL.h
  3. // konvergo
  4. //
  5. // Created by Lionel CHAZALLON on 16/10/2014.
  6. //
  7. //
  8. #ifndef _INPUT_SDL_
  9. #define _INPUT_SDL_
  10. #include <QThread>
  11. #include <QElapsedTimer>
  12. #include <QByteArray>
  13. #include <SDL.h>
  14. #include "input/InputComponent.h"
  15. typedef QMap<int, SDL_Joystick*> SDLJoystickMap;
  16. typedef SDLJoystickMap::const_iterator SDLJoystickMapIterator;
  17. typedef QMap<int, QElapsedTimer*> SDLTimeStampMap;
  18. typedef QMap<int, QElapsedTimer*>::const_iterator SDLTimeStampMapIterator;
  19. #define SDL_POLL_TIME 50
  20. #define SDL_BUTTON_REPEAT_DELAY 500
  21. #define SDL_BUTTON_REPEAT_RATE 100
  22. ///////////////////////////////////////////////////////////////////////////////////////////////////
  23. class InputSDLWorker : public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit InputSDLWorker(QObject* parent) : QObject(parent) {}
  28. public slots:
  29. void run();
  30. bool initialize();
  31. void close();
  32. signals:
  33. void receivedInput(const QString& source, const QString& keycode, bool pressDown = true);
  34. private:
  35. void refreshJoystickList();
  36. QString nameForId(SDL_JoystickID id);
  37. SDLTimeStampMap m_buttonTimestamps;
  38. SDLJoystickMap m_joysticks;
  39. QByteArray m_axisState;
  40. };
  41. ///////////////////////////////////////////////////////////////////////////////////////////////////
  42. class InputSDL : public InputBase
  43. {
  44. Q_OBJECT
  45. public:
  46. explicit InputSDL(QObject* parent);
  47. ~InputSDL() override;
  48. const char* inputName() override { return "SDL"; }
  49. bool initInput() override;
  50. void close();
  51. private:
  52. InputSDLWorker* m_sdlworker;
  53. QThread* m_thread;
  54. signals:
  55. void run();
  56. };
  57. #endif /* _INPUT_SDL_ */