mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-05 20:48:46 +02:00
Inputs: Mouse: Amend c8e3a01 for tracking multiple clicks, renaming. (#3229)
This commit is contained in:
33
imgui.cpp
33
imgui.cpp
@ -3692,29 +3692,26 @@ static void ImGui::UpdateMouseInputs()
|
||||
for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
|
||||
{
|
||||
g.IO.MouseClicked[i] = g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] < 0.0f;
|
||||
g.IO.MouseClickedCount[i] = 0; // Will be filled below
|
||||
g.IO.MouseReleased[i] = !g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] >= 0.0f;
|
||||
g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i];
|
||||
g.IO.MouseDownDuration[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownDuration[i] < 0.0f ? 0.0f : g.IO.MouseDownDuration[i] + g.IO.DeltaTime) : -1.0f;
|
||||
g.IO.MouseMultiClickCount[i] = 0;
|
||||
if (g.IO.MouseClicked[i])
|
||||
{
|
||||
bool is_repeated_click = false;
|
||||
if ((float)(g.Time - g.IO.MouseClickedTime[i]) < g.IO.MouseDoubleClickTime)
|
||||
{
|
||||
ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
|
||||
if (ImLengthSqr(delta_from_click_pos) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
|
||||
g.IO.MouseMultiClickTracker[i]++;
|
||||
else
|
||||
g.IO.MouseMultiClickTracker[i] = 1;
|
||||
is_repeated_click = true;
|
||||
}
|
||||
if (is_repeated_click)
|
||||
g.IO.MouseClickedLastCount[i]++;
|
||||
else
|
||||
{
|
||||
g.IO.MouseMultiClickTracker[i] = 1;
|
||||
}
|
||||
|
||||
g.IO.MouseClickedLastCount[i] = 1;
|
||||
g.IO.MouseClickedTime[i] = g.Time;
|
||||
g.IO.MouseClickedPos[i] = g.IO.MousePos;
|
||||
g.IO.MouseMultiClickCount[i] = g.IO.MouseMultiClickTracker[i];
|
||||
g.IO.MouseDownMultiClickCount[i] = g.IO.MouseMultiClickTracker[i];
|
||||
g.IO.MouseClickedCount[i] = g.IO.MouseClickedLastCount[i];
|
||||
g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f);
|
||||
g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
|
||||
}
|
||||
@ -3727,9 +3724,11 @@ static void ImGui::UpdateMouseInputs()
|
||||
g.IO.MouseDragMaxDistanceAbs[i].y = ImMax(g.IO.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y);
|
||||
}
|
||||
|
||||
if (!g.IO.MouseDown[i] && !g.IO.MouseReleased[i])
|
||||
g.IO.MouseDownMultiClickCount[i] = 0;
|
||||
if (g.IO.MouseClicked[i]) // Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation
|
||||
// We provide io.MouseDoubleClicked[] as a legacy service
|
||||
g.IO.MouseDoubleClicked[i] = (g.IO.MouseClickedCount[i] == 2);
|
||||
|
||||
// Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation
|
||||
if (g.IO.MouseClicked[i])
|
||||
g.NavDisableMouseHover = false;
|
||||
}
|
||||
}
|
||||
@ -4770,14 +4769,14 @@ bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
return g.IO.MouseMultiClickCount[button] == 2;
|
||||
return g.IO.MouseClickedCount[button] == 2;
|
||||
}
|
||||
|
||||
bool ImGui::IsMouseTripleClicked(ImGuiMouseButton button)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
|
||||
return g.IO.MouseMultiClickCount[button] == 3;
|
||||
return g.IO.MouseClickedCount[button] == 3;
|
||||
}
|
||||
|
||||
// Return if a mouse click/drag went past the given threshold. Valid to call during the MouseReleased frame.
|
||||
@ -5457,7 +5456,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
|
||||
if (hovered || held)
|
||||
g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;
|
||||
|
||||
if (held && g.IO.MouseMultiClickCount[0] == 2 && resize_grip_n == 0)
|
||||
if (held && g.IO.MouseClickedCount[0] == 2 && resize_grip_n == 0)
|
||||
{
|
||||
// Manual auto-fit when double-clicking
|
||||
size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit);
|
||||
@ -5992,7 +5991,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
{
|
||||
// We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), so verify that we don't have items over the title bar.
|
||||
ImRect title_bar_rect = window->TitleBarRect();
|
||||
if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max) && g.IO.MouseMultiClickCount[0] == 2)
|
||||
if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max) && g.IO.MouseClickedCount[0] == 2)
|
||||
window->WantCollapseToggle = true;
|
||||
if (window->WantCollapseToggle)
|
||||
{
|
||||
|
Reference in New Issue
Block a user