Exemplo n.º 1
0
        public override void OnRender(DrawingContext drawingContext, Rect bounds)
        {
            if (Polgyons != null)
            {
                var offset = new Vector();

                if (Pen != null)
                {
                    // snap to pixels
                    var half = Pen.Thickness * .5;
                    offset.X -= half;
                    offset.Y -= half;
                }

                StreamGeometry streamGeometry = new StreamGeometry();
                using (StreamGeometryContext geometryContext = streamGeometry.Open())
                {
                    foreach (var absPoly in Polgyons)
                    {
                        var poly = absPoly - offset;
                        geometryContext.BeginFigure(poly.StartPoint, Brush != null, true);
                        geometryContext.PolyLineTo(poly.Points, Pen != null, true);
                    }
                }

                drawingContext.DrawGeometry(Brush, Pen, streamGeometry);
            }
        }
        protected override void OnRenderCore(DrawingContext dc, RenderState state)
        {
            Rect outputWMargin = state.Output;
            var  transform     = Viewport.Transform;

            if (outputWMargin.Width == 0 || outputWMargin.Height == 0)
            {
                return;
            }

            StreamGeometry       cachedGeom     = new StreamGeometry();
            List <List <Point> > transformedPts = new List <List <Point> >();

            foreach (List <Point> list in points)
            {
                transformedPts.Add(list.DataToScreen(transform));
            }

            cachedGeom = new StreamGeometry();
            using (StreamGeometryContext context = cachedGeom.Open())
            {
                foreach (List <Point> pts in transformedPts)
                {
                    context.BeginFigure(pts[0], false, false);
                    context.PolyLineTo(pts, true, true);
                }
            }
            cachedGeom.Freeze();
            dc.DrawGeometry(
                Brushes.LightGray,
                new Pen(Brushes.Black, 1),
                cachedGeom);
        }
Exemplo n.º 3
0
        private Geometry GetGeometry()
        {
            if (dlx == 0 || dly == 0)
            {
                return(StreamGeometry.Empty);
            }
            if (ChartDataSeries == null || ChartDataSeries.Count <= 1)
            {
                return(StreamGeometry.Empty);
            }


            StreamGeometry stream = new StreamGeometry();

            using (StreamGeometryContext geom = stream.Open())
            {
                var points = new List <Point>();
                ChartDataSeries.ToList().ForEach(
                    p =>
                {
                    points.Add(Normalize(p));
                }
                    );
                geom.BeginFigure(points[0], false, false);
                geom.PolyLineTo(points, true, true);
            }
            return(stream);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generate an image to overlay on thumbnails of animations.
        /// </summary>
        /// <returns></returns>
        private static BitmapSource GenerateAnimOverlayImage()
        {
            const int IMAGE_SIZE = 128;

            // Glowy "high tech" blue.
            SolidColorBrush outlineBrush = new SolidColorBrush(Color.FromArgb(255, 0, 216, 255));
            SolidColorBrush fillBrush    = new SolidColorBrush(Color.FromArgb(128, 0, 182, 215));

            DrawingVisual visual = new DrawingVisual();

            using (DrawingContext dc = visual.RenderOpen()) {
                // Thanks: https://stackoverflow.com/a/29249100/294248
                Point          p1 = new Point(IMAGE_SIZE * 5 / 8, IMAGE_SIZE / 2);
                Point          p2 = new Point(IMAGE_SIZE * 3 / 8, IMAGE_SIZE / 4);
                Point          p3 = new Point(IMAGE_SIZE * 3 / 8, IMAGE_SIZE * 3 / 4);
                StreamGeometry sg = new StreamGeometry();
                using (StreamGeometryContext sgc = sg.Open()) {
                    sgc.BeginFigure(p1, true, true);
                    PointCollection points = new PointCollection()
                    {
                        p2, p3
                    };
                    sgc.PolyLineTo(points, true, true);
                }
                sg.Freeze();
                dc.DrawGeometry(fillBrush, new Pen(outlineBrush, 3), sg);
            }

            RenderTargetBitmap bmp = new RenderTargetBitmap(IMAGE_SIZE, IMAGE_SIZE, 96.0, 96.0,
                                                            PixelFormats.Pbgra32);

            bmp.Render(visual);
            bmp.Freeze();
            return(bmp);
        }
Exemplo n.º 5
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     if (!(OriginInfo == ConnectInfo.Empty || TargetInfo == ConnectInfo.Empty))
     {
         bool   run       = Running;
         Brush  brush     = run ? Brushes.GreenYellow : LineBrush;
         double thickness = this.Thickness;
         Pen    pen       = new Pen(brush, thickness);
         pen.StartLineCap = PenLineCap.Round;
         pen.EndLineCap   = PenLineCap.Round;
         pen.LineJoin     = PenLineJoin.Round;
         pen.DashStyle    = DashStyle;
         Panel.SetZIndex(this, run ? 1000 : 0);
         List <Point>   linepoint = PathFinder.GetConnectionLine(OriginInfo, TargetInfo, false);
         StreamGeometry geometry  = new StreamGeometry();
         using (StreamGeometryContext context = geometry.Open())
         {
             context.BeginFigure(linepoint[0], true, false);
             linepoint.RemoveAt(0);
             context.PolyLineTo(linepoint, true, false);
         }
         drawingContext.DrawGeometry(null, pen, geometry);
     }
 }
