Inheritance: Shape, IPolyline
Beispiel #1
0
        public void OnPointerPressed(InqCanvas inqCanvas, PointerRoutedEventArgs e)
        {
            Debug.WriteLine(e.Pointer.PointerDeviceType);
            _currentStroke = new PointCollection();
            _polyline = new Polyline
            {
                Stroke = new SolidColorBrush(StrokeColor),
                StrokeThickness = 3,
                StrokeLineJoin = PenLineJoin.Round
            };
            inqCanvas.Children.Add(_polyline);

            _polyline.Points = _currentStroke;

            var point = e.GetCurrentPoint(inqCanvas);

            _strokeBuilder.BeginStroke(point);
            _currentStroke.Add(point.Position);

            //_inkManager.

            /*
            //TODO: add data binding for thickness and color
            _currentStroke.StrokeThickness = Math.Max(4.0 * e.GetCurrentPoint(inqCanvas).Properties.Pressure, 2);
            _currentInqLineView.StrokeThickness = _currentStroke.StrokeThickness;
            inqCanvas.Children.Add(_currentInqLineView);
            var currentPoint = e.GetCurrentPoint(inqCanvas);
            _currentStroke.AddPoint(new Point(currentPoint.Position.X, currentPoint.Position.Y));
            */
        }
        public void DrawTimeSeries(TimeSeries ts)
        {
            var stepX = (ActualWidth-60)/ts.Values.Count;
            var stepY = ActualHeight-40;
            var points = ts.ToPointCollection(stepX, stepY, 30, 20);
            var pl = new Polyline {StrokeThickness = 3, Stroke = new SolidColorBrush(Colors.Black), Points = points};

            QueryStroqs.Add(ts.ToStroq(stepX, stepY, 30, 20));
            xInqCanvas.Children.Add(pl);
        }
 protected void SetPolylinePointsProperty(Polyline polyline, PointCollection pointCollection)
 {
     // Changing .Points during an Arrange pass can create a layout cycle on Silverlight
     if (!polyline.Points.SequenceEqual(pointCollection))
     {
         polyline.Points = pointCollection;
         // In rare cases, Silverlight doesn't update the line visual to match the new points;
         // calling InvalidateArrange works around that problem.
         polyline.InvalidateArrange();
     }
 }
        private void MainCanvas_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            _line = new Polyline()
            {
                StrokeThickness = 1,
                Stroke = new SolidColorBrush(Colors.Red),
            };

            var position = e.GetCurrentPoint(MainCanvas).Position;
            _line.Points.Add(position);

            MainCanvas.Children.Add(_line);
        }
        private void UnprocessedInput_PointerPressed(InkUnprocessedInput sender, Windows.UI.Core.PointerEventArgs args)
        {
            lasso = new Polyline()
            {
                Stroke = new SolidColorBrush(Windows.UI.Colors.Blue),
                StrokeThickness = 1,
                StrokeDashArray = new DoubleCollection() {5, 2},
            };

            lasso.Points.Add(args.CurrentPoint.RawPosition);

            selectionCanvas.Children.Add(lasso);
        }
 private void MainCanvas_PointerReleased(object sender, PointerRoutedEventArgs e)
 {
     _undo.Push(_line);
     _redo.Clear();
     _line = null;
 }
Beispiel #7
0
 public void AddStroke(Polyline pl, Stroq stroq)
 {
     _strokes.Add(stroq, pl);
     StrokeAdded?.Invoke(this, stroq);
 }
