Inheritance: Shape, IPath
 protected override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     _topChew = GetTemplateChild(TopChew) as Path;
     _botChew = GetTemplateChild(BotChew) as Path;
     PropertyChangedCallback();
 }
        public Path GetCircleSegment(Point centrePoint, Point currentPoint, double radius, double stripWidth, double angle)
        {
            var path = new Path { Stroke = _strokeBrush };

            var pathGeometry = new PathGeometry();

            var circleStart = new Point(centrePoint.X, centrePoint.Y - radius);

            // Arc
            var arcSegment = new ArcSegment
            {
                IsLargeArc = angle > 180.0,
                Point = _mathHelper.ScaleUnitCirclePoint(centrePoint, angle, radius),
                Size = new Size(radius, radius),
                SweepDirection = SweepDirection.Clockwise
            };

            //The path figure includes first, the first line from the centre to line1End, then the arc
            var pathFigure = new PathFigure { StartPoint = circleStart, IsClosed = false };

            pathFigure.Segments.Add(arcSegment);
            pathGeometry.Figures.Add(pathFigure);

            path.Data = pathGeometry;
            path.StrokeThickness = stripWidth;

            return path;
        }
        public void Draw(EasingFunctionBase easingFunction)
        {
            canvas1.Children.Clear();


            var pathSegments = new PathSegmentCollection();

            for (double i = 0; i < 1; i += SamplingInterval)
            {
                double x = i * canvas1.Width;
                double y = easingFunction.Ease(i) * canvas1.Height;

                var segment = new LineSegment();
                segment.Point = new Point(x, y);

                pathSegments.Add(segment);

            }
            var p = new Path();
            p.Stroke = new SolidColorBrush(Colors.Black);
            p.StrokeThickness = 3;
            var figures = new PathFigureCollection();
            figures.Add(new PathFigure() { Segments = pathSegments });
            p.Data = new PathGeometry() { Figures = figures };
            canvas1.Children.Add(p);
        }
Exemple #4
0
        private Windows.UI.Xaml.Shapes.Path GetWindowsPath(Path path, Paint paint, PathFigureCollection pathFigureCollection)
        {
            // TODO paint.ColorFilter
            var isStroke = paint.Style == Paint.PaintStyle.Stroke;

            var gradient = paint.Shader as Gradient;
            var brush    = gradient != null?gradient.GetBrush(paint.Alpha) : new SolidColorBrush(paint.Color);

            var windowsPath = new Windows.UI.Xaml.Shapes.Path
            {
                Stroke          = isStroke ? brush : null,
                StrokeThickness = paint.StrokeWidth,
                StrokeDashCap   = paint.StrokeCap,
                StrokeLineJoin  = paint.StrokeJoin,
                RenderTransform = GetCurrentRenderTransform(),
                Data            = new PathGeometry
                {
                    FillRule = path.FillType == PathFillType.EvenOdd ? FillRule.EvenOdd : FillRule.Nonzero,
                    Figures  = pathFigureCollection
                }
            };

            paint.PathEffect?.Apply(windowsPath, paint);
            if (!isStroke)
            {
                windowsPath.Fill = brush;
            }
            return(windowsPath);
        }
