| 1906 | //----------------------------------------------------------------------------- |
| 1907 | |
| 1908 | void Demo_DragPoints() { |
| 1909 | IMGUI_DEMO_MARKER("Tools/Drag Points"); |
| 1910 | ImGui::BulletText("Click and drag each point."); |
| 1911 | static ImPlotDragToolFlags flags = ImPlotDragToolFlags_None; |
| 1912 | ImGui::CheckboxFlags("NoCursors", (unsigned int*)&flags, ImPlotDragToolFlags_NoCursors); ImGui::SameLine(); |
| 1913 | ImGui::CheckboxFlags("NoFit", (unsigned int*)&flags, ImPlotDragToolFlags_NoFit); ImGui::SameLine(); |
| 1914 | ImGui::CheckboxFlags("NoInput", (unsigned int*)&flags, ImPlotDragToolFlags_NoInputs); |
| 1915 | ImPlotAxisFlags ax_flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks; |
| 1916 | bool clicked[4] = {false, false, false, false}; |
| 1917 | bool hovered[4] = {false, false, false, false}; |
| 1918 | bool held[4] = {false, false, false, false}; |
| 1919 | if (ImPlot::BeginPlot("##Bezier",ImVec2(-1,0),ImPlotFlags_CanvasOnly)) { |
| 1920 | ImPlot::SetupAxes(nullptr,nullptr,ax_flags,ax_flags); |
| 1921 | ImPlot::SetupAxesLimits(0,1,0,1); |
| 1922 | static ImPlotPoint P[] = {ImPlotPoint(.05f,.05f), ImPlotPoint(0.2,0.4), ImPlotPoint(0.8,0.6), ImPlotPoint(.95f,.95f)}; |
| 1923 | |
| 1924 | ImPlot::DragPoint(0,&P[0].x,&P[0].y, ImVec4(0,0.9f,0,1),4,flags, &clicked[0], &hovered[0], &held[0]); |
| 1925 | ImPlot::DragPoint(1,&P[1].x,&P[1].y, ImVec4(1,0.5f,1,1),4,flags, &clicked[1], &hovered[1], &held[1]); |
| 1926 | ImPlot::DragPoint(2,&P[2].x,&P[2].y, ImVec4(0,0.5f,1,1),4,flags, &clicked[2], &hovered[2], &held[2]); |
| 1927 | ImPlot::DragPoint(3,&P[3].x,&P[3].y, ImVec4(0,0.9f,0,1),4,flags, &clicked[3], &hovered[3], &held[3]); |
| 1928 | |
| 1929 | static ImPlotPoint B[100]; |
| 1930 | for (int i = 0; i < 100; ++i) { |
| 1931 | double t = i / 99.0; |
| 1932 | double u = 1 - t; |
| 1933 | double w1 = u*u*u; |
| 1934 | double w2 = 3*u*u*t; |
| 1935 | double w3 = 3*u*t*t; |
| 1936 | double w4 = t*t*t; |
| 1937 | B[i] = ImPlotPoint(w1*P[0].x + w2*P[1].x + w3*P[2].x + w4*P[3].x, w1*P[0].y + w2*P[1].y + w3*P[2].y + w4*P[3].y); |
| 1938 | } |
| 1939 | |
| 1940 | ImPlotSpec spec; |
| 1941 | spec.Offset = 0; |
| 1942 | spec.Stride = sizeof(ImPlotPoint); |
| 1943 | |
| 1944 | spec.LineColor = ImVec4(1,0.5f,1,1); |
| 1945 | spec.LineWeight = hovered[1]||held[1] ? 2.0f : 1.0f; |
| 1946 | ImPlot::PlotLine("##h1",&P[0].x, &P[0].y, 2, spec); |
| 1947 | |
| 1948 | spec.LineColor = ImVec4(0,0.5f,1,1); |
| 1949 | spec.LineWeight = hovered[2]||held[2] ? 2.0f : 1.0f; |
| 1950 | ImPlot::PlotLine("##h2",&P[2].x, &P[2].y, 2, spec); |
| 1951 | |
| 1952 | spec.LineColor = ImVec4(0,0.9f,0,1); |
| 1953 | spec.LineWeight = hovered[0]||held[0]||hovered[3]||held[3] ? 3.0f : 2.0f; |
| 1954 | ImPlot::PlotLine("##bez",&B[0].x, &B[0].y, 100, spec); |
| 1955 | |
| 1956 | ImPlot::EndPlot(); |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | //----------------------------------------------------------------------------- |
| 1961 |
nothing calls this directly
no test coverage detected