@@ -10,17 +10,56 @@ MainWindow::MainWindow()
1010{
1111 ImGui::SetCurrentFont (LoadFonts (14 .0f ));
1212
13- Settings = make_unique<Dasher::XmlSettingsStore>(" Settings.xml" , this );
13+ Settings = std:: make_unique<Dasher::XmlSettingsStore>(" Settings.xml" , this );
1414 Settings->Load ();
1515 Settings->Save ();
1616
17- Controller = make_unique<DasherController>(Settings.get ());
17+ Controller = std:: make_unique<DasherController>(Settings.get ());
1818 Controller->Initialize ();
1919
20- Controller->GetPermittedValues (SP_ALPHABET_ID, Alphabets);
20+ Controller->GetPermittedValues (Dasher:: SP_ALPHABET_ID, Alphabets);
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 ())
@@ -61,16 +100,16 @@ bool MainWindow::render(float DeltaTime)
61100 {
62101 ClearBuffer ();
63102 }
64- int speed = Controller->GetLongParameter (LP_MAX_BITRATE);
103+ int speed = Controller->GetLongParameter (Dasher:: LP_MAX_BITRATE);
65104 if (ImGui::SliderInt (" Speed" , &speed, 1 , 2000 ))
66105 {
67- Controller->SetLongParameter (LP_MAX_BITRATE, speed);
106+ Controller->SetLongParameter (Dasher:: LP_MAX_BITRATE, speed);
68107 }
69108
70109 static int item_current = 0 ;
71110 if (ImGui::Combo (" Alphabet" , &item_current, [](void * data, int idx, const char ** out_text) { *out_text = static_cast <const std::vector<std::string>*>(data)->at (idx).c_str (); return true ; }, (void *)&Alphabets, static_cast <int >(Alphabets.size ()), 10 ))
72111 {
73- Controller->SetStringParameter (SP_ALPHABET_ID, Alphabets[item_current]);
112+ Controller->SetStringParameter (Dasher:: SP_ALPHABET_ID, Alphabets[item_current]);
74113 }
75114
76115 ImGui::EndMenu ();
@@ -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 );
@@ -117,9 +156,11 @@ bool MainWindow::render(float DeltaTime)
117156 ImGui::ColorConvertFloat4ToU32 ({0 ,1 ,0 ,1 })
118157 );
119158
120- Controller->Render (DeltaTime * 1000 .0f , canvasPos, canvasSize); // convert to millis
159+ 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