Button.cpp 666 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "input/Button.h"
  2. Button::Button() : keyDown(false), buttonDown(false), released(false), downTime(0) {
  3. }
  4. void Button::pressKey() {
  5. keyDown = true;
  6. }
  7. void Button::releaseKey() {
  8. keyDown = false;
  9. }
  10. void Button::pressButton() {
  11. buttonDown = true;
  12. }
  13. void Button::tick() {
  14. if(released) {
  15. downTime = 0;
  16. }
  17. released = false;
  18. if(keyDown || buttonDown) {
  19. downTime++;
  20. } else {
  21. released = downTime > 0;
  22. }
  23. buttonDown = false;
  24. }
  25. bool Button::isDown() const {
  26. return downTime > 0;
  27. }
  28. int Button::getDownTime() const {
  29. return downTime;
  30. }
  31. bool Button::wasReleased() const {
  32. return released;
  33. }