@@ -1701,7 +1701,6 @@ struct RendererCircleLine : RendererBase {
17011701 mutable ImVec2 UV1 ;
17021702};
17031703
1704-
17051704static const ImVec2 MARKER_FILL_CIRCLE [10 ] = {ImVec2 (1 .0f , 0 .0f ), ImVec2 (0 .809017f , 0 .58778524f ),ImVec2 (0 .30901697f , 0 .95105654f ),ImVec2 (-0 .30901703f , 0 .9510565f ),ImVec2 (-0 .80901706f , 0 .5877852f ),ImVec2 (-1 .0f , 0 .0f ),ImVec2 (-0 .80901694f , -0 .58778536f ),ImVec2 (-0 .3090171f , -0 .9510565f ),ImVec2 (0 .30901712f , -0 .9510565f ),ImVec2 (0 .80901694f , -0 .5877853f )};
17061705static const ImVec2 MARKER_FILL_SQUARE [4 ] = {ImVec2 (SQRT_1_2 ,SQRT_1_2 ), ImVec2 (SQRT_1_2 ,-SQRT_1_2 ), ImVec2 (-SQRT_1_2 ,-SQRT_1_2 ), ImVec2 (-SQRT_1_2 ,SQRT_1_2 )};
17071706static const ImVec2 MARKER_FILL_DIAMOND [4 ] = {ImVec2 (1 , 0 ), ImVec2 (0 , -1 ), ImVec2 (-1 , 0 ), ImVec2 (0 , 1 )};
@@ -1941,6 +1940,64 @@ void PlotBubbles(const char* label_id, const T* xs, const T* ys, const T* szs, i
19411940CALL_INSTANTIATE_FOR_NUMERIC_TYPES ()
19421941#undef INSTANTIATE_MACRO
19431942
1943+ // -----------------------------------------------------------------------------
1944+ // [SECTION] PlotPolygon
1945+ // -----------------------------------------------------------------------------
1946+
1947+ template <typename Getter>
1948+ void PlotPolygonEx (const char * label_id, const Getter& getter, const ImPlotSpec& spec) {
1949+ if (BeginItemEx (label_id, Fitter1<Getter>(getter), spec, spec.FillColor , spec.Marker )) {
1950+ if (getter.Count < 2 ) {
1951+ EndItem ();
1952+ return ;
1953+ }
1954+ const ImPlotNextItemData& s = GetItemData ();
1955+ const bool is_concave = ImHasFlag (spec.Flags , ImPlotPolygonFlags_Concave);
1956+
1957+ ImDrawList& draw_list = *GetPlotDrawList ();
1958+ const ImPlotAxis& x_axis = GetCurrentPlot ()->Axes [GetCurrentPlot ()->CurrentX ];
1959+ const ImPlotAxis& y_axis = GetCurrentPlot ()->Axes [GetCurrentPlot ()->CurrentY ];
1960+ Transformer2 transformer (x_axis, y_axis);
1961+
1962+ // Flip points to make sure they are in clockwise order for correct filling when one axis is inverted
1963+ bool x_inv = ImHasFlag (x_axis.Flags , ImPlotAxisFlags_Invert);
1964+ bool y_inv = ImHasFlag (y_axis.Flags , ImPlotAxisFlags_Invert);
1965+ bool flip = !((x_inv ? 1 : 0 ) ^ (y_inv ? 1 : 0 ));
1966+
1967+ // Transform all points to screen space
1968+ ImVec2* points = (ImVec2*)alloca (getter.Count * sizeof (ImVec2));
1969+ for (int i = 0 ; i < getter.Count ; ++i) {
1970+ ImPlotPoint p = flip ? getter[getter.Count - 1 - i] : getter[i];
1971+ points[i] = transformer (p);
1972+ }
1973+
1974+ if (s.RenderFill && getter.Count >= 3 ) {
1975+ const ImU32 col_fill = ImGui::GetColorU32 (s.Spec .FillColor );
1976+ if (is_concave)
1977+ draw_list.AddConcavePolyFilled (points, getter.Count , col_fill);
1978+ else
1979+ draw_list.AddConvexPolyFilled (points, getter.Count , col_fill);
1980+ }
1981+ if (s.RenderLine && getter.Count >= 2 ) {
1982+ const ImU32 col_line = ImGui::GetColorU32 (s.Spec .LineColor );
1983+ draw_list.AddPolyline (points, getter.Count , col_line, ImDrawFlags_Closed, s.Spec .LineWeight );
1984+ }
1985+
1986+ EndItem ();
1987+ }
1988+ }
1989+
1990+ template <typename T>
1991+ void PlotPolygon (const char * label_id, const T* xs, const T* ys, int count, const ImPlotSpec& spec) {
1992+ GetterXY<IndexerIdx<T>,IndexerIdx<T>> getter (IndexerIdx<T>(xs,count,spec.Offset ,Stride<T>(spec)),IndexerIdx<T>(ys,count,spec.Offset ,Stride<T>(spec)),count);
1993+ return PlotPolygonEx (label_id, getter, spec);
1994+ }
1995+
1996+ #define INSTANTIATE_MACRO (T ) \
1997+ template IMPLOT_API void PlotPolygon<T>(const char * label_id, const T* xs, const T* ys, int count, const ImPlotSpec& spec);
1998+ CALL_INSTANTIATE_FOR_NUMERIC_TYPES ()
1999+ #undef INSTANTIATE_MACRO
2000+
19442001// -----------------------------------------------------------------------------
19452002// [SECTION] PlotStairs
19462003// -----------------------------------------------------------------------------
0 commit comments