Example #1
0
        private static StreamGeometry createLine(double yOffset)
        {
            StreamGeometry lineGeometry = new StreamGeometry();

            lineGeometry.FillRule = FillRule.EvenOdd;
            using (StreamGeometryContext ctx = lineGeometry.Open())
            {
                double x0 = (0) * scale;
                double x1 = (30) * scale;

                double y0 = yOffset * scale;
                double y1 = (yOffset + 1) * scale;
                ctx.BeginFigure(new Point(x0, y0), true /* is filled */, true /* is closed */);
                ctx.LineTo(new Point(x0, y1), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(x1, y1), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(x1, y0), true /* is stroked */, false /* is smooth join */);
            }
            lineGeometry.Freeze();
            return(lineGeometry);
        }
        private WinShapes.Path DrawRect(float sizeX, float sizeY, float factor, float height)
        {
            WinShapes.Path path     = new WinShapes.Path();
            StreamGeometry geometry = new StreamGeometry();

            path.Stroke          = Brushes.DarkGray;
            path.StrokeThickness = 1;
            path.Opacity         = 1;
            using (StreamGeometryContext context = geometry.Open())
            {
                context.BeginFigure(new Point(0, height), false, false);
                context.LineTo(new Point(sizeX * factor, height), true, false);
                context.LineTo(new Point(sizeX * factor, height - (sizeY * factor)), true, false);
                context.LineTo(new Point(0, height - (sizeY * factor)), true, false);
                context.LineTo(new Point(0, height), true, false);
            }
            geometry.Freeze();
            path.Data = geometry;
            return(path);
        }
Example #3
0
        protected void DrawArrowBackdrop(DrawingContext context, Matrix rotation, Point corner1, Point corner2)
        {
            Point                 startPoint            = new Point(corner1.X, corner1.Y) * rotation;
            Point                 point1                = new Point(corner2.X, corner1.Y) * rotation;
            Point                 point2                = new Point(corner2.X, corner2.Y) * rotation;
            Point                 point3                = new Point(corner1.X, corner2.Y) * rotation;
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.BeginFigure(startPoint, true, true);
            streamGeometryContext.PolyLineTo((IList <Point>) new Point[3]
            {
                point1,
                point2,
                point3
            }, 0 != 0, 0 != 0);
            streamGeometryContext.Close();
            streamGeometry.Freeze();
            context.DrawGeometry((Brush)Brushes.Transparent, (Pen)null, (System.Windows.Media.Geometry)streamGeometry);
        }
Example #4
0
        private Geometry DrawArrow(Point point, bool isleft)
        {
            var tempLen   = isleft ? _arrowLen : -_arrowLen;
            var upPoint   = new Point(point.X + tempLen, point.Y - Math.Tanh(30) * _arrowLen);
            var downPoint = new Point(point.X + tempLen, Math.Tanh(30) * _arrowLen + point.Y);

            var g = new StreamGeometry();

            using (StreamGeometryContext context = g.Open())
            {
                context.BeginFigure(point, true, false);
                context.LineTo(upPoint, true, false);
                context.LineTo(downPoint, true, false);
            }
            g.Freeze();
            Element.AddXGuidelines(downPoint.X + _halfPenWidth);
            Element.AddXGuidelines(upPoint.X + _halfPenWidth);

            return(g);
        }
Example #5
0
        protected override void OnRender(DrawingContext context)
        {
            double w  = this.ActualWidth;
            double h  = this.ActualHeight;
            double th = Thickness;

            // base.OnRender(context);

            if (geometry == null)
            {
                geometry          = new StreamGeometry();
                geometry.FillRule = FillRule.EvenOdd;
                using (StreamGeometryContext ctx = geometry.Open())
                {
                    ctx.BeginFigure(new Point(0, h), true /* is filled */, false /* is closed */);
                    ctx.ArcTo(new Point(w, 0), new Size(w, h), 0, false, SweepDirection.Clockwise, true, false);
                }
            }
            context.DrawGeometry(null, new Pen(Brushes.Black, th), geometry);
        }
