Input.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "Input.h"
  2. Input::Input(): m_x(0), m_y(0), m_xRel(0), m_yRel(0), m_continuer(true)
  3. {
  4. for(int i = 0;i<512;i++)
  5. m_touches[i] = R_RELACHER;
  6. for(int i = 0;i<8;i++)
  7. m_boutonsSouris[i] = R_RELACHER;
  8. }
  9. Input::~Input()
  10. {
  11. }
  12. void Input::updateEvenement()
  13. {
  14. m_xRel = 0;
  15. m_yRel = 0;
  16. while(SDL_PollEvent(&m_evenement))
  17. {
  18. switch(m_evenement.type)
  19. {
  20. case SDL_QUIT:
  21. m_continuer = false;
  22. break;
  23. case SDL_KEYDOWN:
  24. m_touches[m_evenement.key.keysym.sym] = (m_touches[m_evenement.key.keysym.scancode] & R_RELACHER)?APPUYER:R_APPUYER;
  25. break;
  26. case SDL_KEYUP:
  27. m_touches[m_evenement.key.keysym.sym] = (m_touches[m_evenement.key.keysym.scancode] & R_APPUYER)?RELACHER:R_RELACHER;
  28. break;
  29. case SDL_MOUSEBUTTONDOWN:
  30. m_boutonsSouris[m_evenement.button.button] = (m_boutonsSouris[m_evenement.button.button] & R_RELACHER)?APPUYER:R_APPUYER;
  31. break;
  32. case SDL_MOUSEBUTTONUP:
  33. m_boutonsSouris[m_evenement.button.button] = (m_boutonsSouris[m_evenement.button.button] & R_APPUYER)?RELACHER:R_RELACHER;
  34. break;
  35. case SDL_MOUSEMOTION:
  36. m_x = m_evenement.motion.x;
  37. m_y = m_evenement.motion.y;
  38. m_xRel = m_evenement.motion.xrel;
  39. m_yRel = m_evenement.motion.yrel;
  40. break;
  41. default:
  42. break;
  43. }
  44. }
  45. }
  46. bool Input::continuer() const
  47. {
  48. return m_continuer;
  49. }
  50. int Input::getTouches(const SDLKey touche) const
  51. {
  52. return m_touches[touche];
  53. }
  54. int Input::getBoutonSouris(const Uint8 bouton) const
  55. {
  56. return m_boutonsSouris[bouton];
  57. }
  58. bool Input::mouvementSouris() const
  59. {
  60. if(m_xRel == 0 && m_yRel == 0)
  61. return false;
  62. else
  63. return true;
  64. }
  65. int Input::getX() const
  66. {
  67. return m_x;
  68. }
  69. int Input::getY() const
  70. {
  71. return m_y;
  72. }
  73. int Input::getXRel() const
  74. {
  75. return m_xRel;
  76. }
  77. int Input::getYRel() const
  78. {
  79. return m_yRel;
  80. }