Exemplo n.º 6
0
        protected void DrawArrowTail(DrawingContext context, Matrix matrix, Point startPoint, Point endPoint)
        {
            startPoint *= matrix;
            endPoint   *= matrix;
            Matrix identity = Matrix.Identity;

            identity.RotateAt(Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X) * 180.0 / Math.PI, startPoint.X, startPoint.Y);
            Point                 startPoint1           = new Point(startPoint.X - 8.0 - 7.0, startPoint.Y) * identity;
            Point                 point1                = new Point(startPoint.X - 12.0 - 7.0, startPoint.Y - 4.0) * identity;
            Point                 point2                = new Point(startPoint.X - 4.0 - 7.0, startPoint.Y - 4.0) * identity;
            Point                 point3                = new Point(startPoint.X - 7.0, startPoint.Y) * identity;
            Point                 point4                = new Point(startPoint.X - 4.0 - 7.0, startPoint.Y + 4.0) * identity;
            Point                 point5                = new Point(startPoint.X - 12.0 - 7.0, startPoint.Y + 4.0) * identity;
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.BeginFigure(startPoint1, true, true);
            streamGeometryContext.PolyLineTo((IList <Point>) new Point[5]
            {
                point1,
                point2,
                point3,
                point4,
                point5
            }, 1 != 0, 0 != 0);
            streamGeometryContext.Close();
            streamGeometry.Freeze();
            this.DrawArrowBackdrop(context, identity, new Point(startPoint.X, startPoint.Y - 6.0), new Point(startPoint.X - 12.0 - 7.0, startPoint.Y + 6.0));
            Brush brush = this.IsActive ? this.ActiveBrush : this.InactiveBrush;

            context.DrawGeometry(brush, this.ThinPen, (System.Windows.Media.Geometry)streamGeometry);
        }
Exemplo n.º 7
0
        protected override void OnRenderCore(DrawingContext dc, RenderState state)
        {
            if (DataSource == null)
            {
                return;
            }
            if (!IsEnabled)
            {
                return;
            }

            if (filteredPoints.HasPoints)
            {
                using (StreamGeometryContext context = streamGeometry.Open())
                {
                    context.BeginFigure(filteredPoints.StartPoint, false, false);
                    context.PolyLineTo(filteredPoints, true, smoothLinesJoin);
                }

                Brush brush = null;
                Pen   pen   = LinePen;

                bool isTranslated = IsTranslated;
                if (isTranslated)
                {
                    dc.PushTransform(new TranslateTransform(Offset.X, Offset.Y));
                }
                dc.DrawGeometry(brush, pen, streamGeometry);
                if (isTranslated)
                {
                    dc.Pop();
                }
            }
        }
        private void IsoDrawMap(DrawingContext drawingContext)
        {
            /*ImageBrush tile = new ImageBrush
             * {
             *  ImageSource = new BitmapImage(new Uri(@"Resources\TablePattern.png", UriKind.Relative)),
             *  TileMode = TileMode.Tile
             * };
             * int[,] map = new int[15, 8];*/
            int h = 50;

            for (int i = 0; i < this.gm.MapWidth; i++)
            {
                for (int j = 0; j < this.gm.MapHeight; j++)
                {
                    StreamGeometry streamGeometry = new StreamGeometry();
                    using (StreamGeometryContext geometryContext = streamGeometry.Open())
                    {
                        geometryContext.BeginFigure(this.vh.IsoPosition(new Point(i * h, j * h)), true, true);
                        PointCollection points = this.PolygonPoint(i * h, j * h, h, h);

                        geometryContext.PolyLineTo(points, true, true);
                    }

                    // Draw the polygon visual
                    // DrawingVisual visual = new DrawingVisual();
                    drawingContext.DrawGeometry(Brushes.DarkGray, new Pen(Brushes.Gray, 1), streamGeometry);
                }
            }
        }
