2018-02-09 21:31:05 +00:00
|
|
|
//
|
|
|
|
// MultiKeyboardMachine.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 09/02/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-02-09 21:31:05 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "MultiKeyboardMachine.hpp"
|
|
|
|
|
|
|
|
using namespace Analyser::Dynamic;
|
|
|
|
|
2018-10-25 02:20:58 +00:00
|
|
|
MultiKeyboardMachine::MultiKeyboardMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines) :
|
2018-11-24 03:32:32 +00:00
|
|
|
keyboard_(machines_) {
|
2018-02-09 21:31:05 +00:00
|
|
|
for(const auto &machine: machines) {
|
2020-04-02 03:19:34 +00:00
|
|
|
auto keyboard_machine = machine->keyboard_machine();
|
2018-02-19 21:06:46 +00:00
|
|
|
if(keyboard_machine) machines_.push_back(keyboard_machine);
|
2018-05-05 23:32:20 +00:00
|
|
|
}
|
2018-02-09 21:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiKeyboardMachine::clear_all_keys() {
|
|
|
|
for(const auto &machine: machines_) {
|
|
|
|
machine->clear_all_keys();
|
2018-05-05 23:32:20 +00:00
|
|
|
}
|
2018-02-09 21:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiKeyboardMachine::set_key_state(uint16_t key, bool is_pressed) {
|
2018-05-05 23:32:20 +00:00
|
|
|
for(const auto &machine: machines_) {
|
|
|
|
machine->set_key_state(key, is_pressed);
|
|
|
|
}
|
2018-02-09 21:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiKeyboardMachine::type_string(const std::string &string) {
|
2018-05-05 23:32:20 +00:00
|
|
|
for(const auto &machine: machines_) {
|
|
|
|
machine->type_string(string);
|
|
|
|
}
|
2018-02-09 21:31:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 01:25:12 +00:00
|
|
|
bool MultiKeyboardMachine::can_type(char c) {
|
|
|
|
bool can_type = true;
|
|
|
|
for(const auto &machine: machines_) {
|
|
|
|
can_type &= machine->can_type(c);
|
|
|
|
}
|
|
|
|
return can_type;
|
|
|
|
}
|
|
|
|
|
2018-10-25 01:59:30 +00:00
|
|
|
Inputs::Keyboard &MultiKeyboardMachine::get_keyboard() {
|
|
|
|
return keyboard_;
|
2018-02-09 21:31:05 +00:00
|
|
|
}
|
2018-10-25 01:59:30 +00:00
|
|
|
|
2020-04-02 03:19:34 +00:00
|
|
|
MultiKeyboardMachine::MultiKeyboard::MultiKeyboard(const std::vector<::MachineTypes::KeyboardMachine *> &machines)
|
2018-10-25 02:20:58 +00:00
|
|
|
: machines_(machines) {
|
|
|
|
for(const auto &machine: machines_) {
|
|
|
|
observed_keys_.insert(machine->get_keyboard().observed_keys().begin(), machine->get_keyboard().observed_keys().end());
|
|
|
|
is_exclusive_ |= machine->get_keyboard().is_exclusive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 03:08:54 +00:00
|
|
|
bool MultiKeyboardMachine::MultiKeyboard::set_key_pressed(Key key, char value, bool is_pressed) {
|
|
|
|
bool was_consumed = false;
|
2018-10-25 02:20:58 +00:00
|
|
|
for(const auto &machine: machines_) {
|
2020-03-03 03:08:54 +00:00
|
|
|
was_consumed |= machine->get_keyboard().set_key_pressed(key, value, is_pressed);
|
2018-10-25 02:20:58 +00:00
|
|
|
}
|
2020-03-03 03:08:54 +00:00
|
|
|
return was_consumed;
|
2018-10-25 02:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiKeyboardMachine::MultiKeyboard::reset_all_keys() {
|
|
|
|
for(const auto &machine: machines_) {
|
|
|
|
machine->get_keyboard().reset_all_keys();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::set<Inputs::Keyboard::Key> &MultiKeyboardMachine::MultiKeyboard::observed_keys() {
|
|
|
|
return observed_keys_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MultiKeyboardMachine::MultiKeyboard::is_exclusive() {
|
|
|
|
return is_exclusive_;
|
|
|
|
}
|