void DrawingPanel_Paint(object sender, GUI.PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; double scale = m_ScaleSlider.Value; e.Graphics.TranslateTransform(scale * m_x, scale * m_y); // Outlined Matrix4 mtx = Matrix4.CreateTranslation(-m_SVGPathBounds.Center.X, -m_SVGPathBounds.Center.Y); mtx.Scale(scale, scale, MatrixOrder.Append); mtx.Rotate(m_RotateSlider.Value, MatrixOrder.Append); //mtx.Translate(m_x, m_y, MatrixOrder.Append); GeometryStroke stroke = new GeometryStroke(); stroke.Width = m_ScaleSlider.Value; stroke.LineJoin = LineJoin.Round; e.Graphics.Opacity = m_OpacitySlider.Value; #if GEOMETRY_TRANSFORMATIONS m_SVGPath.Render(e.Graphics, mtx, stroke); #else e.Graphics.Transform = mtx.ToMatrix(); m_SVGPath.Render(e.Graphics, stroke); #endif }
public SVGPath() { m_storage = new GraphicsPath(); m_attr_storage = new List <SVGPathAttributes>(); m_attr_stack = new List <SVGPathAttributes>(); m_transform = Matrix4.Identity; m_curved = new FlattenCurveGeometry(m_storage); m_curved_stroked = new GeometryStroke(m_curved); m_curved_stroked_trans = new GeometryMatrix4Transformer(m_curved_stroked, m_transform); m_curved_trans = new GeometryMatrix4Transformer(m_curved, m_transform); m_curved_trans_contour = new GeometryContour(m_curved_trans); m_curved_trans_contour.AutoDetectOrientation = false; }
void DrawingPanel_Paint(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Matrix4 mtx = Matrix4.CreateTranslation(-m_SVGPathBounds.Center.X, -m_SVGPathBounds.Center.Y); mtx.Scale(m_Scale, m_Scale, MatrixOrder.Append); mtx.Translate(m_x, m_y, MatrixOrder.Append); ITransform transform = null; if (rbBilinear.IsChecked) { Bilinear tr = new Bilinear( m_SVGPathScaledBounds.Left, m_SVGPathScaledBounds.Top, m_SVGPathScaledBounds.Right, m_SVGPathScaledBounds.Bottom, m_PolygonElement.Polygon); if (tr.IsValid) { transform = tr; } } else { Perspective tr = new Perspective( m_SVGPathScaledBounds.Left, m_SVGPathScaledBounds.Top, m_SVGPathScaledBounds.Right, m_SVGPathScaledBounds.Bottom, m_PolygonElement.Polygon); if (tr.IsValid() && Perspective.IsConvex(m_PolygonElement.Polygon)) { transform = tr; } } // GeometryTransformer transformer = null; if (transform != null) { transformer = new GeometryTransformer(transform); } // Render transformed SVG m_SVGPath.Render(e.Graphics, mtx, transformer); // Render transformed ellipse Point center = m_SVGPathScaledBounds.Center; EllipseGeometry FilledEllipse = new EllipseGeometry(center.X, center.Y, m_SVGPathScaledBounds.Width / 2, m_SVGPathScaledBounds.Height / 2, 200); GeometryStroke EllipseOutline = new GeometryStroke(FilledEllipse); EllipseOutline.Width = 3.0; Geometry TransformedFilledEllipse = FilledEllipse; Geometry TransformedEllipesOutline = EllipseOutline; if (transform != null) { TransformedFilledEllipse = new GeometryTransformer(FilledEllipse, transform); TransformedEllipesOutline = new GeometryTransformer(EllipseOutline, transform); } SmoothingMode saveSmoothingMode = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = SmoothingMode.None; { e.Graphics.FillGeometry(m_EllipseBrush, TransformedFilledEllipse); } e.Graphics.SmoothingMode = saveSmoothingMode; e.Graphics.FillGeometry(m_EllipsePen.Color, TransformedEllipesOutline); }
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); } }