Example #6
0
        void AddLine(double x1, double y1, double x2, double y2, Brush stroke, LineStyle lineStyle = LineStyle.Solid, double thickness = 1)
        {
            var path = new Path();

            path.Stroke          = stroke;
            path.StrokeThickness = thickness;
            SetLineStyle(path, lineStyle);

            var geom = new StreamGeometry();

            using (var ctx = geom.Open())
            {
                ctx.BeginFigure(new Point(x1, y1), false, false);
                ctx.LineTo(new Point(x2, y2), true, true);
            }
            geom.Freeze();
            path.Data = geom;
            RenderOptions.SetEdgeMode(path, EdgeMode.Aliased);
            GraphCanvas.Children.Add(path);
        }
Example #7
0
        public override void Draw(DrawingContext drawingContext)
        {
            List <Point> points = PointsOfStar(radiusX, m_center);

            var geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(points[0], true /* is filled */, true /* is closed */);
                ctx.PolyLineTo(points, true, false);
            }
            geometry.Freeze();

            Pen pen = this.CreatePen();

            Trans = new RotateTransform(Degree, Center.X, Center.Y);
            drawingContext.PushTransform(Trans);
            drawingContext.DrawGeometry(this.Background, pen, geometry);
            drawingContext.Pop();
        }
Example #8
0
        public void CubicBezier_Absolute()
        {
            Decorator target = new Decorator
            {
                Width  = 200,
                Height = 200,
                Child  = new Path
                {
                    Fill                = Brushes.Gray,
                    Stroke              = Brushes.Red,
                    StrokeThickness     = 1,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Data                = StreamGeometry.Parse("M190,0 C10,10 190,190 10,190 M0,0M200,200"),
                }
            };

            RenderToFile(target);
            CompareImages();
        }
Example #9
0
        public void Path_100px_Triangle_Centered()
        {
            Decorator target = new Decorator
            {
                Width   = 200,
                Height  = 200,
                Content = new Path
                {
                    Fill                = Brushes.Gray,
                    Stroke              = Brushes.Red,
                    StrokeThickness     = 2,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Data                = StreamGeometry.Parse("M 0,100 L 100,100 50,0 Z"),
                }
            };

            this.RenderToFile(target);
            this.CompareImages();
        }
Example #10
0
        public async Task HorizontalLine_Relative()
        {
            Decorator target = new Decorator
            {
                Width  = 200,
                Height = 200,
                Child  = new Path
                {
                    Stroke              = Brushes.Red,
                    StrokeThickness     = 1,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Data = StreamGeometry.Parse("M190,100 h-180 M0,0M200,200"),
                }
            };

            await RenderToFile(target);

            CompareImages();
        }
Example #11
0
        private Geometry GetGeometry()
        {
            Point          start = new Point(Width, 0);
            StreamGeometry geom  = new StreamGeometry();

            using (StreamGeometryContext context = geom.Open())
            {
                context.BeginFigure(start, false, false);
                for (int lIndex = 0; lIndex < 4; lIndex++)
                {
                    Point?nextPoint = CalculatePoint(lIndex);
                    if (nextPoint == null)
                    {
                        break;
                    }
                    context.LineTo((Point)nextPoint, true, true);
                }
            }
            return(geom);
        }
Example #12
0
        private Geometry GetArcBarsGeometry(double offsetStart)
        {
            var   start      = StartAngle + offsetStart;
            Point startPoint = PointAtAngle(Math.Min(start, start + 2));
            Point endPoint   = PointAtAngle(Math.Max(start, start + 2));

            Size arcSize = new Size(Math.Max(0, (RenderSize.Width - StrokeThickness) / 2),
                                    Math.Max(0, (RenderSize.Height - StrokeThickness) / 2));
            bool isLargeArc = false;// Math.Abs(EndAngle - StartAngle) > 180;

            StreamGeometry geom = new StreamGeometry();

            using (StreamGeometryContext context = geom.Open())
            {
                context.BeginFigure(startPoint, false, false);
                context.ArcTo(endPoint, arcSize, 0, isLargeArc, SweepDirection.Clockwise, true, false);
            }
            geom.Transform = new TranslateTransform(StrokeThickness / 2, StrokeThickness / 2);
            return(geom);
        }
Example #13
0
        public override void Draw(DrawingContext drawingContext)
        {
            Pen pen = new Pen(_stokeColor, 5);

            pen.Freeze();

            var geometry = new StreamGeometry();

            using (var ctx = geometry.Open())
            {
                ctx.BeginFigure(_points[0], false, false);
                for (var i = 1; i < _points.Count; ++i)
                {
                    ctx.LineTo(_points[i], true, false);
                }
            }
            geometry.Freeze();

            drawingContext.DrawGeometry(_stokeColor, pen, geometry);
        }
