bsnes/target-tomoko/settings/input.cpp

144 lines
4.8 KiB
C++
Raw Normal View History

InputSettings::InputSettings(TabFrame* parent) : TabFrameItem(parent) {
Update to v094r43 release. byuu says: Updated to compile with all of the new hiro changes. My next step is to write up hiro API documentation, and move the API from alpha (constantly changing) to beta (rarely changing), in preparation for the first stable release (backward-compatible changes only.) Added "--fullscreen" command-line option. I like this over a configuration file option. Lets you use the emulator in both modes without having to modify the config file each time. Also enhanced the command-line game loading. You can now use any of these methods: higan /path/to/game-folder.sfc higan /path/to/game-folder.sfc/ higan /path/to/game-folder.sfc/program.rom The idea is to support launchers that insist on loading files only. Technically, the file can be any name (manifest.bml also works); the only criteria is that the file actually exists and is a file, and not a directory. This is a requirement to support the first version (a directory lacking the trailing / identifier), because I don't want my nall::string class to query the file system to determine if the string is an actual existing file or directory for its pathname() / dirname() functions. Anyway, every game folder I've made so far has program.rom, and that's very unlikely to change, so this should be fine. Now, of course, if you drop a regular "game.sfc" file on the emulator, it won't even try to load it, unless it's in a folder that ends in .fc, .sfc, etc. In which case, it'll bail out immediately by being unable to produce a manifest for what is obviously not really a game folder.
2015-08-30 02:08:26 +00:00
setImage(Icon::Device::Joypad);
setText("Input");
layout.setMargin(5);
for(auto& emulator : inputManager->emulators) {
emulatorList.append(ComboButtonItem().setText(emulator.name));
}
emulatorList.onChange([&] { reloadPorts(); });
portList.onChange([&] { reloadDevices(); });
deviceList.onChange([&] { reloadMappings(); });
mappingList.onActivate([&] { assignMapping(); });
mappingList.onChange([&] { updateControls(); });
assignMouse1.setVisible(false).onActivate([&] { assignMouseInput(0); });
assignMouse2.setVisible(false).onActivate([&] { assignMouseInput(1); });
assignMouse3.setVisible(false).onActivate([&] { assignMouseInput(2); });
resetButton.setText("Reset").onActivate([&] {
Update to v094r23 release. byuu says: The library window is gone, and replaced with hiro::BrowserWindow::openFolder(). This gives navigation capabilities to game loading, and it also completes our slotted cart selection code. As an added bonus, it's less code this way, too. I also set the window size to consistent sizes between all emulated systems, so that switching between SFC and GB don't cause the window size to keep changing, and so that the scaling size is consistent (eg at normal scale, GB @ 3x is closer to SNES @ 2x.) This means black borders in GB/GBA mode, but it doesn't look that bad, and it's not like many people ever use these modes anyway. Finally, added the placeholder tabs for video, audio and timing. I don't intend to add the timing calculator code to v095 (it might be better as a separate tool), but I'll add the ability to set video/audio rates, at least. Glitch 1: despite selecting the first item in the BrowserDialog list, if you press enter when the window appears, it doesn't activate the item until you press an arrow key first. Glitch 2: in Game Boy mode, if you set the 4x window size, it's not honoring the full requested height because the viewport is smaller than the window. 8+ years of trying to get GTK+ and Qt to simply set the god damned window size I ask for, and I still can't get them to do it reliably. Remaining issues: - finish configuration panels (video, audio, timing) - fix ruby driver compilation on Windows - add DIP switch selection window (NSS) [I may end up punting this one to v096]
2015-05-30 11:39:09 +00:00
if(MessageDialog("Are you sure you want to erase all mappings for this device?").setParent(*settingsManager).question() == "Yes") {
for(auto& mapping : activeDevice().mappings) mapping->unbind();
refreshMappings();
}
});
eraseButton.setText("Erase").onActivate([&] {
if(auto mapping = mappingList.selected()) {
activeDevice().mappings[mapping->offset()]->unbind();
refreshMappings();
}
});
reloadPorts();
}
auto InputSettings::updateControls() -> void {
eraseButton.setEnabled((bool)mappingList.selected());
assignMouse1.setVisible(false);
assignMouse2.setVisible(false);
assignMouse3.setVisible(false);
if(auto mapping = mappingList.selected()) {
auto input = activeDevice().mappings[mapping->offset()];
if(input->isDigital()) {
assignMouse1.setVisible().setText("Mouse Left");
assignMouse2.setVisible().setText("Mouse Middle");
assignMouse3.setVisible().setText("Mouse Right");
} else if(input->isAnalog()) {
assignMouse1.setVisible().setText("Mouse X-axis");
assignMouse2.setVisible().setText("Mouse Y-axis");
}
}
}
auto InputSettings::activeEmulator() -> InputEmulator& {
return inputManager->emulators[emulatorList.selected()->offset()];
}
auto InputSettings::activePort() -> InputPort& {
return activeEmulator().ports[portList.selected()->offset()];
}
auto InputSettings::activeDevice() -> InputDevice& {
return activePort().devices[deviceList.selected()->offset()];
}
auto InputSettings::reloadPorts() -> void {
portList.reset();
for(auto& port : activeEmulator().ports) {
portList.append(ComboButtonItem().setText(port.name));
}
reloadDevices();
}
auto InputSettings::reloadDevices() -> void {
deviceList.reset();
for(auto& device : activePort().devices) {
deviceList.append(ComboButtonItem().setText(device.name));
}
reloadMappings();
}
auto InputSettings::reloadMappings() -> void {
eraseButton.setEnabled(false);
mappingList.reset();
mappingList.append(ListViewHeader().setVisible()
.append(ListViewColumn().setText("Name"))
.append(ListViewColumn().setText("Mapping").setExpandable())
.append(ListViewColumn().setText("Device").setForegroundColor({0, 128, 0}))
);
for(auto& mapping : activeDevice().mappings) {
mappingList.append(ListViewItem()
.append(ListViewCell().setText(mapping->name))
.append(ListViewCell())
.append(ListViewCell())
);
}
refreshMappings();
}
auto InputSettings::refreshMappings() -> void {
unsigned position = 0;
for(auto& mapping : activeDevice().mappings) {
mappingList.item(position)->cell(1)->setText(mapping->assignmentName());
mappingList.item(position)->cell(2)->setText(mapping->deviceName());
position++;
}
mappingList.resizeColumns();
}
auto InputSettings::assignMapping() -> void {
inputManager->poll(); //clear any pending events first
if(auto mapping = mappingList.selected()) {
activeMapping = activeDevice().mappings[mapping->offset()];
settingsManager->layout.setEnabled(false);
settingsManager->statusBar.setText({"Press a key or button to map [", activeMapping->name, "] ..."});
}
}
auto InputSettings::assignMouseInput(unsigned id) -> void {
if(auto mouse = inputManager->findMouse()) {
if(auto mapping = mappingList.selected()) {
activeMapping = activeDevice().mappings[mapping->offset()];
if(activeMapping->isDigital()) {
return inputEvent(mouse, HID::Mouse::GroupID::Button, id, 0, 1, true);
} else if(activeMapping->isAnalog()) {
return inputEvent(mouse, HID::Mouse::GroupID::Axis, id, 0, +32767, true);
}
}
}
}
auto InputSettings::inputEvent(shared_pointer<HID::Device> device, unsigned group, unsigned input, int16 oldValue, int16 newValue, bool allowMouseInput) -> void {
if(!activeMapping) return;
if(device->isMouse() && !allowMouseInput) return;
if(activeMapping->bind(device, group, input, oldValue, newValue)) {
activeMapping = nullptr;
settingsManager->statusBar.setText("");
settingsManager->layout.setEnabled(true);
refreshMappings();
}
}