FIXME: Cleanup and move code to ImDrawList.
| 3884 | |
| 3885 | // FIXME: Cleanup and move code to ImDrawList. |
| 3886 | void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding) |
| 3887 | { |
| 3888 | if (x_end_norm == x_start_norm) |
| 3889 | return; |
| 3890 | if (x_start_norm > x_end_norm) |
| 3891 | ImSwap(x_start_norm, x_end_norm); |
| 3892 | |
| 3893 | ImVec2 p0 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_start_norm), rect.Min.y); |
| 3894 | ImVec2 p1 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_end_norm), rect.Max.y); |
| 3895 | if (rounding == 0.0f) |
| 3896 | { |
| 3897 | draw_list->AddRectFilled(p0, p1, col, 0.0f); |
| 3898 | return; |
| 3899 | } |
| 3900 | |
| 3901 | rounding = ImClamp(ImMin((rect.Max.x - rect.Min.x) * 0.5f, (rect.Max.y - rect.Min.y) * 0.5f) - 1.0f, 0.0f, rounding); |
| 3902 | const float inv_rounding = 1.0f / rounding; |
| 3903 | const float arc0_b = ImAcos01(1.0f - (p0.x - rect.Min.x) * inv_rounding); |
| 3904 | const float arc0_e = ImAcos01(1.0f - (p1.x - rect.Min.x) * inv_rounding); |
| 3905 | const float half_pi = IM_PI * 0.5f; // We will == compare to this because we know this is the exact value ImAcos01 can return. |
| 3906 | const float x0 = ImMax(p0.x, rect.Min.x + rounding); |
| 3907 | if (arc0_b == arc0_e) |
| 3908 | { |
| 3909 | draw_list->PathLineTo(ImVec2(x0, p1.y)); |
| 3910 | draw_list->PathLineTo(ImVec2(x0, p0.y)); |
| 3911 | } |
| 3912 | else if (arc0_b == 0.0f && arc0_e == half_pi) |
| 3913 | { |
| 3914 | draw_list->PathArcToFast(ImVec2(x0, p1.y - rounding), rounding, 3, 6); // BL |
| 3915 | draw_list->PathArcToFast(ImVec2(x0, p0.y + rounding), rounding, 6, 9); // TR |
| 3916 | } |
| 3917 | else |
| 3918 | { |
| 3919 | draw_list->PathArcTo(ImVec2(x0, p1.y - rounding), rounding, IM_PI - arc0_e, IM_PI - arc0_b, 3); // BL |
| 3920 | draw_list->PathArcTo(ImVec2(x0, p0.y + rounding), rounding, IM_PI + arc0_b, IM_PI + arc0_e, 3); // TR |
| 3921 | } |
| 3922 | if (p1.x > rect.Min.x + rounding) |
| 3923 | { |
| 3924 | const float arc1_b = ImAcos01(1.0f - (rect.Max.x - p1.x) * inv_rounding); |
| 3925 | const float arc1_e = ImAcos01(1.0f - (rect.Max.x - p0.x) * inv_rounding); |
| 3926 | const float x1 = ImMin(p1.x, rect.Max.x - rounding); |
| 3927 | if (arc1_b == arc1_e) |
| 3928 | { |
| 3929 | draw_list->PathLineTo(ImVec2(x1, p0.y)); |
| 3930 | draw_list->PathLineTo(ImVec2(x1, p1.y)); |
| 3931 | } |
| 3932 | else if (arc1_b == 0.0f && arc1_e == half_pi) |
| 3933 | { |
| 3934 | draw_list->PathArcToFast(ImVec2(x1, p0.y + rounding), rounding, 9, 12); // TR |
| 3935 | draw_list->PathArcToFast(ImVec2(x1, p1.y - rounding), rounding, 0, 3); // BR |
| 3936 | } |
| 3937 | else |
| 3938 | { |
| 3939 | draw_list->PathArcTo(ImVec2(x1, p0.y + rounding), rounding, -arc1_e, -arc1_b, 3); // TR |
| 3940 | draw_list->PathArcTo(ImVec2(x1, p1.y - rounding), rounding, +arc1_b, +arc1_e, 3); // BR |
| 3941 | } |
| 3942 | } |
| 3943 | draw_list->PathFillConvex(col); |
nothing calls this directly
no test coverage detected