|
|
@@ -1243,7 +1243,7 @@ static void ShowDemoWindowWidgets()
|
|
|
static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
|
|
|
ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
|
|
|
|
|
|
- // Create a dummy array of contiguous float values to plot
|
|
|
+ // Fill an array of contiguous float values to plot
|
|
|
// Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float
|
|
|
// and the sizeof() of your structure in the "stride" parameter.
|
|
|
static float values[90] = {};
|
|
|
@@ -1251,7 +1251,7 @@ static void ShowDemoWindowWidgets()
|
|
|
static double refresh_time = 0.0;
|
|
|
if (!animate || refresh_time == 0.0)
|
|
|
refresh_time = ImGui::GetTime();
|
|
|
- while (refresh_time < ImGui::GetTime()) // Create dummy data at fixed 60 Hz rate for the demo
|
|
|
+ while (refresh_time < ImGui::GetTime()) // Create data at fixed 60 Hz rate for the demo
|
|
|
{
|
|
|
static float phase = 0.0f;
|
|
|
values[values_offset] = cosf(phase);
|
|
|
@@ -1351,7 +1351,7 @@ static void ShowDemoWindowWidgets()
|
|
|
|
|
|
ImGui::Text("Color button with Custom Picker Popup:");
|
|
|
|
|
|
- // Generate a dummy default palette. The palette will persist and can be edited.
|
|
|
+ // Generate a default palette. The palette will persist and can be edited.
|
|
|
static bool saved_palette_init = true;
|
|
|
static ImVec4 saved_palette[32] = {};
|
|
|
if (saved_palette_init)
|
|
|
@@ -1932,8 +1932,8 @@ static void ShowDemoWindowWidgets()
|
|
|
if (embed_all_inside_a_child_window)
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
- static char dummy_str[] = "This is a dummy field to be able to tab-out of the widgets above.";
|
|
|
- ImGui::InputText("dummy", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
|
|
|
+ static char unused_str[] = "This widget is only here to be able to tab-out of the widgets above.";
|
|
|
+ ImGui::InputText("unused", unused_str, IM_ARRAYSIZE(unused_str), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
|
|
// Calling IsItemHovered() after begin returns the hovered status of the title bar.
|
|
|
// This is useful in particular if you want to create a context menu associated to the title bar of a window.
|
|
|
@@ -2376,7 +2376,7 @@ static void ShowDemoWindowLayout()
|
|
|
ImGui::SameLine(0.0f, spacing);
|
|
|
if (ImGui::TreeNode("Node##1"))
|
|
|
{
|
|
|
- // Dummy tree data
|
|
|
+ // Placeholder tree data
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
ImGui::BulletText("Item %d..", i);
|
|
|
ImGui::TreePop();
|
|
|
@@ -2392,7 +2392,7 @@ static void ShowDemoWindowLayout()
|
|
|
ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##2");
|
|
|
if (node_open)
|
|
|
{
|
|
|
- // Dummy tree data
|
|
|
+ // Placeholder tree data
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
ImGui::BulletText("Item %d..", i);
|
|
|
ImGui::TreePop();
|
|
|
@@ -2693,7 +2693,7 @@ static void ShowDemoWindowLayout()
|
|
|
ImGui::TextWrapped("(Click and drag)");
|
|
|
ImVec2 pos = ImGui::GetCursorScreenPos();
|
|
|
ImVec4 clip_rect(pos.x, pos.y, pos.x + size.x, pos.y + size.y);
|
|
|
- ImGui::InvisibleButton("##dummy", size);
|
|
|
+ ImGui::InvisibleButton("##empty", size);
|
|
|
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0))
|
|
|
{
|
|
|
offset.x += ImGui::GetIO().MouseDelta.x;
|
|
|
@@ -2869,8 +2869,8 @@ static void ShowDemoWindowPopups()
|
|
|
ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n");
|
|
|
ImGui::Separator();
|
|
|
|
|
|
- //static int dummy_i = 0;
|
|
|
- //ImGui::Combo("Combo", &dummy_i, "Delete\0Delete harder\0");
|
|
|
+ //static int unused_i = 0;
|
|
|
+ //ImGui::Combo("Combo", &unused_i, "Delete\0Delete harder\0");
|
|
|
|
|
|
static bool dont_ask_me_next_time = false;
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
|
|
@@ -2892,7 +2892,7 @@ static void ShowDemoWindowPopups()
|
|
|
{
|
|
|
if (ImGui::BeginMenu("File"))
|
|
|
{
|
|
|
- if (ImGui::MenuItem("Dummy menu item")) {}
|
|
|
+ if (ImGui::MenuItem("Some menu item")) {}
|
|
|
ImGui::EndMenu();
|
|
|
}
|
|
|
ImGui::EndMenuBar();
|
|
|
@@ -2911,8 +2911,8 @@ static void ShowDemoWindowPopups()
|
|
|
// Also demonstrate passing a bool* to BeginPopupModal(), this will create a regular close button which
|
|
|
// will close the popup. Note that the visibility state of popups is owned by imgui, so the input value
|
|
|
// of the bool actually doesn't matter here.
|
|
|
- bool dummy_open = true;
|
|
|
- if (ImGui::BeginPopupModal("Stacked 2", &dummy_open))
|
|
|
+ bool unused_open = true;
|
|
|
+ if (ImGui::BeginPopupModal("Stacked 2", &unused_open))
|
|
|
{
|
|
|
ImGui::Text("Hello from Stacked The Second!");
|
|
|
if (ImGui::Button("Close"))
|
|
|
@@ -3247,7 +3247,7 @@ static void ShowDemoWindowMisc()
|
|
|
if (ImGui::TreeNode("Tabbing"))
|
|
|
{
|
|
|
ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields.");
|
|
|
- static char buf[32] = "dummy";
|
|
|
+ static char buf[32] = "hello";
|
|
|
ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
|
|
|
ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
|
|
|
ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
|
|
|
@@ -3903,7 +3903,7 @@ static void ShowExampleAppMainMenuBar()
|
|
|
// (future version will add explicit flags to BeginMenu() to request processing shortcuts)
|
|
|
static void ShowExampleMenuFile()
|
|
|
{
|
|
|
- ImGui::MenuItem("(dummy menu)", NULL, false, false);
|
|
|
+ ImGui::MenuItem("(demo menu)", NULL, false, false);
|
|
|
if (ImGui::MenuItem("New")) {}
|
|
|
if (ImGui::MenuItem("Open", "Ctrl+O")) {}
|
|
|
if (ImGui::BeginMenu("Open Recent"))
|
|
|
@@ -4067,8 +4067,8 @@ struct ExampleAppConsole
|
|
|
|
|
|
// TODO: display items starting from the bottom
|
|
|
|
|
|
- if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
|
|
|
- if (ImGui::SmallButton("Add Dummy Error")) { AddLog("[error] something went wrong"); } ImGui::SameLine();
|
|
|
+ if (ImGui::SmallButton("Add Debug Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
|
|
|
+ if (ImGui::SmallButton("Add Debug Error")) { AddLog("[error] something went wrong"); } ImGui::SameLine();
|
|
|
if (ImGui::SmallButton("Clear")) { ClearLog(); } ImGui::SameLine();
|
|
|
bool copy_to_clipboard = ImGui::SmallButton("Copy");
|
|
|
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
|
|
|
@@ -4558,7 +4558,7 @@ static void ShowExampleAppLayout(bool* p_open)
|
|
|
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-static void ShowDummyObject(const char* prefix, int uid)
|
|
|
+static void ShowPlaceholderObject(const char* prefix, int uid)
|
|
|
{
|
|
|
// Use object uid as identifier. Most commonly you could also use the object pointer as a base ID.
|
|
|
ImGui::PushID(uid);
|
|
|
@@ -4570,13 +4570,13 @@ static void ShowDummyObject(const char* prefix, int uid)
|
|
|
ImGui::NextColumn();
|
|
|
if (node_open)
|
|
|
{
|
|
|
- static float dummy_members[8] = { 0.0f, 0.0f, 1.0f, 3.1416f, 100.0f, 999.0f };
|
|
|
+ static float placeholder_members[8] = { 0.0f, 0.0f, 1.0f, 3.1416f, 100.0f, 999.0f };
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
{
|
|
|
ImGui::PushID(i); // Use field index as identifier.
|
|
|
if (i < 2)
|
|
|
{
|
|
|
- ShowDummyObject("Child", 424242);
|
|
|
+ ShowPlaceholderObject("Child", 424242);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -4587,9 +4587,9 @@ static void ShowDummyObject(const char* prefix, int uid)
|
|
|
ImGui::NextColumn();
|
|
|
ImGui::SetNextItemWidth(-1);
|
|
|
if (i >= 5)
|
|
|
- ImGui::InputFloat("##value", &dummy_members[i], 1.0f);
|
|
|
+ ImGui::InputFloat("##value", &placeholder_members[i], 1.0f);
|
|
|
else
|
|
|
- ImGui::DragFloat("##value", &dummy_members[i], 0.01f);
|
|
|
+ ImGui::DragFloat("##value", &placeholder_members[i], 0.01f);
|
|
|
ImGui::NextColumn();
|
|
|
}
|
|
|
ImGui::PopID();
|
|
|
@@ -4619,9 +4619,9 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
|
|
|
ImGui::Columns(2);
|
|
|
ImGui::Separator();
|
|
|
|
|
|
- // Iterate dummy objects with dummy members (all the same data)
|
|
|
+ // Iterate placeholder objects (all the same data)
|
|
|
for (int obj_i = 0; obj_i < 3; obj_i++)
|
|
|
- ShowDummyObject("Object", obj_i);
|
|
|
+ ShowPlaceholderObject("Object", obj_i);
|
|
|
|
|
|
ImGui::Columns(1);
|
|
|
ImGui::Separator();
|
|
|
@@ -4859,31 +4859,32 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
|
|
// overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your
|
|
|
// types and ImVec2/ImVec4. Dear 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 are not using the maths operators!
|
|
|
- ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
|
|
|
|
if (ImGui::BeginTabBar("##TabBar"))
|
|
|
{
|
|
|
if (ImGui::BeginTabItem("Primitives"))
|
|
|
{
|
|
|
ImGui::PushItemWidth(-ImGui::GetFontSize() * 10);
|
|
|
+ ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
|
|
|
|
// Draw gradients
|
|
|
// (note that those are currently exacerbating our sRGB/Linear issues)
|
|
|
+ // Calling ImGui::GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the IM_COL32() directly as well..
|
|
|
ImGui::Text("Gradients");
|
|
|
ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), ImGui::GetFrameHeight());
|
|
|
{
|
|
|
ImVec2 p0 = ImGui::GetCursorScreenPos();
|
|
|
ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y);
|
|
|
- ImU32 col_a = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
|
|
- ImU32 col_b = ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
+ ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 0, 0, 255));
|
|
|
+ ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 255, 255, 255));
|
|
|
draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a);
|
|
|
ImGui::InvisibleButton("##gradient1", gradient_size);
|
|
|
}
|
|
|
{
|
|
|
ImVec2 p0 = ImGui::GetCursorScreenPos();
|
|
|
ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y);
|
|
|
- ImU32 col_a = ImGui::GetColorU32(ImVec4(0.0f, 1.0f, 0.0f, 1.0f));
|
|
|
- ImU32 col_b = ImGui::GetColorU32(ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
|
|
|
+ ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 255, 0, 255));
|
|
|
+ ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 0, 0, 255));
|
|
|
draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a);
|
|
|
ImGui::InvisibleButton("##gradient2", gradient_size);
|
|
|
}
|
|
|
@@ -4904,6 +4905,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
|
|
if (ImGui::SliderInt("Circle segments", &circle_segments_override_v, 3, 40))
|
|
|
circle_segments_override = true;
|
|
|
ImGui::ColorEdit4("Color", &colf.x);
|
|
|
+
|
|
|
const ImVec2 p = ImGui::GetCursorScreenPos();
|
|
|
const ImU32 col = ImColor(colf);
|
|
|
const float spacing = 10.0f;
|
|
|
@@ -4911,94 +4913,137 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
|
|
const ImDrawCornerFlags corners_all = ImDrawCornerFlags_All;
|
|
|
const ImDrawCornerFlags corners_tl_br = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight;
|
|
|
const int circle_segments = circle_segments_override ? circle_segments_override_v : 0;
|
|
|
- float x = p.x + 4.0f, y = p.y + 4.0f;
|
|
|
+ float x = p.x + 4.0f;
|
|
|
+ float y = p.y + 4.0f;
|
|
|
for (int n = 0; n < 2; n++)
|
|
|
{
|
|
|
// First line uses a thickness of 1.0f, second line uses the configurable thickness
|
|
|
float th = (n == 0) ? 1.0f : thickness;
|
|
|
- draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // N-gon
|
|
|
- draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments, th); x += sz + spacing; // Circle
|
|
|
- draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square
|
|
|
- draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners
|
|
|
- draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th); x += sz + spacing; // Square with two rounded corners
|
|
|
- draw_list->AddTriangle(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col, th); x += sz + spacing; // Triangle
|
|
|
- draw_list->AddTriangle(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col, th); x += sz*0.4f + spacing; // Thin triangle
|
|
|
- draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y), col, th); x += sz + spacing; // Horizontal line (note: drawing a filled rectangle will be faster!)
|
|
|
- draw_list->AddLine(ImVec2(x, y), ImVec2(x, y + sz), col, th); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!)
|
|
|
- draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y + sz), col, th); x += sz + spacing; // Diagonal line
|
|
|
+ draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // N-gon
|
|
|
+ draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments, th); x += sz + spacing; // Circle
|
|
|
+ draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square
|
|
|
+ draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners
|
|
|
+ draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th); x += sz + spacing; // Square with two rounded corners
|
|
|
+ draw_list->AddTriangle(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col, th);x += sz + spacing; // Triangle
|
|
|
+ //draw_list->AddTriangle(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col, th);x+= sz*0.4f + spacing; // Thin triangle
|
|
|
+ draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y), col, th); x += sz + spacing; // Horizontal line (note: drawing a filled rectangle will be faster!)
|
|
|
+ draw_list->AddLine(ImVec2(x, y), ImVec2(x, y + sz), col, th); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!)
|
|
|
+ draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y + sz), col, th); x += sz + spacing; // Diagonal line
|
|
|
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), col, th);
|
|
|
x = p.x + 4;
|
|
|
y += sz + spacing;
|
|
|
}
|
|
|
- draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // N-gon
|
|
|
- draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments);x += sz + spacing; // Circle
|
|
|
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square
|
|
|
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners
|
|
|
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br); x += sz + spacing; // Square with two rounded corners
|
|
|
- draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col); x += sz + spacing; // Triangle
|
|
|
- draw_list->AddTriangleFilled(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col); x += sz*0.4f + spacing; // Thin triangle
|
|
|
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + thickness), col); x += sz + spacing; // Horizontal line (faster than AddLine, but only handle integer thickness)
|
|
|
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + thickness, y + sz), col); x += spacing*2.0f; // Vertical line (faster than AddLine, but only handle integer thickness)
|
|
|
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + 1, y + 1), col); x += sz; // Pixel (faster than AddLine)
|
|
|
+ draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // N-gon
|
|
|
+ draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments); x += sz + spacing; // Circle
|
|
|
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square
|
|
|
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners
|
|
|
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br); x += sz + spacing; // Square with two rounded corners
|
|
|
+ draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col); x += sz + spacing; // Triangle
|
|
|
+ //draw_list->AddTriangleFilled(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col); x += sz*0.4f + spacing; // Thin triangle
|
|
|
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + thickness), col); x += sz + spacing; // Horizontal line (faster than AddLine, but only handle integer thickness)
|
|
|
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + thickness, y + sz), col); x += spacing * 2.0f;// Vertical line (faster than AddLine, but only handle integer thickness)
|
|
|
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + 1, y + 1), col); x += sz; // Pixel (faster than AddLine)
|
|
|
draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x + sz, y + sz), IM_COL32(0, 0, 0, 255), IM_COL32(255, 0, 0, 255), IM_COL32(255, 255, 0, 255), IM_COL32(0, 255, 0, 255));
|
|
|
- ImGui::Dummy(ImVec2((sz + spacing) * 9.8f, (sz + spacing) * 3));
|
|
|
|
|
|
+ ImGui::Dummy(ImVec2((sz + spacing) * 8.8f, (sz + spacing) * 3.0f));
|
|
|
ImGui::PopItemWidth();
|
|
|
ImGui::EndTabItem();
|
|
|
}
|
|
|
|
|
|
if (ImGui::BeginTabItem("Canvas"))
|
|
|
{
|
|
|
- static ImVector<ImVec2> points;
|
|
|
+ struct ItemLine { ImVec2 p0, p1; ItemLine(const ImVec2& _p0, const ImVec2& _p1) { p0 = _p0; p1 = _p1; } };
|
|
|
+ static ImVector<ItemLine> lines;
|
|
|
+ static ImVec2 scrolling(0.0f, 0.0f);
|
|
|
+ static bool opt_enable_grid = true;
|
|
|
+ static bool opt_enable_context_menu = true;
|
|
|
static bool adding_line = false;
|
|
|
- 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,\nRight-click to undo");
|
|
|
-
|
|
|
- // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use
|
|
|
- // IsItemHovered(). But you can also draw directly and poll mouse/keyboard by yourself.
|
|
|
- // You can manipulate the cursor using GetCursorPos() and SetCursorPos().
|
|
|
- // If you only use the ImDrawList API, you can notify the owner window of its extends with SetCursorPos(max).
|
|
|
- ImVec2 canvas_p = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
|
|
|
+
|
|
|
+ ImGui::Checkbox("Enable grid", &opt_enable_grid);
|
|
|
+ ImGui::Checkbox("Enable context menu", &opt_enable_context_menu);
|
|
|
+ ImGui::Text("Mouse Left: drag to add lines,\nMouse Right: drag to scroll, click for context menu.");
|
|
|
+
|
|
|
+ // Typically you would use a BeginChild()/EndChild() pair to benefit from a clipping region + own scrolling.
|
|
|
+ // Here we demonstrate that this can be replaced by simple offsetting + custom drawing + PushClipRect/PopClipRect() calls.
|
|
|
+ // To use a child window instead we could use, e.g:
|
|
|
+ // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); // Disable padding
|
|
|
+ // ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(50, 50, 50, 255)); // Set a background color
|
|
|
+ // ImGui::BeginChild("canvas", ImVec2(0.0f, 0.0f), true, ImGuiWindowFlags_NoMove);
|
|
|
+ // ImGui::PopStyleColor();
|
|
|
+ // ImGui::PopStyleVar();
|
|
|
+ // [...]
|
|
|
+ // ImGui::EndChild();
|
|
|
+
|
|
|
+ // Using InvisibleButton() as a convenience 1) it will advance the layout cursor and 2) allows us to use IsItemHovered()/IsItemActive()
|
|
|
+ ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
|
|
|
ImVec2 canvas_sz = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
|
|
|
if (canvas_sz.x < 50.0f) canvas_sz.x = 50.0f;
|
|
|
if (canvas_sz.y < 50.0f) canvas_sz.y = 50.0f;
|
|
|
- draw_list->AddRectFilledMultiColor(canvas_p, ImVec2(canvas_p.x + canvas_sz.x, canvas_p.y + canvas_sz.y), IM_COL32(50, 50, 50, 255), IM_COL32(50, 50, 60, 255), IM_COL32(60, 60, 70, 255), IM_COL32(50, 50, 60, 255));
|
|
|
- draw_list->AddRect(canvas_p, ImVec2(canvas_p.x + canvas_sz.x, canvas_p.y + canvas_sz.y), IM_COL32(255, 255, 255, 255));
|
|
|
+ ImVec2 canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
|
|
|
|
|
- bool adding_preview = false;
|
|
|
- ImGui::InvisibleButton("canvas", canvas_sz);
|
|
|
- ImVec2 mouse_pos_global = ImGui::GetIO().MousePos;
|
|
|
- ImVec2 mouse_pos_canvas = ImVec2(mouse_pos_global.x - canvas_p.x, mouse_pos_global.y - canvas_p.y);
|
|
|
+ // Draw border and background color
|
|
|
+ ImGuiIO& io = ImGui::GetIO();
|
|
|
+ ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
|
+ draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(50, 50, 50, 255));
|
|
|
+ draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
|
|
|
+
|
|
|
+ // This will catch our interactions
|
|
|
+ ImGui::InvisibleButton("canvas", canvas_sz, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
|
|
+ const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
|
|
+ const bool is_active = ImGui::IsItemActive(); // Held
|
|
|
+ const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y); // Lock scrolled origin
|
|
|
+ const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
|
|
|
+
|
|
|
+ // Add first and second point
|
|
|
+ if (is_hovered && !adding_line && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
|
|
|
+ {
|
|
|
+ lines.push_back(ItemLine(mouse_pos_in_canvas, mouse_pos_in_canvas));
|
|
|
+ adding_line = true;
|
|
|
+ }
|
|
|
if (adding_line)
|
|
|
{
|
|
|
- adding_preview = true;
|
|
|
- points.push_back(mouse_pos_canvas);
|
|
|
- if (!ImGui::IsMouseDown(0))
|
|
|
- adding_line = adding_preview = false;
|
|
|
+ lines.back().p1 = mouse_pos_in_canvas;
|
|
|
+ if (!ImGui::IsMouseDown(ImGuiMouseButton_Left))
|
|
|
+ adding_line = false;
|
|
|
}
|
|
|
- if (ImGui::IsItemHovered())
|
|
|
+
|
|
|
+ // Pan (we use a zero mouse threshold when there's no context menu)
|
|
|
+ // You may decide to make that threshold dynamic based on whether the mouse is hovering something etc.
|
|
|
+ const float mouse_threshold_for_pan = opt_enable_context_menu ? -1.0f : 0.0f;
|
|
|
+ if (is_active && ImGui::IsMouseDragging(ImGuiMouseButton_Right, mouse_threshold_for_pan))
|
|
|
{
|
|
|
- if (!adding_line && ImGui::IsMouseClicked(0))
|
|
|
- {
|
|
|
- points.push_back(mouse_pos_canvas);
|
|
|
- adding_line = true;
|
|
|
- }
|
|
|
- if (ImGui::IsMouseClicked(1) && !points.empty())
|
|
|
- {
|
|
|
- adding_line = adding_preview = false;
|
|
|
- points.pop_back();
|
|
|
- points.pop_back();
|
|
|
- }
|
|
|
+ scrolling.x += io.MouseDelta.x;
|
|
|
+ scrolling.y += io.MouseDelta.y;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Context menu (under default mouse threshold)
|
|
|
+ ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
|
|
+ if (opt_enable_context_menu && ImGui::IsMouseReleased(ImGuiMouseButton_Right) && drag_delta.x == 0.0f && drag_delta.y == 0.0f)
|
|
|
+ ImGui::OpenPopupContextItem("context");
|
|
|
+ if (ImGui::BeginPopup("context"))
|
|
|
+ {
|
|
|
+ if (adding_line)
|
|
|
+ lines.pop_back();
|
|
|
+ adding_line = false;
|
|
|
+ if (ImGui::MenuItem("Remove one", NULL, false, lines.Size > 0)) { lines.pop_back(); }
|
|
|
+ if (ImGui::MenuItem("Remove all", NULL, false, lines.Size > 0)) { lines.clear(); }
|
|
|
+ ImGui::EndPopup();
|
|
|
}
|
|
|
|
|
|
- // Draw all lines in the canvas (with a clipping rectangle so they don't stray out of it).
|
|
|
- draw_list->PushClipRect(canvas_p, ImVec2(canvas_p.x + canvas_sz.x, canvas_p.y + canvas_sz.y), true);
|
|
|
- for (int i = 0; i < points.Size - 1; i += 2)
|
|
|
- draw_list->AddLine(ImVec2(canvas_p.x + points[i].x, canvas_p.y + points[i].y), ImVec2(canvas_p.x + points[i + 1].x, canvas_p.y + points[i + 1].y), IM_COL32(255, 255, 0, 255), 2.0f);
|
|
|
+ // Draw grid + all lines in the canvas
|
|
|
+ draw_list->PushClipRect(canvas_p0, canvas_p1, true);
|
|
|
+ if (opt_enable_grid)
|
|
|
+ {
|
|
|
+ const float GRID_STEP = 64.0f;
|
|
|
+ for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x; x += GRID_STEP)
|
|
|
+ draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y), ImVec2(canvas_p0.x + x, canvas_p1.y), IM_COL32(200, 200, 200, 40));
|
|
|
+ for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y; y += GRID_STEP)
|
|
|
+ draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y), ImVec2(canvas_p1.x, canvas_p0.y + y), IM_COL32(200, 200, 200, 40));
|
|
|
+ }
|
|
|
+ for (int n = 0; n < lines.Size; n++)
|
|
|
+ draw_list->AddLine(ImVec2(origin.x + lines[n].p0.x, origin.y + lines[n].p0.y), ImVec2(origin.x + lines[n].p1.x, origin.y + lines[n].p1.y), IM_COL32(255, 255, 0, 255), 2.0f);
|
|
|
draw_list->PopClipRect();
|
|
|
- if (adding_preview)
|
|
|
- points.pop_back();
|
|
|
+
|
|
|
ImGui::EndTabItem();
|
|
|
}
|
|
|
|
|
|
@@ -5053,7 +5098,7 @@ struct MyDocument
|
|
|
void DoForceClose() { Open = false; Dirty = false; }
|
|
|
void DoSave() { Dirty = false; }
|
|
|
|
|
|
- // Display dummy contents for the Document
|
|
|
+ // Display placeholder contents for the Document
|
|
|
static void DisplayContents(MyDocument* doc)
|
|
|
{
|
|
|
ImGui::PushID(doc);
|