Exemplo n.º 9
0
 private static void MuscleDrawing(DrawingContext dc, Pen pen)
 {
     foreach (var muscle in shape.muscles)
     {
         Color color;
         if (muscle.currentTick < muscle.timeToContract)
         {
             color   = Colors.Red;
             color.A = (byte)(255 * muscle.contractionSizePrecentage * (1 - ((double)muscle.timeToContract / muscle.cylceDuration)));
         }
         else if (muscle.currentTick < muscle.timeToExtend + muscle.timeToContract)
         {
             color   = Colors.Blue;
             color.A = (byte)(255 - 255 * ((double)muscle.timeToExtend / muscle.cylceDuration));
         }
         else
         {
             color   = Colors.Gray;
             color.A = (byte)(255 - 255 * ((double)muscle.timeIdle / muscle.cylceDuration));
         }
         SolidColorBrush scb            = new SolidColorBrush(color);
         StreamGeometry  streamGeometry = new StreamGeometry();
         using (StreamGeometryContext geometryContext = streamGeometry.Open())
         {
             double          angle  = Angle(muscle);
             PointCollection muscly = new PointCollection();
             geometryContext.BeginFigure(new Point(muscle.nodes[0].GetNormalPoint().X + (nodeSize / 2) * scale - 5 * Math.Sin(angle) * scale, muscle.nodes[0].GetNormalPoint().Y + (nodeSize / 2) * scale - 5 * Math.Cos(angle) * scale), true, true);
             muscly.Add(new Point(muscle.nodes[0].GetNormalPoint().X + (nodeSize / 2) * scale + 5 * Math.Sin(angle) * scale, muscle.nodes[0].GetNormalPoint().Y + (nodeSize / 2) * scale + 5 * Math.Cos(angle) * scale));
             muscly.Add(new Point(muscle.nodes[1].GetNormalPoint().X + (nodeSize / 2) * scale + 5 * Math.Sin(angle) * scale, muscle.nodes[1].GetNormalPoint().Y + (nodeSize / 2) * scale + 5 * Math.Cos(angle) * scale));
             muscly.Add(new Point(muscle.nodes[1].GetNormalPoint().X + (nodeSize / 2) * scale - 5 * Math.Sin(angle) * scale, muscle.nodes[1].GetNormalPoint().Y + (nodeSize / 2) * scale - 5 * Math.Cos(angle) * scale));
             geometryContext.PolyLineTo(muscly, true, true);
         }
         dc.DrawGeometry(scb, pen, streamGeometry);
     }
 }
Exemplo n.º 10
0
        private static void DrawArrow(StreamGeometryContext gc, Point from, Point to2, double Wings, double offset)
        {
            var to = new Point(from.X * (1.0 - offset) + to2.X * offset, from.Y * (1.0 - offset) + to2.Y * offset);

            double dx = to2.X - from.X;
            double dy = to2.Y - from.Y;

            double len = Math.Sqrt(dx * dx + dy * dy);

            if (len == 0)
            {
                return;
            }

            dx = dx / len * Wings;
            dy = dy / len * Wings;

            var A = new Point(to.X - dx, to.Y - dy);

            var pts0 = new Point(to.X, to.Y);

            dx /= 2;
            dy /= 2;
            var pts1 = new Point(A.X - dy, A.Y + dx);
            var pts2 = new Point(A.X + dx / 2, A.Y + dy / 2);
            var pts3 = new Point(A.X + dy, A.Y - dx);

            gc.BeginFigure(pts0, true, true);
            gc.PolyLineTo(new[] { pts1, pts2, pts3 }, true, true);
        }
Exemplo n.º 11
0
        public Geometry GetGeometry()
        {
            List <Point> points = new List <Point>();

            for (int i = 0; i < n; i++)
            {
                double angle = i * 2 * Math.PI / n;
                Point  P     = new Point(r * Math.Cos(angle), r * Math.Sin(angle));
                if (i % 2 == 1)
                {
                    P.X *= 0.2;
                    P.Y *= 0.2;
                }
                P.X += r + Area.X;
                P.Y += r + Area.Y;
                points.Add(P);
            }

            StreamGeometry streamGeometry = new StreamGeometry();

            using (StreamGeometryContext geometryContext = streamGeometry.Open())
            {
                geometryContext.BeginFigure(points[0], true, true);
                geometryContext.PolyLineTo(points, true, true);
            }

            return(streamGeometry);
        }
Exemplo n.º 12
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            double width  = base.ActualWidth;
            double height = base.ActualHeight;
            Brush  brush  = new LinearGradientBrush(new GradientStopCollection {
                new GradientStop(Colors.Tomato, 0.0),
                new GradientStop(Colors.Black, 1.0)
            });

            if (this.Orientation == Orientation.Vertical)
            {
                StreamGeometry geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(width, 0), true, true);
                    context.PolyLineTo(new Point[] { new Point(0, height * 0.5), new Point(width, height) }, true, false);
                }
                drawingContext.DrawGeometry(brush, null, geometry);
            }
            else
            {
                StreamGeometry geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(0, height), true, true);
                    context.PolyLineTo(new Point[] { new Point(width * 0.5, 0), new Point(width, height) }, true, false);
                }
                drawingContext.DrawGeometry(brush, null, geometry);
            }
        }
