diff --git a/backends/imgui_impl_android.cpp b/backends/imgui_impl_android.cpp index 6b1dd4ca..029c2c52 100644 --- a/backends/imgui_impl_android.cpp +++ b/backends/imgui_impl_android.cpp @@ -3,6 +3,7 @@ // Implemented features: // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. // Missing features: // [ ] Platform: Clipboard support. // [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. @@ -196,6 +197,22 @@ int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event) int32_t event_action = AMotionEvent_getAction(input_event); int32_t event_pointer_index = (event_action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; event_action &= AMOTION_EVENT_ACTION_MASK; + + switch (AMotionEvent_getToolType(input_event, event_pointer_index)) + { + case AMOTION_EVENT_TOOL_TYPE_MOUSE: + io.AddMouseSourceEvent(ImGuiMouseSource_Mouse); + break; + case AMOTION_EVENT_TOOL_TYPE_STYLUS: + case AMOTION_EVENT_TOOL_TYPE_ERASER: + io.AddMouseSourceEvent(ImGuiMouseSource_Pen); + break; + case AMOTION_EVENT_TOOL_TYPE_FINGER: + default: + io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen); + break; + } + switch (event_action) { case AMOTION_EVENT_ACTION_DOWN: diff --git a/backends/imgui_impl_android.h b/backends/imgui_impl_android.h index 8bfa1860..eb97c4c8 100644 --- a/backends/imgui_impl_android.h +++ b/backends/imgui_impl_android.h @@ -3,6 +3,7 @@ // Implemented features: // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] +// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen. // Missing features: // [ ] Platform: Clipboard support. // [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f6e18e6c..7123cbc1 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -86,6 +86,7 @@ Other changes: - Backends: GLFW: Added support on Win32 only for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen/Pen. (#2334, #2702) - Backends: GLFW: Fixed key modifiers handling on secondary viewports. (#6248, #6034) [@aiekick] +- Backends: Android: Added support for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen/Pen. [@PathogenDavid] - Examples: Windows: Added 'misc/debuggers/imgui.natstepfilter' file to all Visual Studio projects, now that VS 2022 17.6 Preview 2 support adding Debug Step Filter spec files into projects. - Examples: SDL3: Updated for latest WIP SDL3 branch. (#6243)