1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include "input/Button.h"
- Button::Button() : keyDown(false), buttonDown(false), released(false), downTime(0) {
- }
- void Button::pressKey() {
- keyDown = true;
- }
- void Button::releaseKey() {
- keyDown = false;
- }
- void Button::pressButton() {
- buttonDown = true;
- }
- void Button::tick() {
- if(released) {
- downTime = 0;
- }
- released = false;
- if(keyDown || buttonDown) {
- downTime++;
- } else {
- released = downTime > 0;
- }
- buttonDown = false;
- }
- bool Button::isDown() const {
- return downTime > 0;
- }
- int Button::getDownTime() const {
- return downTime;
- }
- bool Button::wasReleased() const {
- return released;
- }
|