Exemplo n.º 13
0
        public Bin(Brush nColour, double nScaleX, double nScaleY) : base(nColour, nScaleX, nScaleY)
        {
            using (StreamGeometryContext geometryContext = base.BGGeometry.Open())
            {
                geometryContext.BeginFigure(new Point(-16.0d, -16.0d), true, true);

                pc = new PointCollection();
                pc.Add(new Point(16.0d, -16.0d));
                pc.Add(new Point(16.0d, 16.0d));
                pc.Add(new Point(-16.0d, 16.0d));

                geometryContext.PolyLineTo(pc, true, true);
            }
            using (StreamGeometryContext geometryContext2 = base.IconGeometry.Open())
            {
                geometryContext2.BeginFigure(new Point(-16.0d, -16.0d), true, true);

                pc2 = new PointCollection();
                pc2.Add(new Point(16.0d, -16.0d));
                pc2.Add(new Point(16.0d, 16.0d));
                pc2.Add(new Point(-16.0d, 16.0d));

                geometryContext2.PolyLineTo(pc, true, true);
            }
            string uri = "pack://application:,,,/Assets/Bins.png";

            _NextElementID++;
            name    = "Bin " + _NextElementID;
            _FEType = "Bin";

            ImageSource imageSource = new ImageSourceConverter().ConvertFromString(uri) as ImageSource;

            _IconBrush = new ImageBrush(new BitmapImage(new Uri(imageSource.ToString())));
        }
Exemplo n.º 14
0
        //在Canvas绘制多边形,numSides=边数,r=半径
        public StreamGeometry BuildregularPolygon(int numSides, int r)
        {
            Point          c        = new Point(100, 250);//中心点
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                Point  c1   = c;
                double step = 2 * Math.PI / Math.Max(numSides, 3);
                double a    = step;
                //循环绘制并连接点
                for (int i = 0; i < numSides; i++, a += step)
                {
                    c1.X = c.X + r * Math.Cos(a);
                    c1.Y = c.Y + r * Math.Sin(a);
                    if (i == 0)
                    {
                        ctx.BeginFigure(c1, true, true);//图像开始点
                    }
                    else
                    {
                        ctx.LineTo(c1, true, false);//从上一个点连接至新的点
                    }
                }
                for (int i = 0; i < numSides; i++, a += step)
                {
                    c1.X = c.X + r * Math.Cos(a);
                    c1.Y = c.Y + r * Math.Sin(a);
                    Point[] pp = { c, c1 };
                    ctx.PolyLineTo(pp, true, true);      //从中心点连接到该点
                }
            }
            return(geometry);
        }
Exemplo n.º 15
0
        private void InternalDrawArrowGeometry(StreamGeometryContext context)
        {
            var theta = Math.Atan2(Y1 - Y2, X1 - X2);
            var sint  = Math.Sin(theta);
            var cost  = Math.Cos(theta);

            var x2WithOffset = X2 + EndPositionOffset * cost;
            var y2WithOffset = Y2 + EndPositionOffset * sint;

            var pt1 = new Point(X1, Y1);
            var pt2 = new Point(x2WithOffset, y2WithOffset);

            var pt3 = new Point(
                x2WithOffset + (HeadWidth * cost - HeadHeight * sint),
                y2WithOffset + (HeadWidth * sint + HeadHeight * cost));

            var pt4 = new Point(
                x2WithOffset + (HeadWidth * cost + HeadHeight * sint),
                y2WithOffset - (HeadHeight * cost - HeadWidth * sint));

            context.BeginFigure(pt1, true, false);
            context.LineTo(pt2, true, true);
            if (IsDirected)
            {
                context.PolyLineTo(new[] { pt3, pt4, pt2 }, true, true);
            }
        }
Exemplo n.º 16
0
        public override void Render(DrawingContext dc)
        {
            var strokeBrush = new SolidColorBrush(StrokeColor);

            strokeBrush.Freeze();

            var pen = new Pen(strokeBrush, StrokeThickness);

            pen.Freeze();

            var geom = new StreamGeometry();

            using (StreamGeometryContext ctx = geom.Open())
            {
                var startVertex = Canvas.CoordinateSystem.ToScreenSpace(StartPoint);
                ctx.BeginFigure(new System.Windows.Point(startVertex[0], startVertex[1]), false, false);
                ctx.PolyLineTo(Points.Skip(1).Select(p =>
                {
                    var vertex = Canvas.CoordinateSystem.ToScreenSpace(p);
                    return(new System.Windows.Point(vertex[0], vertex[1]));
                }).ToList(),

                               true /* is stroked */, true /* is smooth join */);
            }
            geom.Freeze();

            dc.DrawGeometry(null, pen, geom);
        }
