MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/PositionBasedDynamics / UpdateMouseWheel

Method UpdateMouseWheel

extern/imgui/imgui.cpp:4584–4674  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4582}
4583
4584void ImGui::UpdateMouseWheel()
4585{
4586 ImGuiContext& g = *GImGui;
4587
4588 // Reset the locked window if we move the mouse or after the timer elapses.
4589 // 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)
4590 if (g.WheelingWindow != NULL)
4591 {
4592 g.WheelingWindowReleaseTimer -= g.IO.DeltaTime;
4593 if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold)
4594 g.WheelingWindowReleaseTimer = 0.0f;
4595 if (g.WheelingWindowReleaseTimer <= 0.0f)
4596 LockWheelingWindow(NULL, 0.0f);
4597 }
4598
4599 ImVec2 wheel;
4600 wheel.x = TestKeyOwner(ImGuiKey_MouseWheelX, ImGuiKeyOwner_None) ? g.IO.MouseWheelH : 0.0f;
4601 wheel.y = TestKeyOwner(ImGuiKey_MouseWheelY, ImGuiKeyOwner_None) ? g.IO.MouseWheel : 0.0f;
4602
4603 //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y);
4604 ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow;
4605 if (!mouse_window || mouse_window->Collapsed)
4606 return;
4607
4608 // Zoom / Scale window
4609 // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
4610 if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
4611 {
4612 LockWheelingWindow(mouse_window, wheel.y);
4613 ImGuiWindow* window = mouse_window;
4614 const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
4615 const float scale = new_font_scale / window->FontWindowScale;
4616 window->FontWindowScale = new_font_scale;
4617 if (window == window->RootWindow)
4618 {
4619 const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
4620 SetWindowPos(window, window->Pos + offset, 0);
4621 window->Size = ImFloor(window->Size * scale);
4622 window->SizeFull = ImFloor(window->SizeFull * scale);
4623 }
4624 return;
4625 }
4626 if (g.IO.KeyCtrl)
4627 return;
4628
4629 // Mouse wheel scrolling
4630 // As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead
4631 // (we avoid doing it on OSX as it the OS input layer handles this already)
4632 const bool swap_axis = g.IO.KeyShift && !g.IO.ConfigMacOSXBehaviors;
4633 if (swap_axis)
4634 {
4635 wheel.x = wheel.y;
4636 wheel.y = 0.0f;
4637 }
4638
4639 // Maintain a rough average of moving magnitude on both axises
4640 // FIXME: should by based on wall clock time rather than frame-counter
4641 g.WheelingAxisAvg.x = ImExponentialMovingAverage(g.WheelingAxisAvg.x, ImAbs(wheel.x), 30);

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected