| 4355 | } |
| 4356 | |
| 4357 | void ImGui::UpdateMouseWheel() |
| 4358 | { |
| 4359 | ImGuiContext& g = *GImGui; |
| 4360 | |
| 4361 | // Reset the locked window if we move the mouse or after the timer elapses |
| 4362 | if (g.WheelingWindow != NULL) |
| 4363 | { |
| 4364 | g.WheelingWindowReleaseTimer -= g.IO.DeltaTime; |
| 4365 | if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold) |
| 4366 | g.WheelingWindowReleaseTimer = 0.0f; |
| 4367 | if (g.WheelingWindowReleaseTimer <= 0.0f) |
| 4368 | LockWheelingWindow(NULL, 0.0f); |
| 4369 | } |
| 4370 | |
| 4371 | ImVec2 wheel; |
| 4372 | wheel.x = TestKeyOwner(ImGuiKey_MouseWheelX, ImGuiKeyOwner_None) ? g.IO.MouseWheelH : 0.0f; |
| 4373 | wheel.y = TestKeyOwner(ImGuiKey_MouseWheelY, ImGuiKeyOwner_None) ? g.IO.MouseWheel : 0.0f; |
| 4374 | if (wheel.x == 0.0f && wheel.y == 0.0f) |
| 4375 | return; |
| 4376 | |
| 4377 | //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y); |
| 4378 | ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; |
| 4379 | if (!mouse_window || mouse_window->Collapsed) |
| 4380 | return; |
| 4381 | |
| 4382 | // Zoom / Scale window |
| 4383 | // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. |
| 4384 | if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) |
| 4385 | { |
| 4386 | LockWheelingWindow(mouse_window, wheel.y); |
| 4387 | ImGuiWindow* window = mouse_window; |
| 4388 | const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); |
| 4389 | const float scale = new_font_scale / window->FontWindowScale; |
| 4390 | window->FontWindowScale = new_font_scale; |
| 4391 | if (window == window->RootWindow) |
| 4392 | { |
| 4393 | const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; |
| 4394 | SetWindowPos(window, window->Pos + offset, 0); |
| 4395 | window->Size = ImFloor(window->Size * scale); |
| 4396 | window->SizeFull = ImFloor(window->SizeFull * scale); |
| 4397 | } |
| 4398 | return; |
| 4399 | } |
| 4400 | if (g.IO.KeyCtrl) |
| 4401 | return; |
| 4402 | |
| 4403 | // Mouse wheel scrolling |
| 4404 | // As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead |
| 4405 | // (we avoid doing it on OSX as it the OS input layer handles this already) |
| 4406 | const bool swap_axis = g.IO.KeyShift && !g.IO.ConfigMacOSXBehaviors; |
| 4407 | if (swap_axis) |
| 4408 | { |
| 4409 | wheel.x = wheel.y; |
| 4410 | wheel.y = 0.0f; |
| 4411 | } |
| 4412 | |
| 4413 | // Vertical Mouse Wheel scrolling |
| 4414 | // Bubble up into parent window if: |
nothing calls this directly
no test coverage detected