Exemple #5
0
        public void CreateWorkOutline()
        {
            WorkOutline = new Windows.UI.Xaml.Shapes.Path();
            GeometryGroup   gg     = new GeometryGroup();
            Point           origin = new Point(0, 0);
            EllipseGeometry eg     = new EllipseGeometry();

            eg.Center  = origin;
            eg.RadiusX = eg.RadiusY = (_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.End;
            gg.Children.Add(eg);
            if ((_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.Start > 0)
            {
                eg         = new EllipseGeometry();
                eg.Center  = origin;
                eg.RadiusX = eg.RadiusY = (_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.Start;
                gg.Children.Add(eg);
            }
            WorkOutline.Data            = gg;
            WorkOutline.StrokeThickness = 1 / ScaleFactor;
            WorkOutline.Stroke          = new SolidColorBrush(Colors.Wheat);
            WorkOutline.StrokeDashArray = new DoubleCollection()
            {
                5, 5
            };
            WorkOutline.Name = "WorkOutline";
        }
Exemple #6
0
        private void DrawChart()
        {
            if ((dataSet != null) && (dataSet.Length > 0))
            {
                var path = new Windows.UI.Xaml.Shapes.Path();
                path.Stroke             = chartColor;
                path.StrokeThickness    = 15;
                path.StrokeLineJoin     = PenLineJoin.Round;
                path.StrokeStartLineCap = PenLineCap.Round;
                path.StrokeEndLineCap   = PenLineCap.Round;

                var geometry = new PathGeometry();

                var figure = new PathFigure();
                figure.IsClosed   = false;
                figure.StartPoint = new Point(offsetList[0].OffsetX, offsetList[0].OffsetY);

                for (int i = 0; i < offsetList.Count; i++)
                {
                    var segment = new LineSegment();
                    segment.Point = new Point(offsetList[i].OffsetX, offsetList[i].OffsetY);
                    figure.Segments.Add(segment);
                }
                geometry.Figures.Add(figure);
                path.Data = geometry;
                Children.Add(path);
            }
        }
Exemple #7
0
        private void CurvingEllipse_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            Path path = activeLine.bezierPath;

            if (activeLine.bezierPath == null)
            {
                path = DrawABezierCurve(
                    activeLine.initialX1, activeLine.initialX2,
                    activeLine.initialY1, activeLine.initialY2);

                // We add the path to the Canvas
                ShapesCanvas.Children.Add(path);

                // We keep track of the bezier segment
                activeLine.bezierPath            = path;
                activeLine.initialCenterEllipseX = activeLine.initialX1 + (activeLine.initialX2 - activeLine.initialX1) / 2;
                activeLine.initialCenterEllipseY = activeLine.initialY1 + (activeLine.initialY2 - activeLine.initialY1) / 2;

                // We remove the line
                // i.e. the path will "replace" the line
                ShapesCanvas.Children.Remove(activeLine.line);
            }

            // Initialize the transforms that will be used to manipulate the shape
            curveTranslation = new TranslateTransform();
            Ellipse el = (Ellipse)sender;

            el.RenderTransform = curveTranslation;
            el.Fill            = new SolidColorBrush(Windows.UI.Colors.Orange);
        }
Exemple #8
0
        public static Path GetCircleSegment(Point centerPoint, double radius, double angle)
        {
            var path = new Path();
            var pathGeometry = new PathGeometry();

            var circleStart = new Point(centerPoint.X, centerPoint.Y - radius);

            var arcSegment = new ArcSegment
            {
                IsLargeArc = angle > 180.0,
                Point = ScaleUnitCirclePoint(centerPoint, angle, radius),
                Size = new Size(radius, radius),
                SweepDirection = SweepDirection.Clockwise
            };

            var pathFigure = new PathFigure
            {
                StartPoint = circleStart,
                IsClosed = false
            };

            pathFigure.Segments.Add(arcSegment);
            pathGeometry.Figures.Add(pathFigure);

            path.Data = pathGeometry;
            return path;
        }
Exemple #9
0
        void GenerateSubFromPath(ref StringBuilder sb, Windows.UI.Xaml.Shapes.Path path)
        {
            CurrentPathIndex = (int)path.Tag;
            Bind(ref sb, PathStartTemplate());
            PathFragment points = new PathFragment();

            if (path.Data is GeometryGroup)
            {
                GeometryGroup gg = path.Data as GeometryGroup;
                foreach (PathGeometry pg in gg.Children)
                {
                    foreach (PathFigure pf in pg.Figures)
                    {
                        // now deal with all lines in this figure
                        foreach (PathSegment ps in pf.Segments)
                        {
                            if (ps is LineSegment)
                            {
                                _currentPoint = _context.FirstPoint = new Cartesian(pf.StartPoint);
                                Bind(ref sb, _context.Templates.FirstPointTemplate);
                                LineSegment ls = ps as LineSegment;
                                _currentPoint = _context.LastPoint = new Cartesian(ls.Point);
                                BindableCodeTemplate tmpl = (_context.UseRotaryTable)
                                     ? _context.Templates.RA_Point_Template
                                     : _context.Templates.XY_Point_Template;
                                Bind(ref sb, tmpl);
                                Bind(ref sb, _context.Templates.LastPointTemplate);
                            }
                            if (ps is PolyLineSegment)
                            {
                                PolyLineSegment      pls  = ps as PolyLineSegment;
                                BindableCodeTemplate tmpl = (_context.UseRotaryTable)
                                        ? _context.Templates.RA_Point_Template
                                        : _context.Templates.XY_Point_Template;

                                _context.FirstPoint = new Cartesian(pls.Points.First());
                                _context.LastPoint  = new Cartesian(pls.Points.Last());
                                foreach (Point p in pls.Points)
                                {
                                    _currentPoint = new Cartesian(p);
                                    if (_currentPoint == _context.FirstPoint)
                                    {
                                        Bind(ref sb, _context.Templates.FirstPointTemplate);
                                    }
                                    else if (_currentPoint == _context.LastPoint)
                                    {
                                        Bind(ref sb, _context.Templates.LastPointTemplate);
                                    }
                                    else
                                    {
                                        Bind(ref sb, tmpl);
                                    }
                                }
                            }
                            Bind(ref sb, PathEndTemplate());
                        }
                    }
                }
            }
        }
        private void DrawChart()
        {
            if (_offsetList == null || _offsetList.Count <= 0)
            {
                return;
            }

            var path = new Windows.UI.Xaml.Shapes.Path();

            path.Stroke             = new SolidColorBrush(GRAPG_COLOR);
            path.StrokeThickness    = GRAPH_STROKETHICKNESS;
            path.StrokeLineJoin     = PenLineJoin.Round;
            path.StrokeStartLineCap = PenLineCap.Round;
            path.StrokeEndLineCap   = PenLineCap.Round;

            var geometry = new PathGeometry();

            var figure = new PathFigure();

            figure.IsClosed   = false;
            figure.StartPoint = new Point(_offsetList[0].OffsetX, _offsetList[0].OffsetY);

            for (int i = 0; i < _offsetList.Count; i++)
            {
                var segment = new LineSegment();
                segment.Point = new Point(_offsetList[i].OffsetX, _offsetList[i].OffsetY);
                figure.Segments.Add(segment);
            }
            geometry.Figures.Add(figure);
            path.Data = geometry;
            Children.Add(path);
        }
        private void RenderArc(double Angle, Path pathRoot, PathFigure pathFigure, ArcSegment arcSegment)
        {
            Point startPoint = new Point(Radius, 0);
            Point endPoint = ComputeCartesianCoordinate(Angle, Radius);
            endPoint.X += Radius;
            endPoint.Y += Radius;

            pathRoot.Width = Radius * 2 + StrokeThickness;
            pathRoot.Height = Radius * 2 + StrokeThickness;
            pathRoot.Margin = new Thickness(StrokeThickness, StrokeThickness, 0, 0);

            bool largeArc = Angle > 180.0;

            Size outerArcSize = new Size(Radius, Radius);

            pathFigure.StartPoint = startPoint;

            if (startPoint.X == Math.Round(endPoint.X) && startPoint.Y == Math.Round(endPoint.Y))
            {
                endPoint.X -= 0.01;
            }

            arcSegment.Point = endPoint;
            arcSegment.Size = outerArcSize;
            arcSegment.IsLargeArc = largeArc;
        }
Exemple #12
0
        public void LoadPathIcon(string pathData, Brush iconColor = null, int width = 25, int height = 25)
        {
            if (ccIcon == null)
            {
                return;
            }
            if (iconColor == null)
            {
                iconColor = new SolidColorBrush(Windows.UI.Colors.DimGray);
            }
            if (width == 0)
            {
                width = 25;
            }
            if (height == 0)
            {
                height = 25;
            }

            string pthString = @"<Path xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" 
                Data=""" + pathData + @""" />";

            Windows.UI.Xaml.Shapes.Path pth = (Windows.UI.Xaml.Shapes.Path)Windows.UI.Xaml.Markup.XamlReader.Load(pthString);
            pth.Stretch = Stretch.Uniform;
            pth.Fill    = iconColor;
            pth.Width   = width;
            pth.Height  = height;

            if (pthMoreItems != null)
            {
                pthMoreItems.Fill = iconColor;
            }

            ccIcon.Content = pth;
        }
Exemple #13
0
        private void RenderStroke(InkStroke stroke, Color color, double width, double opacity = 1)
        {
            var renderingStrokes = stroke.GetRenderingSegments();
            var path             = new Windows.UI.Xaml.Shapes.Path();

            path.Data = new PathGeometry();
            ((PathGeometry)path.Data).Figures = new PathFigureCollection();
            var pathFigure = new PathFigure();

            pathFigure.StartPoint = renderingStrokes.First().Position;
            ((PathGeometry)path.Data).Figures.Add(pathFigure);
            foreach (var renderStroke in renderingStrokes)
            {
                pathFigure.Segments.Add(new BezierSegment()
                {
                    Point1 = renderStroke.BezierControlPoint1,
                    Point2 = renderStroke.BezierControlPoint2,
                    Point3 = renderStroke.Position
                });
            }

            path.StrokeThickness = width;
            path.Stroke          = new SolidColorBrush(color);

            path.Opacity = opacity;

            InkCanvas.Children.Add(path);
        }
 private void RefreshPaths()
 {
     for (int i = 0; i < Profile.Path.PathList.Count; i++)
     {
         Windows.UI.Xaml.Shapes.Path segmentBezierPath = paths[i];
         PathGeometry geometry          = new PathGeometry();
         PathFigure   figure            = new PathFigure();
         Point        controlPtOnePoint = new Point(Profile.Path.PathList[i].ControlptOne[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptOne[1]);
         figure.StartPoint = controlPtOnePoint;
         BezierSegment bezierSegment = new BezierSegment
         {
             Point1 = new Point(Profile.Path.PathList[i].ControlptTwo[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptTwo[1]),
             Point2 = new Point(Profile.Path.PathList[i].ControlptThree[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptThree[1]),
             Point3 = new Point(Profile.Path.PathList[i].ControlptFour[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptFour[1])
         };
         figure.Segments.Add(bezierSegment);
         geometry.Figures.Add(figure);
         segmentBezierPath.Data               = geometry;
         segmentBezierPath.Stroke             = new SolidColorBrush(Windows.UI.Colors.Purple);
         segmentBezierPath.StrokeThickness    = (Profile.Robot.Width + Profile.Robot.BumperThickness * 2);
         segmentBezierPath.Opacity            = 0.5;
         segmentBezierPath.StrokeEndLineCap   = PenLineCap.Square;
         segmentBezierPath.StrokeStartLineCap = PenLineCap.Square;
     }
 }
Exemple #15
0
       public Crossline(Color color, PointerPoint point) 
       {
             this.horizontalPath = new Path();
             this.verticalPath = new Path();
            this.point = point;
            horizontalPath.Stroke = new SolidColorBrush(color);
            verticalPath.Stroke = new SolidColorBrush(color);
            LineGeometry horizontalLg = new LineGeometry();
            horizontalLg.StartPoint = new Point(0, 0);
            horizontalLg.EndPoint = new Point(Window.Current.Bounds.Width, 0);
            TranslateTransform horizontalLineTrans = new TranslateTransform();
            horizontalLineTrans.Y = point.Position.Y;
            horizontalLineTrans.X = 0;
            horizontalLg.Transform = horizontalLineTrans;
            horizontalPath.Data = horizontalLg;
            horizontalPath.StrokeThickness = strokeThickness;
            LineGeometry verticalLg = new LineGeometry();
            verticalLg.StartPoint = new Point(0, 0);
            verticalLg.EndPoint = new Point(0, Window.Current.Bounds.Height);
            TranslateTransform verticalLineTrans = new TranslateTransform();
            verticalLineTrans.X = point.Position.X;
            verticalLineTrans.Y = 0;
            verticalLg.Transform = verticalLineTrans;
            verticalPath.Data = verticalLg;
            verticalPath.StrokeThickness = strokeThickness;


       }
Exemple #16
0
        /// <summary>
        /// Draws the collection of ellipses, where all have the same stroke and fill.
        /// This performs better than calling DrawEllipse multiple times.
        /// </summary>
        /// <param name="rectangles">The rectangles.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        public void DrawEllipses(IList <OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness)
        {
            var path = new Path();

            this.SetStroke(path, stroke, thickness);
            if (fill.IsVisible())
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var gg = new GeometryGroup {
                FillRule = FillRule.Nonzero
            };

            foreach (var rect in rectangles)
            {
                gg.Children.Add(
                    new EllipseGeometry
                {
                    Center  = new Point(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2)),
                    RadiusX = rect.Width / 2,
                    RadiusY = rect.Height / 2
                });
            }

            path.Data = gg;
            this.Add(path);
        }
        // </SnippetPointerReleasedHandler>

        // Render ink strokes as cubic bezier segments.
        // <SnippetRenderAllStrokes>
        private void RenderAllStrokes()
        {
            // Clear the canvas.
            InkCanvas.Children.Clear();

            // Get the InkStroke objects.
            IReadOnlyList <InkStroke> inkStrokes = _inkManager.GetStrokes();

            // Process each stroke.
            foreach (InkStroke inkStroke in inkStrokes)
            {
                PathGeometry          pathGeometry = new PathGeometry();
                PathFigureCollection  pathFigures  = new PathFigureCollection();
                PathFigure            pathFigure   = new PathFigure();
                PathSegmentCollection pathSegments = new PathSegmentCollection();

                // Create a path and define its attributes.
                Windows.UI.Xaml.Shapes.Path path = new Windows.UI.Xaml.Shapes.Path();
                path.Stroke          = new SolidColorBrush(Colors.Red);
                path.StrokeThickness = STROKETHICKNESS;

                // Get the stroke segments.
                IReadOnlyList <InkStrokeRenderingSegment> segments;
                segments = inkStroke.GetRenderingSegments();

                // Process each stroke segment.
                bool first = true;
                foreach (InkStrokeRenderingSegment segment in segments)
                {
                    // The first segment is the starting point for the path.
                    if (first)
                    {
                        pathFigure.StartPoint = segment.BezierControlPoint1;
                        first = false;
                    }

                    // Copy each ink segment into a bezier segment.
                    BezierSegment bezSegment = new BezierSegment();
                    bezSegment.Point1 = segment.BezierControlPoint1;
                    bezSegment.Point2 = segment.BezierControlPoint2;
                    bezSegment.Point3 = segment.Position;

                    // Add the bezier segment to the path.
                    pathSegments.Add(bezSegment);
                }

                // Build the path geometerty object.
                pathFigure.Segments = pathSegments;
                pathFigures.Add(pathFigure);
                pathGeometry.Figures = pathFigures;

                // Assign the path geometry object as the path data.
                path.Data = pathGeometry;

                // Render the path by adding it as a child of the Canvas object.
                InkCanvas.Children.Add(path);
            }
        }
 /// <summary>
 /// Invoked when this page is about to be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.
 /// This parameter is typically used to configure the page.</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     PathGeometry geo = new PathGeometry();
     geo.Figures.Add(figure);
     path p = new path();
     p.Data = geo;
     p.Stroke = black;
     G.Children.Add(p);
 }
        private static PathGeometry Clone(string data)
        {
            string p = "<Path xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Data=\"" + data + "\"/>";

            Windows.UI.Xaml.Shapes.Path o = XamlReader.Load(p) as Windows.UI.Xaml.Shapes.Path;
            PathGeometry geo = Clone(o.Data as PathGeometry);

            return(geo);
        }
Exemple #20
0
 public virtual Path CreateGrid()
 {
     Path _outline = new Path();
     _outline.Name = ((Name == null || Name == string.Empty)) ? "GRID" : Name;
     _outline.RenderTransform = new CompositeTransform();
     SolidColorBrush mySolidColorBrush = new SolidColorBrush();
     mySolidColorBrush.Color = Foreground;
     _outline.Stroke = mySolidColorBrush;
     _outline.StrokeThickness = 0.5;
     return _outline;
 }
Exemple #21
0
        public Grid DrawCut(Trajectory trajectory)
        {
            var polygon1 = new Polygon();

            polygon1.Fill = new SolidColorBrush(Windows.UI.Colors.LightBlue);
            var points = new PointCollection();

            points.Add(new Point(10, 200));
            points.Add(new Point(60, 140));
            points.Add(new Point(130, 140));
            points.Add(new Point(180, 200));
            polygon1.Points = points;



            var path1 = new Windows.UI.Xaml.Shapes.Path();

            path1.Stroke          = new SolidColorBrush(Windows.UI.Colors.Black);
            path1.StrokeThickness = 1;

            var geometryGroup1 = new GeometryGroup();


            var pathGeometry1         = new PathGeometry();
            var pathFigureCollection1 = new PathFigureCollection();
            var pathFigure1           = new PathFigure();

            pathFigureCollection1.Add(pathFigure1);
            pathGeometry1.Figures = pathFigureCollection1;

            var pathSegmentCollection1 = new PathSegmentCollection();


            var pathSegment2 = new BezierSegment();

            pathSegment2.Point1 = new Point(125, 300);
            pathSegment2.Point2 = new Point(275, 100);
            pathSegment2.Point3 = new Point(trajectory.Px, trajectory.Px);
            pathSegmentCollection1.Add(pathSegment2);
            pathFigure1.Segments = pathSegmentCollection1;

            geometryGroup1.Children.Add(pathGeometry1);
            path1.Data = geometryGroup1;


            MyGridCut.Children.Add(path1);



            return(MyGridCut);
        }
Exemple #22
0
        protected override void OnPointerMoved(PointerRoutedEventArgs args)
        {
            // Get ID from event arguments
            uint id = args.Pointer.PointerId;

            // If ID is in dictionary, start a loop
            if (pointerDictionary.ContainsKey(id))
            {
                PointerInfo          pointerInfo   = pointerDictionary[id];
                IList <PointerPoint> pointerpoints = args.GetIntermediatePoints(this);

                for (int i = pointerpoints.Count - 1; i >= 0; i--)
                {
                    PointerPoint pointerPoint = pointerpoints[i];

                    // For each point, create a new Line element and add to Grid
                    Point point    = pointerPoint.Position;
                    float pressure = pointerPoint.Properties.Pressure;

                    double   radius   = 24 * pressure;
                    Geometry geometry = CreateTaperedLineGeometry(pointerInfo.PreviousPoint,
                                                                  pointerInfo.PreviosRadius, point, radius);
                    Path path = new Path
                    {
                        Data = geometry,
                        Fill = pointerInfo.Brush
                    };

                    /*
                     * Line line = new Line
                     * {
                     *  X1 = pointerInfo.PreviousPoint.X,
                     *  Y1 = pointerInfo.PreviousPoint.Y,
                     *  X2 = point.X,
                     *  Y2 = point.Y,
                     *  Stroke = pointerInfo.Brush,
                     *  StrokeThickness = pressure * 24,
                     *  StrokeStartLineCap = PenLineCap.Round,
                     *  StrokeEndLineCap = PenLineCap.Round
                     * };*/
                    contentGrid.Children.Add(path);

                    // Update PointerInfo
                    pointerInfo.PreviousPoint = point;
                }
                // Store PointerInfo back in dictionary
                pointerDictionary[id] = pointerInfo;
            }
            base.OnPointerMoved(args);
        }
Exemple #23
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (_glow == null)
            {
                object g = this.GetTemplateChild("Lightbulb");
                if (g is Path)
                {
                    _glow = (Path)g;
                }

            }
        }
Exemple #24
0
        /// <summary>
        /// Draws a collection of polygons, where all polygons have the same stroke and fill.
        /// This performs better than calling DrawPolygon multiple times.
        /// </summary>
        /// <param name="polygons">The polygons.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawPolygons(
            IList <IList <ScreenPoint> > polygons,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();

            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            if (fill.IsVisible())
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var pg = new PathGeometry {
                FillRule = FillRule.Nonzero
            };

            foreach (var polygon in polygons)
            {
                var figure = new PathFigure {
                    IsClosed = true
                };
                bool first = true;
                foreach (var p in polygon)
                {
                    if (first)
                    {
                        figure.StartPoint = p.ToPoint(aliased);
                        first             = false;
                    }
                    else
                    {
                        figure.Segments.Add(new LineSegment {
                            Point = p.ToPoint(aliased)
                        });
                    }
                }

                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
        void OnDragVectorChanged(object sender, Vector e)
        {
            moveDirection = e;
            moveDirection.Normalize();
            movedSoFar = new Vector(0, 0);
            steps      = 0;
            if (e.X == 0 && e.Y == 0)
            {
                // stop moving
                StopMoving();
                if (arrowHead != null)
                {
                    ImageOverlay.Children.Remove(arrowHead);
                    arrowHead = null;
                }
            }
            else
            {
                Point  downPos = gesture.MouseDownPosition;
                Point  endPos  = new Point(downPos.X + e.X, downPos.Y + e.Y);
                Vector v       = new Vector(downPos, endPos);
                double length  = v.Length;
                double msDelay = (10000 / length);
                if (msDelay < 1)
                {
                    msDelay = 1;
                }
                if (msDelay > 1000)
                {
                    msDelay = 1000;
                }

                StartMoving((int)msDelay);

                moveTimer.Interval = TimeSpan.FromMilliseconds(1);

                if (arrowHead == null)
                {
                    arrowHead = new Windows.UI.Xaml.Shapes.Path()
                    {
                        Fill = new SolidColorBrush(Color.FromArgb(0xA0, 0xF0, 0xF0, 0xFF))
                    };
                    ImageOverlay.Children.Add(arrowHead);
                }

                UpdatePathGeometry(arrowHead, downPos, endPos);
            }
        }
Exemple #26
0
        private Path MkPath(double indx, double increment)
        {
            Path path = new Path();
            path.Stroke = new SolidColorBrush(Colors.Red);
            path.Name = string.Format("Braid{0}", indx);
            path.Tag = indx;

            GeometryGroup g = new GeometryGroup();
            path.Data = g;
            PathGeometry pg = new PathGeometry();
            g.Children.Add(pg);

            //pg.Figures.Add(BuildStrand(indx * repeatAngle, 0, increment));
            for (int i = 0; i < bd.NumStrands; i++)
            {
                pg.Figures.Add(BuildStrand(indx * repeatAngle, i, increment));
            } 
            return path;
        }
Exemple #27
0
        public CurvePanel()
        {
            _bgcanvas = new Canvas();
            _bgcanvas.VerticalAlignment = VerticalAlignment.Stretch;
            _bgcanvas.HorizontalAlignment = HorizontalAlignment.Stretch;
            _path = new Path();
            _path.Stroke = Stroke;
            _path.StrokeThickness = StrokeThickness;
            PathGeometry geo = new PathGeometry();
            _bfigure = new PathFigure();
            _bseg = new BezierSegment();
            _bfigure.Segments.Add(_bseg);
            geo.Figures.Add(_bfigure);
            _path.Data = geo;
            _bgcanvas.Children.Add(_path);
            this.Children.Add(_bgcanvas);

            this.SizeChanged += OnSizeChanged;
        }
Exemple #28
0
        Child GetChild(ChildType type)
        {
            while (nextChildIndex < children.Count && children[nextChildIndex].Type != type)
            {
                // TODO: This shape is out of order
                nextChildIndex++;
            }

            if (nextChildIndex >= children.Count)
            {
                FrameworkElement shape;
                switch (type)
                {
                case ChildType.Rectangle: shape = new Shapes.Rectangle(); break;

                case ChildType.Ellipse: shape = new Shapes.Ellipse(); break;

                case ChildType.Path: shape = new Shapes.Path(); break;

                case ChildType.Image: shape = new Image(); break;

                case ChildType.Text: shape = new TextBlock(); break;

                default: throw new NotSupportedException(type + " not supported");
                }
                var ch = new Child {
                    Type  = type,
                    Shape = shape,
                };
                children.Add(ch);
                nextChildIndex = children.Count;
                return(ch);
            }
            else
            {
                var ch = children[nextChildIndex];
                nextChildIndex++;
                return(ch);
            }
        }
Exemple #29
0
        /// <summary>
        /// Draws the multiple line segments defined by points (0,1) (2,3) (4,5) etc.
        /// This should have better performance than calling DrawLine for each segment.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public void DrawLineSegments(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();

            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            var pg = new PathGeometry();

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                // if (points[i].Y==points[i+1].Y)
                // {
                // var line = new Line();

                // line.X1 = 0.5+(int)points[i].X;
                // line.X2 = 0.5+(int)points[i+1].X;
                // line.Y1 = 0.5+(int)points[i].Y;
                // line.Y2 = 0.5+(int)points[i+1].Y;
                // SetStroke(line, OxyColors.DarkRed, thickness, lineJoin, dashArray, aliased);
                // Add(line);
                // continue;
                // }
                var figure = new PathFigure {
                    StartPoint = points[i].ToPoint(aliased), IsClosed = false
                };
                figure.Segments.Add(new LineSegment {
                    Point = points[i + 1].ToPoint(aliased)
                });
                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
Exemple #30
0
        private void RenderStroke(InkStroke stroke, double width = 3.0, double opacity = 1)
        {
            // Each stroke might have more than one segments
            var renderingStrokes = stroke.GetRenderingSegments();

            //
            // Set up the Path to insert the segments
            var path = new Windows.UI.Xaml.Shapes.Path();

            path.Data = new PathGeometry();
            ((PathGeometry)path.Data).Figures = new PathFigureCollection();

            var pathFigure = new PathFigure();

            pathFigure.StartPoint = renderingStrokes.First().Position;
            ((PathGeometry)path.Data).Figures.Add(pathFigure);

            //
            // Foreach segment, we add a BezierSegment
            foreach (var renderStroke in renderingStrokes)
            {
                pathFigure.Segments.Add(new BezierSegment()
                {
                    Point1 = renderStroke.BezierControlPoint1,
                    Point2 = renderStroke.BezierControlPoint2,
                    Point3 = renderStroke.Position
                });
            }

            // Set the general options (i.e. Width and Color)
            path.StrokeThickness = width;
            path.Stroke          = new SolidColorBrush(Colors.Blue);

            // Opacity is used for highlighter
            path.Opacity = opacity;

            PanelCanvas.Children.Add(path);
        }
 //Returns an array of UI path objects that can be displayed
 private Windows.UI.Xaml.Shapes.Path[] GetUIPathObjects()
 {
     Windows.UI.Xaml.Shapes.Path[] PathOutputs = new Windows.UI.Xaml.Shapes.Path[Profile.Path.PathList.Count];
     for (int i = 0; i < Profile.Path.PathList.Count; i++)
     {
         Windows.UI.Xaml.Shapes.Path segmentBezierPath = new Windows.UI.Xaml.Shapes.Path();
         PathGeometry geometry          = new PathGeometry();
         PathFigure   figure            = new PathFigure();
         Point        controlPtOnePoint = new Point(Profile.Path.PathList[i].ControlptOne[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptOne[1]);
         figure.StartPoint = controlPtOnePoint;
         BezierSegment bezierSegment = new BezierSegment
         {
             Point1 = new Point(Profile.Path.PathList[i].ControlptTwo[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptTwo[1]),
             Point2 = new Point(Profile.Path.PathList[i].ControlptThree[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptThree[1]),
             Point3 = new Point(Profile.Path.PathList[i].ControlptFour[0], MainCanvas.Height - Profile.Path.PathList[i].ControlptFour[1])
         };
         figure.Segments.Add(bezierSegment);
         geometry.Figures.Add(figure);
         segmentBezierPath.Data = geometry;
         if (!Profile.Path.IsReversed)
         {
             segmentBezierPath.Stroke = new SolidColorBrush(Windows.UI.Colors.Purple);
         }
         else
         {
             segmentBezierPath.Stroke = new SolidColorBrush(Windows.UI.Colors.Red);
         }
         segmentBezierPath.StrokeThickness    = (Profile.Robot.Width + Profile.Robot.BumperThickness * 2);
         segmentBezierPath.Opacity            = 0.5;
         segmentBezierPath.StrokeEndLineCap   = PenLineCap.Square;
         segmentBezierPath.StrokeStartLineCap = PenLineCap.Square;
         PathOutputs[i] = segmentBezierPath;
     }
     paths = PathOutputs;
     return(PathOutputs);
 }
        public TileUC()
        {
            this.InitializeComponent();
            brush = new SolidColorBrush(Colors.Green);
            var c = 32;
            for (int i = 0; i < c; i++) {

                var f = Dim / c;
                var p = f * i;

                {
                    var geo = new LineGeometry() { StartPoint = new Point(0, p), EndPoint = new Point(Dim - p, Dim) };

                    var item = new Path();
                    item.Data = geo;
                    item.Stroke = brush;
                    item.StrokeThickness = .5;
                    item.StrokeEndLineCap = PenLineCap.Square;

                    this.Content.Children.Add(item);
                }
                if (i == 0) continue;
                {
                    var geo = new LineGeometry() { StartPoint = new Point(p, 0), EndPoint = new Point(Dim, Dim - p) };

                    var item = new Path();
                    item.Data = geo;
                    item.Stroke = brush;
                    item.StrokeThickness = .5;

                    item.StrokeEndLineCap = PenLineCap.Square;

                    this.Content.Children.Add(item);
                }
            }
        }
        public Drawing()
        {
            this.InitializeComponent();
            //path

            PathGeometry geo = new PathGeometry();
            geo.Figures.Add(figure);// constructor(new shape)
            geo.Figures.Add(f);
            figure.StartPoint = new Point(25, 25);
            f.StartPoint = new Point(75, 75);
            path p = new path();//constructor
            p.Data = geo;
            p.Stroke = new SolidColorBrush(new Color {A = 100});
            CompositeTransform c = new CompositeTransform();
            p.RenderTransform = c;
            c.TranslateX = 0;
            c.TranslateY = 0;
            G.Children.Add(p);
            f.Segments.Add(new LineSegment { Point = new Point(100, 100) });
            f.Segments.Add(new LineSegment { Point = new Point(100, 150) });
            figure.Segments.Add(new LineSegment { Point = new Point(50, 50) });
            figure.Segments.Add(new LineSegment { Point = new Point(50, 100) });
            p.Fill = black;
        }
Exemple #34
0
        private void DrawArcSegment(Point start, Point end, SweepDirection dir)
        {
            // DebugUtil.Log("draw arc: " + start.X + " " + start.Y + " " + end.X + " " + end.Y + " " + dir);

            PathFigure pthFigure = new PathFigure();

            pthFigure.StartPoint = start;

            ArcSegment arcSeg = new ArcSegment();

            arcSeg.Point          = end;
            arcSeg.Size           = new Size(Math.Abs(start.X - end.X), Math.Abs(start.Y - end.Y));
            arcSeg.IsLargeArc     = false;
            arcSeg.SweepDirection = dir;
            arcSeg.RotationAngle  = 90;

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(arcSeg);

            pthFigure.Segments = myPathSegmentCollection;

            PathFigureCollection pthFigureCollection = new PathFigureCollection();

            pthFigureCollection.Add(pthFigure);

            PathGeometry pthGeometry = new PathGeometry();

            pthGeometry.Figures = pthFigureCollection;

            Windows.UI.Xaml.Shapes.Path arcPath = new Windows.UI.Xaml.Shapes.Path();
            arcPath.Stroke          = this.Stroke;
            arcPath.StrokeThickness = this.StrokeThickness;
            arcPath.Data            = pthGeometry;
            Lines.Children.Add(arcPath);
        }
Exemple #35
0
        /// <summary>
        /// Draws a collection of rectangles, where all have the same stroke and fill.
        /// This performs better than calling DrawRectangle multiple times.
        /// </summary>
        /// <param name="rectangles">The rectangles.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        public void DrawRectangles(IList <OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness)
        {
            var path = new Path();

            this.SetStroke(path, stroke, thickness);
            if (fill.IsVisible())
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var gg = new GeometryGroup {
                FillRule = FillRule.Nonzero
            };

            foreach (var rect in rectangles)
            {
                gg.Children.Add(new RectangleGeometry {
                    Rect = rect.ToRect(true)
                });
            }

            path.Data = gg;
            this.Add(path);
        }
Exemple #36
0
        public void Draw()
        {
            if (Elements.Count == 0)
            {
                return;
            }
            double unit = ActualWidth / NumberOfDays;

            valueLayer.Children.Clear();

            //Polygon polygon = new Polygon { Fill = new SolidColorBrush(Colors.Gray) , FillRule = FillRule.EvenOdd};
            Path path = new Path {
                Fill = new SolidColorBrush(Colors.Gray)
            };
            var data = new PathGeometry {
                FillRule = FillRule.Nonzero
            };
            PathFigure pathFigure = new PathFigure();

            /*First Point After M is the Start Point*/
            pathFigure.StartPoint = new Point(ActualWidth, root.ActualHeight);

            pathFigure.IsClosed = true;

            data.Figures.Add(pathFigure); /* Adding it to path Geometry*/

            for (int x = 0; x < Elements.Count; x++)
            {
                /* Line line = new Line
                 * {
                 *  X1 = x * unit,
                 *  X2 = x * unit + unit,
                 *  Y1 = root.ActualHeight -  ((Elements[x] == 0? 0 : (Elements[x]/Elements.Max()))) * root.ActualHeight,
                 *  Y2 = root.ActualHeight - ((Elements[x+1] == 0? 0 : (Elements[x+1]/Elements.Max()))) * root.ActualHeight,
                 *  Stroke = Color,
                 *  StrokeThickness = 2.5
                 * };
                 * pathFigure.Segments.Add(new LineSegment {  Point = new Point(line.X1 , line.Y1) });
                 * pathFigure.Segments.Add(new LineSegment {  Point =  new Point(line.X2,line.Y2) });
                 * Ellipse ellipse = new Ellipse
                 * {
                 *  Width = 20 , Height = 20 , StrokeThickness = 0 , Fill = Color
                 *
                 * };
                 * valueLayer.Children.Add(ellipse);
                 * Canvas.SetLeft(ellipse,line.X1 - 5);
                 * Canvas.SetTop(ellipse, line.Y1 - 5);
                 *
                 *
                 * Ellipse ellipse2 = new Ellipse
                 * {
                 *  Width = 10,
                 *  Height = 10,
                 *  StrokeThickness = 0,
                 *  Fill = Color
                 * };
                 * valueLayer.Children.Add(ellipse2);
                 * Canvas.SetLeft(ellipse2, line.X2 - 5);
                 * Canvas.SetTop(ellipse2, line.Y2 - 5);
                 * valueLayer.Children.Add(line);
                 * }
                 * pathFigure.Segments.Add(new LineSegment{Point = new Point(0,root.ActualHeight)
                 * });
                 * path.Data = data;
                 * // polygon.Points.Add(new Point(root.ActualHeight, root.ActualWidth));
                 * // valueLayer.Children.Add(path);
                 *
                 */
                double    height    = ((Elements[x] == 0 ? 0 : (Elements[x] / Elements.Max()))) * root.ActualHeight;
                Rectangle rectangle = new Rectangle
                {
                    Width           = unit,
                    Height          = height,
                    Fill            = new SolidColorBrush(Colors.Orange),
                    Stroke          = new SolidColorBrush(Colors.White),
                    StrokeThickness = 2.5
                };

                valueLayer.Children.Add(rectangle);
                Canvas.SetLeft(rectangle, x * unit);
                Canvas.SetTop(rectangle, root.ActualHeight - height);

                TextBlock block = new TextBlock
                {
                    Text       = Elements[x].ToString(),
                    FontSize   = NumberOfDays > 7?19 : 25,
                    Foreground = rectangle.Fill
                };
                block.Loaded += (a, b) =>
                {
                    var bl = a as TextBlock;
                    Canvas.SetLeft((a as TextBlock), Canvas.GetLeft(bl) - bl.ActualWidth / 2.0);
                    Canvas.SetTop(bl, Canvas.GetTop(bl) - bl.ActualHeight - 5);
                };
                valueLayer.Children.Add(block);
                Canvas.SetLeft(block, Canvas.GetLeft(rectangle) + unit / 2.0);
                Canvas.SetTop(block, Canvas.GetTop(rectangle));
            }
        }
        public void InitializePieChart()
        {
            // draw the full circle/arc
            _arcSegment360 = new ArcSegment
            {
                SweepDirection = SweepDirection.Clockwise
            };

            _pathFigure360 = new PathFigure
            {
                Segments = new PathSegmentCollection
                {
                    _arcSegment360
                }
            };

            _pathRoot360 = new Path
            {
                Stroke = Segment360Color,
                StrokeThickness = StrokeThickness,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Data = new PathGeometry
                {
                    Figures = new PathFigureCollection
                    {
                        _pathFigure360
                    }
                }
            };

            //draw a circle with the given angle

            _arcSegment = new ArcSegment
            {
                SweepDirection = SweepDirection.Clockwise
            };

            _pathFigure = new PathFigure
            {
                Segments = new PathSegmentCollection
                {
                    _arcSegment
                }
            };

            _pathRoot = new Path
            {
                Stroke = SegmentColor,
                StrokeThickness = StrokeThickness,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Data = new PathGeometry
                {
                    Figures = new PathFigureCollection
                    {
                        _pathFigure
                    }
                }
            };

            Content = new Grid
            {
                Background = BackgroundColor,
                Children =
                {
                    _pathRoot360,
                    _pathRoot,
                }
            };
        }
Exemple #38
0
        // Plots a graph of the passed easing function using the given sampling interval on the "Graph" Canvas control 
        private void PlotEasingFunctionGraph(EasingFunctionBase easingFunction, double samplingInterval)
        {
            UISettings UserSettings = new UISettings();
            Graph.Children.Clear();

            Path path = new Path();
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure pathFigure = new PathFigure() { StartPoint = new Point(0, 0) };
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            // Note that an easing function is just like a regular function that operates on doubles.
            // Here we plot the range of the easing function's output on the y-axis of a graph.
            for (double i = 0; i < 1; i += samplingInterval)
            {
                double x = i * GraphContainer.Width;
                double y = easingFunction.Ease(i) * GraphContainer.Height;

                LineSegment segment = new LineSegment();
                segment.Point = new Point(x, y);
                pathSegmentCollection.Add(segment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);
            path.Data = pathGeometry;
            path.Stroke = new SolidColorBrush(UserSettings.UIElementColor(UIElementType.ButtonText));
            path.StrokeThickness = 1;

            // Add the path to the Canvas
            Graph.Children.Add(path);
        }
 private void UpdatePathGeometry(Windows.UI.Xaml.Shapes.Path arrowHead, Point start, Point end)
 {
     arrowHead.Data = GeometryUtilities.CreateFatArrow(end, start, 10, 16, 16);
 }
Exemple #40
0
        private void Draw()
        {
            IsDrawn = true;

            Map.Children.Clear();

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                Map.Children.Add(new TextBlock
                {
                    Text = "Designer preview is not currently available",
                    Foreground = new SolidColorBrush(Colors.White),
                    FontWeight = FontWeights.Bold,
                    FontSize = 12,
                    //Effect = new DropShadowEffect
                    //{
                    //    ShadowDepth = 2,
                    //    RenderingBias = RenderingBias.Performance
                    //}
                });
                return;
            }

            var map = MapResolver.Get(Source);
            if (map == null) return;

            var desiredSize = new Size(map.DesiredWidth, map.DesiredHeight);
            var r = desiredSize.Width/desiredSize.Height;

            var wr = ActualWidth/desiredSize.Width;
            var hr = ActualHeight/desiredSize.Height;
            double s;

            if (wr < hr)
            {
                IsWidthDominant = true;
                Map.Width = ActualWidth;
                Map.Height = Map.Width/r;
                s = wr;
                OriginalPosition = new Point(0, (ActualHeight - Map.Height)*.5);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }
            else
            {
                IsWidthDominant = false;
                Map.Height = ActualHeight;
                Map.Width = r*ActualHeight;
                s = hr;
                OriginalPosition = new Point((ActualWidth - Map.Width)*.5, 0d);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }

            var t = new ScaleTransform() {ScaleX = s, ScaleY = s};

            foreach (var land in map.Data)
            {
                var p = new Path
                {
                    Data = GeometryHelper.Parse(land.Data),
                    RenderTransform = t
                };

                land.Shape = p;
                Lands[land.Id] = land;
                Map.Children.Add(p);

                //p.MouseEnter += POnMouseEnter;
                //p.MouseLeave += POnMouseLeave;
                //p.MouseMove += POnMouseMove;
                //p.MouseDown += POnMouseDown;

                p.SetBinding(Shape.StrokeProperty,
                    new Binding { Path = new PropertyPath("LandStroke"), Source = this });
                var behavior = new MultiBindingBehavior()
                {
                    Converter = new ScaleStrokeConverter(),
                    PropertyName = "StrokeThickness"
                };
                behavior.Items.Add(new MultiBindingItem() {Parent = behavior.Items, Value = new Binding() { Path = new PropertyPath("LandStrokeThickness"), Source = this } });
                behavior.Items.Add(new MultiBindingItem() {Parent = behavior.Items, Value = new Binding() { Path = new PropertyPath("ScaleX"), Source = t } });
                Interaction.SetBehaviors(p, new BehaviorCollection() {behavior});
            }

            ShowMeSomeHeat();
        }
Exemple #41
0
        /// <summary>
        /// Read the SVG file as XML
        /// </summary>
        /// <param name="stream">文件流</param>
        /// <returns></returns>
        private static Tuple <Size, List <Windows.UI.Xaml.Shapes.Path>, SolidColorBrush> ReadStreamAndConvertToPath(Stream stream, bool isDefaultBlack)
        {
            List <Windows.UI.Xaml.Shapes.Path> pathsToReturn = new List <Windows.UI.Xaml.Shapes.Path>();
            SolidColorBrush defaultColor = isDefaultBlack ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.White);

            try
            {
                //Load XAML document
                var root = XElement.Load(stream);

                //Get some info.
                var widthInfo  = root.Attributes().Where(a => a.Name.LocalName == "width").FirstOrDefault();
                var heightInfo = root.Attributes().Where(a => a.Name.LocalName == "height").FirstOrDefault();

                var width  = widthInfo?.Value.Replace("px", string.Empty);
                var height = heightInfo?.Value.Replace("px", string.Empty);

                var size = new Size(double.Parse(width), double.Parse(height));
                if (size.Width == 0 || size.Height == 0)
                {
                    size = Size.Empty;
                }

                //Get all paths
                var elements = root.Descendants().Where(e => (e.Name.LocalName == "path" || e.Name.LocalName == "polygon"));

                foreach (var element in elements)
                {
                    var localName = element.Name.LocalName;
                    if (localName == "path")
                    {
                        var d           = (element.Attributes().Where(e => e.Name.LocalName == "d")).FirstOrDefault();
                        var fill        = (element.Attributes().Where(e => e.Name.LocalName == "fill")).FirstOrDefault();
                        var newColor    = isDefaultBlack ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.White);
                        var opacityInfo = (element.Attributes().Where(e => e.Name.LocalName == "opacity")).FirstOrDefault();

                        var opacity = 1.0d;
                        if (opacityInfo != null)
                        {
                            opacity = double.Parse(opacityInfo.Value);
                        }

                        //In some case fill 's value is "none"
                        if (fill != null)
                        {
                            try
                            {
                                newColor = new SolidColorBrush(ColorConverter.Hex2Color(fill.Value));
                            }
                            catch (Exception)
                            {
                            }
                        }

                        Windows.UI.Xaml.Shapes.Path newPath = new Windows.UI.Xaml.Shapes.Path()
                        {
                            Fill    = newColor,
                            Opacity = opacity,
                        };

                        var binding = new Binding
                        {
                            Source = d.Value,
                        };
                        BindingOperations.SetBinding(newPath, Windows.UI.Xaml.Shapes.Path.DataProperty, binding);

                        pathsToReturn.Add(newPath);
                    }
                    else if (localName == "polygon")
                    {
                        var newColor = isDefaultBlack ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.White);

                        var point       = element.Attributes().Where(a => a.Name.LocalName == "points");
                        var dataStr     = point.FirstOrDefault().Value;
                        var fill        = (element.Attributes().Where(a => a.Name.LocalName == "fill")).FirstOrDefault();
                        var opacityInfo = (element.Attributes().Where(e => e.Name.LocalName == "opacity")).FirstOrDefault();

                        var opacity = 1.0d;
                        if (opacityInfo != null)
                        {
                            opacity = double.Parse(opacityInfo.Value);
                        }

                        Windows.UI.Xaml.Shapes.Path newPath = new Windows.UI.Xaml.Shapes.Path()
                        {
                            Fill = newColor, Opacity = opacity
                        };
                        if (fill != null)
                        {
                            newPath.Fill = new SolidColorBrush(ColorConverter.Hex2Color(fill.Value));
                        }

                        var binding = new Binding()
                        {
                            Source = dataStr.StartsWith("M") ? dataStr : "M" + dataStr,
                        };
                        BindingOperations.SetBinding(newPath, Windows.UI.Xaml.Shapes.Path.DataProperty, binding);

                        pathsToReturn.Add(newPath);
                    }
                }
                return(Tuple.Create(size, pathsToReturn, defaultColor));
            }
            catch (Exception e)
            {
                return(Tuple.Create(new Size(), pathsToReturn, defaultColor));
            }
        }
Exemple #42
0
        private void Draw()
        {
            IsDrawn = true;

            Map.Children.Clear();

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                Map.Children.Add(new TextBlock
                {
                    Text       = "Designer preview is not currently available",
                    Foreground = new SolidColorBrush(Colors.White),
                    FontWeight = FontWeights.Bold,
                    FontSize   = 12,
                    //Effect = new DropShadowEffect
                    //{
                    //    ShadowDepth = 2,
                    //    RenderingBias = RenderingBias.Performance
                    //}
                });
                return;
            }

            var map = MapResolver.Get(Source);

            if (map == null)
            {
                return;
            }

            var desiredSize = new Size(map.DesiredWidth, map.DesiredHeight);
            var r           = desiredSize.Width / desiredSize.Height;

            var    wr = ActualWidth / desiredSize.Width;
            var    hr = ActualHeight / desiredSize.Height;
            double s;

            if (wr < hr)
            {
                IsWidthDominant = true;
                Map.Width       = ActualWidth;
                Map.Height      = Map.Width / r;
                s = wr;
                OriginalPosition = new Point(0, (ActualHeight - Map.Height) * .5);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }
            else
            {
                IsWidthDominant = false;
                Map.Height      = ActualHeight;
                Map.Width       = r * ActualHeight;
                s = hr;
                OriginalPosition = new Point((ActualWidth - Map.Width) * .5, 0d);
                Canvas.SetLeft(Map, OriginalPosition.X);
                Canvas.SetTop(Map, OriginalPosition.Y);
            }

            var t = new ScaleTransform()
            {
                ScaleX = s, ScaleY = s
            };

            foreach (var land in map.Data)
            {
                var p = new Path
                {
                    Data            = GeometryHelper.Parse(land.Data),
                    RenderTransform = t
                };

                land.Shape     = p;
                Lands[land.Id] = land;
                Map.Children.Add(p);

                //p.MouseEnter += POnMouseEnter;
                //p.MouseLeave += POnMouseLeave;
                //p.MouseMove += POnMouseMove;
                //p.MouseDown += POnMouseDown;

                p.SetBinding(Shape.StrokeProperty,
                             new Binding {
                    Path = new PropertyPath("LandStroke"), Source = this
                });
                var behavior = new MultiBindingBehavior()
                {
                    Converter    = new ScaleStrokeConverter(),
                    PropertyName = "StrokeThickness"
                };
                behavior.Items.Add(new MultiBindingItem()
                {
                    Parent = behavior.Items, Value = new Binding()
                    {
                        Path = new PropertyPath("LandStrokeThickness"), Source = this
                    }
                });
                behavior.Items.Add(new MultiBindingItem()
                {
                    Parent = behavior.Items, Value = new Binding()
                    {
                        Path = new PropertyPath("ScaleX"), Source = t
                    }
                });
                Interaction.SetBehaviors(p, new BehaviorCollection()
                {
                    behavior
                });
            }

            ShowMeSomeHeat();
        }
        /// <summary>
        /// The draw line segments.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public void DrawLineSegments(
            IList<ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            var pg = new PathGeometry();
            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                // if (points[i].Y==points[i+1].Y)
                // {
                // var line = new Line();

                // line.X1 = 0.5+(int)points[i].X;
                // line.X2 = 0.5+(int)points[i+1].X;
                // line.Y1 = 0.5+(int)points[i].Y;
                // line.Y2 = 0.5+(int)points[i+1].Y;
                // SetStroke(line, OxyColors.DarkRed, thickness, lineJoin, dashArray, aliased);
                // Add(line);
                // continue;
                // }
                var figure = new PathFigure { StartPoint = points[i].ToPoint(aliased), IsClosed = false };
                figure.Segments.Add(new LineSegment { Point = points[i + 1].ToPoint(aliased) });
                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
        /// <summary>
        /// Draws a collection of rectangles, where all have the same stroke and fill.
        /// This performs better than calling DrawRectangle multiple times.
        /// </summary>
        /// <param name="rectangles">
        /// The rectangles.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        public void DrawRectangles(IList<OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness);
            if (fill != null)
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var gg = new GeometryGroup { FillRule = FillRule.Nonzero };
            foreach (OxyRect rect in rectangles)
            {
                gg.Children.Add(new RectangleGeometry { Rect = rect.ToRect(true) });
            }

            path.Data = gg;
            this.Add(path);
        }
        private Path CreatePath(double scale, uint rating, bool isRightHalf)
        {
            Path newPath = new Path();

            newPath.Fill = new SolidColorBrush(Colors.Transparent);
            newPath.StrokeThickness = 3;
            newPath.Stroke = BorderColor;
            newPath.Tapped += (object sender, TappedRoutedEventArgs e) =>
                {
                    Rating = rating;
                };

            double adj = isRightHalf ? -60 : 0;
            double adjScale = isRightHalf ? -scale : scale;

            PathFigure pathData = new PathFigure();
            pathData.StartPoint = new Windows.Foundation.Point((adj + 30.5) * adjScale, 0 * scale);
            pathData.IsClosed = false;
            pathData.IsFilled = true;

            pathData.Segments.Add(new LineSegment() { Point = new Windows.Foundation.Point((adj + 20.2917) * adjScale, 12.1572 * scale) });
            pathData.Segments.Add(new LineSegment() { Point = new Windows.Foundation.Point((adj + 5.7296) * adjScale, 17.63355 * scale) });
            pathData.Segments.Add(new LineSegment() { Point = new Windows.Foundation.Point((adj + 14.2917) * adjScale, 30.6234 * scale) });
            pathData.Segments.Add(new LineSegment() { Point = new Windows.Foundation.Point((adj + 15) * adjScale, 46.1652 * scale) });
            pathData.Segments.Add(new LineSegment() { Point = new Windows.Foundation.Point((adj + 30.5) * adjScale, 42.0361 * scale) });


            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry.Figures.Add(pathData);

            newPath.Data = pathGeometry;

            return newPath;

            /*
                                x:Name="Region1"
                                Fill="Transparent"
                                Stroke="{StaticResource PhoneForegroundBrush}"
                                StrokeThickness="3"
                                Tapped="Region1_Tapped"
             * 
             * <PathFigure StartPoint="30.5,0" IsClosed="False">
                                                <LineSegment Point="20.2917,12.1572" />
                                                <LineSegment Point="5.7296,17.63355" />
                                                <LineSegment Point="14.2917,30.6234" />
                                                <LineSegment Point="15,46.1652" />
                                                <LineSegment Point="30.5,42.0361" />
                                            </PathFigure>
             * 
                                            <PathFigure StartPoint="29.5,0" IsClosed="False">
                                                <LineSegment Point="39.7082,12.1572" />
                                                <LineSegment Point="54.2705,17.63355" />
                                                <LineSegment Point="45.7082,30.6234" />
                                                <LineSegment Point="45,46.1652" />
                                                <LineSegment Point="29.5,42.0361" />
                                            </PathFigure>
                                        </PathGeometry>
 
             * 
             * 
            */
        }
        /// <summary>
        /// Generates the pie chart.
        /// </summary>
        protected override void GenerateChart()
        {
            RootElement.Children.Clear();
            var data = ItemsSource;
            var validData = data == null ? null : data.Where(d => d.Value > 0);
            if (validData != null && validData.Any())
            {
                if (validData.Count() == 1)
                {
                    // Only one valid dat ==> draw a circle
                    int colorIndex = validData.Select((k, ind) => ind).FirstOrDefault();
                    var kvp = data.Where(d => d.Value > 0).First();

                    EllipseGeometry ellipseGeometry = new EllipseGeometry()
                    {
                        RadiusX = 1,
                        RadiusY = 1
                    };

                    Path path = new Path()
                    {
                        Stretch = Stretch.Uniform,
                        Fill = GetColorByIndex(colorIndex),
                        Data = ellipseGeometry
                    };
                    SetTooltip(path, kvp.Key, string.Format("{0} (100%)", FormattedValue(kvp.Value)));

                    RootElement.Children.Add(path);
                }
                else
                {
                    //We have more than one value to display. Generate pie shapes:
                    var total = validData.Sum(d => d.Value);
                    double current = 0;
                    int colorIndex = 0;
                    const double offset = 0; //Rotational offset (set it to Math.PI * .5 to start first segment upwards, set it to 0 to look like arcgis.com)

                    foreach (var kvp in data)
                    {
                        var val = kvp.Value;

                        if (val <= 0.0) // not valid
                        {
                            colorIndex++;
                            continue;
                        }

                        var fraction = val / total;

                        double angle0 = 2 * Math.PI * current - offset;
                        double angle1 = 2 * Math.PI * (current + fraction) - offset;

                        PathFigure pathFigure = new PathFigure {IsClosed = true, StartPoint = new Point(1, 1)};
                        pathFigure.Segments.Add(new LineSegment { Point = new Point(Math.Cos(angle0) + 1, Math.Sin(angle0) + 1) });
                        bool isLargeArc = fraction > .5;
                        pathFigure.Segments.Add(
                            new ArcSegment
                            {
                                Point = new Point(Math.Cos(angle1) + 1, Math.Sin(angle1) + 1),
                                IsLargeArc = isLargeArc,
                                Size = new Size(1, 1),
                                SweepDirection = SweepDirection.Clockwise
                            });
                        pathFigure.Segments.Add(new LineSegment() { Point = new Point(1, 1) });

                        //Add these two empty line segments to force the drawing to stretch properly
                        //with 1,1 at the center ( 0,0->2,2 is the bounding box for the figure)
                        PathFigure pathFigure2 = new PathFigure() { StartPoint = new Point(0, 0) };
                        pathFigure2.Segments.Add(new LineSegment() { Point = new Point(0, 0) });
                        PathFigure pathFigure3 = new PathFigure() { StartPoint = new Point(2, 2) };
                        pathFigure3.Segments.Add(new LineSegment() { Point = new Point(2, 2) });

                        PathGeometry pathGeometry = new PathGeometry();
                        pathGeometry.Figures.Add(pathFigure2);
                        pathGeometry.Figures.Add(pathFigure3);
                        pathGeometry.Figures.Add(pathFigure);
                        Path path = new Path()
                        {
                            Stretch = Stretch.Uniform,
                            Fill = GetColorByIndex(colorIndex),
                            Data = pathGeometry
                        };

                        // Add outline separating pie slices
                        PathFigure outLineFigure = new PathFigure { IsClosed = false, StartPoint = new Point(1, 1) };
                        outLineFigure.Segments.Add(new LineSegment() { Point = new Point(Math.Cos(angle0) + 1, Math.Sin(angle0) + 1) });

                        //Add these two empty line segments to force the drawing to stretch properly
                        //with 1,1 at the center ( 0,0->2,2 is the bounding box for the figure)
                        PathFigure outLineFigure2 = new PathFigure() { StartPoint = new Point(0, 0) };
                        outLineFigure2.Segments.Add(new LineSegment() { Point = new Point(0, 0) });
                        PathFigure outLineFigure3 = new PathFigure() { StartPoint = new Point(2, 2) };
                        outLineFigure3.Segments.Add(new LineSegment() { Point = new Point(2, 2) });

                        PathGeometry outLineGeometry = new PathGeometry();
                        outLineGeometry.Figures.Add(outLineFigure2);
                        outLineGeometry.Figures.Add(outLineFigure3);
                        outLineGeometry.Figures.Add(outLineFigure);
                        Path outLine = new Path()
                        {
                            Fill = null,
                            Stretch = Stretch.Uniform,
                            Stroke = new SolidColorBrush(Colors.White),
                            StrokeThickness = 1.0,
                            Data = outLineGeometry
                        };

                        SetTooltip(path, kvp.Key, string.Format("{0} ({1:0.##%})", FormattedValue(val), fraction));
                        RootElement.Children.Add(path);
                        RootElement.Children.Add(outLine);
                        current += fraction;
                        colorIndex++;
                    }
                }
            }
        }
Exemple #47
0
        private Windows.UI.Xaml.Shapes.Shape MkPath(int indx, int indy, double inc)
        {
            double rad = BasicLib.ToRadians;
            double deg = BasicLib.ToDegrees;

            Path path = new Path();
            path.Stroke = new SolidColorBrush(Colors.Red);
            path.Name = string.Format("Lattice{0}_{1}", indx, indy);
            GeometryGroup g = new GeometryGroup();
            path.Data = g;
            PathGeometry pg = new PathGeometry();
            g.Children.Add(pg);
            double startAngle = indx * repeatAngle;

            foreach (Line2D ll in ld.Lines)
            { 
                PathFigure pf = new PathFigure();
                double angle1 = startAngle + ll.X1 * colAngle;
                double angl1 = angle1 * rad;
                double angle2 = startAngle + ll.X2 * colAngle;
                double angl2 = angle2 * rad;
                double rowstart = indy * ld.Layout.Height;
                double y1 = ld.Layout.ToolPosition - rowstart  - ll.Y1 * rowHeight;
                double y2 = ld.Layout.ToolPosition - rowstart - ll.Y2 * rowHeight;
                
                pf.StartPoint = new Point(y1 * Math.Cos(angl1),
                                          y1 * Math.Sin(angl1));
                if (ll.IsVertical)
                {      
                    LineSegment ls = new LineSegment();
                    ls.Point = new Point(y2 * Math.Cos(angl1),
                                          y2 * Math.Sin(angl1));
                    pf.Segments.Add(ls);
                   
                }
                else if (ll.IsHorizontal)
                {
                    PolyLineSegment pls = new PolyLineSegment();
                    double a = angl1;
                    Point pnt;
                    do
                    {
                        pnt = new Point(y2 * Math.Cos(a), y2 * Math.Sin(a));
                        pls.Points.Add(pnt);
                        a += (angl1 < angl2) ? inc : -inc;
                    }
                    while ((angl1 < angl2) ? (a < angl2) : ( a > angl2));
                    if ((angl1 < angl2) ? (a != angl2) : (a != angl1))
                    {
                        a = (angl1 < angl2) ? angl2 : angl1;
                        pnt = new Point(y2 * Math.Cos(a), y2 * Math.Sin(a));
                        pls.Points.Add(pnt);
                    }
                    pf.Segments.Add(pls);
                }
                else // is diagonal
                {
                    double i = 0;
                    PolyLineSegment pls = new PolyLineSegment();
                    for (i = 0; i <= 1.0; i += inc)
                    {                  
                        pls.Points.Add(Interp(ll.X1,y1,i,ll.X2,y2,startAngle));
                    }        
                    pls.Points.Add(Interp(ll.X1, y1, 1.0, ll.X2, y2,startAngle));
                  
                    pf.Segments.Add(pls);
                } 
                pg.Figures.Add(pf);
            }
            return path;
        }
        private void GenerateDataPoints(IDictionary<string, double> data, Range dataRange)
        {
            int count = data.Count;

            // Project the data in order to get the points in percent of the drawing space (rectangle 1*1)
            var points = data.Select((kvp, ind) => new { x = (2.0 * ind + 1.0) / (2.0 * count), y = 1.0 - dataRange.Fraction(kvp.Value)});

            // Generate the lines from point to point
            var firstPoint = points.First();
            PathFigure pathFigure = new PathFigure { IsClosed = false, StartPoint = new Point(firstPoint.x, firstPoint.y) };
            foreach (var point in points.Skip(1))
            {
                pathFigure.Segments.Add(new LineSegment {Point = new Point(point.x, point.y)});
            }

            //Add these two empty line segments to force the drawing to stretch properly
            PathFigure pathFigure2 = new PathFigure { StartPoint = new Point(0, 0) };
            pathFigure2.Segments.Add(new LineSegment { Point = new Point(0, 0) });
            PathFigure pathFigure3 = new PathFigure { StartPoint = new Point(1, 1) };
            pathFigure3.Segments.Add(new LineSegment { Point = new Point(1, 1) });

            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry.Figures.Add(pathFigure2);
            pathGeometry.Figures.Add(pathFigure3);
            pathGeometry.Figures.Add(pathFigure);
            Path path = new Path
            {
                Stretch = Stretch.Fill, // stretch the polyline to fill the chart drawing space
                Stroke = GetColorByIndex(0),
                StrokeThickness = 2,
                StrokeLineJoin = PenLineJoin.Round,
                Data = pathGeometry,
                Margin = new Thickness(-1,-1,-1,-1) // half of strokeThickness
            };
            _series.Children.Add(path);

            // Add a new grid for the points
            Grid pointsGrid = new Grid();
            _series.Children.Add(pointsGrid);

            // Generate the points
            foreach (var kvp in data)
            {
                GenerateDataPoint(pointsGrid, kvp, dataRange);
            }
        }
Exemple #49
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _path = (Path)GetTemplateChild(pathName);
            _thumbGrid = (Grid)GetTemplateChild(thumbGridName);
            _readingBlock = (TextBlock)GetTemplateChild(readingName);

            PathGeometry geo = new PathGeometry();
            _bfigure = new PathFigure();
            _bseg = new BezierSegment();
            _bfigure.Segments.Add(_bseg);
            geo.Figures.Add(_bfigure);
            _path.Data = geo;

            this.SizeChanged += OnSizeChanged;
        }
Exemple #50
0
 protected override void OnApplyTemplate()
 {
     ClusterTextBlock = GetTemplateChild("textBlockClusterNumber") as TextBlock;
     StationPath      = GetTemplateChild("path") as Windows.UI.Xaml.Shapes.Path;
 }
Exemple #51
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (mainGrid == null)
            {

                mainGrid = (Grid)GetTemplateChild("grdTile");
                sbTilt = (Storyboard)mainGrid.Resources["sbTilt"];
                sbHide = (Storyboard)mainGrid.Resources["sbHide"];
                sbShow = (Storyboard)mainGrid.Resources["sbShow"];
                sbExplode = (Storyboard)mainGrid.Resources["sbExplode"];
                sbShowImage = (Storyboard)mainGrid.Resources["sbShowImage"];
                recCP = (Rectangle)GetTemplateChild("recCP");
                recBackground = (Rectangle)GetTemplateChild("recBackground");
                recDisabled = (Rectangle)GetTemplateChild("recDisabled");
                recSelected = (Rectangle)GetTemplateChild("recSelected");
                lblLabel = (TextBlock)GetTemplateChild("lblLabel");
                imgBackground = (Image)GetTemplateChild("imgBackground");
                ccIcon = (ContentControl)GetTemplateChild("ccIcon");
                ccContent = (ContentControl)GetTemplateChild("ccContent");
                pthMoreItems = (Path)GetTemplateChild("pthMoreItems");

                DoubleAnimationUsingKeyFrames planeProjectionRotationX = (DoubleAnimationUsingKeyFrames)sbTilt.Children[0];
                DoubleAnimationUsingKeyFrames planeProjectionRotationY = (DoubleAnimationUsingKeyFrames)sbTilt.Children[1];
                DoubleAnimationUsingKeyFrames ScaleTransformX = (DoubleAnimationUsingKeyFrames)sbTilt.Children[2];
                DoubleAnimationUsingKeyFrames ScaleTransformY = (DoubleAnimationUsingKeyFrames)sbTilt.Children[3];
                kfX = (SplineDoubleKeyFrame)planeProjectionRotationX.KeyFrames[0];
                kfY = (SplineDoubleKeyFrame)planeProjectionRotationY.KeyFrames[0];
                kfScaleX = (SplineDoubleKeyFrame)ScaleTransformX.KeyFrames[0];
                kfScaleY = (SplineDoubleKeyFrame)ScaleTransformY.KeyFrames[0];

                
                mainGrid.PointerMoved += mainGrid_PointerMoved;
                mainGrid.PointerPressed += mainGrid_PointerPressed;
                this.Click += TiltTile_Click; //this is what is triggered by buttonbase , pointerreleased is no longer triggered
                mainGrid.PointerReleased += mainGrid_PointerReleased; //may not need this since moving to ButtonBase
                mainGrid.PointerExited += mainGrid_PointerExited;


                recBackground.Fill = NormalBackground;
                recDisabled.Fill = DisabledBackground;
                recSelected.Fill = SelectedBackground;
                if (IsDisabled)
                {
                    recDisabled.Visibility = Visibility.Visible;
                    //mainGrid.Opacity = 0.4;
                }
                else
                {
                    recDisabled.Visibility = Visibility.Collapsed;
                    //mainGrid.Opacity = 1;
                }
            }
        }
		private void DrawChart()
		{
			if ((dataSet != null) && (dataSet.Length > 0))
			{
				var path = new Windows.UI.Xaml.Shapes.Path();
				path.Stroke = chartColor;
				path.StrokeThickness = 15;
				path.StrokeLineJoin = PenLineJoin.Round;
				path.StrokeStartLineCap = PenLineCap.Round;
				path.StrokeEndLineCap = PenLineCap.Round;

				var geometry = new PathGeometry();

				var figure = new PathFigure();
				figure.IsClosed = false;
				figure.StartPoint = new Point(offsetList[0].OffsetX, offsetList[0].OffsetY);

				for (int i = 0; i < offsetList.Count; i++)
				{
					var segment = new LineSegment();
					segment.Point = new Point(offsetList[i].OffsetX, offsetList[i].OffsetY);
					figure.Segments.Add(segment);
				}
				geometry.Figures.Add(figure);
				path.Data = geometry;
				Children.Add(path);
			}
		}
