コード例 #1
1
        public override void Draw(
			IList<Point> points,
			double thickness,
			int miterLimit,
			ILogicalToScreenMapper logicalToScreenMapper)
        {
            // First define the geometric shape
            var streamGeometry = new StreamGeometry();
            using (var gc = streamGeometry.Open())
            {
                gc.BeginFigure(points[0], _fillAndClose, _fillAndClose);
                points.RemoveAt(0);

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

            using (var dc = RenderOpen())
                dc.DrawGeometry(
                    _fillAndClose ? Brushes.White : null,
                    new Pen(
                        Brushes.White,
                        thickness == 1 ? 0.25 : thickness)
                        {
                            MiterLimit = miterLimit
                        },
                    streamGeometry);
        }
コード例 #2
0
    /// <summary>
    /// Does a one off calculation of the geometry to be rendered
    /// </summary>
    private void CalculateGeometry() {

      if(_recalcGeometry) {
        Func<bool, int, StreamGeometry> buildGeometry = (bool isFilled, int pointIndex) => {
          StreamGeometry childGeometry = new StreamGeometry();
          using(StreamGeometryContext ctx = childGeometry.Open()) {
            // Break up into groups of 4
            ctx.BeginFigure(Points[pointIndex], isFilled, isFilled);
            for(int j = 0; j < 4; ++j) {
              ctx.LineTo(Points[pointIndex + j], !isFilled, true);
            }
            if(!isFilled) {
              ctx.LineTo(Points[pointIndex], !isFilled, true);
            }
          }
          return childGeometry;
        };

        _filledGeometry = _filledGeometry ?? new GeometryGroup();
        _unfilledGeometry = _unfilledGeometry ?? new GeometryGroup();

        _filledGeometry.Children.Clear();
        _unfilledGeometry.Children.Clear();
        if(Points.Count > 0) {
          for(int pointIndex = 0, colorIndex = 0; pointIndex < (Points.Count - 3); pointIndex += 4, colorIndex += 1) {
            _unfilledGeometry.Children.Add(buildGeometry(false, pointIndex));
            _filledGeometry.Children.Add(buildGeometry(true, pointIndex));
          }
        }
        _recalcGeometry = false;
      }
    }
コード例 #3
0
ファイル: Signal.cs プロジェクト: DiLRandI/ArduinoMonitor
        //Redraw the streamgeometry
        public void createGeometry() {
            // Create a StreamGeometry to use to specify myPath.
            geometry = new StreamGeometry();
            // Open a StreamGeometryContext that can be used to describe this StreamGeometry  
            // object's contents. 
            using (StreamGeometryContext geo = geometry.Open())
            {
                double xmax = window.anchorOut; //views xmax
                double xmin = window.anchorIn; //views xmin
                int xres = (int)Math.Ceiling((xmax-xmin) / window.plot.Width);

                geo.BeginFigure(new Point(0, 0), false, false);
                for (int i = (int)xmin; i < xmax; i+=1) //always 600 steps
                {
                    double value;
                    if (i < (values.Count() - 1))
                    {
                        value = values[i];
                    }
                    else { break; }
                    geo.LineTo(new Point(i, value), true, false);
                    i++;
                }
            }
            geometry.Freeze(); //Freeze to free resources
            line.Data = geometry;
        }
コード例 #4
0
 public void Draw(TextView textView, DrawingContext drawingContext)
 {
     foreach (TextSegment current in this.SearchHitsSegments)
     {
         foreach (Rect current2 in BackgroundGeometryBuilder.GetRectsForSegment(textView, current))
         {
             Point bottomLeft = current2.BottomLeft;
             Point bottomRight = current2.BottomRight;
             Pen pen = new Pen(new SolidColorBrush(Colors.OrangeRed), 1);
             pen.Freeze();
             double num = 2.5;
             int count = System.Math.Max((int)((bottomRight.X - bottomLeft.X) / num) + 1, 4);
             StreamGeometry streamGeometry = new StreamGeometry();
             using (StreamGeometryContext streamGeometryContext = streamGeometry.Open())
             {
                 streamGeometryContext.BeginFigure(bottomLeft, true, true);
                 streamGeometryContext.LineTo(current2.TopLeft, true, false);
                 streamGeometryContext.LineTo(current2.TopRight, true, false);
                 streamGeometryContext.LineTo(current2.BottomRight, true, false);
             }
             streamGeometry.Freeze();
             drawingContext.DrawGeometry(Brushes.Transparent, pen, streamGeometry);
         }
     }
 }
コード例 #5
0
ファイル: MappingFeedback.cs プロジェクト: Meddington/xyzmidi
        /// <summary>
        /// Create an Arc geometry drawing of an ellipse or circle
        /// </summary>
        /// <param name="rect">Box to hold the whole ellipse described by the arc</param>
        /// <param name="startDegrees">Start angle of the arc degrees within the ellipse. 0 degrees is a line to the right.</param>
        /// <param name="sweepDegrees">Sweep angle, -ve = Counterclockwise, +ve = Clockwise</param>
        /// <returns>GeometryDrawing object</returns>
        private static GeometryDrawing CreateArcDrawing(Rect rect, double startDegrees, double sweepDegrees)
        {
            // degrees to radians conversion
            double startRadians = startDegrees * Math.PI / 180.0;
            double sweepRadians = sweepDegrees * Math.PI / 180.0;

            // x and y radius
            double dx = rect.Width / 2;
            double dy = rect.Height / 2;

            // determine the start point
            double xs = rect.X + dx + (Math.Cos(startRadians) * dx);
            double ys = rect.Y + dy + (Math.Sin(startRadians) * dy);

            // determine the end point
            double xe = rect.X + dx + (Math.Cos(startRadians + sweepRadians) * dx);
            double ye = rect.Y + dy + (Math.Sin(startRadians + sweepRadians) * dy);

            // draw the arc into a stream geometry
            StreamGeometry streamGeom = new StreamGeometry();
            using (StreamGeometryContext ctx = streamGeom.Open())
            {
                bool isLargeArc = Math.Abs(sweepDegrees) > 180;
                SweepDirection sweepDirection = sweepDegrees < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;

                ctx.BeginFigure(new Point(xs, ys), false, false);
                ctx.ArcTo(new Point(xe, ye), new Size(dx, dy), 0, isLargeArc, sweepDirection, true, false);
            }

            // create the drawing
            GeometryDrawing drawing = new GeometryDrawing();
            drawing.Geometry = streamGeom;
            return drawing;
        }
コード例 #6
0
        public TextBoxUpDownAdorner(TextBox adornedTextBox)
            : base(adornedTextBox)
        {
            this.triangle = new StreamGeometry();
            this.triangle.FillRule = FillRule.Nonzero;
            using (StreamGeometryContext geometryContext = this.triangle.Open())
            {
                geometryContext.BeginFigure(new Point(-6, 0), true /* filled */, true /* closed */);
                geometryContext.LineTo(new Point(6, 0), true, false);
                geometryContext.LineTo(new Point(0, 8), true, false);
            }
            this.triangle.Freeze();

            this.MouseDown += (s, e) =>
            {
                if (this.Button_Clicked != null)
                {
                    bool up = e.GetPosition(this.AdornedElement).Y < (top + bottom) / 2;
                    this.Button_Clicked((TextBox)this.AdornedElement, up ? 1 : -1);
                }
            };

            adornedTextBox.LostFocus += this.FocusLostOrSelectionChanged;
            adornedTextBox.SelectionChanged += this.FocusLostOrSelectionChanged;
        }
コード例 #7
0
ファイル: Cake.cs プロジェクト: lkempf/Bwinf-34-r2
		private void CalculateShape()
		{
			//Vorberechnen für bessere Performance
			float angle = Angle * (float)(Math.PI / 180);
			float sinAngle = (float)Math.Sin(angle);
			float cosAngle = (float)Math.Cos(angle);

			//P_L
			startPoint = new Point(Size - cosAngle * Size, Size + sinAngle * Size);
			//P_O
			circleIntersectionPoint = new Point(2 * Size, Size);
			//P_R
			circleEndPoint = new Point(Size * 3 + cosAngle * Size, Size + sinAngle * Size);
			//P_U
			Vector angledVector = new Vector(-sinAngle, cosAngle);
			double lineLength = (2 * Size - (Size * 3 + cosAngle * Size)) / angledVector.X;
			trianglePoint = Point.Add(circleEndPoint, Vector.Multiply(angledVector, lineLength));

			//Form aus Punkten erstellen
			heart = new StreamGeometry();
			using (StreamGeometryContext ctx = heart.Open())
			{
				ctx.BeginFigure(startPoint, true, true);
				ctx.ArcTo(circleIntersectionPoint, new Size(Size, Size), Math.PI + angle, true, SweepDirection.Clockwise, true, false);
				ctx.ArcTo(circleEndPoint, new Size(Size, Size), Math.PI + angle, true, SweepDirection.Clockwise, true, false);
				ctx.LineTo(trianglePoint, true, false);
			}
			heart.Freeze();
		}
コード例 #8
0
        public PathOutlineVisual(IPathOutline outline)
        {
            var brush = new SolidColorBrush(outline.LineColor);
            var pen = new Pen(brush, 1);

            var geometry = new StreamGeometry();
            using (var gc = geometry.Open())
            {

                gc.BeginFigure(outline.BottomLeft, false, false);
                gc.LineTo(outline.TopLeft, true, true);
                gc.ArcTo(outline.TopRight,
                    new Size(outline.Radius + (outline.Width / 2), outline.Radius + (outline.Width / 2)),
                    1,
                    false,
                    outline.Direction == PathType.Convex ? SweepDirection.Clockwise : SweepDirection.Counterclockwise,
                    true,
                    true);

                gc.LineTo(outline.BottomRight, true, true);
                gc.ArcTo(outline.BottomLeft,
                    new Size(outline.Radius - (outline.Width / 2), outline.Radius - (outline.Width / 2)),
                    1,
                    false,
                    outline.Direction == PathType.Convex ? SweepDirection.Counterclockwise : SweepDirection.Clockwise,
                    true,
                    true);

            }

            using (var context = RenderOpen())
            {
                context.DrawGeometry(brush, pen, geometry);
            }
        }
コード例 #9
0
        public PathOutlineVisualOld(IPathOld path, Color color)
        {
            var brush = new SolidColorBrush(color);
            var pen = new Pen(brush, 1);

            var geometry = new StreamGeometry();
            using (var gc = geometry.Open())
            {

                gc.BeginFigure(path.StartBottomEdge, false, false);
                gc.LineTo(path.StartTopEdge, true, true);
                gc.ArcTo(path.EndTopEdge, new Size(path.Radius+(path.Width/2), path.Radius+(path.Width/2)), 1, false, SweepDirection.Clockwise, true, true);
                gc.LineTo(path.EndBottomEdge, true, true);
                gc.ArcTo(path.StartBottomEdge, new Size(path.Radius-(path.Width/2), path.Radius-(path.Width/2)), 1, false, SweepDirection.Counterclockwise, true, true);

            }

            using (var context = RenderOpen())
            {
                context.DrawGeometry(brush, pen, geometry);

                var points = CalculateSteps(path);

                foreach (var point in points)
                {
                    DrawPoint(point, Brushes.Blue, context);
                }
            }
        }
コード例 #10
0
        public void Draw( EdgeLayout layoutState )
        {
            var styleState = myPresentation.GetPropertySetFor<EdgeStyle>().Get( Owner.Id );

            var stream = new StreamGeometry();
            var context = stream.Open();

            context.BeginFigure( layoutState.Points.First(), false, false );

            context.PolyBezierTo( layoutState.Points.Skip( 1 ).ToList(), true, false );

            // draw arrow head
            var start = layoutState.Points.Last();
            var v = start - layoutState.Points.ElementAt( layoutState.Points.Count() - 2 );
            v.Normalize();

            start = start - v * 0.15;
            context.BeginFigure( start + v * 0.28, true, true );
            double t = v.X; v.X = v.Y; v.Y = -t;  // Rotate 90°
            context.LineTo( start + v * 0.08, true, true );
            context.LineTo( start + v * -0.08, true, true );
            context.Close();

            var pen = new Pen( styleState.Color, 0.016 );

            // http://stackoverflow.com/questions/1755520/improve-drawingvisual-renders-speed
            Visual = new DrawingVisual();
            var dc = Visual.RenderOpen();
            dc.DrawGeometry( pen.Brush, pen, stream );
            dc.Close();

            Visual.SetValue( GraphItemProperty, Owner );
        }
コード例 #11
0
        internal void MakeGeometry()
        {
            if (Edge.Points.Count > 0)
            {
                var points = Edge.Points;
                StreamGeometry g = new StreamGeometry();
                StreamGeometryContext c = g.Open();

                c.BeginFigure(points[0], false, false);
                var r = Edge.Points.Where(p => p != Edge.Points[0]);
                c.PolyBezierTo(r.ToList(), true, false);

                if (Edge.EndPoint.HasValue)
                {
                    Point from = Edge.Points.Last();
                    Point to = Edge.EndPoint.Value;

                    DrawArrow(c, from, to, 4);
                }

                if (Edge.StartPoint.HasValue)
                {
                    Point from = Edge.Points.First();
                    Point to = Edge.StartPoint.Value;

                    DrawArrow(c, from, to, 4);
                }

                c.Close();
                g.Freeze();

                EdgeGeometry = g;
            }
        }
コード例 #12
0
        public AreaSeries2D()
        {
            // 初始化保存数据点的变量
            _points = new SeriesPointCollection();
            _points.CollectionChanged += _points_CollectionChanged;

            // 初始化绘制曲线的画板
            gStream_Line = new StreamGeometry();
            gStream_Area = new StreamGeometry();

            gDrawing_Line = new GeometryDrawing();
            gDrawing_Line.Brush = null;
            gDrawing_Line.Pen = new Pen()
            {
                Thickness = 1,
                Brush = Brushes.Black
            };
            gDrawing_Line.Geometry = gStream_Line;

            /* 初始化绘制填充色的画板 */
            gDrawing_Area = new GeometryDrawing();
            gDrawing_Area.Brush = Brushes.Red;
            gDrawing_Area.Pen = new Pen()
            {
                Thickness = 0,
                Brush = null
            };
            gDrawing_Area.Geometry = gStream_Area;

            /* 生成绘画组 */
            drawingGroup = new DrawingGroup();
            drawingGroup.Children.Add(gDrawing_Line);
            drawingGroup.Children.Add(gDrawing_Area);
        }
コード例 #13
0
ファイル: LineSeriesElement.cs プロジェクト: Gusdor/Charting
        public void Draw(DrawingContext context, DrawingArgs args)
        {
            context.PushClip(new RectangleGeometry(args.RenderBounds));
            if (m_IsDirty || args.RequiresFullRedraw)
            {
                m_LonePoints.Clear();
                System.Windows.Media.StreamGeometry geo = new StreamGeometry();
                using (var c = geo.Open())
                {
                    Point? figureStart = null;
                    int pointCount = 0; //point in the figure

                    if (Values.Count() == 1 && Values.First().HasValue)
                    {
                        m_LonePoints.Add(Values.First().Value);
                    }
                    else
                    {
                        foreach (var p in Values)
                        {
                            if (p.HasValue)
                            {
                                if (!figureStart.HasValue)
                                {
                                    figureStart = p.Value;
                                    c.BeginFigure(figureStart.Value, false, false);
                                    pointCount = 1;
                                }
                                else
                                {
                                    c.LineTo(p.Value, true, true);
                                    pointCount++;
                                }
                            }
                            else
                            {
                                //detect lone points and draw a cross
                                if (pointCount == 1)
                                {
                                    m_LonePoints.Add(figureStart.Value);
                                }
                                figureStart = null;
                            }
                        }
                    }
                }

                m_Geo = geo;
                m_IsDirty = false;
            }

            m_Geo.Transform = args.Transform;
            context.DrawGeometry(null, Pen, m_Geo);

            var radius = Pen.Thickness;
            foreach (var p in m_LonePoints)
            {
                context.DrawEllipse(m_Pen.Brush, null, args.Transform.Transform(p), radius, radius);
            }
        }
コード例 #14
0
ファイル: Pen.cs プロジェクト: osmedile/TypeCobol
 public static Pen CreateErrorPen(Color color)
 {
     var geometry = new StreamGeometry();
     using (var context = geometry.Open())
     {
         context.BeginFigure(new Point(-1, 0), false, false);
         context.PolyLineTo(new[] {
                 new Point(-0.5, 0.4),
                 new Point(0, 0),
                 new Point(0.5, -0.4),
                 new Point(1, 0),
             }, true, true);
     }
     var brushPattern = new GeometryDrawing
     {
         Pen = new Pen(new SolidColorBrush(color), 0.4),
         Geometry = geometry
     };
     var brush = new DrawingBrush(brushPattern)
     {
         TileMode = TileMode.Tile,
         Viewport = new Rect(-1, -1, 2, 2),
         ViewportUnits = BrushMappingMode.Absolute,
         Viewbox = new Rect(-1, -1, 2, 2),
         ViewboxUnits = BrushMappingMode.Absolute,
     };
     var pen = new Pen(brush, 3.0);
     pen.Freeze();
     return pen;
 }
コード例 #15
0
        public void Render(DrawingContext context, IElement element)
        {
            var pathElement = element as CurvedPathElement;

            if (pathElement != null)
            {
                var pen = new Pen(new SolidColorBrush(pathElement.LineColor), pathElement.LineWidth);
                var brush = new SolidColorBrush(pathElement.FillColor);
                var topCurveRadius = pathElement.Radius +(pathElement.PathWidth/2);
                var bottomCurveRadius = pathElement.Radius -(pathElement.PathWidth/2);
                var geometry = new StreamGeometry();
                using (var gc = geometry.Open())
                {

                    gc.BeginFigure(pathElement.BottomLeft, false, true);
                    gc.LineTo(pathElement.TopLeft, true, true);
                    gc.ArcTo(pathElement.TopRight,
                             new Size(topCurveRadius, topCurveRadius),
                             1, false, SweepDirection.Clockwise, true, true);
                    gc.LineTo(pathElement.BottomRight, true, true);
                    gc.ArcTo(pathElement.BottomLeft,
                             new Size(bottomCurveRadius, bottomCurveRadius),
                             1, false, SweepDirection.Counterclockwise, true, true);
                }
                context.DrawGeometry(brush, pen, geometry);
                //var topPen = new Pen(Brushes.Red, 1);
                //var bottomPen = new Pen(Brushes.Blue, 1);
                //context.DrawEllipse(brush, topPen, pathElement.Origin, topCurveRadius, topCurveRadius);
                //context.DrawEllipse(brush, bottomPen, pathElement.Origin, bottomCurveRadius, bottomCurveRadius);

                //context.DrawEllipse(brush, pen, pathElement.Origin, pathElement.Radius, pathElement.Radius);
            }
        }
コード例 #16
0
ファイル: LineGeometries.cs プロジェクト: irriss/IronPlot.net
 public static StreamGeometry StreamGeometryFromCurve(Curve curve, MatrixTransform graphToCanvas)
 {
     double[] tempX;
     double[] tempY;
     if (graphToCanvas != null)
     {
         tempX = curve.xTransformed.MultiplyBy(graphToCanvas.Matrix.M11).SumWith(graphToCanvas.Matrix.OffsetX);
         tempY = curve.yTransformed.MultiplyBy(graphToCanvas.Matrix.M22).SumWith(graphToCanvas.Matrix.OffsetY);
     }
     else
     {
         tempX = curve.xTransformed; tempY = curve.yTransformed;
     }
     StreamGeometry streamGeometry = new StreamGeometry();
     StreamGeometryContext context = streamGeometry.Open();
     int lines = 0;
     for (int i = 0; i < curve.x.Count(); ++i)
     {
         if (i == 0)
         {
             context.BeginFigure(new Point(tempX[i], tempY[i]), false, false);
         }
         else
         {
             if (curve.includeLinePoint[i])
             {
                 context.LineTo(new Point(tempX[i], tempY[i]), true, false);
                 lines++;
             }
         }
     }
     context.Close();
     return streamGeometry;
 }
コード例 #17
0
        private void AddArrow(Panel rootCanvas, Point arrowPoint)
        {
            var size = 10.0;

            var relationshipPath = new Path
            {
                Stroke = Brushes.Black,
                StrokeThickness = 2,
                Visibility = Visibility.Visible,
                Fill = Brushes.Black
            };

            var geometry = new StreamGeometry
            {
                FillRule = FillRule.EvenOdd
            };

            using (var ctx = geometry.Open())
            {
                ctx.BeginFigure(new Point(arrowPoint.X, arrowPoint.Y), true, true);

                ctx.LineTo(new Point(arrowPoint.X - size / 2, arrowPoint.Y - size), true, true);
                ctx.LineTo(new Point(arrowPoint.X + size / 2, arrowPoint.Y - size), true, true);
            }

            geometry.Freeze();

            relationshipPath.Data = geometry;
            rootCanvas.Children.Add(relationshipPath);
        }
コード例 #18
0
 public static Geometry ToWpfGeometry(this SqlGeometry sqlGeometry, double pointSize)
 {
     StreamGeometry streamGeometry = new StreamGeometry();
     using (StreamGeometryContext streamGeometryContext = streamGeometry.Open())
     {
         if (sqlGeometry != null && !sqlGeometry.IsNull)
         {
             for (int geometryIndex = 0; geometryIndex < (int)sqlGeometry.STNumGeometries(); geometryIndex++)
             {
                 SqlGeometry subGeometry = sqlGeometry.STGeometryN(geometryIndex + 1);
                 if (subGeometry.STGeometryType() == "Polygon" || subGeometry.STGeometryType() == "MultiPolygon")
                 {
                     Point[] points = GetPointsFromSqlGeometry(subGeometry.STExteriorRing());
                     AddSegmentToGeometry(streamGeometryContext, points, true);
                     for (int interiorRingIndex = 0; interiorRingIndex < subGeometry.STNumInteriorRing(); interiorRingIndex++)
                     {
                         points = GetPointsFromSqlGeometry(subGeometry.STInteriorRingN(interiorRingIndex + 1));
                         AddSegmentToGeometry(streamGeometryContext, points, true);
                     }
                 }
                 else if (subGeometry.STGeometryType() == "MultiPoint" || subGeometry.STGeometryType() == "Point")
                 {
                     Point[] points = GetPointsFromSqlGeometry(subGeometry);
                     AddCircleToGeometry(streamGeometryContext, points, pointSize);
                 }
                 else if (subGeometry.STGeometryType() == "LineString" || subGeometry.STGeometryType() == "MultiLineString")
                 {
                     Point[] points = GetPointsFromSqlGeometry(subGeometry);
                     AddSegmentToGeometry(streamGeometryContext, points, false);
                 }
             }
         }
     }
     return streamGeometry;
 }
コード例 #19
0
ファイル: Arc.cs プロジェクト: guipasmoi/WpfApplication1
        private Geometry GetArcGeoMetry()
        {
            Point startPoint = PointAtAngle(Math.Min(StartAngle, EndAngle));
            Point endPoint = PointAtAngle(Math.Max(StartAngle, EndAngle));
            Size arcSize = new Size(Math.Max(0, (RenderSize.Width - StrokeThickness) / 2),
                                    Math.Max(0, (RenderSize.Height - StrokeThickness) / 2));
            bool isLargeArc = Math.Abs(EndAngle - StartAngle) > 180;
            var sw = SweepDirection.Clockwise;
            if (EndAngle - StartAngle < 0)
            {
                sw = SweepDirection.Counterclockwise;
                isLargeArc = false;
            }

            StreamGeometry geom = new StreamGeometry();
            if (EndAngle - StartAngle >= 360)
            {
                using (StreamGeometryContext context = geom.Open())
                {
                    context.BeginFigure(PointAtAngle(0), false, true);
                    context.ArcTo(PointAtAngle(359.99), arcSize, 0, isLargeArc, sw, true, false);
                }
            }
            else
            {
                using (StreamGeometryContext context = geom.Open())
                {
                    context.BeginFigure(startPoint, false, false);
                    context.ArcTo(endPoint, arcSize, 0, isLargeArc, sw, true, false);
                }
            }
            geom.Transform = new TranslateTransform(StrokeThickness / 2, StrokeThickness / 2);
            return geom;
        }
コード例 #20
0
        //public double GetTheta(double x, double y)
        //{
        //    return
        //}
        public StreamGeometry DrawArrowGeometry(StreamGeometry geometry, double centreX, double centreY, double circleWidth, double circleHeight, double innerWidth,
            double startAngle, double stopAngle)
        {
            //This code is based on http://marktinderholt.wordpress.com/2009/01/30/donut-shape-in-wpf/

            var context = geometry.Open();

            // Setup the Center Point & Radius
            Point c = new Point(centreX, centreY);
            double rOutterX = circleWidth/ 2;
            double rOutterY = circleHeight / 2;

            double rInnerX = rOutterX - innerWidth;
            double rInnerY = rOutterY - innerWidth;

            double theta = 0;
            bool hasBegun = false;
            double x;
            double y;
            Point currentPoint;

            // Draw the Outside Edge
            for (theta = startAngle; theta <= stopAngle; theta++)
            {
                x = c.X + rOutterX * Math.Cos(GetRadian(theta));
                y = c.Y + rOutterY * Math.Sin(GetRadian(theta));
                currentPoint = new Point(x, y);
                if (!hasBegun)
                {
                    context.BeginFigure(currentPoint, true, true);
                    hasBegun = true;
                }
                context.LineTo(currentPoint, true, true);
            }

            // Connect the Outside Edge to the Inner Edge
            x = c.X + rInnerX * Math.Cos(GetRadian(stopAngle));
            y = c.Y + rInnerY * Math.Sin(GetRadian(stopAngle));
            currentPoint = new Point(x, y);
            context.LineTo(currentPoint, true, true);

            // Draw the Inner Edge
            for (theta = stopAngle; theta >= startAngle; theta--)
            {
                x = c.X + rInnerX * Math.Cos(GetRadian(theta));
                y = c.Y + rInnerY * Math.Sin(GetRadian(theta));
                currentPoint = new Point(x, y);
                context.LineTo(currentPoint, true, true);
            }

            // Connect the Inner Edge to the Outside Edge
            x = c.X + rOutterX * Math.Cos(GetRadian(startAngle));
            y = c.Y + rOutterY * Math.Sin(GetRadian(startAngle));
            currentPoint = new Point(x, y);
            context.LineTo(currentPoint, true, true);

            context.Close();
            return geometry;
        }
コード例 #21
0
ファイル: GridLines.cs プロジェクト: goutkannan/ironlab
 public GridLines(Axis2D axis)
 {
     this.axis = axis;
     gridLinesGeometry = new StreamGeometry();
     this.Stroke = Brushes.LightGray;
     this.StrokeThickness = 1;
     this.StrokeLineJoin = PenLineJoin.Miter;
 }
コード例 #22
0
		public GridLineController(DesignerCanvas canvas)
		{
			IsVisible = true;
			_canvas = canvas;
			_geometry = new StreamGeometry();
			GridLines = new ObservableCollection<GridLine>();
			GridLines.CollectionChanged += (s, e) => Invalidate();
			Invalidate();
		}
コード例 #23
0
 private void Draw(DrawingContext dc)
 {
     StreamGeometry sg = new StreamGeometry();
     StreamGeometryContext sgc = sg.Open();
     sgc.BeginFigure(points[0], false, false);
     sgc.PolyLineTo(points, true, true);
     sgc.Close();
     dc.DrawGeometry(null, pen, sg);
 }
コード例 #24
0
        protected override Geometry GetOrCreateBoxGeometry(Size renderSize)
        {
            var rect = new Rect(new Point(0, 0), renderSize);
            this.SetCurrentValue(RectProperty, rect);
            if (rect.Width <= 0 || rect.Height <= 0)
            {
                return Geometry.Empty;
            }

            if (this.CornerRadius.IsAllEqual())
            {
                // using TopLeft here as we have already checked that they are equal
                if (this.BoxGeometry is RectangleGeometry)
                {
                    return this.BoxGeometry;
                }

                var geometry = new RectangleGeometry();
                geometry.Bind(RectangleGeometry.RectProperty)
                    .OneWayTo(this, RectProperty);
                geometry.Bind(RectangleGeometry.RadiusXProperty)
                    .OneWayTo(this, CornerRadiusProperty, CornerRadiusTopLeftConverter.Default);
                geometry.Bind(RectangleGeometry.RadiusYProperty)
                    .OneWayTo(this, CornerRadiusProperty, CornerRadiusTopLeftConverter.Default);
                return geometry;
            }
            else
            {
                var geometry = new StreamGeometry();
                using (var context = geometry.Open())
                {
                    var cr = this.AdjustedCornerRadius();
                    var p = cr.TopLeft > 0
                        ? new Point(cr.TopLeft + this.StrokeThickness / 2, this.StrokeThickness / 2)
                        : new Point(this.StrokeThickness / 2, this.StrokeThickness / 2);
                    context.BeginFigure(p, true, true);
                    p = p.WithOffset(rect.Width - cr.TopLeft - cr.TopRight, 0);
                    context.LineTo(p, true, true);
                    p = context.DrawCorner(p, cr.TopRight, cr.TopRight);

                    p = p.WithOffset(0, rect.Height - cr.TopRight - cr.BottomRight);
                    context.LineTo(p, true, true);
                    p = context.DrawCorner(p, -cr.BottomRight, cr.BottomRight);

                    p = p.WithOffset(-rect.Width + cr.BottomRight + cr.BottomLeft, 0);
                    context.LineTo(p, true, true);
                    p = context.DrawCorner(p, -cr.BottomLeft, -cr.BottomLeft);

                    p = p.WithOffset(0, -rect.Height + cr.TopLeft + cr.BottomLeft);
                    context.LineTo(p, true, true);
                    context.DrawCorner(p, cr.TopLeft, -cr.TopLeft);
                }

                geometry.Freeze();
                return geometry;
            }
        }
コード例 #25
0
 internal static Geometry DefiningTargetArrowHead(EdgeGeometry edgeGeometry, double thickness) {
     if (edgeGeometry.TargetArrowhead == null || edgeGeometry.Curve==null)
         return null;
     var streamGeometry = new StreamGeometry();
     using (StreamGeometryContext context = streamGeometry.Open()) {
         AddArrow(context, edgeGeometry.Curve.End,
                  edgeGeometry.TargetArrowhead.TipPosition, thickness);
         return streamGeometry;
     }
 }
コード例 #26
0
		protected override void OnRender(DrawingContext drawingContext)
		{
			if (Plotter2D == null) return;
			if (DataSource == null) return;
			if (Collection == null) return;
			if (Collection.Lines.Count == 0)
			{
				IsolineBuilder.DataSource = DataSource;
			}

			var dc = drawingContext;
			var dataSource = DataSource;
			var localMinMax = dataSource.GetMinMax();
			var globalMinMax = dataSource.Range.Value;
			double lengthsRatio = globalMinMax.GetLength() / localMinMax.GetLength();

			if (lengthsRatio > 16)
			{
				double log = Math.Round(Math.Log(lengthsRatio, 2));
				double number = 2 * Math.Pow(2, log);
				double delta = globalMinMax.GetLength() / number;

				double start = Math.Floor((localMinMax.Min - globalMinMax.Min) / delta) * delta + globalMinMax.Min;
				double end = localMinMax.Max;

				var transform = Plotter2D.Transform;
				var strokeThickness = StrokeThickness;

				double x = start;
				while (x < end)
				{
					var collection = IsolineBuilder.BuildIsoline(x);

					foreach (LevelLine line in collection)
					{
						StreamGeometry lineGeometry = new StreamGeometry();
						using (var context = lineGeometry.Open())
						{
							context.BeginFigure(line.StartPoint.ViewportToScreen(transform), false, false);
							context.PolyLineTo(line.OtherPoints.ViewportToScreen(transform).ToArray(), true, true);
						}
						lineGeometry.Freeze();

						var paletteRatio = (line.RealValue - globalMinMax.Min) / globalMinMax.GetLength();
						Pen pen = new Pen(new SolidColorBrush(Palette.GetColor(paletteRatio)), strokeThickness);

						dc.DrawGeometry(null, pen, lineGeometry);
					}

					x += delta;
				}
			}
			//dc.DrawRectangle(Brushes.Green.MakeTransparent(0.3), null, new Rect(RenderSize));
		}
コード例 #27
0
        public void FindLines(StreamGeometry geometry, bool stroke, bool fill, Matrix trans) 
        {
            Debug.Assert(stroke || fill, "should not be a nop"); 

            _transform = trans;
            _fill      = fill;
            _stroke    = stroke; 

            PathGeometry.ParsePathGeometryData(geometry.GetPathGeometryData(), this); 
 
            CheckCloseFigure();
        } 
コード例 #28
0
ファイル: parserscommon.cs プロジェクト: JianwenSun/cc
        internal static object DeserializeStreamGeometry( BinaryReader reader )
        {
            StreamGeometry geometry = new StreamGeometry();
            
            using (StreamGeometryContext context = geometry.Open())
            {
                ParserStreamGeometryContext.Deserialize( reader, context, geometry ); 
            }
            geometry.Freeze();

            return geometry; 
        }
コード例 #29
0
ファイル: GaugeTrack.cs プロジェクト: borkaborka/gmit
      /// <summary/>
      protected override void OnRender(DrawingContext dc) {
         base.OnRender(dc);

         var hasFill = (Fill != null);
         var hasStroke = (Stroke != null && StrokeThickness > 0);
         if (!hasFill && !hasStroke) return;

         double cx, cy, r0, r1;
         if (!ComputeBoundingCircles(out cx, out cy, out r0, out r1)) return;

         var a0 = StartAngle;
         var a1 = EndAngle;
         Gauge.NormalizeAngularRange(ref a0, ref a1);
         if (a0.AlmostEquals(a1)) return;

         var isLargeArc = (a1 - a0).CertainlyGreater(180);
         var isCircular = (a1 - a0).AlmostEquals(360);
         a0 = (a0 - 90).ToRadians();
         a1 = (a1 - 90).ToRadians();

         var geometry = new StreamGeometry();
         if (isCircular) {
            using (var gc = geometry.Open()) {
               var p0 = new Point(cx, cy - r1);  // first point on the outer circle
               var p1 = new Point(cx, cy + r1);  // second point on the outer circle
               var p2 = new Point(cx, cy - r0);  // first point on the inner circle
               var p3 = new Point(cx, cy + r0);  // second point on the inner circle
               gc.BeginFigure(p0, hasFill, true);
               gc.ArcTo(p1, new Size(r1, r1), 0, true, SweepDirection.Clockwise, hasStroke, false);
               gc.ArcTo(p0, new Size(r1, r1), 0, true, SweepDirection.Clockwise, hasStroke, false);
               if (r0.IsPositive()) {
                  gc.BeginFigure(p2, hasFill, true);
                  gc.ArcTo(p3, new Size(r0, r0), 0, true, SweepDirection.Clockwise, hasStroke, false);
                  gc.ArcTo(p2, new Size(r0, r0), 0, true, SweepDirection.Clockwise, hasStroke, false);
                  geometry.FillRule = FillRule.EvenOdd;  // this will subtract the inner circle from the outer circle, forming a ring
               }
            }
         } else {
            using (var gc = geometry.Open()) {
               var p0 = new Point(cx + r0 * Math.Cos(a0), cy + r0 * Math.Sin(a0));  // start point of the inner arc
               var p1 = new Point(cx + r1 * Math.Cos(a0), cy + r1 * Math.Sin(a0));  // start point of the outer arc
               var p2 = new Point(cx + r1 * Math.Cos(a1), cy + r1 * Math.Sin(a1));  // end point of the outer arc
               var p3 = new Point(cx + r0 * Math.Cos(a1), cy + r0 * Math.Sin(a1));  // end point of the inner arc
               gc.BeginFigure(p0, hasFill, true);
               gc.LineTo(p1, hasStroke, false);
               gc.ArcTo(p2, new Size(r1, r1), 0, isLargeArc, SweepDirection.Clockwise, hasStroke, false);
               gc.LineTo(p3, hasStroke, false);
               gc.ArcTo(p0, new Size(r0, r0), 0, isLargeArc, SweepDirection.Counterclockwise, hasStroke, false);
            }
         }
         geometry.Freeze();
         dc.DrawGeometry(Fill, GetStrokePen(), geometry);
      }
コード例 #30
0
ファイル: BaseAction.cs プロジェクト: chijianfeng/PNManager
        protected Geometry DrawLine(List<Point> listp)
        {
            StreamGeometry geometry = new StreamGeometry();
            geometry.FillRule = FillRule.EvenOdd;

            using (StreamGeometryContext context = geometry.Open())
            {
                InternalDrawGeometrys(context, listp);
            }

            return geometry;
        }
コード例 #31
0
ファイル: GraphicsHandler.cs プロジェクト: yaram/Eto
        public static swm.Geometry CreateArcDrawing(sw.Rect rect, double startDegrees, double sweepDegrees, bool closed)
        {
            // degrees to radians conversion
            double startRadians = startDegrees * Math.PI / 180.0;
            double sweepRadians = sweepDegrees * Math.PI / 180.0;

            // x and y radius
            double dx = rect.Width / 2;
            double dy = rect.Height / 2;

            // determine the start point
            double xs = rect.X + dx + (Math.Cos(startRadians) * dx);
            double ys = rect.Y + dy + (Math.Sin(startRadians) * dy);

            // determine the end point
            double xe = rect.X + dx + (Math.Cos(startRadians + sweepRadians) * dx);
            double ye = rect.Y + dy + (Math.Sin(startRadians + sweepRadians) * dy);

            var centerPoint = new sw.Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
            // draw the arc into a stream geometry
            var streamGeom = new swm.StreamGeometry();

            using (var ctx = streamGeom.Open())
            {
                bool isLargeArc     = Math.Abs(sweepDegrees) > 180;
                var  sweepDirection = sweepDegrees < 0 ? swm.SweepDirection.Counterclockwise : swm.SweepDirection.Clockwise;

                if (closed)
                {
                    ctx.BeginFigure(centerPoint, true, true);
                    ctx.LineTo(new sw.Point(xs, ys), true, true);
                }
                else
                {
                    ctx.BeginFigure(new sw.Point(xs, ys), true, false);
                }
                ctx.ArcTo(new sw.Point(xe, ye), new sw.Size(dx, dy), 0, isLargeArc, sweepDirection, true, false);
                if (closed)
                {
                    ctx.LineTo(centerPoint, true, true);
                }
            }

            return(streamGeom);
        }
コード例 #32
0
        ///<summary>
        /// Creates a new polygon shape.
        ///</summary>
        /// <param name="shellVertices">The vertices of the shell</param>
        /// <param name="holeVerticesCollection">A collection of Coordinate[] for each hole</param>
        public PolygonWpfStreamGeometry(Coordinate[] shellVertices,
                                        IEnumerable <Coordinate[]> holeVerticesCollection)
        {
            var path = new WpfStreamGeometry();

            using (var sgc = path.Open())
            {
                AddRing(sgc, shellVertices, true);
                if (holeVerticesCollection != null)
                {
                    foreach (var hole in holeVerticesCollection)
                    {
                        AddRing(sgc, hole, false);
                    }
                }
            }
            Path = path;
        }
コード例 #33
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sg"></param>
 /// <returns></returns>
 public string ToSource(WM.StreamGeometry sg)
 {
     return(sg.ToString(CultureInfo.InvariantCulture));
 }
コード例 #34
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xpg"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public WM.StreamGeometry ToStreamGeometry(IPathGeometry xpg, double dx, double dy)
        {
            var sg = new WM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                foreach (var xpf in xpg.Figures)
                {
                    sgc.BeginFigure(
                        new W.Point(xpf.StartPoint.X, xpf.StartPoint.Y),
                        xpf.IsFilled,
                        xpf.IsClosed);

                    foreach (var segment in xpf.Segments)
                    {
                        if (segment is IArcSegment arcSegment)
                        {
                            sgc.ArcTo(
                                new W.Point(arcSegment.Point.X + dx, arcSegment.Point.Y + dy),
                                new W.Size(arcSegment.Size.Width, arcSegment.Size.Height),
                                arcSegment.RotationAngle,
                                arcSegment.IsLargeArc,
                                arcSegment.SweepDirection == SweepDirection.Clockwise ? WM.SweepDirection.Clockwise : WM.SweepDirection.Counterclockwise,
                                arcSegment.IsStroked,
                                arcSegment.IsSmoothJoin);
                        }
                        else if (segment is ICubicBezierSegment cubicBezierSegment)
                        {
                            sgc.BezierTo(
                                new W.Point(cubicBezierSegment.Point1.X + dx, cubicBezierSegment.Point1.Y + dy),
                                new W.Point(cubicBezierSegment.Point2.X + dx, cubicBezierSegment.Point2.Y + dy),
                                new W.Point(cubicBezierSegment.Point3.X + dx, cubicBezierSegment.Point3.Y + dy),
                                cubicBezierSegment.IsStroked,
                                cubicBezierSegment.IsSmoothJoin);
                        }
                        else if (segment is ILineSegment lineSegment)
                        {
                            sgc.LineTo(
                                new W.Point(lineSegment.Point.X + dx, lineSegment.Point.Y + dy),
                                lineSegment.IsStroked,
                                lineSegment.IsSmoothJoin);
                        }
                        else if (segment is IPolyCubicBezierSegment polyCubicBezierSegment)
                        {
                            sgc.PolyBezierTo(
                                ToPoints(polyCubicBezierSegment.Points, dx, dy),
                                polyCubicBezierSegment.IsStroked,
                                polyCubicBezierSegment.IsSmoothJoin);
                        }
                        else if (segment is IPolyLineSegment polyLineSegment)
                        {
                            sgc.PolyLineTo(
                                ToPoints(polyLineSegment.Points, dx, dy),
                                polyLineSegment.IsStroked,
                                polyLineSegment.IsSmoothJoin);
                        }
                        else if (segment is IPolyQuadraticBezierSegment polyQuadraticSegment)
                        {
                            sgc.PolyQuadraticBezierTo(
                                ToPoints(polyQuadraticSegment.Points, dx, dy),
                                polyQuadraticSegment.IsStroked,
                                polyQuadraticSegment.IsSmoothJoin);
                        }
                        else if (segment is IQuadraticBezierSegment quadraticBezierSegment)
                        {
                            sgc.QuadraticBezierTo(
                                new W.Point(quadraticBezierSegment.Point1.X + dx, quadraticBezierSegment.Point1.Y + dy),
                                new W.Point(quadraticBezierSegment.Point2.X + dx, quadraticBezierSegment.Point2.Y + dy),
                                quadraticBezierSegment.IsStroked,
                                quadraticBezierSegment.IsSmoothJoin);
                        }
                        else
                        {
                            throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                        }
                    }
                }
            }

            sg.FillRule = xpg.FillRule == FillRule.Nonzero ? WM.FillRule.Nonzero : WM.FillRule.EvenOdd;
            sg.Freeze();

            return(sg);
        }
コード例 #35
0
 /// <summary>
 /// Creates a geometry stream context which is associated with a given owner
 /// </summary>
 internal StreamGeometryCallbackContext(StreamGeometry owner)
 {
     _owner = owner;
 }
コード例 #36
0
 public void Return(System.Windows.Media.StreamGeometry geometry)
 {
     _Pool.Enqueue(geometry);
 }