2017-10-10 02:26:39 +00:00
|
|
|
//
|
|
|
|
// Keyboard.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 10/9/17.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-10-10 02:26:39 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Keyboard.hpp"
|
|
|
|
|
|
|
|
using namespace Inputs;
|
|
|
|
|
|
|
|
Keyboard::Keyboard() {}
|
|
|
|
|
2018-04-16 01:11:30 +00:00
|
|
|
void Keyboard::set_key_pressed(Key key, char value, bool is_pressed) {
|
2017-11-11 20:28:40 +00:00
|
|
|
std::size_t key_offset = static_cast<std::size_t>(key);
|
2017-10-20 02:01:24 +00:00
|
|
|
if(key_offset >= key_states_.size()) {
|
|
|
|
key_states_.resize(key_offset+1, false);
|
2017-10-10 02:26:39 +00:00
|
|
|
}
|
|
|
|
key_states_[key_offset] = is_pressed;
|
|
|
|
|
|
|
|
if(delegate_) delegate_->keyboard_did_change_key(this, key, is_pressed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Keyboard::reset_all_keys() {
|
|
|
|
std::fill(key_states_.begin(), key_states_.end(), false);
|
2017-10-15 02:07:11 +00:00
|
|
|
if(delegate_) delegate_->reset_all_keys(this);
|
2017-10-10 02:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Keyboard::set_delegate(Delegate *delegate) {
|
|
|
|
delegate_ = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Keyboard::get_key_state(Key key) {
|
2017-11-11 20:28:40 +00:00
|
|
|
std::size_t key_offset = static_cast<std::size_t>(key);
|
2017-10-10 02:26:39 +00:00
|
|
|
if(key_offset >= key_states_.size()) return false;
|
|
|
|
return key_states_[key_offset];
|
|
|
|
}
|