Beispiel #8
0
        /// <summary>
        /// Invoked when an item is clicked.
        /// </summary>
        /// <param name="sender">The GridView (or ListView when the application is snapped)
        /// displaying the item clicked.</param>
        /// <param name="e">Event data that describes the item clicked.</param>
        private void chartDB(XDocument xd)
        {
            bool oneRecord = false;
            string cur = xd.Root.Element("current").Value;
            double curD = Convert.ToDouble(cur);

            if (curD == 0)// there is no data in the file, return
                return;

            string elem = "d" + cur;
            double count = sl1.Value;
            string[] values = new string[30 * 11];

            for (int i = 0; i < count; i++)
            {
                XElement mod = xd.Root.Element("data").Element(elem);

                values[i * 11] = mod.Element("date").Value;
                if (String.Equals(values[i * 11], ""))//deals with blank records
                {
                    if (i == 1)
                    {
                        oneRecord = true;
                        break;
                    }
                    else
                    {
                        count = i;
                        break;
                    }
                }

                values[i * 11 + 1] = mod.Element("ozone").Value;
                values[i * 11 + 2] = mod.Element("ozoneAQI").Value;
                values[i * 11 + 3] = mod.Element("pm10").Value;
                values[i * 11 + 4] = mod.Element("pm10AQI").Value;
                values[i * 11 + 5] = mod.Element("pm25").Value;
                values[i * 11 + 6] = mod.Element("pm25AQI").Value;
                values[i * 11 + 7] = mod.Element("no2").Value;
                values[i * 11 + 8] = mod.Element("noAQI").Value;
                values[i * 11 + 9] = mod.Element("so2").Value;
                values[i * 11 + 10] = mod.Element("so2AQI").Value;

                if (curD == 1)
                {
                    curD = 30;
                    elem = "d" + Convert.ToString(curD);
                }
                else
                {
                    curD--;
                    elem = "d" + Convert.ToString(curD);

                }
            }

            Dictionary<string, double> dailyVal =
        new Dictionary<string, double>();

            double v;
            if (Double.TryParse(values[2], out v))
                dailyVal.Add("Ozone", v);
            else
                dailyVal.Add("Ozone", -9999);
            if (Double.TryParse(values[4], out v))
                dailyVal.Add("PM10", v);
            else
                dailyVal.Add("PM10", -9999);
            if (Double.TryParse(values[6], out v))
                dailyVal.Add("PM25", v);
            else
                dailyVal.Add("PM25", -9999);
            if (Double.TryParse(values[8], out v))
                dailyVal.Add("NO2", v);
            else
                dailyVal.Add("NO2", -9999);
            if (Double.TryParse(values[10], out v))
                dailyVal.Add("SO2", v);
            else
                dailyVal.Add("SO2", -9999);

            var sortList = from x in dailyVal
                           orderby x.Value descending
                           select x;

            //sets color
            if (sortList.ElementAt(0).Value <= 50 && sortList.ElementAt(0).Value >= 0)
            {
                s1.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }
            else if (sortList.ElementAt(0).Value > 50 && sortList.ElementAt(0).Value <= 100)
            {
                s1.Fill = new SolidColorBrush(Colors.Yellow);
            }
            else if (sortList.ElementAt(0).Value > 100 && sortList.ElementAt(0).Value <= 150)
            {
                s1.Fill = new SolidColorBrush(Colors.Orange);
            }
            else if (sortList.ElementAt(0).Value > 150 && sortList.ElementAt(0).Value <= 200)
            {
                s1.Fill = new SolidColorBrush(Colors.Red);
            }
            else if (sortList.ElementAt(0).Value > 200 && sortList.ElementAt(0).Value <= 300)
            {
                s1.Fill = new SolidColorBrush(Colors.Purple);
            }
            else if (sortList.ElementAt(0).Value > 300 && sortList.ElementAt(0).Value <= 500)
            {
                s1.Fill = new SolidColorBrush(Colors.Maroon);
            }
            else
            {
                s1.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }

            if (sortList.ElementAt(1).Value <= 50 && sortList.ElementAt(1).Value >= 0)
            {
                s2.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }
            else if (sortList.ElementAt(1).Value > 50 && sortList.ElementAt(1).Value <= 100)
            {
                s2.Fill = new SolidColorBrush(Colors.Yellow);
            }
            else if (sortList.ElementAt(1).Value > 100 && sortList.ElementAt(1).Value <= 150)
            {
                s2.Fill = new SolidColorBrush(Colors.Orange);
            }
            else if (sortList.ElementAt(1).Value > 150 && sortList.ElementAt(1).Value <= 200)
            {
                s2.Fill = new SolidColorBrush(Colors.Red);
            }
            else if (sortList.ElementAt(1).Value > 200 && sortList.ElementAt(1).Value <= 300)
            {
                s2.Fill = new SolidColorBrush(Colors.Purple);
            }
            else if (sortList.ElementAt(1).Value > 300 && sortList.ElementAt(1).Value <= 500)
            {
                s2.Fill = new SolidColorBrush(Colors.Maroon);
            }
            else
            {
                s2.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }

            if (sortList.ElementAt(2).Value <= 50 && sortList.ElementAt(2).Value >= 0)
            {
                s3.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }
            else if (sortList.ElementAt(2).Value > 50 && sortList.ElementAt(2).Value <= 100)
            {
                s3.Fill = new SolidColorBrush(Colors.Yellow);
            }
            else if (sortList.ElementAt(2).Value > 100 && sortList.ElementAt(2).Value <= 150)
            {
                s3.Fill = new SolidColorBrush(Colors.Orange);
            }
            else if (sortList.ElementAt(2).Value > 150 && sortList.ElementAt(2).Value <= 200)
            {
                s3.Fill = new SolidColorBrush(Colors.Red);
            }
            else if (sortList.ElementAt(2).Value > 200 && sortList.ElementAt(2).Value <= 300)
            {
                s3.Fill = new SolidColorBrush(Colors.Purple);
            }
            else if (sortList.ElementAt(2).Value > 300 && sortList.ElementAt(2).Value <= 500)
            {
                s3.Fill = new SolidColorBrush(Colors.Maroon);
            }
            else
            {
                s3.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }

            if (sortList.ElementAt(3).Value <= 50 && sortList.ElementAt(3).Value >= 0)
            {
                s4.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }
            else if (sortList.ElementAt(3).Value > 50 && sortList.ElementAt(3).Value <= 100)
            {
                s4.Fill = new SolidColorBrush(Colors.Yellow);
            }
            else if (sortList.ElementAt(3).Value > 100 && sortList.ElementAt(3).Value <= 150)
            {
                s4.Fill = new SolidColorBrush(Colors.Orange);
            }
            else if (sortList.ElementAt(3).Value > 150 && sortList.ElementAt(3).Value <= 200)
            {
                s4.Fill = new SolidColorBrush(Colors.Red);
            }
            else if (sortList.ElementAt(3).Value > 200 && sortList.ElementAt(3).Value <= 300)
            {
                s4.Fill = new SolidColorBrush(Colors.Purple);
            }
            else if (sortList.ElementAt(3).Value > 300 && sortList.ElementAt(3).Value <= 500)
            {
                s4.Fill = new SolidColorBrush(Colors.Maroon);
            }
            else
            {
                s4.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }

            if (sortList.ElementAt(4).Value <= 50 && sortList.ElementAt(4).Value >= 0)
            {
                s5.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }
            else if (sortList.ElementAt(4).Value > 50 && sortList.ElementAt(4).Value <= 100)
            {
                s5.Fill = new SolidColorBrush(Colors.Yellow);
            }
            else if (sortList.ElementAt(4).Value > 100 && sortList.ElementAt(4).Value <= 150)
            {
                s5.Fill = new SolidColorBrush(Colors.Orange);
            }
            else if (sortList.ElementAt(4).Value > 150 && sortList.ElementAt(4).Value <= 200)
            {
                s5.Fill = new SolidColorBrush(Colors.Red);
            }
            else if (sortList.ElementAt(4).Value > 200 && sortList.ElementAt(4).Value <= 300)
            {
                s5.Fill = new SolidColorBrush(Colors.Purple);
            }
            else if (sortList.ElementAt(4).Value > 300 && sortList.ElementAt(4).Value <= 500)
            {
                s5.Fill = new SolidColorBrush(Colors.Maroon);
            }
            else
            {
                s5.Fill = new SolidColorBrush(Color.FromArgb(255, 102, 232, 74));
            }

            p1.Text = sortList.ElementAt(0).Key;
            if (sortList.ElementAt(0).Value != -9999)
                n1.Text = Convert.ToString(sortList.ElementAt(0).Value);
            else
                n1.Text = "N/A";

            p2.Text = sortList.ElementAt(1).Key;
            if (sortList.ElementAt(1).Value != -9999)
                n2.Text = Convert.ToString(sortList.ElementAt(1).Value);
            else
                n2.Text = "N/A";

            p3.Text = sortList.ElementAt(2).Key;
            if (sortList.ElementAt(2).Value != -9999)
                n3.Text = Convert.ToString(sortList.ElementAt(2).Value);
            else
                n3.Text = "N/A";

            p4.Text = sortList.ElementAt(3).Key;
            if (sortList.ElementAt(3).Value != -9999)
                n4.Text = Convert.ToString(sortList.ElementAt(3).Value);
            else
                n4.Text = "N/A";

            p5.Text = sortList.ElementAt(4).Key;
            if (sortList.ElementAt(4).Value != -9999)
                n5.Text = Convert.ToString(sortList.ElementAt(4).Value);
            else
                n5.Text = "N/A";

            if (oneRecord)
                return;

            double temp = 0;
            double max = 0;
            double min = 10000000;// way bigger than anything in the array

            //proably a better way to do this, but couldnt get linq quite working
            for (int i = 0; i < (count * 11); i++)
            {
                if (Double.TryParse(values[i], out temp))
                {
                    if (temp > max && temp < 10000)//second check because of dates
                        max = temp;
                    if (temp < min)
                        min = temp;
                }
            }

            double llxcanv = 0.0;
            double llycanv = cv.Height - 1;
            double urxcanv = cv.Width - 1;
            double urycanv = 0.0;

            double xscale = (urxcanv - llxcanv) / (count - 1);
            double yscale = (urycanv - llycanv) / (max - min);
            double parse;

            //Ozone
            Polyline ploz = new Polyline();
            ploz.StrokeThickness = 6;
            ploz.Stroke = new SolidColorBrush(Colors.Blue);

            for (int i = 0; i < count; i++)
            {
                Point newp;
                newp.X = (i + 1 - 1) * xscale + llxcanv;
                if (!Double.TryParse(values[i * 11 + 2], out parse))
                    parse = 0;
                newp.Y = (parse - min) * yscale + llycanv;
                ploz.Points.Add(newp);

            }

            //PM10
            Polyline plpm10 = new Polyline();
            plpm10.StrokeDashArray = new DoubleCollection() { 4 };
            plpm10.StrokeThickness = 6;
            plpm10.Stroke = new SolidColorBrush(Colors.DarkOrange);

            for (int i = 0; i < count; i++)
            {
                Point newp;
                newp.X = (i + 1 - 1) * xscale + llxcanv;
                if (!Double.TryParse(values[i * 11 + 4], out parse))
                    parse = 0;
                newp.Y = (parse - min) * yscale + llycanv;
                plpm10.Points.Add(newp);

            }

            //PM25
            Polyline plpm25 = new Polyline();
            plpm25.StrokeDashArray = new DoubleCollection() { 3 };
            plpm25.StrokeThickness = 6;
            plpm25.Stroke = new SolidColorBrush(Colors.Gray);

            for (int i = 0; i < count; i++)
            {
                Point newp;
                newp.X = (i + 1 - 1) * xscale + llxcanv;
                if (!Double.TryParse(values[i * 11 + 6], out parse))
                    parse = 0;
                newp.Y = (parse - min) * yscale + llycanv;
                plpm25.Points.Add(newp);

            }

            //no2
            Polyline plno2 = new Polyline();
            plno2.StrokeDashArray = new DoubleCollection() { 1 };
            plno2.StrokeThickness = 6;
            plno2.Stroke = new SolidColorBrush(Colors.Green);

            for (int i = 0; i < count; i++)
            {
                Point newp;
                newp.X = (i + 1 - 1) * xscale + llxcanv;
                if (!Double.TryParse(values[i * 11 + 8], out parse))
                    parse = 0;
                newp.Y = (parse - min) * yscale + llycanv;
                plno2.Points.Add(newp);

            }

            //so2
            Polyline plso2 = new Polyline();
            plso2.StrokeDashArray = new DoubleCollection() { 2 }; ;
            plso2.StrokeThickness = 6;
            plso2.Stroke = new SolidColorBrush(Colors.SkyBlue);

            for (int i = 0; i < count; i++)
            {
                Point newp;
                newp.X = (i + 1 - 1) * xscale + llxcanv;
                if (!Double.TryParse(values[i * 11 + 10], out parse))
                    parse = 0;
                newp.Y = (parse - min) * yscale + llycanv;
                plso2.Points.Add(newp);

            }

            cv.Children.Clear();
            cv.Children.Add(ploz);
            cv.Children.Add(plpm10);
            cv.Children.Add(plpm25);
            cv.Children.Add(plno2);
            cv.Children.Add(plso2);
        }
