MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / UpdateMouseWheel

Method UpdateMouseWheel

Source/3rdParty/imgui/imgui.cpp:10332–10419  ·  view source on GitHub ↗

Called by NewFrame()

Source from the content-addressed store, hash-verified

10330
10331// Called by NewFrame()
10332void ImGui::UpdateMouseWheel()
10333{
10334 // Reset the locked window if we move the mouse or after the timer elapses.
10335 // 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)
10336 ImGuiContext& g = *GImGui;
10337 if (g.WheelingWindow != NULL)
10338 {
10339 g.WheelingWindowReleaseTimer -= g.IO.DeltaTime;
10340 if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold)
10341 g.WheelingWindowReleaseTimer = 0.0f;
10342 if (g.WheelingWindowReleaseTimer <= 0.0f)
10343 LockWheelingWindow(NULL, 0.0f);
10344 }
10345
10346 ImVec2 wheel;
10347 wheel.x = TestKeyOwner(ImGuiKey_MouseWheelX, ImGuiKeyOwner_NoOwner) ? g.IO.MouseWheelH : 0.0f;
10348 wheel.y = TestKeyOwner(ImGuiKey_MouseWheelY, ImGuiKeyOwner_NoOwner) ? g.IO.MouseWheel : 0.0f;
10349
10350 //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y);
10351 ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow;
10352 if (!mouse_window || mouse_window->Collapsed)
10353 return;
10354
10355 // Zoom / Scale window
10356 // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
10357 if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
10358 {
10359 LockWheelingWindow(mouse_window, wheel.y);
10360 ImGuiWindow* window = mouse_window;
10361 const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
10362 const float scale = new_font_scale / window->FontWindowScale;
10363 window->FontWindowScale = new_font_scale;
10364 if (window == window->RootWindow)
10365 {
10366 const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
10367 SetWindowPos(window, window->Pos + offset, 0);
10368 window->Size = ImTrunc(window->Size * scale); // FIXME: Legacy-ish code, call SetWindowSize()?
10369 window->SizeFull = ImTrunc(window->SizeFull * scale);
10370 MarkIniSettingsDirty(window);
10371 }
10372 return;
10373 }
10374 if (g.IO.KeyCtrl)
10375 return;
10376
10377 // Mouse wheel scrolling
10378 // Read about io.MouseWheelRequestAxisSwap and its issue on Mac+Emscripten in UpdateMouseInputs()
10379 if (g.IO.MouseWheelRequestAxisSwap)
10380 wheel = ImVec2(wheel.y, 0.0f);
10381
10382 // Maintain a rough average of moving magnitude on both axes
10383 // FIXME: should by based on wall clock time rather than frame-counter
10384 g.WheelingAxisAvg.x = ImExponentialMovingAverage(g.WheelingAxisAvg.x, ImAbs(wheel.x), 30);
10385 g.WheelingAxisAvg.y = ImExponentialMovingAverage(g.WheelingAxisAvg.y, ImAbs(wheel.y), 30);
10386
10387 // In the rare situation where FindBestWheelingWindow() had to defer first frame of wheeling due to ambiguous main axis, reinject it now.
10388 wheel += g.WheelingWindowWheelRemainder;
10389 g.WheelingWindowWheelRemainder = ImVec2(0.0f, 0.0f);

Callers

nothing calls this directly

Calls 12

ImLengthSqrFunction · 0.85
LockWheelingWindowFunction · 0.85
ImClampFunction · 0.85
SetWindowPosFunction · 0.85
ImTruncFunction · 0.85
ImVec2Function · 0.85
ImAbsFunction · 0.85
FindBestWheelingWindowFunction · 0.85
ImMinFunction · 0.85
GetWidthMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected