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