Beispiel #9
0
 public void AddStroke(Polyline currentStroke, bool refresh = true, bool disableShapes = false)
 {
     currentStroke.Points.Clear();
 }
        private void ModifySymbol(object sender, RoutedEventArgs e)
        {
            foreach(SymbolUserControl s in sucs)
            {
                bool checker = (bool)s.EditRadioButton.IsChecked;
                if(checker)
                {
                    (App.Current as App).CurrentSymbol = s.YouMapsSymbol;

                    foreach (PointCollection p in s.YouMapsSymbol.SymbolPoints)
                    {
                        double thickness = 10;

                        polyLine = new Polyline { Stroke = new SolidColorBrush { Color = Colors.Black }, StrokeThickness = thickness };
                        polyLine.Points = p;
                        SymbolName.Text = s.YouMapsSymbol.Name;
                        DrawingCanvas.Children.Add(polyLine);
                        AddSymbol(sender,e);

                    }
                }
            }
        }
        void canvas_pointer_pressed(object sender, PointerRoutedEventArgs e)
        {

            if (tool != "eraser")
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Cross, 1);
            else
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);


            switch (tool)
            {

                case "line":
                    {
                        NewLine = new Line();
                        NewLine.X1 = e.GetCurrentPoint(canvas).Position.X;
                        NewLine.Y1 = e.GetCurrentPoint(canvas).Position.Y;
                        NewLine.X2 = NewLine.X1 + 1;
                        NewLine.Y2 = NewLine.Y1 + 1;
                        NewLine.StrokeThickness = StrokeThickness;
                        NewLine.Stroke = new SolidColorBrush(BorderColor);
                        canvas.Children.Add(NewLine);
                    }
                    break;

                case "pencil":
                    {

                        /* old code
                         StartPoint = e.GetCurrentPoint(canvas).Position;
                         Pencil = new Polyline();
                         Pencil.Stroke = new SolidColorBrush(BorderColor);
                         Pencil.StrokeThickness = StrokeThickness;
                         canvas.Children.Add(Pencil);
                         * */


                        var MyDrawingAttributes = new InkDrawingAttributes();
                        MyDrawingAttributes.Size = new Size(StrokeThickness, StrokeThickness);
                        MyDrawingAttributes.Color = BorderColor;
                        MyDrawingAttributes.FitToCurve = true;
                        MyInkManager.SetDefaultDrawingAttributes(MyDrawingAttributes);

                        PreviousContactPoint = e.GetCurrentPoint(canvas).Position;
                        //PointerDeviceType pointerDevType = e.Pointer.PointerDeviceType;  to identify the pointer device
                        if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed)
                        {
                            // Pass the pointer information to the InkManager.
                            MyInkManager.ProcessPointerDown(e.GetCurrentPoint(canvas));
                            PenID = e.GetCurrentPoint(canvas).PointerId;
                            e.Handled = true;
                        }
                    }
                    break;

                case "rect":
                    {
                        NewRectangle = new Rectangle();
                        X1 = e.GetCurrentPoint(canvas).Position.X;
                        Y1 = e.GetCurrentPoint(canvas).Position.Y;
                        X2 = X1;
                        Y2 = Y1;
                        NewRectangle.Width = Math.Abs(X2 - X1);
                        NewRectangle.Height = Math.Abs(Y2 - Y1);
                        NewRectangle.StrokeThickness = StrokeThickness;
                        NewRectangle.Stroke = new SolidColorBrush(BorderColor);
                        NewRectangle.Fill = new SolidColorBrush(FillColor);
                        canvas.Children.Add(NewRectangle);
                    }
                    break;

                case "ellipse":
                    {
                        NewEllipse = new Ellipse();
                        X1 = e.GetCurrentPoint(canvas).Position.X;
                        Y1 = e.GetCurrentPoint(canvas).Position.Y;
                        X2 = X1;
                        Y2 = Y1;
                        NewEllipse.Width = Math.Abs(X2 - X1);
                        NewEllipse.Height = Math.Abs(Y2 - Y1);
                        NewEllipse.StrokeThickness = StrokeThickness;
                        NewEllipse.Stroke = new SolidColorBrush(BorderColor);
                        NewEllipse.Fill = new SolidColorBrush(FillColor);
                        canvas.Children.Add(NewEllipse);
                    }
                    break;

                case "eraser":
                    {
                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);
                        StartPoint = e.GetCurrentPoint(canvas).Position;
                        Pencil = new Polyline();
                        Pencil.Stroke = new SolidColorBrush(Colors.White);
                        Pencil.StrokeThickness = 10;
                        canvas.Children.Add(Pencil);
                    }
                    break;

                default:
                    break;
            }
        }
