| 4460 | } |
| 4461 | |
| 4462 | static void ImGui::UpdateMouseInputs() |
| 4463 | { |
| 4464 | ImGuiContext& g = *GImGui; |
| 4465 | ImGuiIO& io = g.IO; |
| 4466 | |
| 4467 | // Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well) |
| 4468 | if (IsMousePosValid(&io.MousePos)) |
| 4469 | io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos); |
| 4470 | |
| 4471 | // If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta |
| 4472 | if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev)) |
| 4473 | io.MouseDelta = io.MousePos - io.MousePosPrev; |
| 4474 | else |
| 4475 | io.MouseDelta = ImVec2(0.0f, 0.0f); |
| 4476 | |
| 4477 | // 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. |
| 4478 | if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f) |
| 4479 | g.NavDisableMouseHover = false; |
| 4480 | |
| 4481 | io.MousePosPrev = io.MousePos; |
| 4482 | for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) |
| 4483 | { |
| 4484 | io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f; |
| 4485 | io.MouseClickedCount[i] = 0; // Will be filled below |
| 4486 | io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f; |
| 4487 | io.MouseDownDurationPrev[i] = io.MouseDownDuration[i]; |
| 4488 | io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f; |
| 4489 | if (io.MouseClicked[i]) |
| 4490 | { |
| 4491 | bool is_repeated_click = false; |
| 4492 | if ((float)(g.Time - io.MouseClickedTime[i]) < io.MouseDoubleClickTime) |
| 4493 | { |
| 4494 | ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); |
| 4495 | if (ImLengthSqr(delta_from_click_pos) < io.MouseDoubleClickMaxDist * io.MouseDoubleClickMaxDist) |
| 4496 | is_repeated_click = true; |
| 4497 | } |
| 4498 | if (is_repeated_click) |
| 4499 | io.MouseClickedLastCount[i]++; |
| 4500 | else |
| 4501 | io.MouseClickedLastCount[i] = 1; |
| 4502 | io.MouseClickedTime[i] = g.Time; |
| 4503 | io.MouseClickedPos[i] = io.MousePos; |
| 4504 | io.MouseClickedCount[i] = io.MouseClickedLastCount[i]; |
| 4505 | io.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); |
| 4506 | io.MouseDragMaxDistanceSqr[i] = 0.0f; |
| 4507 | } |
| 4508 | else if (io.MouseDown[i]) |
| 4509 | { |
| 4510 | // Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold |
| 4511 | ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); |
| 4512 | io.MouseDragMaxDistanceSqr[i] = ImMax(io.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos)); |
| 4513 | io.MouseDragMaxDistanceAbs[i].x = ImMax(io.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x); |
| 4514 | io.MouseDragMaxDistanceAbs[i].y = ImMax(io.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y); |
| 4515 | } |
| 4516 | |
| 4517 | // We provide io.MouseDoubleClicked[] as a legacy service |
| 4518 | io.MouseDoubleClicked[i] = (io.MouseClickedCount[i] == 2); |
| 4519 |
nothing calls this directly
no test coverage detected