mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-25 21:17:01 +00:00
Shadows: Fixes + two fixes for PVS Studio static analyzer.
This commit is contained in:
parent
5ee0af776a
commit
e3dc0c4001
@ -7701,92 +7701,72 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
ImGui::Dummy(ImVec2(200.0f, 200.0f));
|
||||
|
||||
const ImVec2 poly_centre(pos.x + 50.0f, pos.y + 100.0f);
|
||||
ImVec2* poly_points;
|
||||
int num_poly_points;
|
||||
ImVec2 poly_points[8];
|
||||
int poly_points_count = 0;
|
||||
|
||||
switch (poly_shape_index)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
{
|
||||
ImVec2 poly_point_data[] =
|
||||
{
|
||||
ImVec2(poly_centre.x - 32.0f, poly_centre.y),
|
||||
ImVec2(poly_centre.x - 24.0f, poly_centre.y + 24.0f),
|
||||
ImVec2(poly_centre.x, poly_centre.y + 32.0f),
|
||||
ImVec2(poly_centre.x + 24.0f, poly_centre.y + 24.0f),
|
||||
ImVec2(poly_centre.x + 32.0f, poly_centre.y),
|
||||
ImVec2(poly_centre.x + 24.0f, poly_centre.y - 24.0f),
|
||||
ImVec2(poly_centre.x, poly_centre.y - 32.0f),
|
||||
ImVec2(poly_centre.x - 32.0f, poly_centre.y - 32.0f)
|
||||
};
|
||||
poly_points = poly_point_data;
|
||||
num_poly_points = 8;
|
||||
poly_points[0] = ImVec2(poly_centre.x - 32.0f, poly_centre.y);
|
||||
poly_points[1] = ImVec2(poly_centre.x - 24.0f, poly_centre.y + 24.0f);
|
||||
poly_points[2] = ImVec2(poly_centre.x, poly_centre.y + 32.0f);
|
||||
poly_points[3] = ImVec2(poly_centre.x + 24.0f, poly_centre.y + 24.0f);
|
||||
poly_points[4] = ImVec2(poly_centre.x + 32.0f, poly_centre.y);
|
||||
poly_points[5] = ImVec2(poly_centre.x + 24.0f, poly_centre.y - 24.0f);
|
||||
poly_points[6] = ImVec2(poly_centre.x, poly_centre.y - 32.0f);
|
||||
poly_points[7] = ImVec2(poly_centre.x - 32.0f, poly_centre.y - 32.0f);
|
||||
poly_points_count = 8;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
ImVec2 poly_point_data[] =
|
||||
{
|
||||
ImVec2(poly_centre.x + 40.0f, poly_centre.y - 20.0f),
|
||||
ImVec2(poly_centre.x, poly_centre.y + 32.0f),
|
||||
ImVec2(poly_centre.x - 24.0f, poly_centre.y - 32.0f)
|
||||
};
|
||||
poly_points = poly_point_data;
|
||||
num_poly_points = 3;
|
||||
poly_points[0] = ImVec2(poly_centre.x + 40.0f, poly_centre.y - 20.0f);
|
||||
poly_points[1] = ImVec2(poly_centre.x, poly_centre.y + 32.0f);
|
||||
poly_points[2] = ImVec2(poly_centre.x - 24.0f, poly_centre.y - 32.0f);
|
||||
poly_points_count = 3;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
ImVec2 poly_point_data[] =
|
||||
{
|
||||
ImVec2(poly_centre.x - 32.0f, poly_centre.y),
|
||||
ImVec2(poly_centre.x, poly_centre.y + 32.0f),
|
||||
ImVec2(poly_centre.x + 32.0f, poly_centre.y),
|
||||
ImVec2(poly_centre.x, poly_centre.y - 32.0f)
|
||||
};
|
||||
poly_points = poly_point_data;
|
||||
num_poly_points = 4;
|
||||
poly_points[0] = ImVec2(poly_centre.x - 32.0f, poly_centre.y);
|
||||
poly_points[1] = ImVec2(poly_centre.x, poly_centre.y + 32.0f);
|
||||
poly_points[2] = ImVec2(poly_centre.x + 32.0f, poly_centre.y);
|
||||
poly_points[3] = ImVec2(poly_centre.x, poly_centre.y - 32.0f);
|
||||
poly_points_count = 4;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
ImVec2 poly_point_data[] =
|
||||
{
|
||||
ImVec2(poly_centre.x - 4.0f, poly_centre.y - 20.0f),
|
||||
ImVec2(poly_centre.x + 12.0f, poly_centre.y + 2.0f),
|
||||
ImVec2(poly_centre.x + 8.0f, poly_centre.y + 16.0f),
|
||||
ImVec2(poly_centre.x, poly_centre.y + 32.0f),
|
||||
ImVec2(poly_centre.x - 16.0f, poly_centre.y - 32.0f)
|
||||
};
|
||||
poly_points = poly_point_data;
|
||||
num_poly_points = 5;
|
||||
poly_points[0] = ImVec2(poly_centre.x - 4.0f, poly_centre.y - 20.0f);
|
||||
poly_points[1] = ImVec2(poly_centre.x + 12.0f, poly_centre.y + 2.0f);
|
||||
poly_points[2] = ImVec2(poly_centre.x + 8.0f, poly_centre.y + 16.0f);
|
||||
poly_points[3] = ImVec2(poly_centre.x, poly_centre.y + 32.0f);
|
||||
poly_points[4] = ImVec2(poly_centre.x - 16.0f, poly_centre.y - 32.0f);
|
||||
poly_points_count = 5;
|
||||
break;
|
||||
}
|
||||
case 4: // Same as test case 3 but with reversed winding
|
||||
{
|
||||
ImVec2 poly_point_data[] =
|
||||
{
|
||||
ImVec2(poly_centre.x - 16.0f, poly_centre.y - 32.0f),
|
||||
ImVec2(poly_centre.x, poly_centre.y + 32.0f),
|
||||
ImVec2(poly_centre.x + 8.0f, poly_centre.y + 16.0f),
|
||||
ImVec2(poly_centre.x + 12.0f, poly_centre.y + 2.0f),
|
||||
ImVec2(poly_centre.x - 4.0f, poly_centre.y - 20.0f)
|
||||
};
|
||||
poly_points = poly_point_data;
|
||||
num_poly_points = 5;
|
||||
poly_points[0] = ImVec2(poly_centre.x - 16.0f, poly_centre.y - 32.0f);
|
||||
poly_points[1] = ImVec2(poly_centre.x, poly_centre.y + 32.0f);
|
||||
poly_points[2] = ImVec2(poly_centre.x + 8.0f, poly_centre.y + 16.0f);
|
||||
poly_points[3] = ImVec2(poly_centre.x + 12.0f, poly_centre.y + 2.0f);
|
||||
poly_points[4] = ImVec2(poly_centre.x - 4.0f, poly_centre.y - 20.0f);
|
||||
poly_points_count = 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME-SHADOWS: Offset forced to zero when shadow is not filled because it isn't supported
|
||||
ImDrawShadowFlags shadow_flags = shadow_filled ? ImDrawShadowFlags_None : ImDrawShadowFlags_CutOutShapeBackground;
|
||||
draw_list->AddShadowConvexPoly(poly_points, num_poly_points, ImGui::GetColorU32(shadow_color), shadow_thickness, shadow_filled ? shadow_offset : ImVec2(0.0f, 0.0f), shadow_flags);
|
||||
draw_list->AddShadowConvexPoly(poly_points, poly_points_count, ImGui::GetColorU32(shadow_color), shadow_thickness, shadow_filled ? shadow_offset : ImVec2(0.0f, 0.0f), shadow_flags);
|
||||
|
||||
if (wireframe)
|
||||
draw_list->AddPolyline(poly_points, num_poly_points, ImGui::GetColorU32(shape_color), true, 1.0f);
|
||||
draw_list->AddPolyline(poly_points, poly_points_count, ImGui::GetColorU32(shape_color), true, 1.0f);
|
||||
else
|
||||
draw_list->AddConvexPolyFilled(poly_points, num_poly_points, ImGui::GetColorU32(shape_color));
|
||||
draw_list->AddConvexPolyFilled(poly_points, poly_points_count, ImGui::GetColorU32(shape_color));
|
||||
}
|
||||
|
||||
draw_list->Flags = old_flags;
|
||||
|
@ -394,8 +394,7 @@ int ImFontAtlasShadowTexConfig::CalcConvexTexWidth() const
|
||||
|
||||
int ImFontAtlasShadowTexConfig::CalcConvexTexHeight() const
|
||||
{
|
||||
// We have to pad the texture enough that we don't go off the edges when we expand the corner triangles
|
||||
return (int)((TexCornerSize / ImCos(IM_PI * 0.25f)) + (GetConvexTexPadding() * 2));
|
||||
return CalcConvexTexWidth(); // Same value
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2217,9 +2216,10 @@ void ImDrawList::AddShadowConvexPoly(const ImVec2* points, int points_count, ImU
|
||||
|
||||
if (cos_angle_coverage < 0.999999f)
|
||||
{
|
||||
// If we are covering more than 90 degrees we need an intermediate vertex to stop the required expansion tending towards infinity, and thus the effective angle will be halved
|
||||
// If we are covering more than 90 degrees we need an intermediate vertex to stop the required expansion tending towards infinity.
|
||||
// And thus the effective angle will be halved (matches the similar code in loop below)
|
||||
float angle_coverage = ImAcos(cos_angle_coverage);
|
||||
if (cos_angle_coverage <= 0.0f)
|
||||
if (cos_angle_coverage <= 0.0f) // -V1051
|
||||
angle_coverage *= 0.5f;
|
||||
edge_size_scales[edge_index] = 1.0f / ImCos(angle_coverage * 0.5f); // How much we need to expand our size by to avoid clipping the corner of the texture off
|
||||
}
|
||||
@ -2258,10 +2258,10 @@ void ImDrawList::AddShadowConvexPoly(const ImVec2* points, int points_count, ImU
|
||||
|
||||
// Add corner section
|
||||
float cos_angle_coverage = ImDot(edge_normal, prev_edge_normal);
|
||||
|
||||
if (cos_angle_coverage < 0.999999f) // Don't fill if the corner is actually straight
|
||||
{
|
||||
// If we are covering more than 90 degrees we need an intermediate vertex to stop the required expansion tending towards infinity
|
||||
// If we are covering more than 90 degrees we need an intermediate vertex to stop the required expansion tending towards infinity.
|
||||
// And thus the effective angle has been halved (matches the similar code in loop above)
|
||||
int num_steps = (cos_angle_coverage <= 0.0f) ? 2 : 1;
|
||||
|
||||
for (int step = 0; step < num_steps; step++)
|
||||
|
Loading…
Reference in New Issue
Block a user