Skip to content

Commit 99d4ed8

Browse files
committed
TestSuite: amend 'inputs_io_inputqueue" for analog input trickling.
ocornut/imgui#8508
1 parent ebf94e9 commit 99d4ed8

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

imgui_test_engine/imgui_te_engine.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,15 @@ void ImGuiTestEngine_ApplyInputToImGuiContext(ImGuiTestEngine* engine)
547547
if (g.InputEventsQueue[n].AddedByTestEngine == false)
548548
g.InputEventsQueue.erase(&g.InputEventsQueue[n--]);
549549

550-
// Special flags to stop submitting events
551-
if (engine->TestContext->RunFlags & ImGuiTestRunFlags_EnableRawInputs)
552-
return;
553-
554550
// To support using ImGuiKey_NavXXXX shortcuts pointing to gamepad actions
555551
// FIXME-TEST-ENGINE: Should restore
556552
g.IO.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
557553
g.IO.BackendFlags |= ImGuiBackendFlags_HasGamepad;
558554

555+
// Special flags to stop submitting events
556+
if (engine->TestContext->RunFlags & ImGuiTestRunFlags_EnableRawInputs)
557+
return;
558+
559559
const int input_event_count_prev = g.InputEventsQueue.Size;
560560

561561
// Apply mouse viewport

imgui_test_suite/imgui_tests_inputs.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,33 @@ void RegisterTests_Inputs(ImGuiTestEngine* e)
531531
IM_CHECK(io.InputQueueCharacters.Size == 1 && io.InputQueueCharacters[0] == 'B');
532532
ctx->Yield();
533533
IM_CHECK(io.InputQueueCharacters.Size == 0);
534+
535+
// Test analog values with trickling
536+
// ImGuiTestEngine_ApplyInputToImGuiContext() currently sets _HasGamepad even in ImGuiTestRunFlags_EnableRawInputs mode
537+
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, false, 0.0f);
538+
ctx->Yield();
539+
IM_CHECK_EQ(ImGui::IsKeyPressed(ImGuiKey_GamepadLStickUp), false);
540+
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, true, 0.5f);
541+
ctx->Yield();
542+
IM_CHECK_EQ(ImGui::IsKeyPressed(ImGuiKey_GamepadLStickUp), true);
543+
IM_CHECK_EQ(ImGui::GetKeyData(ImGuiKey_GamepadLStickUp)->AnalogValue, 0.5f);
544+
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, true, 0.6f);
545+
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, true, 0.7f);
546+
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, true, 0.8f);
547+
ctx->Yield();
548+
IM_CHECK_EQ(ImGui::IsKeyDown(ImGuiKey_GamepadLStickUp), true);
549+
IM_CHECK_EQ(ImGui::GetKeyData(ImGuiKey_GamepadLStickUp)->AnalogValue, 0.8f);
550+
#if IMGUI_VERSION_NUM >= 19192
551+
io.AddMousePosEvent(0.0f, 0.0f);
552+
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, true, 0.81f);
553+
io.AddMousePosEvent(10.0f, 10.0f);
554+
io.AddMousePosEvent(20.0f, 20.0f);
555+
io.AddKeyAnalogEvent(ImGuiKey_GamepadLStickUp, true, 0.82f);
556+
ctx->Yield();
557+
IM_CHECK_EQ(ImGui::GetMousePos(), ImVec2(20.0f, 20.0));
558+
IM_CHECK_EQ(ImGui::IsKeyDown(ImGuiKey_GamepadLStickUp), true);
559+
IM_CHECK_EQ(ImGui::GetKeyData(ImGuiKey_GamepadLStickUp)->AnalogValue, 0.82f);
560+
#endif
534561
};
535562

536563
// ## Test IO with multiple-context (#6199, #6256)

0 commit comments

Comments
 (0)