MouseManager.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "MouseManager.h"
  2. MouseManager::MouseManager()
  3. {
  4. for(int i = 0; i < NUMBER_OF_BUTTONS; i++)
  5. {
  6. mappingArray[i] = 0;
  7. }
  8. }
  9. bool MouseManager::isDown(int mapping)
  10. {
  11. return isInRange(mapping) && mouseArray[mappingArray[mapping]].down;
  12. }
  13. bool MouseManager::isReleased(int mapping)
  14. {
  15. return isInRange(mapping) && mouseArray[mappingArray[mapping]].shouldRelease;
  16. }
  17. unsigned int MouseManager::getDownTime(int mapping)
  18. {
  19. bool m = isInRange(mapping);
  20. return m * mouseArray[mappingArray[mapping * m]].downTime;
  21. }
  22. void MouseManager::resetDownTime(int mapping)
  23. {
  24. mouseArray[mappingArray[mapping * isInRange(mapping)]].downTime = 0;
  25. }
  26. bool MouseManager::map(int mapping, int mouse)
  27. {
  28. bool b = isInRange(mapping) && isInRange(mouse);
  29. mappingArray[mapping * b] = b * mouse;
  30. }
  31. bool MouseManager::isInRange(int i)
  32. {
  33. return i >= 0 && i < NUMBER_OF_BUTTONS;
  34. }
  35. void MouseManager::tick()
  36. {
  37. for(int i = 0; i < NUMBER_OF_BUTTONS; i++)
  38. {
  39. mouseArray[i].downTime += mouseArray[i].down;
  40. mouseArray[i].down = mouseArray[i].down && !mouseArray[i].shouldRelease;
  41. mouseArray[i].downTime *= !mouseArray[i].shouldRelease;
  42. mouseArray[i].shouldRelease = false;
  43. }
  44. }
  45. bool MouseManager::press(int mouse)
  46. {
  47. int index = isInRange(mouse) * mouse;
  48. mouseArray[index].down = true;
  49. mouseArray[index].shouldRelease = false;
  50. }
  51. bool MouseManager::release(int mouse)
  52. {
  53. int index = isInRange(mouse) * mouse;
  54. mouseArray[index].shouldRelease = true;
  55. }