MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / ShowExampleAppCustomRendering

Function ShowExampleAppCustomRendering

3rdparty/imgui/src/imgui_demo.cpp:10148–10451  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

ShowDemoWindowMethod · 0.85

Calls 15

BeginFunction · 0.85
EndFunction · 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

Tested by

no test coverage detected