MCPcopy Create free account
hub / github.com/AlexandreRouma/SDRPlusPlus / ShowExampleAppCustomRendering

Function ShowExampleAppCustomRendering

core/src/imgui/imgui_demo.cpp:7204–7438  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

7202
7203// Demonstrate using the low-level ImDrawList to draw custom shapes.
7204static void ShowExampleAppCustomRendering(bool* p_open)
7205{
7206 if (!ImGui::Begin("Example: Custom rendering", p_open))
7207 {
7208 ImGui::End();
7209 return;
7210 }
7211
7212 // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of
7213 // overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your
7214 // types and ImVec2/ImVec4. Dear ImGui defines overloaded operators but they are internal to imgui.cpp and not
7215 // exposed outside (to avoid messing with your types) In this example we are not using the maths operators!
7216
7217 if (ImGui::BeginTabBar("##TabBar"))
7218 {
7219 if (ImGui::BeginTabItem("Primitives"))
7220 {
7221 ImGui::PushItemWidth(-ImGui::GetFontSize() * 15);
7222 ImDrawList* draw_list = ImGui::GetWindowDrawList();
7223
7224 // Draw gradients
7225 // (note that those are currently exacerbating our sRGB/Linear issues)
7226 // Calling ImGui::GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the IM_COL32() directly as well..
7227 ImGui::Text("Gradients");
7228 ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), ImGui::GetFrameHeight());
7229 {
7230 ImVec2 p0 = ImGui::GetCursorScreenPos();
7231 ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y);
7232 ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 0, 0, 255));
7233 ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 255, 255, 255));
7234 draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a);
7235 ImGui::InvisibleButton("##gradient1", gradient_size);
7236 }
7237 {
7238 ImVec2 p0 = ImGui::GetCursorScreenPos();
7239 ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y);
7240 ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 255, 0, 255));
7241 ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 0, 0, 255));
7242 draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a);
7243 ImGui::InvisibleButton("##gradient2", gradient_size);
7244 }
7245
7246 // Draw a bunch of primitives
7247 ImGui::Text("All primitives");
7248 static float sz = 36.0f;
7249 static float thickness = 3.0f;
7250 static int ngon_sides = 6;
7251 static bool circle_segments_override = false;
7252 static int circle_segments_override_v = 12;
7253 static bool curve_segments_override = false;
7254 static int curve_segments_override_v = 8;
7255 static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f);
7256 ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 100.0f, "%.0f");
7257 ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f");
7258 ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12);
7259 ImGui::Checkbox("##circlesegmentoverride", &circle_segments_override);
7260 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
7261 circle_segments_override |= ImGui::SliderInt("Circle segments override", &circle_segments_override_v, 3, 40);

Callers 1

ShowDemoWindowMethod · 0.85

Calls 15

BeginFunction · 0.85
EndFunction · 0.85
ImVec2Function · 0.85
ImVec4Class · 0.85
DragFloatFunction · 0.85
ImColorClass · 0.85
HelpMarkerFunction · 0.85
GetForegroundDrawListFunction · 0.85
AddNgonMethod · 0.80
AddCircleMethod · 0.80
AddRectMethod · 0.80

Tested by

no test coverage detected