123456789101112131415161718192021222324252627282930313233343536 |
- #include "input/Button.h"
- Button::Button(int key, const char* name)
- : key(key), downTime(0), keyboardUp(0), keyboardDown(0),
- controllerDown(false), released(false), name(name) {
- }
- void Button::tick() {
- bool down = (keyboardDown > 0) || controllerDown;
- bool up = (keyboardUp == keyboardDown) && !controllerDown;
- if(released) {
- downTime = 0;
- }
- downTime += down;
- released = down && up;
- keyboardDown -= keyboardUp;
- keyboardUp = 0;
- }
- 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;
- }
|