MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / ShowExampleAppCustomRendering

Function ShowExampleAppCustomRendering

external/imgui/imgui_demo.cpp:10165–10468  ·  view source on GitHub ↗

Demonstrate using the low-level ImDrawList to draw custom shapes.

Source from the content-addressed store, hash-verified

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

Callers 1

ShowDemoWindowMethod · 0.85

Calls 15

ImVec2Function · 0.85
ImVec4Class · 0.85
ImColorClass · 0.85
PathConcaveShapeFunction · 0.85
HelpMarkerFunction · 0.85
GetForegroundDrawListFunction · 0.85
AddNgonMethod · 0.80
AddCircleMethod · 0.80
AddEllipseMethod · 0.80
AddTriangleMethod · 0.80
PathStrokeMethod · 0.80

Tested by

no test coverage detected