Demonstrate using the low-level ImDrawList to draw custom shapes.
| 10048 | |
| 10049 | // Demonstrate using the low-level ImDrawList to draw custom shapes. |
| 10050 | static void ShowExampleAppCustomRendering(bool* p_open) |
| 10051 | { |
| 10052 | if (!ImGui::Begin("Example: Custom rendering", p_open)) |
| 10053 | { |
| 10054 | ImGui::End(); |
| 10055 | return; |
| 10056 | } |
| 10057 | IMGUI_DEMO_MARKER("Examples/Custom rendering"); |
| 10058 | |
| 10059 | // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of |
| 10060 | // overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your |
| 10061 | // types and ImVec2/ImVec4. Dear ImGui defines overloaded operators but they are internal to imgui.cpp and not |
| 10062 | // exposed outside (to avoid messing with your types) In this example we are not using the maths operators! |
| 10063 | |
| 10064 | if (ImGui::BeginTabBar("##TabBar")) |
| 10065 | { |
| 10066 | if (ImGui::BeginTabItem("Primitives")) |
| 10067 | { |
| 10068 | IMGUI_DEMO_MARKER("Examples/Custom rendering/Primitives"); |
| 10069 | ImGui::PushItemWidth(-ImGui::GetFontSize() * 15); |
| 10070 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
| 10071 | |
| 10072 | // Draw gradients |
| 10073 | // (note that those are currently exacerbating our sRGB/Linear issues) |
| 10074 | // Calling ImGui::GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the IM_COL32() directly as well.. |
| 10075 | ImGui::Text("Gradients"); |
| 10076 | ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), ImGui::GetFrameHeight()); |
| 10077 | { |
| 10078 | ImVec2 p0 = ImGui::GetCursorScreenPos(); |
| 10079 | ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y); |
| 10080 | ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)); |
| 10081 | ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)); |
| 10082 | draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); |
| 10083 | ImGui::InvisibleButton("##gradient1", gradient_size); |
| 10084 | } |
| 10085 | { |
| 10086 | ImVec2 p0 = ImGui::GetCursorScreenPos(); |
| 10087 | ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y); |
| 10088 | ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 255, 0, 255)); |
| 10089 | ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 0, 0, 255)); |
| 10090 | draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); |
| 10091 | ImGui::InvisibleButton("##gradient2", gradient_size); |
| 10092 | } |
| 10093 | |
| 10094 | // Draw a bunch of primitives |
| 10095 | ImGui::Text("All primitives"); |
| 10096 | static float sz = 36.0f; |
| 10097 | static float thickness = 3.0f; |
| 10098 | static int ngon_sides = 6; |
| 10099 | static bool circle_segments_override = false; |
| 10100 | static int circle_segments_override_v = 12; |
| 10101 | static bool curve_segments_override = false; |
| 10102 | static int curve_segments_override_v = 8; |
| 10103 | static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f); |
| 10104 | ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 100.0f, "%.0f"); |
| 10105 | ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f"); |
| 10106 | ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12); |
| 10107 | ImGui::Checkbox("##circlesegmentoverride", &circle_segments_override); |
no test coverage detected