| 2315 | static const float MOUSE_CURSOR_DRAG_THRESHOLD = 5.0f; |
| 2316 | |
| 2317 | void HandleInput(ImPlot3DPlot& plot) { |
| 2318 | if (ImHasFlag(plot.Flags, ImPlot3DFlags_NoInputs)) |
| 2319 | return; |
| 2320 | |
| 2321 | ImGuiIO& IO = ImGui::GetIO(); |
| 2322 | |
| 2323 | // clang-format off |
| 2324 | const ImGuiButtonFlags plot_button_flags = ImGuiButtonFlags_AllowOverlap |
| 2325 | | ImGuiButtonFlags_PressedOnClick |
| 2326 | | ImGuiButtonFlags_PressedOnDoubleClick |
| 2327 | | ImGuiButtonFlags_MouseButtonLeft |
| 2328 | | ImGuiButtonFlags_MouseButtonRight |
| 2329 | | ImGuiButtonFlags_MouseButtonMiddle; |
| 2330 | // clang-format on |
| 2331 | const bool plot_clicked = ImGui::ButtonBehavior(plot.PlotRect, plot.ID, &plot.Hovered, &plot.Held, plot_button_flags); |
| 2332 | #if (IMGUI_VERSION_NUM < 18966) |
| 2333 | ImGui::SetItemAllowOverlap(); // Handled by ButtonBehavior() |
| 2334 | #endif |
| 2335 | |
| 2336 | // State |
| 2337 | const ImVec2 rot_drag = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right); |
| 2338 | const bool rotating = ImLengthSqr(rot_drag) > MOUSE_CURSOR_DRAG_THRESHOLD; |
| 2339 | const bool axis_equal = ImHasFlag(plot.Flags, ImPlot3DFlags_Equal); |
| 2340 | const bool allow_rotate = !ImHasFlag(plot.Flags, ImPlot3DFlags_NoRotate); |
| 2341 | const bool allow_pan = !ImHasFlag(plot.Flags, ImPlot3DFlags_NoPan); |
| 2342 | const bool allow_zoom = !ImHasFlag(plot.Flags, ImPlot3DFlags_NoZoom); |
| 2343 | |
| 2344 | // HOVERING STATE ------------------------------------------------------------------- |
| 2345 | |
| 2346 | // Check if any axis/plane is hovered |
| 2347 | bool active_faces[3]; |
| 2348 | ImVec2 corners_pix[8]; |
| 2349 | ImPlot3DPoint corners[8]; |
| 2350 | int plane_2d; |
| 2351 | int axis_corners[3][2]; |
| 2352 | GetAxesParameters(plot, active_faces, corners_pix, corners, plane_2d, axis_corners); |
| 2353 | int hovered_plane_idx = -1; |
| 2354 | int hovered_plane = GetMouseOverPlane(active_faces, corners_pix, &hovered_plane_idx); |
| 2355 | int hovered_edge_idx = -1; |
| 2356 | int hovered_axis = GetMouseOverAxis(plot, corners_pix, plane_2d, axis_corners, &hovered_edge_idx); |
| 2357 | if (hovered_axis != -1) { |
| 2358 | hovered_plane_idx = -1; |
| 2359 | hovered_plane = -1; |
| 2360 | } |
| 2361 | |
| 2362 | // If the user is no longer pressing the translation/zoom buttons, set axes as not held |
| 2363 | if (!ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDown(ImGuiMouseButton_Middle)) { |
| 2364 | for (int i = 0; i < 3; i++) |
| 2365 | plot.Axes[i].Held = false; |
| 2366 | } |
| 2367 | |
| 2368 | // Reset held edge/plane indices (it will be set if mouse button is down) |
| 2369 | if (!plot.Held) { |
| 2370 | plot.HeldEdgeIdx = -1; |
| 2371 | plot.HeldPlaneIdx = -1; |
| 2372 | } |
| 2373 | |
| 2374 | // Check which axes should be transformed (fit/zoom/translate) |
no test coverage detected