|
|
|
@ -1763,7 +1763,7 @@ static void ShowExampleAppManipulatingWindowTitle(bool* opened) |
|
|
|
|
|
|
|
|
|
static void ShowExampleAppCustomRendering(bool* opened) |
|
|
|
|
{ |
|
|
|
|
ImGui::SetNextWindowSize(ImVec2(300,350), ImGuiSetCond_FirstUseEver); |
|
|
|
|
ImGui::SetNextWindowSize(ImVec2(350,560), ImGuiSetCond_FirstUseEver); |
|
|
|
|
if (!ImGui::Begin("Example: Custom rendering", opened)) |
|
|
|
|
{ |
|
|
|
|
ImGui::End(); |
|
|
|
@ -1773,16 +1773,46 @@ static void ShowExampleAppCustomRendering(bool* opened) |
|
|
|
|
// Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc.
|
|
|
|
|
// Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4.
|
|
|
|
|
// ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types)
|
|
|
|
|
// In this example we aren't using the operators.
|
|
|
|
|
// In this example we are not using the maths operators!
|
|
|
|
|
ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
|
|
|
|
|
|
|
|
|
// Primitives
|
|
|
|
|
ImGui::Text("Primitives"); |
|
|
|
|
static float sz = 36.0f; |
|
|
|
|
static ImVec4 col = ImVec4(1.0f,1.0f,0.4f,1.0f); |
|
|
|
|
ImGui::DragFloat("Size", &sz, 0.2f, 1.0f, 72.0f, "%.0f");
|
|
|
|
|
ImGui::ColorEdit3("Color", &col.x); |
|
|
|
|
{ |
|
|
|
|
const ImVec2 p = ImGui::GetCursorScreenPos(); |
|
|
|
|
const ImU32 col32 = ImColor(col); |
|
|
|
|
float x = p.x + 4.0f, y = p.y + 4.0f, spacing = 8.0f; |
|
|
|
|
draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 32); x += sz+spacing; |
|
|
|
|
draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; |
|
|
|
|
draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); x += sz+spacing; |
|
|
|
|
draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32); x += sz+spacing; |
|
|
|
|
draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; |
|
|
|
|
draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32); x += spacing; |
|
|
|
|
draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x+sz*1.3f,y+sz*0.3f), ImVec2(x+sz-sz*1.3f,y+sz-sz*0.3f), ImVec2(x+sz, y+sz), col32, 1.0f); |
|
|
|
|
x = p.x + 4; |
|
|
|
|
y += sz+spacing; |
|
|
|
|
draw_list->AddCircleFilled(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 32); x += sz+spacing; |
|
|
|
|
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; |
|
|
|
|
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); x += sz+spacing; |
|
|
|
|
draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32, 4.0f); x += sz+spacing; |
|
|
|
|
draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 4.0f); x += sz+spacing; |
|
|
|
|
draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32, 4.0f); x += spacing; |
|
|
|
|
draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x+sz*1.3f,y+sz*0.3f), ImVec2(x+sz-sz*1.3f,y+sz-sz*0.3f), ImVec2(x+sz, y+sz), col32, 4.0f); x += sz+spacing; |
|
|
|
|
draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x+sz, y+sz), ImColor(0,0,0), ImColor(255,0,0), ImColor(255,255,0), ImColor(0,255,0)); |
|
|
|
|
ImGui::Dummy(ImVec2((sz+spacing)*8, (sz+spacing)*2)); |
|
|
|
|
} |
|
|
|
|
ImGui::Separator(); |
|
|
|
|
{ |
|
|
|
|
static ImVector<ImVec2> points; |
|
|
|
|
static bool adding_line = false; |
|
|
|
|
ImGui::Text("Canvas example"); |
|
|
|
|
if (ImGui::Button("Clear")) points.clear(); |
|
|
|
|
if (points.Size >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } } |
|
|
|
|
ImGui::Text("Left-click and drag to add lines"); |
|
|
|
|
ImGui::Text("Right-click to undo"); |
|
|
|
|
|
|
|
|
|
ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
|
|
|
|
ImGui::Text("Left-click and drag to add lines,\nRight-click to undo"); |
|
|
|
|
|
|
|
|
|
// Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
|
|
|
|
|
// However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
|
|
|
|
@ -1791,11 +1821,9 @@ static void ShowExampleAppCustomRendering(bool* opened) |
|
|
|
|
ImVec2 canvas_size = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
|
|
|
|
|
if (canvas_size.x < 50.0f) canvas_size.x = 50.0f; |
|
|
|
|
if (canvas_size.y < 50.0f) canvas_size.y = 50.0f; |
|
|
|
|
draw_list->AddRectFilledMultiColor(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(0,0,0), ImColor(255,0,0), ImColor(255,255,0), ImColor(0,255,0)); |
|
|
|
|
draw_list->AddRectFilledMultiColor(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(50,50,50), ImColor(50,50,60), ImColor(60,60,70), ImColor(50,50,60)); |
|
|
|
|
draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(255,255,255)); |
|
|
|
|
|
|
|
|
|
draw_list->AddBezierCurve(ImVec2(canvas_pos.x+20,canvas_pos.y+20), ImVec2(canvas_pos.x+100,canvas_pos.y+20), ImVec2(canvas_pos.x+canvas_size.x-100,canvas_pos.y+canvas_size.y-20), ImVec2(canvas_pos.x+canvas_size.x-20,canvas_pos.y+canvas_size.y-20), ImColor(255,200,0), 5.0f); |
|
|
|
|
|
|
|
|
|
bool adding_preview = false; |
|
|
|
|
ImGui::InvisibleButton("canvas", canvas_size); |
|
|
|
|
if (ImGui::IsItemHovered()) |
|
|
|
@ -1826,6 +1854,7 @@ static void ShowExampleAppCustomRendering(bool* opened) |
|
|
|
|
draw_list->PopClipRect(); |
|
|
|
|
if (adding_preview) |
|
|
|
|
points.pop_back(); |
|
|
|
|
} |
|
|
|
|
ImGui::End(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|