Exemplo n.º 17
0
        protected override void OnRender(DrawingContext dc)
        {
            BitmapSource bit = null;

            if (opacity_value != 0)
            {
                var reduced = OriginalImage.Clone();
                Core.ImageExtensions.OpacityReduction(reduced, opacity_value);
                bit = BitmapSourceConvert.ToBitmapSource(reduced);
            }
            base.OnRender(dc);


            if (!above && bit != null)
            {
                dc.DrawImage(bit, new Rect(0, 0, Width, Height));
            }
            foreach (DominoInCanvas dic in Stones)
            {
                Point point1 = dic.canvasPoints[0];
                Point point2 = dic.canvasPoints[1];
                Point point3 = dic.canvasPoints[2];
                Point point4 = dic.canvasPoints[3];

                StreamGeometry streamGeometry = new StreamGeometry();
                using (StreamGeometryContext geometryContext = streamGeometry.Open())
                {
                    geometryContext.BeginFigure(point1, true, true);
                    var points = new System.Windows.Media.PointCollection
                    {
                        point2, point3, point4
                    };
                    geometryContext.PolyLineTo(points, true, true);
                }

                Pen pen = new Pen();
                if (dic.isSelected)
                {
                    pen.Brush     = new SolidColorBrush(SelectedBorderColor);
                    pen.Thickness = BorderSize;
                }
                else if (dic.PossibleToPaste)
                {
                    pen.Brush     = Brushes.Plum;
                    pen.Thickness = BorderSize;
                }
                else
                {
                    pen.Brush     = new SolidColorBrush(UnselectedBorderColor);
                    pen.Thickness = BorderSize / 2;
                }

                dc.DrawGeometry(new SolidColorBrush(dic.StoneColor), pen, streamGeometry);
            }
            if (above && bit != null)
            {
                dc.DrawImage(bit, new Rect(0, 0, Width, Height));
            }
        }
Exemplo n.º 18
0
        public EdgeTableVisualization GenerateEdgeColorVisualizationWithPath([NotNull] EdgeData data, [NotNull] StParticlePath path)
        {
            var options = Settings.Current.VisualizationOptions;

            var backgroundBrush = new SolidColorBrush(options.BackgroundColor);

            var visual = new DrawingVisual();

            using (DrawingContext drawingContext = visual.RenderOpen())
            {
                // Draw background
                drawingContext.DrawRectangle(backgroundBrush, null, new Rect(0, 0, data.Size.Width, data.Size.Height));

                // Draw colors
                drawingContext.DrawImage(GenerateEdgeColorImage(data), new Rect(0, 0, data.Size.Width, data.Size.Height));

                // Draw grid
                if (options.DrawGrid)
                {
                    DrawingUtil.DrawGrid(drawingContext, options.GridPen, data.Size.Width, data.Size.Height);
                }

                // Draw path
                if (path.Points.Count > 0)
                {
                    var pathGeometry = new StreamGeometry();
                    using (StreamGeometryContext ctx = pathGeometry.Open())
                    {
                        var points = path.Points.Select(p => new Point(p.J + 0.5, p.I + 0.5)).ToList();
                        ctx.BeginFigure(points.First(), true, false);
                        ctx.PolyLineTo(points.Skip(1).ToList(), true, true);
                    }
                    pathGeometry.Freeze();
                    drawingContext.DrawGeometry(null, options.PathPen, pathGeometry);
                }

                // Draw start point
                if (options.DrawStartPoint)
                {
                    drawingContext.PushTransform(new TranslateTransform(path.StartPoint.J + 0.5, path.StartPoint.I + 0.5));
                    drawingContext.DrawDrawing(options.StartPointDrawing);
                    drawingContext.Pop();
                }

                // Draw end point
                if (options.DrawEndPoint && path.EndPoint.HasValue)
                {
                    var pnt = path.EndPoint.GetValueOrDefault();
                    drawingContext.PushTransform(new TranslateTransform(pnt.J + 0.5, pnt.I + 0.5));
                    drawingContext.DrawDrawing(options.EndPointDrawing);
                    drawingContext.Pop();
                }
            }

            var image = new DrawingImage(visual.Drawing);

            image.Freeze();
            return(new EdgeTableVisualization(image, data));
        }
Exemplo n.º 19
0
 /// <summary>
 /// 没有梯度的区域里的点绘制出来
 /// </summary>
 /// <param name="sgc"></param>
 /// <param name="points"></param>
 /// <param name="pointLength"></param>
 private void DrawingPoint(StreamGeometryContext sgc, IEnumerable <Point> points, int pointLength)
 {
     foreach (var point in points)
     {
         sgc.BeginFigure(new Point(point.X, point.Y), true, true);
         sgc.PolyLineTo(new Point[] { new Point(point.X + pointLength, point.Y), new Point(point.X + pointLength, point.Y + pointLength), new Point(point.X, point.Y + pointLength) }, false, false);
     }
 }
Exemplo n.º 20
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (markers == null || !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 (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    var geoBuilder = new BackgroundGeometryBuilder {
                        AlignToWholePixels = true, CornerRadius = 3
                    };
                    geoBuilder.AddSegment(textView, marker);
                    Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        Color color = marker.BackgroundColor.Value;
                        var   brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                {
                    Point startPoint = r.BottomLeft;
                    Point endPoint   = r.BottomRight;

                    var usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);
                    usedPen.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, endPoint, offset, count).ToArray(), true, false);
                    }

                    geometry.Freeze();

                    drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                    break;
                }
            }
        }
