Input.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef INPUT_H_INCLUDED
  2. #define INPUT_H_INCLUDED
  3. #include <SDL/SDL.h>
  4. #undef main
  5. class Input
  6. {
  7. public:
  8. Input(): m_x(0), m_y(0), m_xRel(0), m_yRel(0), m_continuer(true)
  9. {
  10. reset();
  11. }
  12. ~Input()
  13. {
  14. }
  15. void updateEvenement()
  16. {
  17. m_xRel = 0;
  18. m_yRel = 0;
  19. while(SDL_PollEvent(&m_evenement))
  20. {
  21. switch(m_evenement.type)
  22. {
  23. case SDL_QUIT:
  24. m_continuer = false;
  25. break;
  26. case SDL_KEYDOWN:
  27. m_touches[m_evenement.key.keysym.sym] = true;
  28. break;
  29. case SDL_KEYUP:
  30. m_touches[m_evenement.key.keysym.sym] = false;
  31. break;
  32. case SDL_MOUSEBUTTONDOWN:
  33. m_boutonsSouris[m_evenement.button.button] = true;
  34. break;
  35. case SDL_MOUSEBUTTONUP:
  36. m_boutonsSouris[m_evenement.button.button] = false;
  37. break;
  38. case SDL_MOUSEMOTION:
  39. m_x = m_evenement.motion.x;
  40. m_y = m_evenement.motion.y;
  41. m_xRel = m_evenement.motion.xrel;
  42. m_yRel = m_evenement.motion.yrel;
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. }
  49. bool continuer() const
  50. {
  51. return m_continuer;
  52. }
  53. bool getTouches(const SDLKey touche) const
  54. {
  55. return m_touches[touche];
  56. }
  57. bool getBoutonSouris(const Uint8 bouton) const
  58. {
  59. return m_boutonsSouris[bouton];
  60. }
  61. bool mouvementSouris() const
  62. {
  63. if(m_xRel == 0 && m_yRel == 0)
  64. return false;
  65. else
  66. return true;
  67. }
  68. int getX() const
  69. {
  70. return m_x;
  71. }
  72. int getY() const
  73. {
  74. return m_y;
  75. }
  76. int getXRel() const
  77. {
  78. return m_xRel;
  79. }
  80. int getYRel() const
  81. {
  82. return m_yRel;
  83. }
  84. void afficherPointeur(bool reponse) const
  85. {
  86. if(reponse)
  87. SDL_ShowCursor(SDL_ENABLE);
  88. else
  89. SDL_ShowCursor(SDL_DISABLE);
  90. }
  91. void reset()
  92. {
  93. for(int i = 0;i<323;i++)
  94. m_touches[i] = false;
  95. for(int i = 0;i<8;i++)
  96. m_boutonsSouris[i] = false;
  97. }
  98. private:
  99. SDL_Event m_evenement;
  100. bool m_touches[323];
  101. bool m_boutonsSouris[8];
  102. int m_x, m_y;
  103. int m_xRel, m_yRel;
  104. bool m_continuer;
  105. };
  106. #endif // INPUT_H_INCLUDED