bsnes/higan/target-bsnes/input/hotkeys.cpp

87 lines
2.5 KiB
C++

auto InputManager::bindHotkeys() -> void {
static int stateSlot = 1;
hotkeys.append(InputHotkey("Toggle Fullscreen Mode").onPress([] {
presentation.toggleFullscreenMode();
}));
hotkeys.append(InputHotkey("Toggle Mouse Capture").onPress([] {
input.acquired() ? input.release() : input.acquire();
}));
hotkeys.append(InputHotkey("Toggle Cheat Codes").onPress([] {
cheatEditor.enableCheats.setChecked(!cheatEditor.enableCheats.checked()).doToggle();
}));
hotkeys.append(InputHotkey("Save State").onPress([&] {
program.saveState({"Quick/Slot ", stateSlot});
}));
hotkeys.append(InputHotkey("Load State").onPress([&] {
program.loadState({"Quick/Slot ", stateSlot});
}));
hotkeys.append(InputHotkey("Load Undo State").onPress([&] {
program.loadState("Quick/Undo");
}));
hotkeys.append(InputHotkey("Load Redo State").onPress([&] {
program.loadState("Quick/Redo");
}));
hotkeys.append(InputHotkey("Increment State Slot").onPress([&] {
if(--stateSlot < 1) stateSlot = 9;
program.showMessage({"Selected state slot ", stateSlot});
}));
hotkeys.append(InputHotkey("Decrement State Slot").onPress([&] {
if(++stateSlot > 9) stateSlot = 1;
program.showMessage({"Selected state slot ", stateSlot});
}));
hotkeys.append(InputHotkey("Capture Screenshot").onPress([] {
program.captureScreenshot();
}));
hotkeys.append(InputHotkey("Fast Forward").onPress([] {
video.setBlocking(false);
audio.setBlocking(false);
}).onRelease([] {
video.setBlocking(settings.video.blocking);
audio.setBlocking(settings.audio.blocking);
}));
hotkeys.append(InputHotkey("Pause Emulation").onPress([] {
presentation.pauseEmulation.setChecked(!presentation.pauseEmulation.checked());
}));
hotkeys.append(InputHotkey("Frame Advance").onPress([] {
presentation.frameAdvance.doActivate();
}));
hotkeys.append(InputHotkey("Reset Emulation").onPress([] {
program.reset();
}));
hotkeys.append(InputHotkey("Quit Emulator").onPress([] {
program.quit();
}));
for(auto& hotkey : hotkeys) {
hotkey.path = string{"Hotkey/", hotkey.name}.replace(" ", "");
hotkey.assignment = settings(hotkey.path).text();
hotkey.bind();
}
}
auto InputManager::pollHotkeys() -> void {
if(Application::modal() || !program.focused()) return;
for(auto& hotkey : hotkeys) {
auto state = hotkey.poll();
if(hotkey.state == 0 && state == 1 && hotkey.press) hotkey.press();
if(hotkey.state == 1 && state == 0 && hotkey.release) hotkey.release();
hotkey.state = state;
}
}