MCPcopy Create free account
hub / github.com/brenocq/implot3d / GetMouseOverAxis

Function GetMouseOverAxis

implot3d.cpp:658–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

656}
657
658int GetMouseOverAxis(const ImPlot3DPlot& plot, const ImVec2* corners_pix, const int plane_2d, const int axis_corners[3][2], int* edge_out = nullptr) {
659 ImGuiIO& io = ImGui::GetIO();
660 ImVec2 mouse_pos = io.MousePos;
661 if (edge_out)
662 *edge_out = -1;
663
664 // Compute box center in screen space (average of all corners)
665 ImVec2 box_center(0, 0);
666 for (int i = 0; i < 8; i++)
667 box_center = box_center + corners_pix[i];
668 box_center = box_center * (1.0f / 8.0f);
669
670 // Check each axis for mouse containment in hover rectangle
671 for (int axis_idx = 0; axis_idx < 3; axis_idx++) {
672 // In 2D mode, skip the perpendicular axis
673 if (plane_2d != -1 && axis_idx == plane_2d)
674 continue;
675
676 int idx0 = axis_corners[axis_idx][0];
677 int idx1 = axis_corners[axis_idx][1];
678
679 // Skip if axis corners are not defined
680 if (idx0 == -1 || idx1 == -1)
681 continue;
682
683 // Find the edge index for these two corners
684 int edge = -1;
685 for (int e = 0; e < 12; e++) {
686 if ((edges[e][0] == idx0 && edges[e][1] == idx1) || (edges[e][0] == idx1 && edges[e][1] == idx0)) {
687 edge = e;
688 break;
689 }
690 }
691
692 if (edge == -1)
693 continue;
694
695 ImVec2 p0 = corners_pix[idx0];
696 ImVec2 p1 = corners_pix[idx1];
697 ImVec2 outward_dir = ComputeEdgeOutwardDir(p0, p1, box_center);
698 float hover_width = ComputeAxisHoverWidth(plot.Axes[axis_idx]);
699
700 // Check if mouse is within the edge's hover region
701 if (IsPointInEdgeHoverRegion(mouse_pos, p0, p1, outward_dir, hover_width)) {
702 if (edge_out)
703 *edge_out = edge;
704 return axis_idx;
705 }
706 }
707
708 return -1; // Not over any axis
709}
710
711void RenderPlotBackground(ImDrawList* draw_list, const ImPlot3DPlot& plot, const ImVec2* corners_pix, const bool* active_faces, const int plane_2d,
712 const int axis_corners[3][2]) {

Callers 3

RenderPlotBackgroundFunction · 0.85
RenderAxisRectsFunction · 0.85
HandleInputFunction · 0.85

Calls 3

ComputeEdgeOutwardDirFunction · 0.85
ComputeAxisHoverWidthFunction · 0.85
IsPointInEdgeHoverRegionFunction · 0.85

Tested by

no test coverage detected