Exemple #1
0
 public void CloseSubPath()                               // Z, z
 {
     m_storage.ClosePolygon(GeometryVertexCommandAndFlags.FlagClose);
 }
        void panel2_Paint(object sender, GUI.PaintEventArgs e)
        {
            Graphics graphics           = e.Graphics;
            bool     isSoftwareGraphics = graphics is SoftwareGraphics;

            //if (isSoftwareGraphics)
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
            }


            // Two simple paths
            if (rbGeometry5.IsChecked)
            {
                GraphicsPath ps1_path = new GraphicsPath();

                double x = m_X - m_DrawingPanel.ClientRectangle.Center.X / 2 + 100;
                double y = m_Y - m_DrawingPanel.ClientRectangle.Center.Y / 2 + 100;
                ps1_path.MoveTo(x + 140, y + 145);
                ps1_path.LineTo(x + 225, y + 44);
                ps1_path.LineTo(x + 296, y + 219);
                ps1_path.ClosePolygon();

                ps1_path.LineTo(x + 226, y + 289);
                ps1_path.LineTo(x + 82, y + 292);

                ps1_path.MoveTo(x + 220, y + 222);
                ps1_path.LineTo(x + 363, y + 249);
                ps1_path.LineTo(x + 265, y + 331);

                ps1_path.MoveTo(x + 242, y + 243);
                ps1_path.LineTo(x + 268, y + 309);
                ps1_path.LineTo(x + 325, y + 261);

                ps1_path.MoveTo(x + 259, y + 259);
                ps1_path.LineTo(x + 273, y + 288);
                ps1_path.LineTo(x + 298, y + 266);

                Rect ps1Bounds          = ps1_path.Bounds;
                GeometryTransformer ps1 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps1_path, Matrix4.CreateTranslation(
                                                                                                    m_X - ps1Bounds.Center.X,
                                                                                                    m_Y - ps1Bounds.Center.Y));


                GraphicsPath ps2_path = new GraphicsPath();
                ps2_path.MoveTo(100 + 32, 100 + 77);
                ps2_path.LineTo(100 + 473, 100 + 263);
                ps2_path.LineTo(100 + 351, 100 + 290);
                ps2_path.LineTo(100 + 354, 100 + 374);
                Rect ps2Bounds          = ps2_path.Bounds;
                GeometryTransformer ps2 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps2_path, Matrix4.CreateTranslation(
                                                                                                    (m_DrawingPanel.Width - ps2Bounds.Width) / 2 - ps2Bounds.Left,
                                                                                                    (m_DrawingPanel.Height - ps2Bounds.Height) / 2 - ps2Bounds.Top));


                graphics.FillGeometry(m_GeometryBColor, ps2);
                graphics.FillGeometry(m_GeometryAColor, ps1);

                CombinedGeometry clp = new CombinedGeometry(ps1, ps2, CombinedGeometry.CombineMode.Or, CombinedGeometry.FillType.NonZero, CombinedGeometry.FillType.NonZero);

                PerformRendering(graphics, clp);
            }
            // Closed stroke
            else if (rbGeometry4.IsChecked)
            {
                GraphicsPath ps1_path = new GraphicsPath();

                double x = m_X - m_DrawingPanel.ClientRectangle.Center.X / 2 + 100;
                double y = m_Y - m_DrawingPanel.ClientRectangle.Center.Y / 2 + 100;
                ps1_path.MoveTo(x + 140, y + 145);
                ps1_path.LineTo(x + 225, y + 44);
                ps1_path.LineTo(x + 296, y + 219);
                ps1_path.ClosePolygon();

                ps1_path.LineTo(x + 226, y + 289);
                ps1_path.LineTo(x + 82, y + 292);

                ps1_path.MoveTo(x + 220 - 50, y + 222);
                ps1_path.LineTo(x + 265 - 50, y + 331);
                ps1_path.LineTo(x + 363 - 50, y + 249);
                ps1_path.ClosePolygon(GeometryVertexCommandAndFlags.FlagCCW);

                Rect ps1Bounds          = ps1_path.Bounds;
                GeometryTransformer ps1 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps1_path, Matrix4.CreateTranslation(
                                                                                                    m_X - ps1Bounds.Center.X,
                                                                                                    m_Y - ps1Bounds.Center.Y));


                GraphicsPath ps2_path = new GraphicsPath();
                ps2_path.MoveTo(100 + 32, 100 + 77);
                ps2_path.LineTo(100 + 473, 100 + 263);
                ps2_path.LineTo(100 + 351, 100 + 290);
                ps2_path.LineTo(100 + 354, 100 + 374);
                ps2_path.ClosePolygon();
                Rect ps2Bounds          = ps2_path.Bounds;
                GeometryTransformer ps2 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps2_path, Matrix4.CreateTranslation(
                                                                                                    (m_DrawingPanel.Width - ps2Bounds.Width) / 2 - ps2Bounds.Left,
                                                                                                    (m_DrawingPanel.Height - ps2Bounds.Height) / 2 - ps2Bounds.Top));

                GeometryStroke stroke = new GeometryStroke(ps2, 10);


                graphics.FillGeometry(m_GeometryBColor, stroke);
                graphics.FillGeometry(m_GeometryAColor, ps1);

                CombinedGeometry clp = new CombinedGeometry(ps1, stroke, CombinedGeometry.CombineMode.Or, CombinedGeometry.FillType.NonZero, CombinedGeometry.FillType.NonZero);

                PerformRendering(graphics, clp);
            }
            // Great Britain and Arrows
            else if (rbGeometry3.IsChecked)
            {
                Geometry poly       = GreatBritain;
                Rect     polyBounds = poly.Bounds;
                double   scale      = 3;
                Matrix4  mtx        = Matrix4.CreateTranslation(-polyBounds.Center.X, -polyBounds.Center.Y);
                mtx *= Matrix4.CreateScaling(scale, scale);
                mtx *= Matrix4.CreateTranslation(m_DrawingPanel.Width / 2, m_DrawingPanel.Height / 2);
                GeometryTransformer trans_gb_poly = GeometryMatrix4Transformer.CreateOptimizedTransformer(poly, mtx);

                Geometry arrows       = Arrows;
                Rect     arrowsBounds = arrows.Bounds;
                mtx  = Matrix4.CreateTranslation(-arrowsBounds.Center.X, -arrowsBounds.Center.Y);
                mtx *= Matrix4.CreateScaling(scale, scale);
                mtx *= Matrix4.CreateTranslation(m_X, m_Y);
                GeometryTransformer trans_arrows = GeometryMatrix4Transformer.CreateOptimizedTransformer(arrows, mtx);

                CombinedGeometry clp = new CombinedGeometry(trans_gb_poly, trans_arrows,
                                                            CombinedGeometry.CombineMode.Or,
                                                            CombinedGeometry.FillType.NonZero,
                                                            CombinedGeometry.FillType.NonZero);

                graphics.FillGeometry(m_GeometryBColor, trans_gb_poly);
                graphics.DrawGeometry(isSoftwareGraphics ? m_GreatBritainContourPen_SWR : m_GreatBritainContourPen_HWR, trans_gb_poly);
                graphics.FillGeometry(m_GeometryAColor, trans_arrows);

                PerformRendering(graphics, clp);
            }
            // Great Britain and a Spiral
            else if (rbGeometry2.IsChecked)
            {
                Geometry poly       = GreatBritain;
                Rect     polyBounds = poly.Bounds;
                double   scale      = 3;
                Matrix4  mtx        = Matrix4.CreateTranslation(-polyBounds.Center.X, -polyBounds.Center.Y);
                mtx *= Matrix4.CreateScaling(scale, scale);
                mtx *= Matrix4.CreateTranslation(m_DrawingPanel.Width / 2, m_DrawingPanel.Height / 2);
                GeometryTransformer trans_gb_poly = GeometryMatrix4Transformer.CreateOptimizedTransformer(poly, mtx);

                Geometry       sp     = GeometryMatrix4Transformer.CreateOptimizedTransformer(Spiral, Matrix4.CreateTranslation(m_X, m_Y));
                GeometryStroke stroke = new GeometryStroke(sp, 15);

                CombinedGeometry clp = new CombinedGeometry(trans_gb_poly, stroke,
                                                            CombinedGeometry.CombineMode.Or,
                                                            CombinedGeometry.FillType.NonZero,
                                                            CombinedGeometry.FillType.NonZero);

                graphics.FillGeometry(m_GeometryBColor, trans_gb_poly);
                graphics.DrawGeometry(isSoftwareGraphics ? m_GreatBritainContourPen_SWR : m_GreatBritainContourPen_HWR, trans_gb_poly);
                graphics.DrawGeometry(m_SpiralPen, sp);

                PerformRendering(graphics, clp);
            }
            // Spiral and text
            else if (rbGeometry1.IsChecked)
            {
                Geometry            text            = Text;
                Rect                textBounds      = text.Bounds;
                GeometryTransformer transformedText = GeometryMatrix4Transformer.CreateOptimizedTransformer(text,
                                                                                                            Matrix4.CreateTranslation(
                                                                                                                (m_DrawingPanel.Width - textBounds.Width) / 2 - textBounds.Left,
                                                                                                                (m_DrawingPanel.Height - textBounds.Height) / 2 - textBounds.Top));

                Geometry       sp     = GeometryMatrix4Transformer.CreateOptimizedTransformer(Spiral, Matrix4.CreateTranslation(m_X, m_Y));
                GeometryStroke stroke = new GeometryStroke(sp, 15);

                CombinedGeometry clp = new CombinedGeometry(stroke, transformedText,
                                                            CombinedGeometry.CombineMode.Or,
                                                            CombinedGeometry.FillType.NonZero,
                                                            CombinedGeometry.FillType.NonZero);

                graphics.FillGeometry(m_GeometryBColor, transformedText);
                graphics.DrawGeometry(m_SpiralPen, sp);

                PerformRendering(graphics, clp);
            }
        }