| 3812 | } |
| 3813 | |
| 3814 | void ImGui::UpdateMouseWheel() |
| 3815 | { |
| 3816 | ImGuiContext& g = *GImGui; |
| 3817 | |
| 3818 | // Reset the locked window if we move the mouse or after the timer elapses |
| 3819 | if (g.WheelingWindow != NULL) |
| 3820 | { |
| 3821 | g.WheelingWindowTimer -= g.IO.DeltaTime; |
| 3822 | if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold) |
| 3823 | g.WheelingWindowTimer = 0.0f; |
| 3824 | if (g.WheelingWindowTimer <= 0.0f) |
| 3825 | { |
| 3826 | g.WheelingWindow = NULL; |
| 3827 | g.WheelingWindowTimer = 0.0f; |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | if (g.IO.MouseWheel == 0.0f && g.IO.MouseWheelH == 0.0f) |
| 3832 | return; |
| 3833 | |
| 3834 | if ((g.ActiveId != 0 && g.ActiveIdUsingMouseWheel) || (g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrameUsingMouseWheel)) |
| 3835 | return; |
| 3836 | |
| 3837 | ImGuiWindow* window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; |
| 3838 | if (!window || window->Collapsed) |
| 3839 | return; |
| 3840 | |
| 3841 | // Zoom / Scale window |
| 3842 | // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. |
| 3843 | if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) |
| 3844 | { |
| 3845 | StartLockWheelingWindow(window); |
| 3846 | const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); |
| 3847 | const float scale = new_font_scale / window->FontWindowScale; |
| 3848 | window->FontWindowScale = new_font_scale; |
| 3849 | if (window == window->RootWindow) |
| 3850 | { |
| 3851 | const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; |
| 3852 | SetWindowPos(window, window->Pos + offset, 0); |
| 3853 | window->Size = ImFloor(window->Size * scale); |
| 3854 | window->SizeFull = ImFloor(window->SizeFull * scale); |
| 3855 | } |
| 3856 | return; |
| 3857 | } |
| 3858 | |
| 3859 | // Mouse wheel scrolling |
| 3860 | // If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent |
| 3861 | if (g.IO.KeyCtrl) |
| 3862 | return; |
| 3863 | |
| 3864 | // As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead |
| 3865 | // (we avoid doing it on OSX as it the OS input layer handles this already) |
| 3866 | const bool swap_axis = g.IO.KeyShift && !g.IO.ConfigMacOSXBehaviors; |
| 3867 | const float wheel_y = swap_axis ? 0.0f : g.IO.MouseWheel; |
| 3868 | const float wheel_x = swap_axis ? g.IO.MouseWheel : g.IO.MouseWheelH; |
| 3869 | |
| 3870 | // Vertical Mouse Wheel scrolling |
| 3871 | if (wheel_y != 0.0f) |
nothing calls this directly
no test coverage detected