Example #14
0
        override public void Draw(DrawingContext drawingContext, ViewPort vp)
        {
            var geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(worldPoints[0], true, false);
                foreach (var point in worldPoints)
                {
                    ctx.LineTo(point, true, true);
                }
            }

            var center = new Point(geometry.Bounds.X + geometry.Bounds.Width / 2, geometry.Bounds.Y + geometry.Bounds.Height / 2);

            drawingContext.PushTransform(new RotateTransform(rotationAngle, center.X, center.Y));
            drawingContext.PushTransform(new ScaleTransform(scale, scale, center.X, center.Y));
            drawingContext.PushTransform(new TranslateTransform(offsetX, offsetY));
            drawingContext.DrawGeometry(brush, p, geometry);
        }
Example #15
0
        private static void DrawPolygonOrPolyline(DrawingContext drawingContext, Brush brush, Pen pen, Point[] points)
        {
            // Make a StreamGeometry to hold the drawing objects.
            var geo = new StreamGeometry();

            //geo.FillRule = fill_rule;

            // Open the context to use for drawing.
            using (var context = geo.Open())
            {
                // Start at the first point.
                context.BeginFigure(points[0], true, true);

                // Add the points after the first one.
                context.PolyLineTo(points.Skip(1).ToArray(), true, false);
            }

            // Draw.
            drawingContext.DrawGeometry(brush, pen, geo);
        }
Example #16
0
        private void CreateRegion()
        {
            regionGeo = new StreamGeometry();

            var p0 = PointSnapper.SnapPoint(Points[0]);
            var p1 = PointSnapper.SnapPoint(Points[1]);

            using (var gdc = regionGeo.Open())
            {
                var ptTemp = new Point(p0.X, p0.Y - 3);

                gdc.BeginFigure(ptTemp, true, true);
                ptTemp = new Point(p1.X, p1.Y - 3);
                gdc.LineTo(ptTemp, false, false);
                ptTemp = new Point(p1.X, p1.Y + 3);
                gdc.LineTo(ptTemp, false, false);
                ptTemp = new Point(p0.X, p0.Y + 3);
                gdc.LineTo(ptTemp, false, false);
            }
        }
Example #17
0
        public void Arc_Relative()
        {
            Decorator target = new Decorator
            {
                Width  = 200,
                Height = 200,
                Child  = new Path
                {
                    Fill                = Brushes.Gray,
                    Stroke              = Brushes.Red,
                    StrokeThickness     = 1,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Data                = StreamGeometry.Parse("M190,100 a90,90 0 1,0 -180,0  M0,0M200,200"),
                }
            };

            RenderToFile(target);
            CompareImages();
        }
        private void DrawLine(Connection c)
        {
            Path linePath = new Path();

            linePath.Stroke          = Brushes.DeepPink;
            linePath.StrokeThickness = 3;

            StreamGeometry streamGeometry = new StreamGeometry();

            using (StreamGeometryContext sgc = streamGeometry.Open())
            {
                sgc.BeginFigure(new Point(c.Point1.X, 500 - c.Point1.Y), false, false);
                sgc.LineTo(new Point(c.Point2.X, 500 - c.Point2.Y), true, false);
            }

            streamGeometry.Freeze();
            linePath.Data = streamGeometry;
            MyCanvas.Children.Add(linePath);
            paths.Add(linePath);
        }
        private void CreateRegion(Point[] ptSnapped)
        {
            regionGeo = new GeometryGroup();

            var line1Geo = new StreamGeometry();

            using (var gdc = line1Geo.Open())
            {
                var ptTemp = new Point(ptSnapped[0].X, ptSnapped[0].Y - 3);

                gdc.BeginFigure(ptTemp, true, true);
                ptTemp = new Point(ptSnapped[1].X, ptSnapped[1].Y - 3);
                gdc.LineTo(ptTemp, false, false);
                ptTemp = new Point(ptSnapped[1].X, ptSnapped[1].Y + 3);
                gdc.LineTo(ptTemp, false, false);
                ptTemp = new Point(ptSnapped[0].X, ptSnapped[0].Y + 3);
                gdc.LineTo(ptTemp, false, false);
            }
            regionGeo.Children.Add(line1Geo);

            var line2Geo = new StreamGeometry();

            using (var gdc = line2Geo.Open())
            {
                var diffX = ptSnapped[1].X - ptSnapped[2].X;
                var diffY = ptSnapped[1].Y - ptSnapped[2].Y;

                var pt20 = new Point(ptSnapped[0].X - diffX, ptSnapped[0].Y - diffY);

                var ptTemp = new Point(pt20.X, pt20.Y - 3);
                gdc.BeginFigure(ptTemp, true, true);
                ptTemp = new Point(ptSnapped[2].X, ptSnapped[2].Y - 3);
                gdc.LineTo(ptTemp, false, false);
                ptTemp = new Point(ptSnapped[2].X, ptSnapped[2].Y + 3);
                gdc.LineTo(ptTemp, false, false);
                ptTemp = new Point(ptTemp.X, ptTemp.Y + 3);
                gdc.LineTo(ptTemp, false, false);
            }

            regionGeo.Children.Add(line2Geo);
        }
