MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / UpdateMouseWheel

Method UpdateMouseWheel

imgui_tiny_app/imgui/imgui.cpp:10937–11024  ·  view source on GitHub ↗

Called by NewFrame()

Source from the content-addressed store, hash-verified

10935
10936// Called by NewFrame()
10937void ImGui::UpdateMouseWheel()
10938{
10939 // Reset the locked window if we move the mouse or after the timer elapses.
10940 // 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)
10941 ImGuiContext& g = *GImGui;
10942 if (g.WheelingWindow != NULL)
10943 {
10944 g.WheelingWindowReleaseTimer -= g.IO.DeltaTime;
10945 if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold)
10946 g.WheelingWindowReleaseTimer = 0.0f;
10947 if (g.WheelingWindowReleaseTimer <= 0.0f)
10948 LockWheelingWindow(NULL, 0.0f);
10949 }
10950
10951 ImVec2 wheel;
10952 wheel.x = TestKeyOwner(ImGuiKey_MouseWheelX, ImGuiKeyOwner_NoOwner) ? g.IO.MouseWheelH : 0.0f;
10953 wheel.y = TestKeyOwner(ImGuiKey_MouseWheelY, ImGuiKeyOwner_NoOwner) ? g.IO.MouseWheel : 0.0f;
10954
10955 //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y);
10956 ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow;
10957 if (!mouse_window || mouse_window->Collapsed)
10958 return;
10959
10960 // Zoom / Scale window
10961 // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
10962 if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
10963 {
10964 LockWheelingWindow(mouse_window, wheel.y);
10965 ImGuiWindow* window = mouse_window;
10966 const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
10967 const float scale = new_font_scale / window->FontWindowScale;
10968 window->FontWindowScale = new_font_scale;
10969 if (window == window->RootWindow)
10970 {
10971 const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
10972 SetWindowPos(window, window->Pos + offset, 0);
10973 window->Size = ImTrunc(window->Size * scale); // FIXME: Legacy-ish code, call SetWindowSize()?
10974 window->SizeFull = ImTrunc(window->SizeFull * scale);
10975 MarkIniSettingsDirty(window);
10976 }
10977 return;
10978 }
10979 if (g.IO.KeyCtrl)
10980 return;
10981
10982 // Mouse wheel scrolling
10983 // Read about io.MouseWheelRequestAxisSwap and its issue on Mac+Emscripten in UpdateMouseInputs()
10984 if (g.IO.MouseWheelRequestAxisSwap)
10985 wheel = ImVec2(wheel.y, 0.0f);
10986
10987 // Maintain a rough average of moving magnitude on both axes
10988 // FIXME: should by based on wall clock time rather than frame-counter
10989 g.WheelingAxisAvg.x = ImExponentialMovingAverage(g.WheelingAxisAvg.x, ImAbs(wheel.x), 30);
10990 g.WheelingAxisAvg.y = ImExponentialMovingAverage(g.WheelingAxisAvg.y, ImAbs(wheel.y), 30);
10991
10992 // In the rare situation where FindBestWheelingWindow() had to defer first frame of wheeling due to ambiguous main axis, reinject it now.
10993 wheel += g.WheelingWindowWheelRemainder;
10994 g.WheelingWindowWheelRemainder = ImVec2(0.0f, 0.0f);

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected