1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include <GLFW/glfw3.h>
- #include "input/Keys.h"
- Keys::Key::Key() : glfwKey(-1), down(false), downTime(0) {
- }
- uint Keys::searchKey(int glfwKey) const {
- for(uint i = 1; i < keys.size(); i++) {
- if(keys[i].glfwKey == glfwKey) {
- return i;
- }
- }
- return 0;
- }
- uint Keys::getIndex(uint key) const {
- return key * (key < keys.size());
- }
- int Keys::add(int glfwKey) {
- int index = searchKey(-1);
- keys[index].glfwKey = glfwKey;
- return index;
- }
- bool Keys::isDown(uint key) const {
- return keys[getIndex(key)].down;
- }
- uint Keys::getDownTime(uint key) const {
- return keys[getIndex(key)].downTime;
- }
- void Keys::release(int glfwKey) {
- uint index = searchKey(glfwKey);
- keys[index].down = false;
- keys[index].downTime = 0;
- }
- void Keys::press(int glfwKey) {
- uint index = searchKey(glfwKey);
- keys[index].down = true;
- }
- void Keys::tick() {
- for(uint i = 1; i < keys.size(); i++) {
- keys[i].downTime += keys[i].down;
- }
- }
|