Example #20
0
        /// <summary>
        /// creates path from list of points, for performance set addBlurEffect to false
        /// </summary>
        /// <param name="pl"></param>
        /// <returns></returns>
        public virtual Path CreatePath(List <Point> localPath, bool addBlurEffect)
        {
            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(localPath[0], true, true);
                // Draw a line to the next specified point.
                ctx.PolyLineTo(localPath, true, true);
            }
            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();
            // Create a path to draw a geometry with.
            Path myPath = new Path();

            {
                // Specify the shape of the Path using the StreamGeometry.
                myPath.Data = geometry;
                if (addBlurEffect)
                {
                    BlurEffect ef = new BlurEffect();
                    {
                        ef.KernelType    = KernelType.Gaussian;
                        ef.Radius        = 3.0;
                        ef.RenderingBias = RenderingBias.Performance;
                    }
                    myPath.Effect = ef;
                }
                myPath.Stroke             = Brushes.MidnightBlue;
                myPath.StrokeThickness    = 5;
                myPath.StrokeLineJoin     = PenLineJoin.Round;
                myPath.StrokeStartLineCap = PenLineCap.Triangle;
                myPath.StrokeEndLineCap   = PenLineCap.Square;
                myPath.Fill             = Brushes.AliceBlue;
                myPath.Opacity          = 0.6;
                myPath.IsHitTestVisible = false;
            }
            return(myPath);
        }
Example #21
0
        private Geometry GetGeometry()
        {
            double cornerRadius = 10;
            double speechOffset = 30;
            double speechDepth  = 20;
            double speechWidth  = 20;
            double width        = ActualWidth - StrokeThickness;
            double height       = ActualHeight - StrokeThickness;
            var    g            = new StreamGeometry();

            using (var context = g.Open())
            {
                double x0 = StrokeThickness / 2;
                double x1 = x0 + cornerRadius;
                double x2 = width - cornerRadius - x0;
                double x3 = x2 + cornerRadius;

                double x4 = x0 + speechOffset;
                double x5 = x4 + speechWidth;

                double y0 = StrokeThickness / 2;
                double y1 = y0 + cornerRadius;
                double y2 = height - speechDepth - (cornerRadius * 2);
                double y3 = y2 + cornerRadius;
                double y4 = y3 + speechDepth;
                context.BeginFigure(new Point(x1, y0), true, true);
                context.LineTo(new Point(x2, y0), true, true);
                context.ArcTo(new Point(x3, y1), new Size(cornerRadius, cornerRadius), 90, false, SweepDirection.Clockwise, true, true);
                context.LineTo(new Point(x3, y2), true, true);
                context.ArcTo(new Point(x2, y3), new Size(cornerRadius, cornerRadius), 90, false, SweepDirection.Clockwise, true, true);
                context.LineTo(new Point(x5, y3), true, true);
                context.LineTo(new Point(x4, y4), true, true);
                context.LineTo(new Point(x4, y3), true, true);
                context.LineTo(new Point(x1, y3), true, true);
                context.ArcTo(new Point(x0, y2), new Size(cornerRadius, cornerRadius), 90, false, SweepDirection.Clockwise, true, true);
                context.LineTo(new Point(x0, y1), true, true);
                context.ArcTo(new Point(x1, y0), new Size(cornerRadius, cornerRadius), 90, false, SweepDirection.Clockwise, true, true);
            }
            g.Freeze();
            return(g);
        }
