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