InputSDL.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, InputBase::InputkeyState keyState);
  34. private:
  35. void refreshJoystickList();
  36. QString nameForId(SDL_JoystickID id);
  37. SDLJoystickMap m_joysticks;
  38. // map axis to up = true or down = false
  39. QHash<quint8, bool> m_axisState;
  40. QString m_lastHat;
  41. };
  42. ///////////////////////////////////////////////////////////////////////////////////////////////////
  43. class InputSDL : public InputBase
  44. {
  45. Q_OBJECT
  46. public:
  47. explicit InputSDL(QObject* parent);
  48. ~InputSDL() override;
  49. const char* inputName() override { return "SDL"; }
  50. bool initInput() override;
  51. void close();
  52. private:
  53. InputSDLWorker* m_sdlworker;
  54. QThread* m_thread;
  55. signals:
  56. void run();
  57. };
  58. #endif /* _INPUT_SDL_ */