mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
IO: removed unused MouseDragMaxDistanceAbs(). Using a shortcut variable in UpdateMouseInputs().
This commit is contained in:
parent
c5a3cae83a
commit
206b9ead8f
60
imgui.cpp
60
imgui.cpp
@ -3747,62 +3747,60 @@ static bool IsWindowActiveAndVisible(ImGuiWindow* window)
|
|||||||
static void ImGui::UpdateMouseInputs()
|
static void ImGui::UpdateMouseInputs()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
ImGuiIO& io = g.IO;
|
||||||
|
|
||||||
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
|
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
|
||||||
if (IsMousePosValid(&g.IO.MousePos))
|
if (IsMousePosValid(&io.MousePos))
|
||||||
g.IO.MousePos = g.MouseLastValidPos = ImFloor(g.IO.MousePos);
|
io.MousePos = g.MouseLastValidPos = ImFloor(io.MousePos);
|
||||||
|
|
||||||
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
|
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
|
||||||
if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev))
|
if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev))
|
||||||
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
|
io.MouseDelta = io.MousePos - io.MousePosPrev;
|
||||||
else
|
else
|
||||||
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
|
io.MouseDelta = ImVec2(0.0f, 0.0f);
|
||||||
|
|
||||||
// If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true.
|
// If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true.
|
||||||
if (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)
|
if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)
|
||||||
g.NavDisableMouseHover = false;
|
g.NavDisableMouseHover = false;
|
||||||
|
|
||||||
g.IO.MousePosPrev = g.IO.MousePos;
|
io.MousePosPrev = io.MousePos;
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
|
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
|
||||||
{
|
{
|
||||||
g.IO.MouseClicked[i] = g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] < 0.0f;
|
io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f;
|
||||||
g.IO.MouseClickedCount[i] = 0; // Will be filled below
|
io.MouseClickedCount[i] = 0; // Will be filled below
|
||||||
g.IO.MouseReleased[i] = !g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] >= 0.0f;
|
io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f;
|
||||||
g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i];
|
io.MouseDownDurationPrev[i] = 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;
|
io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f;
|
||||||
if (g.IO.MouseClicked[i])
|
if (io.MouseClicked[i])
|
||||||
{
|
{
|
||||||
bool is_repeated_click = false;
|
bool is_repeated_click = false;
|
||||||
if ((float)(g.Time - g.IO.MouseClickedTime[i]) < g.IO.MouseDoubleClickTime)
|
if ((float)(g.Time - io.MouseClickedTime[i]) < io.MouseDoubleClickTime)
|
||||||
{
|
{
|
||||||
ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
|
ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
|
||||||
if (ImLengthSqr(delta_from_click_pos) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
|
if (ImLengthSqr(delta_from_click_pos) < io.MouseDoubleClickMaxDist * io.MouseDoubleClickMaxDist)
|
||||||
is_repeated_click = true;
|
is_repeated_click = true;
|
||||||
}
|
}
|
||||||
if (is_repeated_click)
|
if (is_repeated_click)
|
||||||
g.IO.MouseClickedLastCount[i]++;
|
io.MouseClickedLastCount[i]++;
|
||||||
else
|
else
|
||||||
g.IO.MouseClickedLastCount[i] = 1;
|
io.MouseClickedLastCount[i] = 1;
|
||||||
g.IO.MouseClickedTime[i] = g.Time;
|
io.MouseClickedTime[i] = g.Time;
|
||||||
g.IO.MouseClickedPos[i] = g.IO.MousePos;
|
io.MouseClickedPos[i] = io.MousePos;
|
||||||
g.IO.MouseClickedCount[i] = g.IO.MouseClickedLastCount[i];
|
io.MouseClickedCount[i] = io.MouseClickedLastCount[i];
|
||||||
g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f);
|
io.MouseDragMaxDistanceSqr[i] = 0.0f;
|
||||||
g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
|
|
||||||
}
|
}
|
||||||
else if (g.IO.MouseDown[i])
|
else if (io.MouseDown[i])
|
||||||
{
|
{
|
||||||
// Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold
|
// Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold
|
||||||
ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
|
float delta_sqr_click_pos = IsMousePosValid(&io.MousePos) ? ImLengthSqr(io.MousePos - io.MouseClickedPos[i]) : 0.0f;
|
||||||
g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos));
|
io.MouseDragMaxDistanceSqr[i] = ImMax(io.MouseDragMaxDistanceSqr[i], delta_sqr_click_pos);
|
||||||
g.IO.MouseDragMaxDistanceAbs[i].x = ImMax(g.IO.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x);
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We provide io.MouseDoubleClicked[] as a legacy service
|
// We provide io.MouseDoubleClicked[] as a legacy service
|
||||||
g.IO.MouseDoubleClicked[i] = (g.IO.MouseClickedCount[i] == 2);
|
io.MouseDoubleClicked[i] = (io.MouseClickedCount[i] == 2);
|
||||||
|
|
||||||
// Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation
|
// Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation
|
||||||
if (g.IO.MouseClicked[i])
|
if (io.MouseClicked[i])
|
||||||
g.NavDisableMouseHover = false;
|
g.NavDisableMouseHover = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
imgui.h
3
imgui.h
@ -1937,8 +1937,7 @@ struct ImGuiIO
|
|||||||
bool MouseDownOwnedUnlessPopupClose[5]; //Track if button was clicked inside a dear imgui window.
|
bool MouseDownOwnedUnlessPopupClose[5]; //Track if button was clicked inside a dear imgui window.
|
||||||
float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked)
|
float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked)
|
||||||
float MouseDownDurationPrev[5]; // Previous time the mouse button has been down
|
float MouseDownDurationPrev[5]; // Previous time the mouse button has been down
|
||||||
ImVec2 MouseDragMaxDistanceAbs[5]; // Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point
|
float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the clicking point (used for moving thresholds)
|
||||||
float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the clicking point
|
|
||||||
float NavInputsDownDuration[ImGuiNavInput_COUNT];
|
float NavInputsDownDuration[ImGuiNavInput_COUNT];
|
||||||
float NavInputsDownDurationPrev[ImGuiNavInput_COUNT];
|
float NavInputsDownDurationPrev[ImGuiNavInput_COUNT];
|
||||||
float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui.
|
float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui.
|
||||||
|
Loading…
Reference in New Issue
Block a user