Exemple #53
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _canvas = (Canvas)GetTemplateChild(canvasName);
            _roundTriangle = (Path)GetTemplateChild(roundTriangeName);
            _verticalTick = (Canvas)GetTemplateChild(verticalTickName);
            _arcTick = (Canvas)GetTemplateChild(arcTickName);
            _rudderBtn = (Ellipse)GetTemplateChild(rudderBtnName);
            _trackerBtn = (Ellipse)GetTemplateChild(trackerBtnName);

            _canvas.SizeChanged += OnSizeChanged;
            _trackerBtn.PointerPressed += _trackerBtn_PointerPressed;
            _trackerBtn.PointerReleased += _trackerBtn_PointerReleased;
            _trackerBtn.PointerMoved += _trackerBtn_PointerMoved;
        }
        /// <summary>
        /// The draw ellipses.
        /// </summary>
        /// <param name="rectangles">
        /// The rectangles.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        public void DrawEllipses(IList<OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness);
            if (fill != null)
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var gg = new GeometryGroup { FillRule = FillRule.Nonzero };
            foreach (OxyRect rect in rectangles)
            {
                gg.Children.Add(
                    new EllipseGeometry
                        {
                            Center = new Point(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2)),
                            RadiusX = rect.Width / 2,
                            RadiusY = rect.Height / 2
                        });
            }

            path.Data = gg;
            this.Add(path);
        }
        private Point DrawLine(Grid container, Brush Palette, double linethickness, Point prevPoint, LineDataPoint DataPoint)
        {
            Point Current = getLinePlottingPoint(DataPoint);
            Point[] LinePoints = Utilities.GetLinePointsOnCircle(prevPoint, Current, DataPoint.CircleRadius);


            PathFigure path = new PathFigure();
            path.StartPoint = LinePoints[0];
            path.IsClosed = false;
            LineSegment Line = new LineSegment();
            Line.Point = LinePoints[1];
            path.Segments.Add(Line);
            PathGeometry myPath = new PathGeometry();
            myPath.Figures.Add(path);
            Path output = new Path();
            output.Data = myPath;
            output.StrokeThickness = linethickness;
            output.Stroke = Palette;
            container.Children.Add(output);
            prevPoint = Current;
            return prevPoint;
        }
        /// <summary>
        /// The draw polygons.
        /// </summary>
        /// <param name="polygons">
        /// The polygons.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        /// <param name="dashArray">
        /// The dash array.
        /// </param>
        /// <param name="lineJoin">
        /// The line join.
        /// </param>
        /// <param name="aliased">
        /// The aliased.
        /// </param>
        public void DrawPolygons(
            IList<IList<ScreenPoint>> polygons,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased);
            if (fill != null)
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var pg = new PathGeometry { FillRule = FillRule.Nonzero };
            foreach (var polygon in polygons)
            {
                var figure = new PathFigure { IsClosed = true };
                bool first = true;
                foreach (ScreenPoint p in polygon)
                {
                    if (first)
                    {
                        figure.StartPoint = p.ToPoint(aliased);
                        first = false;
                    }
                    else
                    {
                        figure.Segments.Add(new LineSegment { Point = p.ToPoint(aliased) });
                    }
                }

                pg.Figures.Add(figure);
            }

            path.Data = pg;
            this.Add(path);
        }
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            // Code might use some null reference checks here.

            this.layoutRoot = this.GetTemplateChild(LayoutRootPartName) as Grid;

            this.selectRegion = this.GetTemplateChild(SelectRegionPartName) as Path;
            this.selectRegion.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY;
            selectedRegion = new SelectedRegion { MinSelectRegionSize = 2 * CornerSize };
            this.DataContext = selectedRegion;

            this.topLeftCorner = this.GetTemplateChild(TopLeftCornerPartName) as ContentControl;
            this.topRightCorner = this.GetTemplateChild(TopRightCornerPartName) as ContentControl;
            this.bottomLeftCorner = this.GetTemplateChild(BottomLeftCornerPartName) as ContentControl;
            this.bottomRightCorner = this.GetTemplateChild(BottomRightCornerPartName) as ContentControl;

            this.imageCanvas = this.GetTemplateChild(ImageCanvasPartName) as Canvas;
            this.sourceImage = this.GetTemplateChild(SourceImagePartName) as Image;

            // Handle the pointer events of the corners.
            AddCornerEvents(this.topLeftCorner);
            AddCornerEvents(this.topRightCorner);
            AddCornerEvents(this.bottomLeftCorner);
            AddCornerEvents(this.bottomRightCorner);

            // Handle the manipulation events of the selectRegion
            this.selectRegion.ManipulationDelta += SelectRegion_ManipulationDelta;
            this.selectRegion.ManipulationCompleted += SelectRegion_ManipulationCompleted;

            this.sourceImage.SizeChanged += SourceImage_SizeChanged;
        }
