void FillGeometry(Graphics graphics, PolarTransform transform, Color color, Geometry geometry)
        {
            if (graphics == null ||
                geometry == null)
            {
                return;
            }

            GeometrySegmentator geometrySegmentator = new GeometrySegmentator(geometry);
            GeometryTransformer geometrySegmentatorPolarTransformer = new GeometryTransformer(geometrySegmentator, transform);

            graphics.FillGeometry(color, geometrySegmentatorPolarTransformer);
        }
        void DrawGeometry(Graphics graphics, PolarTransform transform, Color color, Geometry geometry, double thickness)
        {
            if (graphics == null ||
                geometry == null)
            {
                return;
            }

            GeometrySegmentator geometrySegmentator = new GeometrySegmentator(geometry);
            GeometryTransformer geometrySegmentatorPolarTransformer = new GeometryTransformer(geometrySegmentator, transform);

            graphics.DrawGeometry(color, geometrySegmentatorPolarTransformer, thickness);
        }
 void DrawGeometry(Graphics graphics, PolarTransform transform, Color color, Geometry geometry)
 {
     DrawGeometry(graphics, transform, color, geometry, 1);
 }
        protected override void OnPaint(GUI.PaintEventArgs e)
        {
            base.OnPaint(e);


            Graphics graphics = e.Graphics;

            graphics.SmoothingMode = SmoothingMode.AntiAlias;


            PolarTransform polarTransform = new PolarTransform();

            polarTransform.FullCircle = -600;
            polarTransform.BaseScale  = -1;
            polarTransform.SetBaseOffset(0, m_BaseYSlider.Value);
            polarTransform.SetTranslation(ClientWidth / 2.0, ClientHeight / 2.0 - 30.0);
            polarTransform.Spiral = m_SpiralSlider.Value;


            //  Draw Background
            RectangleGeometry borderGeometry = new RectangleGeometry(0, 0, m_TextBox.Width, m_TextBox.Height);
            //  Just for little optimization
            GeometrySegmentator borderGeometrySegmentator = new GeometrySegmentator(borderGeometry);
            GeometryTransformer borderGeometrySegmentatorPolarTransformer = new GeometryTransformer(borderGeometrySegmentator, polarTransform);

            graphics.FillGeometry(Color.WhiteSmoke, borderGeometrySegmentatorPolarTransformer);


            //  Selection
            if (m_TextBox.HasSelectionAndVisible)
            {
                RectangleGeometry selectionGeometry = new RectangleGeometry(m_TextBox.SelectionBounds
                                                                            //  Just to prevent some artefacts
                                                                            - new PointI(0, 1) + new SizeI(0, 2));

                FillGeometry(graphics, polarTransform, m_TextBox.SelectionColor, selectionGeometry);
            }


            //  Caret
            if (m_TextBox.IsCaretVisible)
            {
                RectangleGeometry caretGeometry = new RectangleGeometry(m_TextBox.CaretBounds);

                FillGeometry(graphics, polarTransform, Color.Black, caretGeometry);
            }


            //  Draw Border
            graphics.DrawGeometry(Color.DodgerBlue, borderGeometrySegmentatorPolarTransformer, 2);


            //  Text
            Font         font         = m_TextBox.Font;
            GraphicsPath textGeometry = new GraphicsPath();

            textGeometry.AddString(
                m_TextBox.Text,
                font.FontFamily, font.Style, font.Size * 96.0 / 72.0, new Point(4, 1), StringFormat.GenericTypographic);

            FlattenCurveGeometry textFlattenGeometry = new FlattenCurveGeometry(textGeometry);
            //  Need for clip text
            Geometry clippedTextFlattenGeometry = new FlattenCurveGeometry(
                new CombinedGeometry(textFlattenGeometry, new RectangleGeometry(1, 1, m_TextBox.Width - 2, m_TextBox.Height - 2), CombinedGeometry.CombineMode.And));

            FillGeometry(graphics, polarTransform, m_TextBox.TextColor, clippedTextFlattenGeometry);
        }