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

Method UpdateMouseWheel

KBotExt/imgui/imgui.cpp:8726–8810  ·  view source on GitHub ↗

Called by NewFrame()

Source from the content-addressed store, hash-verified

8724
8725// Called by NewFrame()
8726void ImGui::UpdateMouseWheel()
8727{
8728 // Reset the locked window if we move the mouse or after the timer elapses.
8729 // FIXME: Ideally we could refactor to have one timer for "changing window w/ same axis" and a shorter timer for "changing window or axis w/ other axis" (#3795)
8730 ImGuiContext& g = *GImGui;
8731 if (g.WheelingWindow != NULL)
8732 {
8733 g.WheelingWindowReleaseTimer -= g.IO.DeltaTime;
8734 if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold)
8735 g.WheelingWindowReleaseTimer = 0.0f;
8736 if (g.WheelingWindowReleaseTimer <= 0.0f)
8737 LockWheelingWindow(NULL, 0.0f);
8738 }
8739
8740 ImVec2 wheel;
8741 wheel.x = TestKeyOwner(ImGuiKey_MouseWheelX, ImGuiKeyOwner_None) ? g.IO.MouseWheelH : 0.0f;
8742 wheel.y = TestKeyOwner(ImGuiKey_MouseWheelY, ImGuiKeyOwner_None) ? g.IO.MouseWheel : 0.0f;
8743
8744 //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y);
8745 ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow;
8746 if (!mouse_window || mouse_window->Collapsed)
8747 return;
8748
8749 // Zoom / Scale window
8750 // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
8751 if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
8752 {
8753 LockWheelingWindow(mouse_window, wheel.y);
8754 ImGuiWindow* window = mouse_window;
8755 const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
8756 const float scale = new_font_scale / window->FontWindowScale;
8757 window->FontWindowScale = new_font_scale;
8758 if (window == window->RootWindow)
8759 {
8760 const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
8761 SetWindowPos(window, window->Pos + offset, 0);
8762 window->Size = ImFloor(window->Size * scale);
8763 window->SizeFull = ImFloor(window->SizeFull * scale);
8764 }
8765 return;
8766 }
8767 if (g.IO.KeyCtrl)
8768 return;
8769
8770 // Mouse wheel scrolling
8771 // Read about io.MouseWheelRequestAxisSwap and its issue on Mac+Emscripten in UpdateMouseInputs()
8772 if (g.IO.MouseWheelRequestAxisSwap)
8773 wheel = ImVec2(wheel.y, 0.0f);
8774
8775 // Maintain a rough average of moving magnitude on both axises
8776 // FIXME: should by based on wall clock time rather than frame-counter
8777 g.WheelingAxisAvg.x = ImExponentialMovingAverage(g.WheelingAxisAvg.x, ImAbs(wheel.x), 30);
8778 g.WheelingAxisAvg.y = ImExponentialMovingAverage(g.WheelingAxisAvg.y, ImAbs(wheel.y), 30);
8779
8780 // In the rare situation where FindBestWheelingWindow() had to defer first frame of wheeling due to ambiguous main axis, reinject it now.
8781 wheel += g.WheelingWindowWheelRemainder;
8782 g.WheelingWindowWheelRemainder = ImVec2(0.0f, 0.0f);
8783 if (wheel.x == 0.0f && wheel.y == 0.0f)

Callers

nothing calls this directly

Calls 9

ImLengthSqrFunction · 0.85
LockWheelingWindowFunction · 0.85
ImClampFunction · 0.85
ImFloorFunction · 0.85
ImVec2Function · 0.85
ImAbsFunction · 0.85
FindBestWheelingWindowFunction · 0.85
ImMinFunction · 0.85

Tested by

no test coverage detected