Demonstrate using the low-level ImDrawList to draw custom shapes.
| 10165 | |
| 10166 | // Demonstrate using the low-level ImDrawList to draw custom shapes. |
| 10167 | static void ShowExampleAppCustomRendering(bool* p_open) |
| 10168 | { |
| 10169 | if (!ImGui::Begin("Example: Custom rendering", p_open)) |
| 10170 | { |
| 10171 | ImGui::End(); |
| 10172 | return; |
| 10173 | } |
| 10174 | IMGUI_DEMO_MARKER("Examples/Custom rendering"); |
| 10175 | |
| 10176 | // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of |
| 10177 | // overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your |
| 10178 | // types and ImVec2/ImVec4. Dear ImGui defines overloaded operators but they are internal to imgui.cpp and not |
| 10179 | // exposed outside (to avoid messing with your types) In this example we are not using the maths operators! |
| 10180 | |
| 10181 | if (ImGui::BeginTabBar("##TabBar")) |
| 10182 | { |
| 10183 | if (ImGui::BeginTabItem("Primitives")) |
| 10184 | { |
| 10185 | IMGUI_DEMO_MARKER("Examples/Custom rendering/Primitives"); |
| 10186 | ImGui::PushItemWidth(-ImGui::GetFontSize() * 15); |
| 10187 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
| 10188 | |
| 10189 | // Draw gradients |
| 10190 | // (note that those are currently exacerbating our sRGB/Linear issues) |
| 10191 | // Calling ImGui::GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the IM_COL32() directly as well.. |
| 10192 | ImGui::Text("Gradients"); |
| 10193 | ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), ImGui::GetFrameHeight()); |
| 10194 | { |
| 10195 | ImVec2 p0 = ImGui::GetCursorScreenPos(); |
| 10196 | ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y); |
| 10197 | ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)); |
| 10198 | ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)); |
| 10199 | draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); |
| 10200 | ImGui::InvisibleButton("##gradient1", gradient_size); |
| 10201 | } |
| 10202 | { |
| 10203 | ImVec2 p0 = ImGui::GetCursorScreenPos(); |
| 10204 | ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y); |
| 10205 | ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 255, 0, 255)); |
| 10206 | ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 0, 0, 255)); |
| 10207 | draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a); |
| 10208 | ImGui::InvisibleButton("##gradient2", gradient_size); |
| 10209 | } |
| 10210 | |
| 10211 | // Draw a bunch of primitives |
| 10212 | ImGui::Text("All primitives"); |
| 10213 | static float sz = 36.0f; |
| 10214 | static float thickness = 3.0f; |
| 10215 | static int ngon_sides = 6; |
| 10216 | static bool circle_segments_override = false; |
| 10217 | static int circle_segments_override_v = 12; |
| 10218 | static bool curve_segments_override = false; |
| 10219 | static int curve_segments_override_v = 8; |
| 10220 | static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f); |
| 10221 | ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 100.0f, "%.0f"); |
| 10222 | ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f"); |
| 10223 | ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12); |
| 10224 | ImGui::Checkbox("##circlesegmentoverride", &circle_segments_override); |
no test coverage detected