Example #22
0
        public Form1()
        {
            InitializeComponent();

            _render = new PlatformRenderInterface();
            PerspexLocator.CurrentMutable.Bind <IPlatformRenderInterface>().ToConstant(_render);
            _geometry     = new StreamGeometry();
            _rbitmap      = new RenderTargetBitmap(50, 50);
            _renderTarget = _render.CreateRenderer(new PlatformHandle(Handle, "HWND"), ClientSize.Width,
                                                   ClientSize.Height);
            var timer = new Timer()
            {
                Interval = 20
            };

            timer.Tick += delegate { Invalidate(); };
            timer.Start();
            components.Add(timer);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            using (var ctx = _geometry.Open())
            {
                ctx.BeginFigure(new Point(10, 10), true);
                ctx.LineTo(new Point(40, 25));
                ctx.BezierTo(new Point(50, 45), new Point(43, 48), new Point(20, 90));
                ctx.LineTo(new Point(10, 60));
                ctx.EndFigure(true);
            }

            _text =
                new FormattedText(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
                    "Arial", 25, FontStyle.Normal, TextAlignment.Left, FontWeight.Normal);

            _text.Constraint = new Size(400, double.PositiveInfinity);

            using (var ctx = _rbitmap.CreateDrawingContext())
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Aqua)), new Rect(10, 10, 30, 30), 5);

            _bitmap = new Bitmap(@"C:\Users\keks\Desktop\phoenix.png");
        }
Example #23
0
        /// <summary> Builds the geometry of the polyline. </summary>
        /// <param name="mapView">Map view which will show the lines.</param>
        /// <param name="lines"> A collection of point collections to build the geometry for (multiple) polylines. </param>
        /// <returns> The geometry corresponding to the given point collections. </returns>
        protected Geometry BuildGeometry(MapView mapView, ICollection <PointCollection> lines)
        {
            var streamGeometry = new StreamGeometry();

            using (var streamGeometryContext = streamGeometry.Open())
            {
                foreach (var points in lines)
                {
                    double len   = CurrentThickness(mapView.CurrentScale) * 2;
                    int    pos   = 0;
                    double rel   = 0;
                    var    pp1   = points[0];
                    var    first = true;
                    while (GetNextArrPos(points, first? len / 2 : len, ref pos, ref rel))
                    {
                        first = false;

                        var p1 = points[pos];
                        var p2 = points[pos + 1];

                        double vx = p2.X - p1.X;
                        double vy = p2.Y - p1.Y;

                        double lv = Math.Sqrt(vx * vx + vy * vy);

                        var p = new Point {
                            X = p1.X + vx * rel / lv, Y = p1.Y + vy * rel / lv
                        };

                        var vpp = new Point {
                            X = 2 * p.X - pp1.X, Y = 2 * p.Y - pp1.Y
                        };

                        DrawArrow(streamGeometryContext, p, vpp, len * .5, 0);
                        pp1 = p;
                    }
                }
            }

            return(streamGeometry);
        }
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (!markers.Any() || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            foreach (ErrorTextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                foreach (Rect rect in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                {
                    Point startPoint = rect.BottomLeft;
                    Point endPoint   = rect.BottomRight;

                    var pen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);
                    pen.Freeze();

                    const double offset = 2.5;
                    int          count  = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                    var geometry = new StreamGeometry();
                    using (StreamGeometryContext ctx = geometry.Open())
                    {
                        ctx.BeginFigure(startPoint, false, false);
                        ctx.PolyLineTo(CreatePoints(startPoint, offset, count).ToArray(), true, false);
                    }
                    geometry.Freeze();

                    drawingContext.DrawGeometry(Brushes.Transparent, pen, geometry);
                    break;
                }
            }
        }
        public override void Draw(DrawingContext context, Matrix matrix)
        {
            if (!this.shouldDraw || !PlatformTypes.Rectangle.IsAssignableFrom((ITypeId)this.Element.Type))
            {
                return;
            }
            Size ofTransformedRect = Adorner.GetSizeOfTransformedRect(this.ElementBounds, matrix);

            if (ofTransformedRect.Width < 5.0 || ofTransformedRect.Height < 5.0)
            {
                return;
            }
            Point clickablePoint = this.GetClickablePoint(matrix);
            Point point          = new Point(this.EffectiveRadiusX, this.EffectiveRadiusY) * matrix;
            Pen   pen            = this.ThinPen;

            if (VectorUtilities.SquaredDistance(clickablePoint, point) < 10000000000.0)
            {
                pen           = pen.Clone();
                pen.DashStyle = RoundedRectangleAdorner.dashStyle;
                pen.Freeze();
            }
            context.DrawLine(pen, point, clickablePoint);
            Vector                vector1               = RoundedRectangleAdorner.radius * this.NormalDirection;
            Vector                vector2               = new Vector(vector1.Y, -vector1.X);
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.BeginFigure(clickablePoint + vector1, true, true);
            streamGeometryContext.PolyLineTo((IList <Point>) new Point[3]
            {
                clickablePoint + vector2,
                clickablePoint - vector1,
                clickablePoint - vector2
            }, 1 != 0, 0 != 0);
            streamGeometryContext.Close();
            streamGeometry.Freeze();
            Brush brush = this.IsActive ? this.ActiveBrush : this.InactiveBrush;

            context.DrawGeometry(brush, this.ThinPen, (System.Windows.Media.Geometry)streamGeometry);
        }
