Button.cpp 575 B

12345678910111213141516171819202122232425262728293031
  1. #include "input/Button.h"
  2. Button::Button(int key, const char* name) : key(key), downTime(0), released(false), name(name) {
  3. }
  4. void Button::tick(bool down) {
  5. if(down) {
  6. downTime++;
  7. } else if(released) {
  8. released = false;
  9. downTime = 0;
  10. } else if(!released && downTime > 0) {
  11. released = true;
  12. }
  13. }
  14. bool Button::isDown() const {
  15. return downTime > 0;
  16. }
  17. int Button::getDownTime() const {
  18. return downTime;
  19. }
  20. bool Button::wasReleased() const {
  21. return released;
  22. }
  23. const char* Button::getName() const {
  24. return name;
  25. }