Called by NewFrame()
| 9415 | |
| 9416 | // Called by NewFrame() |
| 9417 | void ImGui::UpdateMouseWheel() |
| 9418 | { |
| 9419 | // Reset the locked window if we move the mouse or after the timer elapses. |
| 9420 | // 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) |
| 9421 | ImGuiContext& g = *GImGui; |
| 9422 | if (g.WheelingWindow != NULL) |
| 9423 | { |
| 9424 | g.WheelingWindowReleaseTimer -= g.IO.DeltaTime; |
| 9425 | if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold) |
| 9426 | g.WheelingWindowReleaseTimer = 0.0f; |
| 9427 | if (g.WheelingWindowReleaseTimer <= 0.0f) |
| 9428 | LockWheelingWindow(NULL, 0.0f); |
| 9429 | } |
| 9430 | |
| 9431 | ImVec2 wheel; |
| 9432 | wheel.x = TestKeyOwner(ImGuiKey_MouseWheelX, ImGuiKeyOwner_NoOwner) ? g.IO.MouseWheelH : 0.0f; |
| 9433 | wheel.y = TestKeyOwner(ImGuiKey_MouseWheelY, ImGuiKeyOwner_NoOwner) ? g.IO.MouseWheel : 0.0f; |
| 9434 | |
| 9435 | //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y); |
| 9436 | ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; |
| 9437 | if (!mouse_window || mouse_window->Collapsed) |
| 9438 | return; |
| 9439 | |
| 9440 | // Zoom / Scale window |
| 9441 | // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. |
| 9442 | if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) |
| 9443 | { |
| 9444 | LockWheelingWindow(mouse_window, wheel.y); |
| 9445 | ImGuiWindow* window = mouse_window; |
| 9446 | const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); |
| 9447 | const float scale = new_font_scale / window->FontWindowScale; |
| 9448 | window->FontWindowScale = new_font_scale; |
| 9449 | if (window == window->RootWindow) |
| 9450 | { |
| 9451 | const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; |
| 9452 | SetWindowPos(window, window->Pos + offset, 0); |
| 9453 | window->Size = ImTrunc(window->Size * scale); |
| 9454 | window->SizeFull = ImTrunc(window->SizeFull * scale); |
| 9455 | } |
| 9456 | return; |
| 9457 | } |
| 9458 | if (g.IO.KeyCtrl) |
| 9459 | return; |
| 9460 | |
| 9461 | // Mouse wheel scrolling |
| 9462 | // Read about io.MouseWheelRequestAxisSwap and its issue on Mac+Emscripten in UpdateMouseInputs() |
| 9463 | if (g.IO.MouseWheelRequestAxisSwap) |
| 9464 | wheel = ImVec2(wheel.y, 0.0f); |
| 9465 | |
| 9466 | // Maintain a rough average of moving magnitude on both axises |
| 9467 | // FIXME: should by based on wall clock time rather than frame-counter |
| 9468 | g.WheelingAxisAvg.x = ImExponentialMovingAverage(g.WheelingAxisAvg.x, ImAbs(wheel.x), 30); |
| 9469 | g.WheelingAxisAvg.y = ImExponentialMovingAverage(g.WheelingAxisAvg.y, ImAbs(wheel.y), 30); |
| 9470 | |
| 9471 | // In the rare situation where FindBestWheelingWindow() had to defer first frame of wheeling due to ambiguous main axis, reinject it now. |
| 9472 | wheel += g.WheelingWindowWheelRemainder; |
| 9473 | g.WheelingWindowWheelRemainder = ImVec2(0.0f, 0.0f); |
| 9474 | if (wheel.x == 0.0f && wheel.y == 0.0f) |
nothing calls this directly
no test coverage detected