Skip to content

Commit 18c0e65

Browse files
author
Sebastian Pape
committed
Reworking usage of keys in DasherCore and adding keyboard input for UI
1 parent d5e907d commit 18c0e65

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

DasherCore

src/DasherController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ void DasherController::Render(long deltaTime, ImVec2 canvasPos, ImVec2 canvasSiz
110110
//Handle Input
111111
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsMouseHoveringRect(canvasPos, canvasPos + canvasSize))
112112
{
113-
KeyDown(Time, 100); //100 is the keycode for LMB
113+
KeyDown(Time, Dasher::Keys::Primary_Input); //100 is the keycode for LMB
114114
}
115115

116116
if(ImGui::IsMouseReleased(ImGuiMouseButton_Left))
117117
{
118-
KeyUp(Time, 100); //100 is the keycode for LMB
118+
KeyUp(Time, Dasher::Keys::Primary_Input); //100 is the keycode for LMB
119119
}
120120
}

src/MainWindow.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2463
bool 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

src/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class MainWindow : public Dasher::CommandlineErrorDisplay
1414
MainWindow();
1515
~MainWindow() = default;
1616

17+
void HandleInput(const std::unique_ptr<DasherController>& controller, long time);
1718
bool render(float DeltaTime);
1819

1920
void CopyTextToClipboard(const std::string& text) const;

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(int, char**)
7676
IMGUI_CHECKVERSION();
7777
ImGui::CreateContext();
7878
ImGuiIO& io = ImGui::GetIO(); (void)io;
79-
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
79+
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
8080
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
8181

8282
// Setup Dear ImGui style

0 commit comments

Comments
 (0)