mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Avoid requesting IO.WantCaptureMouse if earlier click/hold was outside of ImGui window
This commit is contained in:
parent
94c7eddb17
commit
c6de9502f8
19
imgui.cpp
19
imgui.cpp
@ -235,7 +235,6 @@
|
|||||||
==================
|
==================
|
||||||
|
|
||||||
- misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
|
- misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
|
||||||
!- i/o: avoid requesting mouse capture if button held and initial click was out of reach for imgui
|
|
||||||
- window: add horizontal scroll
|
- window: add horizontal scroll
|
||||||
- window: fix resize grip rendering scaling along with Rounding style setting
|
- window: fix resize grip rendering scaling along with Rounding style setting
|
||||||
- window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
|
- window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
|
||||||
@ -1699,8 +1698,20 @@ void ImGui::NewFrame()
|
|||||||
else
|
else
|
||||||
g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
|
g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
|
||||||
|
|
||||||
// Are we using inputs? Tell user so they can capture/discard them.
|
// Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application.
|
||||||
g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0);
|
// When clicking outside of a window we assume the click is owned by the application and won't request capture.
|
||||||
|
// FIXME: For completeness we should completely disregard the mouse when 'mouse_owned_by_application' is set.
|
||||||
|
int mouse_earliest_button_down = -1;
|
||||||
|
for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
|
||||||
|
{
|
||||||
|
if (g.IO.MouseClicked[i])
|
||||||
|
g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL);
|
||||||
|
if (g.IO.MouseDown[i])
|
||||||
|
if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[mouse_earliest_button_down] > g.IO.MouseClickedTime[i])
|
||||||
|
mouse_earliest_button_down = i;
|
||||||
|
}
|
||||||
|
bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down];
|
||||||
|
g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (g.ActiveId != 0);
|
||||||
g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
|
g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
|
||||||
|
|
||||||
// Scale & Scrolling
|
// Scale & Scrolling
|
||||||
@ -7715,6 +7726,8 @@ void ImGui::ShowTestWindow(bool* opened)
|
|||||||
ImGui::Text("ImGui says hello.");
|
ImGui::Text("ImGui says hello.");
|
||||||
//ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
|
//ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
|
||||||
//ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
|
//ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
|
||||||
|
//ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse);
|
||||||
|
//ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard);
|
||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
if (ImGui::CollapsingHeader("Help"))
|
if (ImGui::CollapsingHeader("Help"))
|
||||||
|
17
imgui.h
17
imgui.h
@ -566,14 +566,15 @@ struct ImGuiIO
|
|||||||
// [Internal] ImGui will maintain those fields for you
|
// [Internal] ImGui will maintain those fields for you
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
ImVec2 MousePosPrev;
|
ImVec2 MousePosPrev; //
|
||||||
ImVec2 MouseDelta;
|
ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling.
|
||||||
bool MouseClicked[5];
|
bool MouseClicked[5]; // Mouse button went from !Down to Down
|
||||||
ImVec2 MouseClickedPos[5];
|
ImVec2 MouseClickedPos[5]; // Position at time of clicking
|
||||||
float MouseClickedTime[5];
|
float MouseClickedTime[5]; // Time of last click (used to figure out double-click)
|
||||||
bool MouseDoubleClicked[5];
|
bool MouseDoubleClicked[5]; // Has mouse button been double-clicked?
|
||||||
float MouseDownTime[5];
|
bool MouseDownOwned[5]; // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds.
|
||||||
float KeysDownTime[512];
|
float MouseDownTime[5]; // Time the mouse button has been down
|
||||||
|
float KeysDownTime[512]; // Time the keyboard key has been down
|
||||||
|
|
||||||
IMGUI_API ImGuiIO();
|
IMGUI_API ImGuiIO();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user