Exemplo n.º 21
0
 private static void AddArcToFigureToStreamGeometryContext(StreamGeometryContext context, List <Point> abPoints, List <Point> dcPoints, List <Point> polyLinePoints)
 {
     if (abPoints.Count == 0 || dcPoints.Count == 0)
     {
         return;
     }
     context.BeginFigure(abPoints[0], isFilled: true, isClosed: true);
     for (int i = 0; i < 2; i++)
     {
         List <Point> list = (i == 0) ? abPoints : dcPoints;
         int          num  = (i == 0) ? 1 : 0;
         int          num2 = num;
         while (num2 < list.Count)
         {
             Point point = list[num2];
             if (point == ArcToMarker)
             {
                 if (polyLinePoints.Count > 0)
                 {
                     context.PolyLineTo(polyLinePoints, isStroked: true, isSmoothJoin: true);
                     polyLinePoints.Clear();
                 }
                 if (num2 + 2 < list.Count)
                 {
                     Point point2     = list[num2 + 1];
                     Size  size       = new Size(point2.X / 2.0, point2.Y / 2.0);
                     Point point3     = list[num2 + 2];
                     bool  isLargeArc = false;
                     context.ArcTo(point3, size, 0.0, isLargeArc, SweepDirection.Clockwise, isStroked: true, isSmoothJoin: true);
                 }
                 num2 += 3;
             }
             else
             {
                 polyLinePoints.Add(point);
                 num2++;
             }
         }
         if (polyLinePoints.Count > 0)
         {
             context.PolyLineTo(polyLinePoints, isStroked: true, isSmoothJoin: true);
             polyLinePoints.Clear();
         }
     }
 }
Exemplo n.º 22
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (Issues == null)
            {
                return;
            }

            var segments = new TextSegmentCollection <IssueMarker>();

            foreach (var issue in Issues)
            {
                segments.Add(new IssueMarker(Theme, issue));
            }

            var visualLines = textView.VisualLines;

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

            foreach (var marker in segments.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                var brush   = marker.Brush;
                var usedPen = new Pen(brush, 1);
                usedPen.Freeze();
                if (brush == null)
                {
                    continue;
                }

                foreach (var r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                {
                    var startPoint = r.BottomLeft;
                    var endPoint   = r.BottomRight;

                    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), true, false);
                    }

                    geometry.Freeze();


                    drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                }
            }
        }
Exemplo n.º 23
0
            public override void Render(EtaCtlGraph ctl_graph, CGroup group, DrawingContext dc, ref double description_offset, double x, double y, double width, double height, Brush foreground, Typeface typeface)
            {
                base.Render(ctl_graph, @group, dc, ref description_offset, x, y, width, height, foreground, typeface); Pen _pen_graph = new Pen(foreground, 1);
                double _y_diff = group.MaxGroupYValue - group.MinGroupYValue; int _samples_cnt = SamplesCount; double _group_cnt = (group.MaxGroupXValue - group.MinGroupXValue) * SamplesPerUnit;

                x += (MinXValue - group.MinGroupXValue) / (group.MaxGroupXValue - group.MinGroupXValue) * width;
                StreamGeometry _sg = new StreamGeometry();
                List <Point>   _list_points = new List <Point>(128);

                using (StreamGeometryContext _sgc = _sg.Open()) {
                    if (_samples_cnt <= 128)
                    {
                        double _x_step = width / (_group_cnt - 1); bool _is_first = true;
                        foreach (double _sample in Samples)
                        {
                            double _y_curr = y + ((group.MaxGroupYValue - _sample) / _y_diff * height);
                            if (_is_first)
                            {
                                _is_first = false; _sgc.BeginFigure(new Point(x, _y_curr), true, false);
                            }
                            else
                            {
                                _list_points.Add(new Point(x, _y_curr));
                            }
                            x += _x_step;
                        }
                    }
                    else
                    {
                        double _ovf_step = ((double)_samples_cnt) / 128;
                        double _x_step = width / _group_cnt; bool _is_first = true;
                        double _sample_trace = 0, _trace_ovf = 0; int _trace_cnt = 0;
                        IEnumerator <double> _samples_enumerator = Samples.GetEnumerator();
                        bool _is_value = _samples_enumerator.MoveNext();
                        while (_is_value)
                        {
                            double _sample = _samples_enumerator.Current;
                            if (_is_first)
                            {
                                _is_first = false; _sgc.BeginFigure(new Point(x, y + ((group.MaxGroupYValue - _sample) / _y_diff * height)), true, false);
                            }
                            _sample_trace += _sample; _trace_ovf += 1; _trace_cnt++;
                            _is_value      = _samples_enumerator.MoveNext();
                            if (_trace_ovf >= _ovf_step || (!_is_value && _trace_cnt > 0))
                            {
                                _trace_ovf -= _ovf_step; _sample_trace /= _trace_cnt;
                                double _y_curr = y + ((group.MaxGroupYValue - (_is_value ? _sample_trace : _sample)) / _y_diff * height), _x_off = _x_step * _trace_cnt;
                                _list_points.Add(new Point(x + _x_off, _y_curr)); x += _x_off;
                                _sample_trace = 0; _trace_cnt = 0;
                            }
                        }
                    }
                    _sgc.PolyLineTo(_list_points, true, false);
                }
                _sg.Freeze();
                dc.DrawGeometry(null, _pen_graph, _sg);
            }