Example #26
0
        public virtual Drawing GetOneWay()
        {
            const double HeadHeight  = 0.4;
            const double TailHeight  = 0.4;
            const double HeadRange   = 0.4;
            const double TailRange   = 0.15;
            const double Cave        = TailRange;
            const double Caliber     = 0.16;
            const double HalfCaliber = Caliber / 2;

            var drawingVisual = new DrawingVisual();

            using (var dc = drawingVisual.RenderOpen()) {
                var geometry = new StreamGeometry();
                using (var sgc = geometry.Open()) {
                    var p = new Point(0.5 + HeadHeight, 0.5);
                    sgc.BeginFigure(p, true, true);
                    p.Offset(-HeadHeight, -HeadRange);
                    sgc.LineTo(p, true, false);
                    p.Offset(0, HeadRange - TailRange);
                    sgc.LineTo(p, true, false);
                    p.Offset(-TailHeight, 0);
                    sgc.LineTo(p, true, false);
                    p.Offset(Cave, TailRange);
                    sgc.LineTo(p, true, false);
                    p.Offset(-Cave, TailRange);
                    sgc.LineTo(p, true, false);
                    p.Offset(TailHeight, 0);
                    sgc.LineTo(p, true, false);
                    p.Offset(0, HeadRange - TailRange);
                    sgc.LineTo(p, true, false);
                }
                geometry.Freeze();
                var rect   = Freeze(new RectangleGeometry(new Rect(0, 0.5 - HalfCaliber, 1, Caliber)));
                var border = Freeze(Geometry.Combine(geometry, rect, GeometryCombineMode.Exclude, DefaultScaleTransform));
                var mirror = Freeze(Geometry.Combine(geometry, rect, GeometryCombineMode.Intersect, DefaultScaleTransform));
                dc.DrawGeometry(Brushes.Black, null, border);
                dc.DrawGeometry(MirrorBrush, null, mirror);
            }
            return(Freeze(drawingVisual.Drawing));
        }
Example #27
0
        public MainWindow()
        {
            InitializeComponent();

            sg = new StreamGeometry();

            var ox = new StreamGeometry();

            using (StreamGeometryContext ctx = ox.Open())
            {
                ctx.BeginFigure(new Point(xadd, yadd + CanvasArea.Height), true, false);

                ctx.LineTo(new Point(xadd + 300.0, yadd + CanvasArea.Height), true, false);
            }

            var oy = new StreamGeometry();

            using (StreamGeometryContext ctx = oy.Open())
            {
                ctx.BeginFigure(new Point(xadd, yadd + CanvasArea.Height), true, false);

                ctx.LineTo(new Point(xadd, yadd + CanvasArea.Height - 300.0), true, false);
            }

            using (StreamGeometryContext ctx = sg.Open())
            {
                ctx.BeginFigure(new Point(xadd + 200.0 / 5.0, yadd + CanvasArea.Height - Func(200.0 / 100.0)), true, false);
                for (int i = 200; i < 700; ++i)
                {
                    ctx.LineTo(new Point(xadd + i / 5.0, yadd + CanvasArea.Height - Func(i / 100.0)), true, true);
                }
            }
            GraphiPath.Data = sg;
            YPath.Data      = oy;
            XPath.Data      = ox;



            t        = F(4.0).ToString();
            te.Text += t;
        }
