Retrieve the drop rectangles for a given direction or for the center + perform hit testing.
| 19828 | |
| 19829 | // Retrieve the drop rectangles for a given direction or for the center + perform hit testing. |
| 19830 | bool ImGui::DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir dir, ImRect& out_r, bool outer_docking, ImVec2* test_mouse_pos) |
| 19831 | { |
| 19832 | ImGuiContext& g = *GImGui; |
| 19833 | |
| 19834 | const float parent_smaller_axis = ImMin(parent.GetWidth(), parent.GetHeight()); |
| 19835 | const float hs_for_central_nodes = ImMin(g.FontSize * 1.5f, ImMax(g.FontSize * 0.5f, parent_smaller_axis / 8.0f)); |
| 19836 | float hs_w; // Half-size, longer axis |
| 19837 | float hs_h; // Half-size, smaller axis |
| 19838 | ImVec2 off; // Distance from edge or center |
| 19839 | if (outer_docking) |
| 19840 | { |
| 19841 | //hs_w = ImTrunc(ImClamp(parent_smaller_axis - hs_for_central_nodes * 4.0f, g.FontSize * 0.5f, g.FontSize * 8.0f)); |
| 19842 | //hs_h = ImTrunc(hs_w * 0.15f); |
| 19843 | //off = ImVec2(ImTrunc(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h), ImTrunc(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h)); |
| 19844 | hs_w = ImTrunc(hs_for_central_nodes * 1.50f); |
| 19845 | hs_h = ImTrunc(hs_for_central_nodes * 0.80f); |
| 19846 | off = ImTrunc(ImVec2(parent.GetWidth() * 0.5f - hs_h, parent.GetHeight() * 0.5f - hs_h)); |
| 19847 | } |
| 19848 | else |
| 19849 | { |
| 19850 | hs_w = ImTrunc(hs_for_central_nodes); |
| 19851 | hs_h = ImTrunc(hs_for_central_nodes * 0.90f); |
| 19852 | off = ImTrunc(ImVec2(hs_w * 2.40f, hs_w * 2.40f)); |
| 19853 | } |
| 19854 | |
| 19855 | ImVec2 c = ImTrunc(parent.GetCenter()); |
| 19856 | if (dir == ImGuiDir_None) { out_r = ImRect(c.x - hs_w, c.y - hs_w, c.x + hs_w, c.y + hs_w); } |
| 19857 | else if (dir == ImGuiDir_Up) { out_r = ImRect(c.x - hs_w, c.y - off.y - hs_h, c.x + hs_w, c.y - off.y + hs_h); } |
| 19858 | else if (dir == ImGuiDir_Down) { out_r = ImRect(c.x - hs_w, c.y + off.y - hs_h, c.x + hs_w, c.y + off.y + hs_h); } |
| 19859 | else if (dir == ImGuiDir_Left) { out_r = ImRect(c.x - off.x - hs_h, c.y - hs_w, c.x - off.x + hs_h, c.y + hs_w); } |
| 19860 | else if (dir == ImGuiDir_Right) { out_r = ImRect(c.x + off.x - hs_h, c.y - hs_w, c.x + off.x + hs_h, c.y + hs_w); } |
| 19861 | |
| 19862 | if (test_mouse_pos == NULL) |
| 19863 | return false; |
| 19864 | |
| 19865 | ImRect hit_r = out_r; |
| 19866 | if (!outer_docking) |
| 19867 | { |
| 19868 | // Custom hit testing for the 5-way selection, designed to reduce flickering when moving diagonally between sides |
| 19869 | hit_r.Expand(ImTrunc(hs_w * 0.30f)); |
| 19870 | ImVec2 mouse_delta = (*test_mouse_pos - c); |
| 19871 | float mouse_delta_len2 = ImLengthSqr(mouse_delta); |
| 19872 | float r_threshold_center = hs_w * 1.4f; |
| 19873 | float r_threshold_sides = hs_w * (1.4f + 1.2f); |
| 19874 | if (mouse_delta_len2 < r_threshold_center * r_threshold_center) |
| 19875 | return (dir == ImGuiDir_None); |
| 19876 | if (mouse_delta_len2 < r_threshold_sides * r_threshold_sides) |
| 19877 | return (dir == ImGetDirQuadrantFromDelta(mouse_delta.x, mouse_delta.y)); |
| 19878 | } |
| 19879 | return hit_r.Contains(*test_mouse_pos); |
| 19880 | } |
| 19881 | |
| 19882 | // host_node may be NULL if the window doesn't have a DockNode already. |
| 19883 | // FIXME-DOCK: This is misnamed since it's also doing the filtering. |
nothing calls this directly
no test coverage detected