Refactor input handling in Emulator and Controller for improved key event management
This commit is contained in:
@@ -261,7 +261,101 @@ void Emulator::RenderNavBar() {
|
||||
|
||||
void Emulator::HandleEvents() {
|
||||
// Handle user input events
|
||||
// ...
|
||||
if (ImGui::IsKeyPressed(keybindings_.a_button)) {
|
||||
snes_.SetButtonState(1, 0, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.b_button)) {
|
||||
snes_.SetButtonState(1, 1, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.select_button)) {
|
||||
snes_.SetButtonState(1, 2, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.start_button)) {
|
||||
snes_.SetButtonState(1, 3, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.up_button)) {
|
||||
snes_.SetButtonState(1, 4, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.down_button)) {
|
||||
snes_.SetButtonState(1, 5, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.left_button)) {
|
||||
snes_.SetButtonState(1, 6, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.right_button)) {
|
||||
snes_.SetButtonState(1, 7, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.x_button)) {
|
||||
snes_.SetButtonState(1, 8, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.y_button)) {
|
||||
snes_.SetButtonState(1, 9, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.l_button)) {
|
||||
snes_.SetButtonState(1, 10, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(keybindings_.r_button)) {
|
||||
snes_.SetButtonState(1, 11, true);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.a_button)) {
|
||||
snes_.SetButtonState(1, 0, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.b_button)) {
|
||||
snes_.SetButtonState(1, 1, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.select_button)) {
|
||||
snes_.SetButtonState(1, 2, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.start_button)) {
|
||||
snes_.SetButtonState(1, 3, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.up_button)) {
|
||||
snes_.SetButtonState(1, 4, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.down_button)) {
|
||||
snes_.SetButtonState(1, 5, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.left_button)) {
|
||||
snes_.SetButtonState(1, 6, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.right_button)) {
|
||||
snes_.SetButtonState(1, 7, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.x_button)) {
|
||||
snes_.SetButtonState(1, 8, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.y_button)) {
|
||||
snes_.SetButtonState(1, 9, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.l_button)) {
|
||||
snes_.SetButtonState(1, 10, false);
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyReleased(keybindings_.r_button)) {
|
||||
snes_.SetButtonState(1, 11, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Emulator::RenderBreakpointList() {
|
||||
|
||||
@@ -19,6 +19,21 @@ namespace app {
|
||||
*/
|
||||
namespace emu {
|
||||
|
||||
struct EmulatorKeybindings {
|
||||
ImGuiKey a_button = ImGuiKey_Z;
|
||||
ImGuiKey b_button = ImGuiKey_A;
|
||||
ImGuiKey x_button = ImGuiKey_S;
|
||||
ImGuiKey y_button = ImGuiKey_X;
|
||||
ImGuiKey l_button = ImGuiKey_Q;
|
||||
ImGuiKey r_button = ImGuiKey_W;
|
||||
ImGuiKey start_button = ImGuiKey_RETURN;
|
||||
ImGuiKey select_button = ImGuiKey_BACKSPACE;
|
||||
ImGuiKey up_button = ImGuiKey_UP;
|
||||
ImGuiKey down_button = ImGuiKey_DOWN;
|
||||
ImGuiKey left_button = ImGuiKey_LEFT;
|
||||
ImGuiKey right_button = ImGuiKey_RIGHT;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Emulator
|
||||
* @brief A class for emulating and debugging SNES games.
|
||||
@@ -145,6 +160,8 @@ class Emulator : public SharedRom {
|
||||
|
||||
std::vector<uint8_t> rom_data_;
|
||||
|
||||
EmulatorKeybindings keybindings_;
|
||||
|
||||
gui::zeml::Node emulator_node_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user