Example #28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="arc"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            if (!arc.IsFilled && !arc.IsStroked)
            {
                return;
            }

            var _dc = dc as DrawingContext;

            Brush brush = ToSolidBrush(arc.Style.Fill);
            Pen   pen   = ToPen(arc.Style, _scaleToPage);

            var sg = new StreamGeometry();

            using (var sgc = sg.Open())
            {
                var a = WpfArc.FromXArc(arc, dx, dy);

                sgc.BeginFigure(
                    new Point(a.Start.X, a.Start.Y),
                    arc.IsFilled);

                sgc.ArcTo(
                    new Point(a.End.X, a.End.Y),
                    new Size(a.Radius.Width, a.Radius.Height),
                    0.0,
                    a.IsLargeArc,
                    SweepDirection.Clockwise);

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                arc.IsFilled ? brush : null,
                arc.IsStroked ? pen : null,
                sg);

            // TODO: sg.Dispose();
            // TODO: brush.Dispose();
            // TODO: pen.Dispose();
        }
        public StreamGeometryTriangleExample()
        {
            // Create a path to draw a geometry with.
            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;

            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            geometry.FillRule = FillRule.EvenOdd;

            // Open a StreamGeometryContext that can be used to describe this StreamGeometry
            // object's contents.
            using (StreamGeometryContext ctx = geometry.Open())
            {
                // Begin the triangle at the point specified. Notice that the shape is set to
                // be closed so only two lines need to be specified below to make the triangle.
                ctx.BeginFigure(new Point(10, 100), true /* is filled */, true /* is closed */);

                // Draw a line to the next specified point.
                ctx.LineTo(new Point(100, 100), true /* is stroked */, false /* is smooth join */);

                // Draw another line to the next specified point.
                ctx.LineTo(new Point(100, 50), true /* is stroked */, false /* is smooth join */);
            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

            // Specify the shape (triangle) of the Path using the StreamGeometry.
            myPath.Data = geometry;

            // Add path shape to the UI.
            StackPanel mainPanel = new StackPanel();

            mainPanel.Children.Add(myPath);
            this.Content = mainPanel;
        }
Example #30
0
        public async Task Arc_Absolute()
        {
            Decorator target = new Decorator
            {
                Width  = 200,
                Height = 200,
                Child  = new Path
                {
                    Fill                = Brushes.Gray,
                    Stroke              = Brushes.Red,
                    StrokeThickness     = 1,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Data                = StreamGeometry.Parse("M190,100 A90,90 0 1,0 10,100  M0,0M200,200"),
                }
            };

            await RenderToFile(target);

            CompareImages();
        }
        internal static void Deserialize(BinaryReader br, StreamGeometryContext sc, StreamGeometry geometry)
        {
            bool closed = false;
            Byte currentByte;

            while (!closed)
            {
                currentByte = br.ReadByte();

                ParserGeometryContextOpCodes opCode = UnPackOpCode(currentByte);

                switch(opCode)
                {
                    case ParserGeometryContextOpCodes.FillRule :
                        DeserializeFillRule(br, currentByte, geometry);
                        break;

                    case ParserGeometryContextOpCodes.BeginFigure :
                        DeserializeBeginFigure(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.LineTo :
                        DeserializeLineTo(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.QuadraticBezierTo :
                        DeserializeQuadraticBezierTo(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.BezierTo :
                        DeserializeBezierTo(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.PolyLineTo :
                        DeserializePolyLineTo(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.PolyQuadraticBezierTo :
                        DeserializePolyQuadraticBezierTo(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.PolyBezierTo :
                        DeserializePolyBezierTo(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.ArcTo :
                        DeserializeArcTo(br, currentByte, sc);
                        break;

                    case ParserGeometryContextOpCodes.Closed :
                        closed = true;
                        break;
                }
            }
        }
Example #32
0
 public GeoStream() {
   _StreamGeometry = new StreamGeometry();
 }
        //
        // Deserialization Methods.
        //
        // These are only required at "runtime" - therefore only in PRESENTATION_CORE
        //

#if PRESENTATION_CORE

        private static void DeserializeFillRule(BinaryReader br, Byte firstByte, StreamGeometry geometry)
        {
            bool boolFillRule;
            bool unused;
            FillRule fillRule;

            UnPackBools(firstByte, out boolFillRule, out unused);

            fillRule = BoolToFillRule(boolFillRule);

            geometry.FillRule = fillRule;

        }