Exemple #58
0
        private void DrawFibonacciSpiral(Point StartPoint, double w, double h)
        {
            // DebugUtil.Log("draw fibonaci: " + w + " " + h);

            PathFigure figure = new PathFigure();

            figure.StartPoint = StartPoint;

            var FullWidth  = w;
            var FullHeight = h;

            var HorizontallyReversed = false;
            var VerticallyReversed   = false;

            if (StartPoint.X == w)
            {
                HorizontallyReversed = true;
            }
            else if (StartPoint.X != 0)
            {
                DebugUtil.Log("Error: start point must be at corner");
                return;
            }

            if (StartPoint.Y == h)
            {
                VerticallyReversed = true;
            }
            else if (StartPoint.Y != 0)
            {
                DebugUtil.Log("Error: start point must be at corner");
                return;
            }

            // first control point
            var x1 = 0.0;
            var y1 = 0.0;

            // second contorl point
            var x2 = 0.0;
            var y2 = h;

            // end of line
            var x3 = w * (1 - GoldenRatio);
            var y3 = h;

            for (int i = 0; i < 10; i++)
            {
                // DebugUtil.Log("Bezier: " + x1 + " " + y1 + " / " + x2 + " " + y2 + " / " + x3 + " " + y3);
                var seg    = new BezierSegment();
                var tempX1 = x1;
                var tempY1 = y1;
                var tempX2 = x2;
                var tempY2 = y2;
                var tempX3 = x3;
                var tempY3 = y3;

                if (HorizontallyReversed)
                {
                    tempX1 = FullWidth - tempX1;
                    tempX2 = FullWidth - tempX2;
                    tempX3 = FullWidth - tempX3;
                }

                if (VerticallyReversed)
                {
                    tempY1 = FullHeight - tempY1;
                    tempY2 = FullHeight - tempY2;
                    tempY3 = FullHeight - tempY3;
                }

                seg.Point1 = new Point(tempX1, tempY1);
                seg.Point2 = new Point(tempX2, tempY2);
                seg.Point3 = new Point(tempX3, tempY3);

                figure.Segments.Add(seg);

                x1 = x3;
                y1 = y3;

                switch (i % 4)
                {
                case 0:     // lower right
                    w  = w * GoldenRatio;
                    x2 = x1 + w;
                    y2 = y1;
                    x3 = x1 + w;
                    y3 = y1 - h * (1 - GoldenRatio);
                    break;

                case 1:
                    h  = h * GoldenRatio;
                    x2 = x1;
                    y2 = y1 - h;
                    x3 = x1 - w * (1 - GoldenRatio);
                    y3 = y1 - h;
                    break;

                case 2:
                    w  = w * GoldenRatio;
                    x2 = x1 - w;
                    y2 = y1;
                    x3 = x1 - w;
                    y3 = y1 + h * (1 - GoldenRatio);
                    break;

                case 3:
                    h  = h * GoldenRatio;
                    x2 = x1;
                    y2 = y1 + h;
                    x3 = x1 + w * (1 - GoldenRatio);
                    y3 = y1 + h;
                    break;
                }
            }

            PathFigureCollection pthFigureCollection = new PathFigureCollection();

            pthFigureCollection.Add(figure);

            PathGeometry pthGeometry = new PathGeometry();

            pthGeometry.Figures = pthFigureCollection;

            Windows.UI.Xaml.Shapes.Path Fibonacci = new Windows.UI.Xaml.Shapes.Path();
            Fibonacci.Stroke          = Stroke = this.Stroke;
            Fibonacci.StrokeThickness = this.StrokeThickness;
            Fibonacci.Data            = pthGeometry;
            Lines.Children.Add(Fibonacci);
        }
        void dispatcherTimer_Tick(object sender, object e)
        {
            DateTimeOffset time = DateTimeOffset.Now;
            TimeSpan       span = time - lastTime;

            lastTime = time;
            //Time since last tick should be very very close to Interval
            //TimerLog.Text += timesTicked + "\t time since last tick: " + span.ToString() + "\n";  for debugging
            timesTicked++;

            if (a > 255)
            {
                a = 0;
            }
            else
            {
                a += 51;
            }

            if (r > 255)
            {
                r = 0;
            }
            else
            {
                r += 5;
            }

            if (g < 0)
            {
                g = 255;
            }
            else
            {
                g--;
            }

            if (b > 255)
            {
                b = 0;
            }
            else
            {
                b++;
            }

            /*
             * if (timesTicked > timesToTick)
             * {
             *  stopTime = time;
             *  //TimerLog.Text += "Calling dispatcherTimer.Stop()\n"; for debugging end dispatch timer
             *  dispatcherTimer.Stop();
             *  //IsEnabled should now be false after calling stop
             *  // TimerLog.Text += "dispatcherTimer.IsEnabled = " + dispatcherTimer.IsEnabled + "\n";  for debugging
             *  span = stopTime - startTime;
             *  //TimerLog.Text += "Total Time Start-Stop: " + span.ToString() + "\n";  for debugging
             * }
             */
            var path1 = new Windows.UI.Xaml.Shapes.Path();


            /*
             * public static Windows.UI.Color.FromArgb(byte a, byte r, byte g, byte b);
             * The above line of code allows us to adjust specific values of: Brightness, Red, Green and Blue
             */

            path1.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(a, r, g, b));

            var geometryGroup1 = new GeometryGroup();

            var ellipseGeometry1 = new EllipseGeometry();

            ellipseGeometry1.Center  = new Point(positionX, positionY);
            ellipseGeometry1.RadiusX = radius;
            ellipseGeometry1.RadiusY = radius;
            geometryGroup1.Children.Add(ellipseGeometry1);

            var pathGeometry1 = new PathGeometry();


            geometryGroup1.Children.Add(pathGeometry1);
            path1.Data = geometryGroup1;

            layoutRoot.Children.Clear();
            layoutRoot.Children.Add(path1);

            positionX += speedX;
            positionY += speedY;

            if (positionY + radius > layoutRoot.ActualHeight)
            {
                speedY *= -1;
            }

            if (positionX + radius > layoutRoot.ActualWidth)
            {
                speedX *= -1;
            }
            if (positionY - radius < 0)
            {
                speedY *= -1;
            }

            if (positionX - radius < 0)
            {
                speedX *= -1;
            }
        }