@@ -21,6 +21,45 @@ MainWindow::MainWindow()
2121
2222}
2323
24+ #define FORWARD_KEY (ImGui_Key, DasherKey ) { \
25+ if (ImGui::IsKeyPressed (ImGui_Key, false )) Controller->KeyDown (time, DasherKey); \
26+ if (ImGui::IsKeyReleased (ImGui_Key, false )) Controller->KeyUp (time, DasherKey); \
27+ }
28+ void MainWindow::HandleInput (const std::unique_ptr<DasherController>& controller, long time)
29+ {
30+ // Space
31+ FORWARD_KEY (ImGuiKey_Space, Dasher::Keys::Big_Start_Stop_Key)
32+
33+ // Button 1
34+ FORWARD_KEY (ImGuiKey_LeftArrow, Dasher::Keys::Button_1)
35+ FORWARD_KEY (ImGuiKey_Keypad4, Dasher::Keys::Button_1)
36+ FORWARD_KEY (ImGuiKey_A, Dasher::Keys::Button_1)
37+ FORWARD_KEY (ImGuiKey_J, Dasher::Keys::Button_1)
38+ FORWARD_KEY (ImGuiKey_1, Dasher::Keys::Button_1)
39+
40+ // Button 2
41+ FORWARD_KEY (ImGuiKey_UpArrow, Dasher::Keys::Button_2)
42+ FORWARD_KEY (ImGuiKey_Keypad8, Dasher::Keys::Button_2)
43+ FORWARD_KEY (ImGuiKey_W, Dasher::Keys::Button_2)
44+ FORWARD_KEY (ImGuiKey_I, Dasher::Keys::Button_2)
45+ FORWARD_KEY (ImGuiKey_2, Dasher::Keys::Button_2)
46+
47+ // Button 3
48+ FORWARD_KEY (ImGuiKey_RightArrow, Dasher::Keys::Button_3)
49+ FORWARD_KEY (ImGuiKey_Keypad6, Dasher::Keys::Button_3)
50+ FORWARD_KEY (ImGuiKey_S, Dasher::Keys::Button_3)
51+ FORWARD_KEY (ImGuiKey_K, Dasher::Keys::Button_3)
52+ FORWARD_KEY (ImGuiKey_3, Dasher::Keys::Button_3)
53+
54+ // Button 4
55+ FORWARD_KEY (ImGuiKey_DownArrow, Dasher::Keys::Button_4)
56+ FORWARD_KEY (ImGuiKey_Keypad2, Dasher::Keys::Button_4)
57+ FORWARD_KEY (ImGuiKey_Z, Dasher::Keys::Button_4)
58+ FORWARD_KEY (ImGuiKey_M, Dasher::Keys::Button_4)
59+ FORWARD_KEY (ImGuiKey_4, Dasher::Keys::Button_4)
60+ }
61+ #undef FORWARD_KEY
62+
2463bool MainWindow::render (float DeltaTime)
2564{
2665 static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBackground ;
@@ -29,7 +68,7 @@ bool MainWindow::render(float DeltaTime)
2968 const ImVec2 spacing = ImGui::GetStyle ().ItemSpacing ;
3069 ImGui::SetNextWindowPos (viewport->WorkPos );
3170 ImGui::SetNextWindowSize (viewport->WorkSize );
32-
71+
3372 if (ImGui::Begin (" MainWindow" , nullptr , flags))
3473 {
3574 if (ImGui::BeginMainMenuBar ())
@@ -105,7 +144,7 @@ bool MainWindow::render(float DeltaTime)
105144 }
106145 ImGui::EndGroup ();
107146
108- const ImVec2 canvasPos = ImGui::GetCursorScreenPos ();
147+ const ImVec2 canvasPos = ImGui::GetCursorScreenPos ();
109148 const ImVec2 canvasSize = ImGui::GetContentRegionAvail ();
110149
111150 ImGui::PushClipRect (canvasPos, canvasPos + canvasSize, false );
@@ -120,6 +159,8 @@ bool MainWindow::render(float DeltaTime)
120159 Controller->Render (static_cast <long >(DeltaTime * 1000 .0f ), canvasPos, canvasSize); // convert to millis
121160
122161 ImGui::PopClipRect ();
162+
163+ HandleInput (Controller, static_cast <long >(DeltaTime * 1000 .0f ));
123164 }
124165 ImGui::End ();
125166
0 commit comments