yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
input_handler.cc
Go to the documentation of this file.
2
3#include <SDL.h>
4
6#include "imgui/imgui.h"
7
8namespace yaze {
9namespace emu {
10namespace ui {
11
13 if (!manager || !manager->backend()) return;
14
15 auto config = manager->GetConfig();
16
17 ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.2f, 1.0f),
18 ICON_MD_INFO " Keyboard Configuration");
19 ImGui::Separator();
20
21 ImGui::Text("Backend: %s", manager->backend()->GetBackendName().c_str());
22 ImGui::Separator();
23
24 ImGui::TextWrapped("Configure keyboard bindings for SNES controller emulation. "
25 "Click a button and press a key to rebind.");
26 ImGui::Spacing();
27
28 auto RenderKeyBind = [&](const char* label, int* key) {
29 ImGui::Text("%s:", label);
30 ImGui::SameLine(150);
31
32 // Show current key
33 const char* key_name = SDL_GetKeyName(*key);
34 ImGui::PushID(label);
35 if (ImGui::Button(key_name, ImVec2(120, 0))) {
36 ImGui::OpenPopup("Rebind");
37 }
38
39 if (ImGui::BeginPopup("Rebind")) {
40 ImGui::Text("Press any key...");
41 ImGui::Separator();
42
43 // Poll for key press (SDL2-specific for now)
44 SDL_Event event;
45 if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) {
46 if (event.key.keysym.sym != SDLK_UNKNOWN && event.key.keysym.sym != SDLK_ESCAPE) {
47 *key = event.key.keysym.sym;
48 ImGui::CloseCurrentPopup();
49 }
50 }
51
52 if (ImGui::Button("Cancel", ImVec2(-1, 0))) {
53 ImGui::CloseCurrentPopup();
54 }
55
56 ImGui::EndPopup();
57 }
58 ImGui::PopID();
59 };
60
61 // Face Buttons
62 if (ImGui::CollapsingHeader("Face Buttons", ImGuiTreeNodeFlags_DefaultOpen)) {
63 RenderKeyBind("A Button", &config.key_a);
64 RenderKeyBind("B Button", &config.key_b);
65 RenderKeyBind("X Button", &config.key_x);
66 RenderKeyBind("Y Button", &config.key_y);
67 }
68
69 // D-Pad
70 if (ImGui::CollapsingHeader("D-Pad", ImGuiTreeNodeFlags_DefaultOpen)) {
71 RenderKeyBind("Up", &config.key_up);
72 RenderKeyBind("Down", &config.key_down);
73 RenderKeyBind("Left", &config.key_left);
74 RenderKeyBind("Right", &config.key_right);
75 }
76
77 // Shoulder Buttons
78 if (ImGui::CollapsingHeader("Shoulder Buttons")) {
79 RenderKeyBind("L Button", &config.key_l);
80 RenderKeyBind("R Button", &config.key_r);
81 }
82
83 // Start/Select
84 if (ImGui::CollapsingHeader("Start/Select")) {
85 RenderKeyBind("Start", &config.key_start);
86 RenderKeyBind("Select", &config.key_select);
87 }
88
89 ImGui::Spacing();
90 ImGui::Separator();
91
92 // Input mode
93 ImGui::Checkbox("Continuous Polling", &config.continuous_polling);
94 if (ImGui::IsItemHovered()) {
95 ImGui::SetTooltip("Recommended: ON for games (detects held buttons)\nOFF for event-based input");
96 }
97
98 ImGui::Spacing();
99
100 // Apply button
101 if (ImGui::Button("Apply Changes", ImVec2(-1, 30))) {
102 manager->SetConfig(config);
103 }
104
105 ImGui::Spacing();
106
107 // Defaults
108 if (ImGui::Button("Reset to Defaults", ImVec2(-1, 30))) {
109 config = input::InputConfig(); // Reset to defaults
110 manager->SetConfig(config);
111 }
112
113 ImGui::Spacing();
114 ImGui::Separator();
115 ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f),
116 "Default Bindings:");
117 ImGui::BulletText("A/B/X/Y: X/Z/S/A");
118 ImGui::BulletText("L/R: D/C");
119 ImGui::BulletText("D-Pad: Arrow Keys");
120 ImGui::BulletText("Start/Select: Enter/RShift");
121}
122
123} // namespace ui
124} // namespace emu
125} // namespace yaze
126
virtual std::string GetBackendName() const =0
Get backend name for debugging.
void SetConfig(const InputConfig &config)
InputConfig GetConfig() const
#define ICON_MD_INFO
Definition icons.h:991
void RenderKeyboardConfig(input::InputManager *manager)
Render keyboard configuration UI.
Main namespace for the application.
Definition controller.cc:20
Input configuration (platform-agnostic key codes)