Exemplo n.º 24
0
        protected override void DrawGeometry(StreamGeometryContext context)
        {
            context.BeginFigure(Values[0], false, false);
            List <Point>    lPoints = new List <Point>();
            PolyLineSegment line    = new PolyLineSegment();

            lPoints.AddRange(Values.GetRange(1, Values.Count - 1));
            context.PolyLineTo(lPoints, true, true);
        }
Exemplo n.º 25
0
        public static System.Windows.Media.Geometry GetTransformedRectangleGeometry(Rect rect, Matrix matrix, double thickness)
        {
            if (rect.IsEmpty)
            {
                return((System.Windows.Media.Geometry)null);
            }
            Vector vector1 = new Vector(1.0, 0.0) * matrix;
            Vector vector2 = new Vector(0.0, 1.0) * matrix;
            Vector v1      = new Vector(vector2.Y, -vector2.X);
            Vector v2      = new Vector(vector1.Y, -vector1.X);

            if (v1 * vector1 < 0.0)
            {
                v1 *= -1.0;
            }
            if (v2 * vector2 < 0.0)
            {
                v2 *= -1.0;
            }
            double length1 = v1.Length;

            if (length1 > 0.0)
            {
                v1 /= length1;
            }
            double length2 = v2.Length;

            if (length2 > 0.0)
            {
                v2 /= length2;
            }
            Vector                vector3               = (Vector)(rect.TopLeft * matrix);
            Vector                vector4               = (Vector)(rect.BottomRight * matrix);
            double                num                   = thickness / 2.0;
            double                c1_1                  = v1 * vector3 - num;
            double                c2_1                  = v2 * vector3 - num;
            double                c1_2                  = v1 * vector4 + num;
            double                c2_2                  = v2 * vector4 + num;
            Point                 intersection1         = Adorner.GetIntersection(v1, c1_1, v2, c2_1);
            Point                 intersection2         = Adorner.GetIntersection(v1, c1_2, v2, c2_1);
            Point                 intersection3         = Adorner.GetIntersection(v1, c1_1, v2, c2_2);
            Point                 intersection4         = Adorner.GetIntersection(v1, c1_2, v2, c2_2);
            StreamGeometry        streamGeometry        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.BeginFigure(intersection1, true, true);
            streamGeometryContext.PolyLineTo((IList <Point>) new Point[3]
            {
                intersection2,
                intersection4,
                intersection3
            }, 1 != 0, 0 != 0);
            streamGeometryContext.Close();
            streamGeometry.Freeze();
            return((System.Windows.Media.Geometry)streamGeometry);
        }
Exemplo n.º 26
0
        private static void DeserializePolyLineTo(BinaryReader br, Byte firstByte, StreamGeometryContext sc)
        {
            bool          isStroked;
            bool          isSmoothJoin;
            IList <Point> points;

            points = DeserializeListOfPointsAndTwoBools(br, firstByte, out isStroked, out isSmoothJoin);

            sc.PolyLineTo(points, isStroked, isSmoothJoin);
        }
Exemplo n.º 27
0
        private void DrawGeometry(StreamGeometryContext context)
        {
            context.BeginFigure(canvasPoints[0], true, true); //Top Left
            IList <System.Windows.Point> points = new List <System.Windows.Point>();

            points.Add(canvasPoints[1]); //Top Right
            points.Add(canvasPoints[2]); // Bottom Right
            points.Add(canvasPoints[3]); // Bottom Left
            context.PolyLineTo(points, true, true);
        }
