MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / UpdateMouseInputs

Method UpdateMouseInputs

KBotExt/imgui/imgui.cpp:8592–8665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8590}
8591
8592static void ImGui::UpdateMouseInputs()
8593{
8594 ImGuiContext& g = *GImGui;
8595 ImGuiIO& io = g.IO;
8596
8597 // Mouse Wheel swapping flag
8598 // As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead
8599 // - We avoid doing it on OSX as it the OS input layer handles this already.
8600 // - FIXME: However this means when running on OSX over Emscripten, Shift+WheelY will incur two swapping (1 in OS, 1 here), canceling the feature.
8601 // - FIXME: When we can distinguish e.g. touchpad scroll events from mouse ones, we'll set this accordingly based on input source.
8602 io.MouseWheelRequestAxisSwap = io.KeyShift && !io.ConfigMacOSXBehaviors;
8603
8604 // Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
8605 if (IsMousePosValid(&io.MousePos))
8606 io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos);
8607
8608 // If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
8609 if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev))
8610 io.MouseDelta = io.MousePos - io.MousePosPrev;
8611 else
8612 io.MouseDelta = ImVec2(0.0f, 0.0f);
8613
8614 // Update stationary timer.
8615 // FIXME: May need to rework again to have some tolerance for occasional small movement, while being functional on high-framerates.
8616 const float mouse_stationary_threshold = (io.MouseSource == ImGuiMouseSource_Mouse) ? 2.0f : 3.0f; // Slightly higher threshold for ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen, may need rework.
8617 const bool mouse_stationary = (ImLengthSqr(io.MouseDelta) <= mouse_stationary_threshold * mouse_stationary_threshold);
8618 g.MouseStationaryTimer = mouse_stationary ? (g.MouseStationaryTimer + io.DeltaTime) : 0.0f;
8619 //IMGUI_DEBUG_LOG("%.4f\n", g.MouseStationaryTimer);
8620
8621 // 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.
8622 if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)
8623 g.NavDisableMouseHover = false;
8624
8625 io.MousePosPrev = io.MousePos;
8626 for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
8627 {
8628 io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f;
8629 io.MouseClickedCount[i] = 0; // Will be filled below
8630 io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f;
8631 io.MouseDownDurationPrev[i] = io.MouseDownDuration[i];
8632 io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f;
8633 if (io.MouseClicked[i])
8634 {
8635 bool is_repeated_click = false;
8636 if ((float)(g.Time - io.MouseClickedTime[i]) < io.MouseDoubleClickTime)
8637 {
8638 ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
8639 if (ImLengthSqr(delta_from_click_pos) < io.MouseDoubleClickMaxDist * io.MouseDoubleClickMaxDist)
8640 is_repeated_click = true;
8641 }
8642 if (is_repeated_click)
8643 io.MouseClickedLastCount[i]++;
8644 else
8645 io.MouseClickedLastCount[i] = 1;
8646 io.MouseClickedTime[i] = g.Time;
8647 io.MouseClickedPos[i] = io.MousePos;
8648 io.MouseClickedCount[i] = io.MouseClickedLastCount[i];
8649 io.MouseDragMaxDistanceSqr[i] = 0.0f;

Callers

nothing calls this directly

Calls 4

ImFloorSignedFunction · 0.85
ImVec2Function · 0.85
ImLengthSqrFunction · 0.85
ImMaxFunction · 0.85

Tested by

no test coverage detected