mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-21 17:41:54 -08:00
77 lines
3.7 KiB
Diff
77 lines
3.7 KiB
Diff
From b11b32c2e0a607d9da2931c7e73ebc6401f62410 Mon Sep 17 00:00:00 2001
|
|
From: Guillaume Meunier <[email protected]>
|
|
Date: Wed, 16 Oct 2024 20:51:52 +0200
|
|
Subject: [PATCH 1/2] Change ImGui::ButtonBehavior default flags when using
|
|
hand tracking
|
|
|
|
---
|
|
imgui.cpp | 2 +-
|
|
imgui.h | 2 ++
|
|
imgui_demo.cpp | 5 +++++
|
|
imgui_widgets.cpp | 7 ++++++-
|
|
4 files changed, 14 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/imgui.cpp b/imgui.cpp
|
|
index 2c536fa8f..cf3dd125c 100644
|
|
--- a/imgui.cpp
|
|
+++ b/imgui.cpp
|
|
@@ -10625,7 +10625,7 @@ static const char* GetInputSourceName(ImGuiInputSource source)
|
|
}
|
|
static const char* GetMouseSourceName(ImGuiMouseSource source)
|
|
{
|
|
- const char* mouse_source_names[] = { "Mouse", "TouchScreen", "Pen" };
|
|
+ const char* mouse_source_names[] = { "Mouse", "TouchScreen", "Pen", "VRHandTracking", "VRController" };
|
|
IM_ASSERT(IM_COUNTOF(mouse_source_names) == ImGuiMouseSource_COUNT);
|
|
if (source < 0 || source >= ImGuiMouseSource_COUNT)
|
|
return "Unknown";
|
|
diff --git a/imgui.h b/imgui.h
|
|
index da664cb8e..35e944c90 100644
|
|
--- a/imgui.h
|
|
+++ b/imgui.h
|
|
@@ -2012,6 +2012,8 @@ enum ImGuiMouseSource : int
|
|
ImGuiMouseSource_Mouse = 0, // Input is coming from an actual mouse.
|
|
ImGuiMouseSource_TouchScreen, // Input is coming from a touch screen (no hovering prior to initial press, less precise initial press aiming, dual-axis wheeling possible).
|
|
ImGuiMouseSource_Pen, // Input is coming from a pressure/magnetic pen (often used in conjunction with high-sampling rates).
|
|
+ ImGuiMouseSource_VRHandTracking, // Input is coming from a tracked hand in virtual reality
|
|
+ ImGuiMouseSource_VRController, // Input is coming from a controller in virtual reality
|
|
ImGuiMouseSource_COUNT
|
|
};
|
|
|
|
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
|
|
index f9b3d0108..01da063ab 100644
|
|
--- a/imgui_demo.cpp
|
|
+++ b/imgui_demo.cpp
|
|
@@ -8023,6 +8023,11 @@ static void DemoWindowInputs()
|
|
ImGui::Text("Mouse clicked count:");
|
|
for (int i = 0; i < IM_COUNTOF(io.MouseDown); i++) if (io.MouseClickedCount[i] > 0) { ImGui::SameLine(); ImGui::Text("b%d: %d", i, io.MouseClickedCount[i]); }
|
|
|
|
+ const char* mouse_source_names[] = { "Mouse", "TouchScreen", "Pen", "VRHandTracking", "VRController" };
|
|
+ IM_ASSERT(IM_ARRAYSIZE(mouse_source_names) == ImGuiMouseSource_COUNT && io.MouseSource >= 0 && io.MouseSource < ImGuiMouseSource_COUNT);
|
|
+
|
|
+ ImGui::Text("Mouse source: %s", mouse_source_names[io.MouseSource]);
|
|
+
|
|
// We iterate both legacy native range and named ImGuiKey ranges. This is a little unusual/odd but this allows
|
|
// displaying the data for old/new backends.
|
|
// User code should never have to go through such hoops!
|
|
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
|
|
index 6c324e7b0..70340b472 100644
|
|
--- a/imgui_widgets.cpp
|
|
+++ b/imgui_widgets.cpp
|
|
@@ -561,7 +561,12 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
|
|
|
|
// Default behavior requires click + release inside bounding box
|
|
if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0)
|
|
- flags |= (item_flags & ImGuiItemFlags_ButtonRepeat) ? ImGuiButtonFlags_PressedOnClick : ImGuiButtonFlags_PressedOnDefault_;
|
|
+ {
|
|
+ if (g.IO.MouseSource == ImGuiMouseSource_VRHandTracking)
|
|
+ flags |= ImGuiButtonFlags_PressedOnClick;
|
|
+ else
|
|
+ flags |= ImGuiButtonFlags_PressedOnDefault_;
|
|
+ }
|
|
|
|
ImGuiWindow* backup_hovered_window = g.HoveredWindow;
|
|
const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindow == window->RootWindow;
|
|
--
|
|
2.55.0
|
|
|