Beispiel #12
0
        public void HandlePressed(Point _position, Pointer _pointer)
        {
            FlagFactory factory = control.factory;
            Point IllusionPoint = _position;
            if (!IsOnPainter(IllusionPoint))
                return;

            if (factory.CanPutStamp())
            {
                Image image = new Image();
                image.Source = factory.DragPic.Source;
                image.VerticalAlignment = VerticalAlignment.Top;
                image.HorizontalAlignment = HorizontalAlignment.Left;
                image.Stretch = Stretch.None;
                image.Margin = new Thickness(IllusionPoint.X - control.Painter.Margin.Left, IllusionPoint.Y - control.Painter.Margin.Top, 0, 0);
                control.Painter.Children.Add(image);
            }

            if (factory.CurrentPenColor.Equals(""))
                return;

            Point point = new Point();
            point.X = IllusionPoint.X - control.Painter.Margin.Left;
            point.Y = IllusionPoint.Y - control.Painter.Margin.Top;
            if (factory.IsWaterbrushOrEraser())
            {
                uint id = _pointer.PointerId;
                if (!factory.pointerDictionary.ContainsKey(id))
                {
                    Color color = factory.GetCurrentColor();

                    SolidColorBrush brush = new SolidColorBrush(color);
                    brush.Opacity = factory.CurrentOpacity;

                    Polyline polyline = new Polyline
                    {
                        Stroke = brush,
                        StrokeThickness = 20,
                    };
                    polyline.Points.Add(point);
                    control.Painter.Children.Add(polyline);
                    factory.pointerDictionary.Add(id, polyline);
                }
            }

            else if (factory.IsOilpastel())
            {
                DrawOilPastel(point);
            }

            factory.Pressed = true;
        }
 protected override void OnPointerPressed(PointerRoutedEventArgs e)
 {
     base.OnPointerPressed(e);
     if (this.cVsCover.Visibility == Visibility.Visible)
         this.cVsCover.Visibility = Visibility.Collapsed;
     PointerPoint point = e.GetCurrentPoint(this);
     var line = new Crossline(Colors.White, point);
     line.Tag = point.PointerId;
     Color color = colors[random.Next(0, colors.Count - 1)];
     line.LineColor = color;
     CanvasLine.Children.Add(line.HorizontalPath);
     CanvasLine.Children.Add(line.VerticalPath);
     points.Add(line);
     if (points.Count > Config.supportMaxTouchs.Value)
     {
         Config.supportMaxTouchs.Value = points.Count;
     }
     if (Config.isNeedShowTrace.Value)
     {
         //var pointForTrace = new Point(point.Position.X, point.Position.Y - Config.TOUCH_Y_OFFSET);
         var pointForTrace = new Point(point.Position.X, point.Position.Y);
         var polyline = new Polyline();
         polyline.Stroke = new SolidColorBrush(color);
         polyline.StrokeThickness = Config.TraceThickness.Value;
         CanvasLine.Children.Add(polyline);
         PointerDictionary.AddValue(point.PointerId, polyline);
     }
     if (Config.isShowCoord.Value)
     {
         TextBlock textBlock = new TextBlock();
         textBlock.TextWrapping = TextWrapping.Wrap;
         textBlock.Width = StackPanelCoords.Width;
         textBlock.Height = 40;
         textBlock.Tag = point.PointerId;
         textBlock.Foreground = new SolidColorBrush(color);
         textBlocks.Add(textBlock);
         textBlock.Text = string.Format("Point{0}:  x:{1:N0} y:{2:N0}", textBlocks.IndexOf(textBlock)+1, point.Position.X*Config.scaleFactor,
             point.Position.Y*Config.scaleFactor);
         StackPanelCoords.Children.Add(textBlock);
        
     }
    
 }
        private async void drawStatistics()
        {
            statisticsViewCanvas.Height = ((Window.Current.Bounds.Width - 50) / 2 - 40) / 6 * 5;
            statisticsViewCanvas.Width = Window.Current.Bounds.Width - 90;

            double CanvasWidth = statisticsViewCanvas.Width;
            double CanvasHeight = statisticsViewCanvas.Height;

            IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder;
            //读
            string text = "";
            IStorageFile storageFileRE = await applicationFolder.GetFileAsync("num");
            IRandomAccessStream accessStream = await storageFileRE.OpenReadAsync();
            using (StreamReader streamReader = new StreamReader(accessStream.AsStreamForRead((int)accessStream.Size)))
            {
                text = streamReader.ReadToEnd();
            }
            Debug.WriteLine(text);

            int temp = 0;
            try
            {
                for (int i = 0; i < 7; i++)
                {
                    time[i] = Int32.Parse(text.Substring(temp, text.IndexOf("$", temp) - temp));
                    temp = text.IndexOf("$", temp) + 1;
                    Debug.WriteLine(time[i]);
                }
            }
            catch (Exception) { }

            temp = 0;
            double sum = 0;
            int num = 1;
            try
            {
                while (true)
                {
                    sum += Int32.Parse(text.Substring(temp, text.IndexOf("$", temp) - temp));
                    temp = text.IndexOf("$", temp) + 1;
                    num++;
                    Debug.WriteLine(sum + "   " + num);

                }
            }
            catch (Exception) { }

            sumTextBlock.Text = sum.ToString();
            aveTextBlock.Text = Math.Round((sum / num), 1).ToString();

            int max = IntArray_Max_Min.FindMax(time);
            int min = IntArray_Max_Min.FindMin(time);

            highTextBlock.Text = max.ToString();
            lowTextBlock.Text = min.ToString();


            if (max == -1) max = 0;
            if (min == -1) min = 0;

            MaxLTextBlock.Text = max.ToString();
            MinLTextBlock.Text = "0";

            //canvasLine.Y1 = 0;
            //canvasLine.Y2 = CanvasHeight + 5;

            Polyline ChartPolyLine = new Polyline();
            ChartPolyLine.Stroke = this.Foreground;
            ChartPolyLine.StrokeThickness = 1;

            PointCollection ChartPolyLinePointCollection = new PointCollection();
            Point p = new Point();
            for (int i = 6; i >= 0; i--)
            {
                if (time[i] == -1) time[i] = 0;
                p.X = CanvasWidth / 6 * (6 - i);
                p.Y = CanvasHeight - CanvasHeight * ((time[i] - 0) / (double)(max - 0));
                ChartPolyLinePointCollection.Add(p);
            }
            ChartPolyLine.Points = ChartPolyLinePointCollection;
            statisticsViewCanvas.Children.Clear();
            statisticsViewCanvas.Children.Add(ChartPolyLine);

        }
        public void AddStroke(Polyline currentStroke, Canvas InkCanvas)
        {
            var points = new PointCollection();
            foreach (var point in currentStroke.Points)
            {
                points.Add(point);
            }
            var polyline = new Polyline
            {
                Stroke = currentStroke.Stroke,
                StrokeThickness = currentStroke.StrokeThickness,
                Points = points,
                StrokeStartLineCap = PenLineCap.Round,
                StrokeEndLineCap = PenLineCap.Round,
                StrokeLineJoin = PenLineJoin.Round
            };

            InkCanvas.Children.Add(polyline);
            InkCanvas.Children.Remove(currentStroke);
            currentStroke.Points.Clear();
        }
        /// <summary>
        /// Clears existing content then calculates new UI elements of the <see cref="Graph"/>
        /// for the current <see cref="BarometerTestUIModel.Graph"/>.
        /// </summary>
        private void DrawGraph()
        {
            // Initialize
            Graph.Children.Clear();

            // Calculate range and average
            var count = Model.Graph.Count;
            if (count == 0)
            {
                // Nothing to draw
                return;
            }
            var pressureMin = (double?)null;
            var pressureMax = (double?)null;
            var temperatureMin = (double?)null;
            var temperatureMax = (double?)null;
            var pressureTotal = (double?)null;
            var temperatureTotal = (double?)null;
            foreach (var point in Model.Graph)
            {
                var pressure = point.Pressure;
                if (!pressureMax.HasValue || pressure > pressureMax) pressureMax = pressure;
                if (!pressureMin.HasValue || pressure < pressureMin) pressureMin = pressure;
                pressureTotal = (pressureTotal ?? 0) + pressure;

                var temperature = point.Temperature;
                if (!temperatureMax.HasValue || temperature > temperatureMax) temperatureMax = temperature;
                if (!temperatureMin.HasValue || temperature < temperatureMin) temperatureMin = temperature;
                temperatureTotal = (temperatureTotal ?? 0) + temperature;
            }
            var pressureRange = (pressureMax ?? 0) - (pressureMin ?? 0);
            var pressureAverage = pressureTotal / count;
            var temperatureRange = (temperatureMax ?? 0) - (temperatureMin ?? 0);
            var temperatureAverage = temperatureTotal / count;

            // Calculate metrics
            Graph.UpdateLayout();
            var height = Graph.ActualHeight;
            var drawHeight = height - (GraphPadding * 2);
            var width = Graph.ActualWidth;
            var drawWidth = width - (GraphPadding * 2);
            var graphYMax = GraphPadding + drawHeight;
            Func<double, double, double, double> calculateGraphY = (double value, double minimum, double range) =>
            {
                if (range > 0)
                {
                    // Relative within range
                    return graphYMax - (drawHeight * ((value - minimum) / range));
                }
                else
                {
                    // Middle when flat line
                    return graphYMax - (drawHeight / 2);
                }
            };

            // Get resources
            var pressureBrush = (SolidColorBrush)Resources["GraphPressureBrush"];
            var temperatureBrush = (SolidColorBrush)Resources["GraphTemperatureBrush"];

            // Draw pressure average lines
            var pressureAverageY = calculateGraphY(pressureAverage.Value, pressureMin.Value, pressureRange);
            Graph.Children.Add(new Line
            {
                Stroke = pressureBrush,
                StrokeThickness = 1,
                X1 = GraphPadding,
                Y1 = pressureAverageY,
                X2 = GraphPadding + drawWidth,
                Y2 = pressureAverageY
            });

            // Draw temperature average line
            var temperatureAverageY = calculateGraphY(temperatureAverage.Value, temperatureMin.Value, temperatureRange);
            Graph.Children.Add(new Line
            {
                Stroke = temperatureBrush,
                StrokeThickness = 1,
                X1 = GraphPadding,
                Y1 = temperatureAverageY,
                X2 = GraphPadding + drawWidth,
                Y2 = temperatureAverageY
            });

            // Plot graph points
            var graphX = GraphPadding;
            var pressureLine = new Polyline
            {
                Stroke = pressureBrush,
                StrokeThickness = 1
            };
            var temperatureLine = new Polyline
            {
                Stroke = temperatureBrush,
                StrokeThickness = 1
            };
            for (var index = Model.Graph.Count - 1; index >= 0; index--)
            {
                // Iterate backwards so we start with latest measurement
                var point = Model.Graph[index];

                // Calculate relative pressure point
                var pressureY = calculateGraphY(point.Pressure, pressureMin.Value, pressureRange);
                var pressurePoint = new Point(graphX, pressureY);
                pressureLine.Points.Add(pressurePoint);

                // Calculate relative temperature point
                var temperatureY = calculateGraphY(point.Temperature, temperatureMin.Value, temperatureRange);
                var temperaturePoint = new Point(graphX, temperatureY);
                temperatureLine.Points.Add(temperaturePoint);

                // Move X for next point...
                graphX += GraphZoom;
                if (graphX > width)
                {
                    // Stop when outside view
                    break;
                }
            }
            Graph.Children.Add(pressureLine);
            Graph.Children.Add(temperatureLine);

            // Draw average text
            var pressureAverageString = string.Format(CultureInfo.CurrentCulture,
                "Pressure: {0}mbar", pressureAverage.Value);
            var pressureAverageText = new TextBlock
            {
                Foreground = pressureBrush,
                Text = pressureAverageString
            };
            Graph.Children.Add(pressureAverageText);
            var temperatureAverageString = string.Format(CultureInfo.CurrentCulture,
                "Temperature: {0}°c", temperatureAverage.Value);
            var temperatureAverageText = new TextBlock
            {
                Foreground = temperatureBrush,
                Text = temperatureAverageString
            };
            Graph.Children.Add(temperatureAverageText);

            // Position average text so that it does not overlap
            pressureAverageText.UpdateLayout();
            temperatureAverageText.UpdateLayout();
            Canvas.SetTop(pressureAverageText, pressureAverageY
                - pressureAverageText.ActualHeight);
            Canvas.SetLeft(pressureAverageText, width
                - pressureAverageText.ActualWidth - GraphPadding
                - temperatureAverageText.ActualWidth - GraphPadding);
            Canvas.SetTop(temperatureAverageText, temperatureAverageY
                - temperatureAverageText.ActualHeight);
            Canvas.SetLeft(temperatureAverageText, width
                - temperatureAverageText.ActualWidth - GraphPadding);
        }
        private void DrawGraph(TimeSeries ts)
        {
            float w = ((float) xCanvas.Width - 10)/ts.Values.Count;
            float h = (float) xCanvas.Height - 10;

            var pc = ts.ToPointCollection(w, h, 5, 5);
            _pl = new Polyline {StrokeThickness = 3, Stroke = new SolidColorBrush(Colors.White), Points = pc};
            xCanvas.Children.Add(_pl);

            /*
            var pls = new PolyLineSegment {Points = pc};
            var pf = new PathFigure();

            pf.Segments.Add(pls);
            pf.StartPoint = pc.First();
            var pg = new PathGeometry();
            pg.Figures.Add(pf);
            _geometryGroup.Children.Add(pg);
            */
        }
        public void DrawXyAxis()
        {
            XyRect = new Rect( 30, 20, ActualWidth-60, ActualHeight-40);

            var pl = new Polyline { StrokeThickness = 3, Stroke = new SolidColorBrush(Colors.Black) };
            var tl = new Point(XyRect.Left, XyRect.Top);
            var bl = new Point(XyRect.Left, XyRect.Bottom);
            var br = new Point(XyRect.Right, XyRect.Bottom);
            pl.Points.Add(tl);
            pl.Points.Add(bl);
            pl.Points.Add(br);
            xInqCanvas.Children.Add(pl);
            _axisDrawn = true;
        }
        protected override void OnPointerPressed(PointerRoutedEventArgs e)
        {
            Debug.WriteLine(e.OriginalSource.GetType().Name);
            Debug.WriteLine("The Poine Id is :" + e.Pointer.PointerId);
            if (e.OriginalSource is Grid)
            {
                Debug.WriteLine((e.OriginalSource as Grid).Name);
            }
            base.OnPointerPressed(e);
            if (this.gridCover.Visibility == Visibility.Visible)
            {
                if (gridSetting.Visibility == Visibility.Visible)
                {

                  //  if (e.OriginalSource is Grid){
                        //  Debug.WriteLine((e.OriginalSource as Grid).Name);
                        if ((e.OriginalSource as FrameworkElement).Name == "layoutRoot")
                        {
                            Config.TraceThickness.Value = (float)this.SliderTraceThickness.Value;
                            Config.isNeedShowTrace.Value = this.SwitchShowTrace.IsOn;
                            Config.isReserveTrace.Value = this.SwitchKeepTrace.IsOn;
                            Config.isShowCoord.Value = this.SwitchShowCoord.IsOn;
                            this.gridSetting.Visibility = Visibility.Collapsed;
                            this.gridCover.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            return;
                        }

                  //  }

                }
                else
                {
                    this.gridCover.Visibility = Visibility.Collapsed;
                }

            }
            PointerPoint point = e.GetCurrentPoint(this);
            var line = new Crossline(Colors.White, point);
            line.Tag = point.PointerId;
            Color color = colors[random.Next(0, colors.Count - 1)];
            line.LineColor = color;
            CanvasLine.Children.Add(line.HorizontalPath);
            CanvasLine.Children.Add(line.VerticalPath);
            points.Add(line);
            if (points.Count > Config.supportMaxTouchs.Value)
            {
                Config.supportMaxTouchs.Value = points.Count;
            }
            if (Config.isNeedShowTrace.Value)
            {
                //var pointForTrace = new Point(point.Position.X, point.Position.Y - Config.TOUCH_Y_OFFSET);
                var pointForTrace = new Point(point.Position.X, point.Position.Y);
                var polyline = new Polyline();
                polyline.Stroke = new SolidColorBrush(color);
                polyline.StrokeThickness = Config.TraceThickness.Value;
                CanvasLine.Children.Add(polyline);
                LineDictionary.AddValue(point.PointerId, polyline);
            }
            if (Config.isShowCoord.Value)
            {
                TextBlock textBlock = new TextBlock();
                textBlock.TextWrapping = TextWrapping.Wrap;
                textBlock.Width = StackPanelCoords.Width;
                textBlock.Height = 60;
                textBlock.Tag = point.PointerId;
                textBlock.Foreground = new SolidColorBrush(color);
                textBlocks.Add(textBlock);
                textBlock.Text = string.Format("Point{0}:  x:{1:N0} y:{2:N0}", textBlocks.IndexOf(textBlock) + 1, point.Position.X * Config.scaleFactor,
                    point.Position.Y * Config.scaleFactor);
                StackPanelCoords.Children.Add(textBlock);
            }
            ResetMenu();
        }
