MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / RenderRectFilledRangeH

Method RenderRectFilledRangeH

lib/imgui/imgui_draw.cpp:3189–3247  ·  view source on GitHub ↗

FIXME: Cleanup and move code to ImDrawList.

Source from the content-addressed store, hash-verified

3187
3188// FIXME: Cleanup and move code to ImDrawList.
3189void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding)
3190{
3191 if (x_end_norm == x_start_norm)
3192 return;
3193 if (x_start_norm > x_end_norm)
3194 ImSwap(x_start_norm, x_end_norm);
3195
3196 ImVec2 p0 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_start_norm), rect.Min.y);
3197 ImVec2 p1 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_end_norm), rect.Max.y);
3198 if (rounding == 0.0f)
3199 {
3200 draw_list->AddRectFilled(p0, p1, col, 0.0f);
3201 return;
3202 }
3203
3204 rounding = ImClamp(ImMin((rect.Max.x - rect.Min.x) * 0.5f, (rect.Max.y - rect.Min.y) * 0.5f) - 1.0f, 0.0f, rounding);
3205 const float inv_rounding = 1.0f / rounding;
3206 const float arc0_b = ImAcos01(1.0f - (p0.x - rect.Min.x) * inv_rounding);
3207 const float arc0_e = ImAcos01(1.0f - (p1.x - rect.Min.x) * inv_rounding);
3208 const float half_pi = IM_PI * 0.5f; // We will == compare to this because we know this is the exact value ImAcos01 can return.
3209 const float x0 = ImMax(p0.x, rect.Min.x + rounding);
3210 if (arc0_b == arc0_e)
3211 {
3212 draw_list->PathLineTo(ImVec2(x0, p1.y));
3213 draw_list->PathLineTo(ImVec2(x0, p0.y));
3214 }
3215 else if (arc0_b == 0.0f && arc0_e == half_pi)
3216 {
3217 draw_list->PathArcToFast(ImVec2(x0, p1.y - rounding), rounding, 3, 6); // BL
3218 draw_list->PathArcToFast(ImVec2(x0, p0.y + rounding), rounding, 6, 9); // TR
3219 }
3220 else
3221 {
3222 draw_list->PathArcTo(ImVec2(x0, p1.y - rounding), rounding, IM_PI - arc0_e, IM_PI - arc0_b, 3); // BL
3223 draw_list->PathArcTo(ImVec2(x0, p0.y + rounding), rounding, IM_PI + arc0_b, IM_PI + arc0_e, 3); // TR
3224 }
3225 if (p1.x > rect.Min.x + rounding)
3226 {
3227 const float arc1_b = ImAcos01(1.0f - (rect.Max.x - p1.x) * inv_rounding);
3228 const float arc1_e = ImAcos01(1.0f - (rect.Max.x - p0.x) * inv_rounding);
3229 const float x1 = ImMin(p1.x, rect.Max.x - rounding);
3230 if (arc1_b == arc1_e)
3231 {
3232 draw_list->PathLineTo(ImVec2(x1, p0.y));
3233 draw_list->PathLineTo(ImVec2(x1, p1.y));
3234 }
3235 else if (arc1_b == 0.0f && arc1_e == half_pi)
3236 {
3237 draw_list->PathArcToFast(ImVec2(x1, p0.y + rounding), rounding, 9, 12); // TR
3238 draw_list->PathArcToFast(ImVec2(x1, p1.y - rounding), rounding, 0, 3); // BR
3239 }
3240 else
3241 {
3242 draw_list->PathArcTo(ImVec2(x1, p0.y + rounding), rounding, -arc1_e, -arc1_b, 3); // TR
3243 draw_list->PathArcTo(ImVec2(x1, p1.y - rounding), rounding, +arc1_b, +arc1_e, 3); // BR
3244 }
3245 }
3246 draw_list->PathFillConvex(col);

Callers

nothing calls this directly

Calls 12

ImSwapFunction · 0.85
ImVec2Class · 0.85
ImLerpFunction · 0.85
ImClampFunction · 0.85
ImMinFunction · 0.85
ImAcos01Function · 0.85
ImMaxFunction · 0.85
AddRectFilledMethod · 0.80
PathLineToMethod · 0.80
PathArcToFastMethod · 0.80
PathArcToMethod · 0.80
PathFillConvexMethod · 0.80

Tested by

no test coverage detected