Demonstrate using the low-level ImDrawList to draw custom shapes.
| 9827 | |
| 9828 | // Demonstrate using the low-level ImDrawList to draw custom shapes. |
| 9829 | static void ShowExampleAppCustomRendering(bool* p_open) |
| 9830 | { |
| 9831 | if (!ImGui::Begin("Example: Custom rendering", p_open)) |
| 9832 | { |
| 9833 | ImGui::End(); |
| 9834 | return; |
| 9835 | } |
| 9836 | IMGUI_DEMO_MARKER("Examples/Custom Rendering"); |
| 9837 | |
| 9838 | // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of |
| 9839 | // overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your |
| 9840 | // types and ImVec2/ImVec4. Dear ImGui defines overloaded operators but they are internal to imgui.cpp and not |
| 9841 | // exposed outside (to avoid messing with your types) In this example we are not using the maths operators! |
| 9842 | |
| 9843 | if (ImGui::BeginTabBar("##TabBar")) |
| 9844 | { |
| 9845 | if (ImGui::BeginTabItem("Primitives")) |
| 9846 | { |
| 9847 | ImGui::PushItemWidth(-ImGui::GetFontSize() * 15); |
| 9848 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
| 9849 | |
| 9850 | // Draw gradients |
| 9851 | // (note that those are currently exacerbating our sRGB/Linear issues) |
| 9852 | // Calling ImGui::GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the IM_COL32() directly as well.. |
| 9853 | ImGui::Text("Gradients"); |
| 9854 | ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), ImGui::GetFrameHeight()); |
| 9855 | { |
| 9856 | ImVec2 p0 = ImGui::GetCursorScreenPos(); |
| 9857 | ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y); |
| 9858 | ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)); |
| 9859 | ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)); |
| 9860 | draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); |
| 9861 | ImGui::InvisibleButton("##gradient1", gradient_size); |
| 9862 | } |
| 9863 | { |
| 9864 | ImVec2 p0 = ImGui::GetCursorScreenPos(); |
| 9865 | ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y); |
| 9866 | ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 255, 0, 255)); |
| 9867 | ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 0, 0, 255)); |
| 9868 | draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); |
| 9869 | ImGui::InvisibleButton("##gradient2", gradient_size); |
| 9870 | } |
| 9871 | |
| 9872 | // Draw a bunch of primitives |
| 9873 | ImGui::Text("All primitives"); |
| 9874 | static float sz = 36.0f; |
| 9875 | static float thickness = 3.0f; |
| 9876 | static int ngon_sides = 6; |
| 9877 | static bool circle_segments_override = false; |
| 9878 | static int circle_segments_override_v = 12; |
| 9879 | static bool curve_segments_override = false; |
| 9880 | static int curve_segments_override_v = 8; |
| 9881 | static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f); |
| 9882 | ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 100.0f, "%.0f"); |
| 9883 | ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f"); |
| 9884 | ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12); |
| 9885 | ImGui::Checkbox("##circlesegmentoverride", &circle_segments_override); |
| 9886 | ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); |
no test coverage detected