12345678910111213141516171819202122232425262728293031 |
- #include "input/Button.h"
- Button::Button(int key, const char* name) : key(key), downTime(0), released(false), name(name) {
- }
- void Button::tick(bool down) {
- if(down) {
- downTime++;
- } else if(released) {
- released = false;
- downTime = 0;
- } else if(!released && downTime > 0) {
- released = true;
- }
- }
- bool Button::isDown() const {
- return downTime > 0;
- }
- int Button::getDownTime() const {
- return downTime;
- }
- bool Button::wasReleased() const {
- return released;
- }
- const char* Button::getName() const {
- return name;
- }
|