Exemplo n.º 28
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            double width  = this.ActualWidth / 2.0;
            double height = this.ActualHeight / 2.0;
            Point  point  = new Point(width, height);
            Color  color  = this.ControlBrush.Color;
            Brush  brush  = new SolidColorBrush(color.AddColorDelta(-80));
            Brush  brush1 = color.CreateLinearTwoGradientsBrush(90.0, 80, -80);
            Brush  brush2 = new SolidColorBrush(color);
            Brush  brush3 = color.CreateLinearTwoGradientsBrush(90.0, -80, 80);
            Pen    pen    = new Pen(brush, StrokeThickness);

            drawingContext.PushTransform(new RotateTransform(450 - this.StartAngle, width, height));
            StreamGeometry geometry;

            switch (Design)
            {
            case NeedleDesign.Standard:
                geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(0.85 * width, 0), true, true);
                    context.PolyLineTo(new Point[] { new Point(1.15 * width, 0), new Point(1.45 * width, height), new Point(0.55 * width, height) }, false, false);
                }
                geometry.Freeze();
                drawingContext.DrawGeometry(Brushes.Red, pen, geometry);
                drawingContext.DrawEllipse(brush1, pen, point, width * 1.5, width * 1.5);
                drawingContext.DrawEllipse(brush2, null, point, width * 1.2, width * 1.2);
                break;

            case NeedleDesign.Classic:
                drawingContext.DrawLine(new Pen(Brushes.Blue, 5), new Point(width, 0), new Point(width, 1.3 * height));
                drawingContext.DrawEllipse(brush1, pen, point, width * 1.5, width * 1.5);
                drawingContext.DrawEllipse(brush2, null, point, width * 1.2, width * 1.2);
                break;

            case NeedleDesign.Shape:
                geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(width, 0), true, true);
                    context.LineTo(new Point(1.5 * width, height), true, false);
                    context.ArcTo(new Point(0.5 * width, height), new Size(width * 1.2, width * 1.2), 0.0, true, SweepDirection.Clockwise, true, true);
                }
                geometry.Freeze();
                drawingContext.DrawGeometry(ControlBrush, pen, geometry);
                break;

            case NeedleDesign.Thin:
                drawingContext.DrawLine(pen, new Point(width, 0), new Point(width, height));
                break;
            }

            //base.OnRender(drawingContext);
        }
Exemplo n.º 29
0
        public void DrawLine(double x1, double y1, double x2, double y2, SequenceLineType lineType, SequenceArrowType arrowHead)
        {
            Pen    pen          = lineType == SequenceLineType.Solid ? m_solidLinePen : m_dashedLinePen;
            double halfPenWidth = m_solidLinePen.Thickness / 2;

            GuidelineSet guidelines = new GuidelineSet();

            guidelines.GuidelinesX.Add(x1 + halfPenWidth);
            guidelines.GuidelinesX.Add(x2 + halfPenWidth);
            guidelines.GuidelinesY.Add(y1 + halfPenWidth);
            guidelines.GuidelinesY.Add(y2 + halfPenWidth);

            m_drawingContext.PushGuidelineSet(guidelines);

            // Draw the main line segment
            Point start = new Point(x1, y1);
            Point end   = new Point(x2, y2);

            DrawLine(m_drawingContext, pen, start, end);

            // Draw the arrowhead
            double direction = (x1 > x2) ? 1 : -1;
            Point  arrow0    = new Point(end.X + direction * LineThickness, end.Y);
            Point  arrow1    = new Point(x2 + direction * s_arrowHeadSize.Width, y2 - s_arrowHeadSize.Height);
            Point  arrow2    = new Point(x2 + direction * s_arrowHeadSize.Width, y2 + s_arrowHeadSize.Height);

            switch (arrowHead)
            {
            case SequenceArrowType.Filled:
            {
                var streamGeometry = new StreamGeometry();
                using (StreamGeometryContext geometryContext = streamGeometry.Open())
                {
                    geometryContext.BeginFigure(arrow0, true, true);
                    PointCollection points = new PointCollection {
                        arrow1, arrow2
                    };
                    geometryContext.PolyLineTo(points, true, true);
                }

                streamGeometry.Freeze();
                m_drawingContext.DrawGeometry(m_arrowBrush, m_solidLinePen, streamGeometry);
                break;
            }

            case SequenceArrowType.Open:
            {
                m_drawingContext.DrawLine(m_solidLinePen, arrow0, arrow1);
                m_drawingContext.DrawLine(m_solidLinePen, arrow0, arrow2);
                break;
            }
            }

            m_drawingContext.Pop();
        }
Exemplo n.º 30
0
 private static void AddFigureToStreamGeometryContext(StreamGeometryContext context, List <Point> points, bool isBezierFigure)
 {
     context.BeginFigure(points[points.Count - 1], isFilled: true, isClosed: true);
     if (isBezierFigure)
     {
         context.PolyBezierTo(points, isStroked: true, isSmoothJoin: true);
     }
     else
     {
         context.PolyLineTo(points, isStroked: true, isSmoothJoin: true);
     }
 }
Exemplo n.º 31
0
        private static void DeserializePolyLineTo(BinaryReader br, Byte firstByte, StreamGeometryContext sc)
        {
            bool isStroked;
            bool isSmoothJoin;
            IList<Point> points;

            points = DeserializeListOfPointsAndTwoBools(br, firstByte, out isStroked, out isSmoothJoin);

            sc.PolyLineTo(points, isStroked, isSmoothJoin);
        }