-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathhotkeys.cpp
163 lines (138 loc) · 5.09 KB
/
hotkeys.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
auto InputManager::createHotkeys() -> void {
static bool fastForwardVideoBlocking;
static bool fastForwardAudioBlocking;
static bool fastForwardAudioDynamic;
hotkeys.append(InputHotkey("Toggle Fullscreen").onPress([&] {
program.videoFullScreenToggle();
}));
hotkeys.append(InputHotkey("Toggle Mouse Capture").onPress([&] {
if(!emulator) return;
if(!ruby::input.acquired()) {
ruby::input.acquire();
} else {
ruby::input.release();
}
}));
hotkeys.append(InputHotkey("Toggle Keyboard Capture").onPress([&] {
if(!emulator) return;
program.keyboardCaptured = !program.keyboardCaptured;
print("Keyboard capture: ", program.keyboardCaptured, "\n");
}));
hotkeys.append(InputHotkey("Fast Forward").onPress([&] {
if(!emulator || program.rewinding) return;
program.fastForwarding = true;
fastForwardVideoBlocking = ruby::video.blocking();
fastForwardAudioBlocking = ruby::audio.blocking();
fastForwardAudioDynamic = ruby::audio.dynamic();
ruby::video.setBlocking(false);
ruby::audio.setBlocking(false);
ruby::audio.setDynamic(false);
}).onRelease([&] {
if(!emulator) return;
program.fastForwarding = false;
ruby::video.setBlocking(fastForwardVideoBlocking);
ruby::audio.setBlocking(fastForwardAudioBlocking);
ruby::audio.setDynamic(fastForwardAudioDynamic);
}));
hotkeys.append(InputHotkey("Toggle Fast Forward").onPress([&] {
if(!emulator || program.rewinding) return;
program.fastForwarding = !program.fastForwarding;
if (program.fastForwarding) {
fastForwardVideoBlocking = ruby::video.blocking();
fastForwardAudioBlocking = ruby::audio.blocking();
fastForwardAudioDynamic = ruby::audio.dynamic();
ruby::video.setBlocking(false);
ruby::audio.setBlocking(false);
ruby::audio.setDynamic(false);
return;
}
ruby::video.setBlocking(fastForwardVideoBlocking);
ruby::audio.setBlocking(fastForwardAudioBlocking);
ruby::audio.setDynamic(fastForwardAudioDynamic);
}));
hotkeys.append(InputHotkey("Rewind").onPress([&] {
if(!emulator || program.fastForwarding) return;
if(program.rewind.frequency == 0) {
return program.showMessage("Please enable rewind support in the emulator settings first.");
}
program.rewinding = true;
program.rewindSetMode(Program::Rewind::Mode::Rewinding);
}).onRelease([&] {
if(!emulator) return;
program.rewinding = false;
program.rewindSetMode(Program::Rewind::Mode::Playing);
}));
hotkeys.append(InputHotkey("Frame Advance").onPress([&] {
if(!emulator) return;
if(!program.paused) program.pause(true);
program.requestFrameAdvance = true;
}));
hotkeys.append(InputHotkey("Capture Screenshot").onPress([&] {
if(!emulator) return;
program.requestScreenshot = true;
}));
hotkeys.append(InputHotkey("Save State").onPress([&] {
if(!emulator) return;
program.stateSave(program.state.slot);
}));
hotkeys.append(InputHotkey("Load State").onPress([&] {
if(!emulator) return;
program.stateLoad(program.state.slot);
}));
hotkeys.append(InputHotkey("Decrement State Slot").onPress([&] {
if(!emulator) return;
if(program.state.slot == 1) program.state.slot = 9;
else program.state.slot--;
program.showMessage({"Selected state slot ", program.state.slot});
}));
hotkeys.append(InputHotkey("Increment State Slot").onPress([&] {
if(!emulator) return;
if(program.state.slot == 9) program.state.slot = 1;
else program.state.slot++;
program.showMessage({"Selected state slot ", program.state.slot});
}));
hotkeys.append(InputHotkey("Pause Emulation").onPress([&] {
if(!emulator) return;
program.pause(!program.paused);
}));
hotkeys.append(InputHotkey("Reset System").onPress([&] {
if(!emulator) return;
emulator->root->power(true);
}));
hotkeys.append(InputHotkey("Reload Current Game").onPress([&] {
if(!emulator) return;
program.load(emulator, emulator->game->location);
}));
hotkeys.append(InputHotkey("Quit Emulator").onPress([&] {
program.quit();
}));
hotkeys.append(InputHotkey("Mute Audio").onPress([&] {
if(!emulator) return;
program.mute();
}));
hotkeys.append(InputHotkey("Increase Audio").onPress([&] {
if(!emulator) return;
if(settings.audio.volume <= (f64)(1.9)) settings.audio.volume += (f64)(0.1);
}));
hotkeys.append(InputHotkey("Decrease Audio").onPress([&] {
if(!emulator) return;
if(settings.audio.volume >= (f64)(0.1)) settings.audio.volume -= (f64)(0.1);
}));
#if defined(PLATFORM_WINDOWS)
hotkeys.append(InputHotkey("Toggle Borderless Window").onPress([&] {
program.updateBorderless();
}));
#endif
}
auto InputManager::pollHotkeys() -> void {
if(Application::modal()) return;
if(!driverSettings.inputDefocusAllow.checked()) {
if (!presentation.focused() && !ruby::video.fullScreen()) return;
}
for(auto& hotkey : hotkeys) {
auto state = hotkey.value();
if(hotkey.state == 0 && state == 1 && hotkey.press) hotkey.press();
if(hotkey.state == 1 && state == 0 && hotkey.release) hotkey.release();
hotkey.state = state;
}
}