Shadows: Tweak demo to use AddShadowCircle() functions + fix warnings.

(+ stripped old polygon generation code from commits)
# Conflicts:
#	imgui_demo.cpp
This commit is contained in:
omar 2020-06-13 14:48:32 +02:00 committed by ocornut
parent 542f1da1e2
commit 01078a6077
2 changed files with 13 additions and 13 deletions

View File

@ -7618,10 +7618,11 @@ static void ShowExampleAppCustomRendering(bool* p_open)
if (ImGui::BeginTabItem("Shadows")) if (ImGui::BeginTabItem("Shadows"))
{ {
static float shadow_thickness = 40.0f; static float shadow_thickness = 40.0f;
static ImVec4 shadow_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
static bool shadow_filled = false; static bool shadow_filled = false;
static ImVec4 shape_color = ImVec4(0.9f, 0.9f, 0.9f, 1.0f); static ImVec4 shadow_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
static ImVec4 shape_color = ImVec4(0.9f, 0.0f, 0.0f, 1.0f);
static float shape_rounding = 0.0f; static float shape_rounding = 0.0f;
static ImVec4 bg_color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
ImGui::Checkbox("Shadow filled", &shadow_filled); ImGui::Checkbox("Shadow filled", &shadow_filled);
ImGui::SameLine(); ImGui::SameLine();
HelpMarker("This will fill the section behind the shape to shadow. It's often unnecessary and wasteful but provided for consistency."); HelpMarker("This will fill the section behind the shape to shadow. It's often unnecessary and wasteful but provided for consistency.");
@ -7630,12 +7631,14 @@ static void ShowExampleAppCustomRendering(bool* p_open)
ImGui::ColorEdit4("Shadow Color", &shadow_color.x); ImGui::ColorEdit4("Shadow Color", &shadow_color.x);
ImGui::ColorEdit4("Shape Color", &shape_color.x); ImGui::ColorEdit4("Shape Color", &shape_color.x);
ImGui::DragFloat("Shape Rounding", &shape_rounding, 1.0f, 0.0f, 20.0f, "%.02f"); ImGui::DragFloat("Shape Rounding", &shape_rounding, 1.0f, 0.0f, 20.0f, "%.02f");
ImGui::ColorEdit4("Background Color", &bg_color.x);
ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImDrawList* draw_list = ImGui::GetWindowDrawList();
{ {
ImVec2 p = ImGui::GetCursorScreenPos(); ImVec2 p = ImGui::GetCursorScreenPos();
ImVec2 r1(p.x + 50.0f, p.y + 50.0f); ImVec2 r1(p.x + 50.0f, p.y + 50.0f);
ImVec2 r2(p.x + 150.0f, p.y + 150.0f); ImVec2 r2(p.x + 150.0f, p.y + 150.0f);
draw_list->AddRectFilled(p, ImVec2(p.x + 200.0f, p.y + 200.0f), ImGui::GetColorU32(bg_color));
if (shadow_filled) if (shadow_filled)
draw_list->AddShadowRectFilled(r1, r2, shadow_thickness, ImVec2(0.0f, 0.0f), ImGui::GetColorU32(shadow_color)); draw_list->AddShadowRectFilled(r1, r2, shadow_thickness, ImVec2(0.0f, 0.0f), ImGui::GetColorU32(shadow_color));
else else
@ -7644,21 +7647,18 @@ static void ShowExampleAppCustomRendering(bool* p_open)
ImGui::Dummy(ImVec2(200.0f, 200.0f)); ImGui::Dummy(ImVec2(200.0f, 200.0f));
} }
{ {
// FIXME-SHADOWS: We properly need AddShadowCircle() api ?
ImVec2 p = ImGui::GetCursorScreenPos(); ImVec2 p = ImGui::GetCursorScreenPos();
float off = 10.0f; ImVec2 center(p.x + 100.0f, p.y + 100.0f);
ImVec2 r1(p.x + 50.0f + off, p.y + 50.0f + off); float radius = 50.0f;
ImVec2 r2(p.x + 150.0f - off, p.y + 150.0f - off); draw_list->AddRectFilled(p, ImVec2(p.x + 200.0f, p.y + 200.0f), ImGui::GetColorU32(bg_color));
ImVec2 c(p.x + 100.0f, p.y + 100.0f);
if (shadow_filled) if (shadow_filled)
draw_list->AddShadowRectFilled(r1, r2, shadow_thickness, ImVec2(0.0f, 0.0f), ImGui::GetColorU32(shadow_color)); draw_list->AddShadowCircleFilled(center, radius, shadow_thickness, ImVec2(0.0f, 0.0f), ImGui::GetColorU32(shadow_color), 0);
else else
draw_list->AddShadowRect(r1, r2, shadow_thickness, ImVec2(0.0f, 0.0f), ImGui::GetColorU32(shadow_color), 50.0f); draw_list->AddShadowCircle(center, radius, shadow_thickness, ImVec2(0.0f, 0.0f), ImGui::GetColorU32(shadow_color), 0);
draw_list->AddCircleFilled(c, 50.0f, ImGui::GetColorU32(shape_color), 0); draw_list->AddCircleFilled(center, radius, ImGui::GetColorU32(shape_color), 0);
ImGui::Dummy(ImVec2(200.0f, 200.0f)); ImGui::Dummy(ImVec2(200.0f, 200.0f));
} }
ImGui::EndTabItem(); ImGui::EndTabItem();
} }

View File

@ -2210,13 +2210,13 @@ static void AddShadowConvexShapeEx(ImDrawList* draw_list, const ImVec2* points,
ImDrawVert* vtx_write = draw_list->_VtxWritePtr; ImDrawVert* vtx_write = draw_list->_VtxWritePtr;
ImDrawIdx current_idx = (ImDrawIdx)draw_list->_VtxCurrentIdx; ImDrawIdx current_idx = (ImDrawIdx)draw_list->_VtxCurrentIdx;
ImVec2 previous_edge_start = points[0]; //ImVec2 previous_edge_start = points[0];
ImVec2 edge_start = points[0]; ImVec2 edge_start = points[0];
ImVec2 prev_edge_normal = edge_normals[num_edges - 1]; ImVec2 prev_edge_normal = edge_normals[num_edges - 1];
for (int edge_index = 0; edge_index < num_edges; edge_index++) for (int edge_index = 0; edge_index < num_edges; edge_index++)
{ {
ImVec2 edge_end = points[(edge_index + 1) % num_edges]; const ImVec2 edge_end = points[(edge_index + 1) % num_edges];
ImVec2 edge_normal = edge_normals[edge_index]; ImVec2 edge_normal = edge_normals[edge_index];
// Add corner section // Add corner section