2015-03-02 09:13:28 +00:00
|
|
|
#include "../tomoko.hpp"
|
|
|
|
InputManager* inputManager = nullptr;
|
|
|
|
|
|
|
|
auto InputMapping::bind() -> void {
|
|
|
|
auto token = assignment.split("/");
|
|
|
|
if(token.size() < 3) return;
|
|
|
|
uint64_t id = token[0].hex();
|
|
|
|
unsigned group = token[1].decimal();
|
|
|
|
unsigned input = token[2].decimal();
|
|
|
|
|
|
|
|
for(auto& device : inputManager->devices) {
|
|
|
|
if(id != device->id) continue;
|
|
|
|
|
|
|
|
this->device = device;
|
|
|
|
this->group = group;
|
|
|
|
this->input = input;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputMapping::bind(HID::Device& device, unsigned group, unsigned input, int16 oldValue, int16 newValue) -> bool {
|
Update to v094r13 release.
byuu says:
This version polishes up the input dialogue (reset, erase, disable
button when item not focused, split device ID from mapping name), adds
color emulation toggle, and add dummy menu items for remaining features
(to be filled in later.)
Also, it now compiles cleanly on Windows with GTK.
I didn't test with TDM-GCC-32, because for god knows what reason, the
32-bit version ships with headers from Windows 95 OSR2 only. So I built
with TDM-GCC-64 with arch=x86.
And uh, apparently, moving or resizing a window causes a Visual C++
runtime exception in the GTK+ DLLs. This doesn't happen with trance or
renshuu built with TDM-GCC-32. So, yeah, like I said, don't use -m32.
2015-03-07 10:21:47 +00:00
|
|
|
if(device.group[group].input[input].name == "Escape") return unbind(), true;
|
|
|
|
|
2015-03-02 09:13:28 +00:00
|
|
|
this->assignment = {hex(device.id), "/", group, "/", input, "/", device.group[group].input[input].name};
|
|
|
|
this->device = &device;
|
|
|
|
this->group = group;
|
|
|
|
this->input = input;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputMapping::poll() -> int16 {
|
|
|
|
if(device) return device->group[group].input[input].value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Update to v094r13 release.
byuu says:
This version polishes up the input dialogue (reset, erase, disable
button when item not focused, split device ID from mapping name), adds
color emulation toggle, and add dummy menu items for remaining features
(to be filled in later.)
Also, it now compiles cleanly on Windows with GTK.
I didn't test with TDM-GCC-32, because for god knows what reason, the
32-bit version ships with headers from Windows 95 OSR2 only. So I built
with TDM-GCC-64 with arch=x86.
And uh, apparently, moving or resizing a window causes a Visual C++
runtime exception in the GTK+ DLLs. This doesn't happen with trance or
renshuu built with TDM-GCC-32. So, yeah, like I said, don't use -m32.
2015-03-07 10:21:47 +00:00
|
|
|
auto InputMapping::unbind() -> void {
|
|
|
|
this->assignment = "None";
|
|
|
|
this->device = nullptr;
|
|
|
|
this->group = 0;
|
|
|
|
this->input = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-02 09:13:28 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
InputManager::InputManager() {
|
|
|
|
inputManager = this;
|
|
|
|
input.onChange = {&InputManager::onChange, this};
|
|
|
|
|
|
|
|
for(auto& emulator : program->emulators) {
|
|
|
|
Configuration::Node nodeEmulator;
|
|
|
|
|
|
|
|
emulators.append(InputEmulator());
|
|
|
|
auto& inputEmulator = emulators.last();
|
|
|
|
inputEmulator.name = emulator->information.name;
|
|
|
|
|
|
|
|
for(auto& port : emulator->port) {
|
|
|
|
Configuration::Node nodePort;
|
|
|
|
|
|
|
|
inputEmulator.ports.append(InputPort());
|
|
|
|
auto& inputPort = inputEmulator.ports.last();
|
|
|
|
inputPort.name = port.name;
|
|
|
|
for(auto& device : port.device) {
|
|
|
|
Configuration::Node nodeDevice;
|
|
|
|
|
|
|
|
inputPort.devices.append(InputDevice());
|
|
|
|
auto& inputDevice = inputPort.devices.last();
|
|
|
|
inputDevice.name = device.name;
|
|
|
|
for(auto number : device.order) {
|
|
|
|
auto& input = device.input[number];
|
|
|
|
inputDevice.mappings.append(new InputMapping());
|
|
|
|
auto& inputMapping = inputDevice.mappings.last();
|
|
|
|
inputMapping->name = input.name;
|
|
|
|
inputMapping->link = &input;
|
|
|
|
input.guid = (uintptr_t)inputMapping;
|
|
|
|
|
|
|
|
nodeDevice.append(inputMapping->assignment, inputMapping->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodePort.append(nodeDevice, string{inputDevice.name}.replace(" ", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeEmulator.append(nodePort, string{inputPort.name}.replace(" ", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
config.append(nodeEmulator, string{inputEmulator.name}.replace(" ", ""));
|
|
|
|
}
|
|
|
|
|
2015-03-03 10:14:49 +00:00
|
|
|
config.load({configpath(), "tomoko/input.bml"});
|
|
|
|
config.save({configpath(), "tomoko/input.bml"});
|
2015-03-02 09:13:28 +00:00
|
|
|
poll(); //will call bind();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::bind() -> void {
|
|
|
|
for(auto& emulator : emulators) {
|
|
|
|
for(auto& port : emulator.ports) {
|
|
|
|
for(auto& device : port.devices) {
|
|
|
|
for(auto& mapping : device.mappings) {
|
|
|
|
mapping->bind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::poll() -> void {
|
|
|
|
auto devices = input.poll();
|
|
|
|
bool changed = devices.size() != this->devices.size();
|
|
|
|
if(changed == false) {
|
|
|
|
for(auto n : range(devices)) {
|
|
|
|
changed = devices[n] != this->devices[n];
|
|
|
|
if(changed) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(changed == true) {
|
|
|
|
this->devices = devices;
|
|
|
|
bind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::onChange(HID::Device& device, unsigned group, unsigned input, int16 oldValue, int16 newValue) -> void {
|
|
|
|
if(settingsManager->focused()) {
|
|
|
|
settingsManager->input.inputEvent(device, group, input, oldValue, newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::quit() -> void {
|
2015-03-03 10:14:49 +00:00
|
|
|
config.save({configpath(), "tomoko/input.bml"});
|
2015-03-02 09:13:28 +00:00
|
|
|
}
|