System.Drawing.Drawing2D.GraphicsPath.Reverse C# (CSharp) Method

Reverse() public method

public Reverse ( ) : void
return void
        public void Reverse()
        {
            var length = points.Count;
            var start = 0;
            var isPrevHadMarker = false;

            // shortcut
            if (length <= 1)
                return;

            // PathTypes reversal

            // First adjust the flags for each subpath
            var newTypes = new List<byte> (length);

            for (int i = 1; i < length; i++) {
                byte t = types [i];
                if ((t & (byte)PathPointType.PathTypeMask) == (byte)PathPointType.Start)
                {
                    ReverseSubpathAndAdjustFlags (start, i - 1, types, newTypes, ref isPrevHadMarker);
                    start = i;
                }
            }

            if (start < length - 1)
                ReverseSubpathAndAdjustFlags (start, length - 1, types, newTypes, ref isPrevHadMarker);

            /* Then reverse the resulting array */
            for (int i = 0; i < (length >> 1); i++) {
                byte a = newTypes [i];
                byte b = newTypes [length - i - 1];
                byte temp = a;
                newTypes [i] = b;
                newTypes [length - i - 1] = temp;
            }

            types = newTypes;

            // PathPoints reversal
             		// note: if length is odd then the middle point doesn't need to switch side
             		//
            for (int i = 0; i < (length >> 1); i++) {
                PointF first = points [i];
                PointF last = points [length - i - 1];

                PointF temp = PointF.Empty;
                temp.X = first.X;
                temp.Y = first.Y;
                points [i] = last;
                points [length - i - 1] = temp;
            }
        }

Usage Example

        private static void ArcRenderRange(this Graphics Graphics, Rectangle ClientRectangle, Point Center, Int32 ArcStart, Int32 ArcSweep, Single MinimumValue, Single MaximumValue, ArcRangeDef Range)
        {
            Graphics.SetClip(ClientRectangle);
            Graphics.SmoothingMode = SmoothingMode.HighQuality;
            Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            using (var graphicsPath = new GraphicsPath()) {
                if (Range.EndValue > Range.StartValue && Range.Enabled) {
                    var rangeStartAngle = ArcStart + (Range.StartValue - MinimumValue) * ArcSweep / (MaximumValue - MinimumValue);
                    var rangeSweepAngle = (Range.EndValue - Range.StartValue) * ArcSweep / (MaximumValue - MinimumValue);
                    graphicsPath.Reset();
                    graphicsPath.AddPie(new Rectangle(Center.X - Range.OuterRadius, Center.Y - Range.OuterRadius, 2 * Range.OuterRadius, 2 * Range.OuterRadius), rangeStartAngle, rangeSweepAngle);
                    graphicsPath.Reverse();
                    graphicsPath.AddPie(new Rectangle(Center.X - Range.InnerRadius, Center.Y - Range.InnerRadius, 2 * Range.InnerRadius, 2 * Range.InnerRadius), rangeStartAngle, rangeSweepAngle);
                    graphicsPath.Reverse();
                    Graphics.SetClip(graphicsPath);
                    using (var solidBrush = new SolidBrush(Range.ForeColor)) {
                        Graphics.FillPie(solidBrush, new Rectangle(Center.X - Range.OuterRadius, Center.Y - Range.OuterRadius, 2 * Range.OuterRadius, 2 * Range.OuterRadius), rangeStartAngle, rangeSweepAngle);
                    }
                }
            }
        }
All Usage Examples Of System.Drawing.Drawing2D.GraphicsPath::Reverse