Beispiel #20
0
 /// <summary>
 /// Add stroke to ink
 /// </summary>
 /// <param name="inkData">Pointer to ink data</param>
 /// <param name="currentStroke">Stroke as a polyline</param>
 /// <returns></returns>
 public static bool AddStroke(IntPtr inkData, Polyline currentStroke)
 {
     if (currentStroke.Points.Count == 0)
         return false;
     var pointArray = new CGStroke[currentStroke.Points.Count];
     for (var i = 0; i < currentStroke.Points.Count; i++)
     {
         pointArray[i].pressure = 127;
         pointArray[i].pt.x = (float)currentStroke.Points[i].X;
         pointArray[i].pt.y = (float)currentStroke.Points[i].Y;
     }
     INK_AddStroke(inkData, pointArray, pointArray.Length, (int)currentStroke.StrokeThickness - 1,
         ColorToCOLORREF(((SolidColorBrush)currentStroke.Stroke).Color));
     return false;
 }
        void  canvas_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if(DrawingTool != "Eraser")
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Cross, 1);
            else
                Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);

            switch (DrawingTool)
            {
                    //all events are working on canvas.. we will be collecting points to draw on writablebitmap also.
                case "Line":
                    {
                        NewLine = new Line();
                        NewLine.X1 = e.GetCurrentPoint(canvas).Position.X;
                        NewLine.Y1 = e.GetCurrentPoint(canvas).Position.Y;
                        lineX1 = e.GetCurrentPoint(canvas).Position.X;
                        lineY1 = e.GetCurrentPoint(canvas).Position.Y;
                        NewLine.X2 = NewLine.X1 + 1;
                        NewLine.Y2 = NewLine.Y1 + 1;
                        NewLine.StrokeThickness = StrokeThickness;
                        NewLine.Stroke = new SolidColorBrush(BorderColor);
                        canvas.Children.Add(NewLine);
                       
                    }
                    break;

                case "Pencil":
                    {
                        /* Old Code
                        StartPoint = e.GetCurrentPoint(canvas).Position;
                        Pencil = new Polyline();
                        Pencil.Stroke = new SolidColorBrush(BorderColor);
                        Pencil.StrokeThickness = StrokeThickness;
                        canvas.Children.Add(Pencil);
                        */

                        var MyDrawingAttributes = new InkDrawingAttributes();
                        MyDrawingAttributes.Size = new Size(StrokeThickness, StrokeThickness);
                        MyDrawingAttributes.Color = BorderColor;
                        MyDrawingAttributes.FitToCurve = true;
                        MyInkManager.SetDefaultDrawingAttributes(MyDrawingAttributes);

                        PreviousContactPoint = e.GetCurrentPoint(canvas).Position;
                        //PointerDeviceType pointerDevType = e.Pointer.PointerDeviceType;  to identify the pointer device
                        if (e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed)
                        {
                            // Pass the pointer information to the InkManager.
                            MyInkManager.ProcessPointerDown(e.GetCurrentPoint(canvas));
                            PenID = e.GetCurrentPoint(canvas).PointerId;
                            e.Handled = true;
                        }
                    }
                    break;                

                case "Rectagle":
                    {
                        NewRectangle = new Rectangle();
                        X1 = e.GetCurrentPoint(canvas).Position.X;
                        Y1 = e.GetCurrentPoint(canvas).Position.Y;
                        X2 = X1;
                        Y2 = Y1;
                        NewRectangle.Width = X2 - X1;
                        NewRectangle.Height = Y2 - Y1;
                        rectX1 = X1;
                        rectY1 = Y1;
                        NewRectangle.StrokeThickness = StrokeThickness;
                        NewRectangle.Stroke = new SolidColorBrush(BorderColor);
                       // NewRectangle.Fill = new SolidColorBrush(FillColor);
                        canvas.Children.Add(NewRectangle);
                    }
                    break;

                case "Ellipse":
                    {
                        NewEllipse = new Ellipse();
                        X1 = e.GetCurrentPoint(canvas).Position.X;
                        Y1 = e.GetCurrentPoint(canvas).Position.Y;
                        X2 = X1;
                        Y2 = Y1;
                        elipX1 = X1;
                        elipY1 = Y1;
                        NewEllipse.Width = X2 - X1;
                        NewEllipse.Height = Y2 - Y1;
                        NewEllipse.StrokeThickness = StrokeThickness;
                        NewEllipse.Stroke = new SolidColorBrush(BorderColor);
                        //NewEllipse.Fill = new SolidColorBrush(FillColor);
                        canvas.Children.Add(NewEllipse);
                    }
                    break;

                case "Eraser":
                    {
                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.UniversalNo, 1);
                        StartPoint = e.GetCurrentPoint(canvas).Position;
                        Pencil = new Polyline();
                        Pencil.Stroke = new SolidColorBrush(Colors.Wheat);
                        Pencil.StrokeThickness = 10;
                        canvas.Children.Add(Pencil);
                    }
                    break;

                default:
                    break;
            }
        }
        /// <summary>
        /// The draw line.
        /// </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 DrawLine(
            IList<ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            OxyPenLineJoin lineJoin,
            bool aliased)
        {
            var e = new Polyline();
            this.SetStroke(e, stroke, thickness, lineJoin, dashArray, aliased);

            var pc = new PointCollection();
            foreach (ScreenPoint p in points)
            {
                pc.Add(p.ToPoint(aliased));
            }

            e.Points = pc;

            this.Add(e);
        }
        void canvas_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == PenID || e.Pointer.PointerId == TouchID)
                MyInkManager.ProcessPointerUp(e.GetCurrentPoint(canvas));

            TouchID = 0;
            PenID = 0;
            e.Handled = true;
            Pencil = null;
            NewLine = null;
            NewRectangle = null;
            NewEllipse = null;
            

            //to draw line on our writable bitmap not on canvas.
            if (itisline)
            {
                wb.DrawLineDDA((int)lineX1, (int)lineY1, (int)lineX2, (int)lineY2, clr);
            }
            //to draw line on our actual rectangle.
            if (itisrectangle)
            {
                if(rectX2>rectX1 && rectY2>rectY1)
                wb.DrawRectangle((int)rectX1,(int) rectY1,(int) rectX2,(int) rectY2, clr);
                else if(rectX2<rectX1 && rectY2<rectY1)
                    wb.DrawRectangle((int)rectX2, (int)rectY2, (int)rectX1, (int)rectY1, clr);
                else if(rectX2>rectX1 && rectY2<rectY1)
                    wb.DrawRectangle((int)rectX1, (int)rectY2, (int)rectX2, (int)rectY1, clr);
                else if(rectX2<rectX1 && rectY2>rectY1)
                    wb.DrawRectangle((int)rectX2, (int)rectY1, (int)rectX1, (int)rectY2, clr);
            }
            // to draw a ellipse
            if (itisellipse)
            {
                if(elipX2>elipX1 && elipY2>elipY1)
                wb.DrawEllipse((int)elipX1,(int) elipY1, (int)elipX2,(int) elipY2, clr);
                else if(elipX2<elipX1 && elipY2<elipY1)
                    wb.DrawEllipse((int)elipX2, (int)elipY2, (int)elipX1, (int)elipY1, clr);
                else if (elipX2 > elipX1 && elipY2 < elipY1)
                    wb.DrawEllipse((int)elipX1, (int)elipY2, (int)elipX2, (int)elipY1, clr);
                else if (elipX2 < elipX1 && elipY2 > elipY1)
                    wb.DrawEllipse((int)elipX2, (int)elipY1, (int)elipX1, (int)elipY2, clr);
  
            }
        }
        void canvas_pointer_released(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerId == PenID || e.Pointer.PointerId == TouchID)
                MyInkManager.ProcessPointerUp(e.GetCurrentPoint(canvas));

            TouchID = 0;
            PenID = 0;
            e.Handled = true;
            Pencil = null;
            NewLine = null;
            NewRectangle = null;
            NewEllipse = null;
        }
 private void drawingPointerIsPressed(object sender, PointerRoutedEventArgs e)
 {
     double thickness = 10;
      
     polyLine = new Polyline { Stroke = new SolidColorBrush { Color = Colors.Black }, StrokeThickness = thickness };
     PointCollection pointCollection = new PointCollection();
     polyLine.Points = pointCollection;
     pointsForSaveing.Add(pointCollection);
     DrawingCanvas.Children.Add(polyLine);
     mousePressed = true;
    
 }