Пример #1
0
        /// <summary>
        /// Adds vertex to the graph and draws it on the canvas.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateVertex(object sender, MouseButtonEventArgs e)
        {
            Point  current = e.GetPosition((UIElement)sender);
            double x       = current.X;
            double y       = current.Y;

            DrawingVisual visual = new DrawingVisual();

            using (DrawingContext dc = visual.RenderOpen())
            {
                Vertex v = new Vertex(x, y, ++numberOfVertices);
                foreach (Vertex vertex in graph.vertices)
                {
                    if (v.GetDistance(vertex) <= 2 * Vertex.rad)
                    {
                        MessageBox.Show("Don't put vertices on top of each other", "",
                                        MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                }

                SolidColorBrush brush   = new SolidColorBrush(Colors.ForestGreen);
                SolidColorBrush contour = new SolidColorBrush(Colors.Black);
                Pen             pen     = new Pen(contour, 2);
                dc.DrawEllipse(brush, pen, current, 7, 7);

                graph.vertices.Add(v);
                if (numberOfVertices == 1)
                {
                    graph.starting = v;
                }
            }
            drawingCanvas.AddVisual(visual);
        }
Пример #2
0
 private void ResetVisualsBackground()
 {
     BackgroundIndLayer.ClearVisuals();
     foreach (var ind in BackgroundIndicators)
         BackgroundIndLayer.AddVisual(ind.IndicatorVisual);
     ResetPricesTimes();
 }
Пример #3
0
        public void AddElement(HookElement el)
        {
            el.SetChart(Chart);
            el.SetDeleteAction(DeleteElement);
            el.Moving += MoveIndicator;
            ForegroundIndicators.Add(el);
            ForegroundIndLayer.AddVisual(el.IndicatorVisual);
            
            if (el is Painting)
            {
                PricesCanvas.AddVisual(el.PriceVisual);
                TimesCanvas.AddVisual(el.TimeVisual);
            }

            ResetHooks();
            el.Rendering();
        }
Пример #4
0
        public TimeLineModule(View chart, DrawingCanvas GridLayer) : base(chart)
        {
            this.GridLayer = GridLayer;

            Chart.FontBrushChanged += () => Redraw();
            GridLayer.AddVisual(TimeGridVisual);
            Chart.TimesLayer.AddVisual(TimesVisual);
        }
Пример #5
0
 private void ShowCursor(object sender, MouseEventArgs e)
 {
     Chart.CursorLinesLayer.AddVisual(CursorLinesVisual);
     CursorLayer.AddVisual(CursorVisual);
     MagnetLayer.AddVisual(MagnetVisual);
     TimeLine.AddVisual(CursorTimeVisual);
     PriceLine.AddVisual(CursorPriceVisual);
 }
Пример #6
0
        public PriceLineModule(View chart,
                               DrawingCanvas GridLayer, DrawingCanvas PriceLine,
                               PriceMarksModule PriceMarksModule) : base(chart)
        {
            this.GridLayer        = GridLayer;
            this.PriceLine        = PriceLine;
            this.PriceMarksModule = PriceMarksModule;

            Chart.FontBrushChanged += () => Redraw();
            GridLayer.AddVisual(PriceGridVisual);
            PriceLine.AddVisual(PricesVisual);
        }
Пример #7
0
        /// <summary>
        /// 在画板上绘制折线
        /// </summary>
        public void DrawingLinesOnCanvas()
        {
            canvas.ClearVisual();

            for (int i = 0; i < BrokenLines.Count; ++i)
            {
                //每条线作为一个visual对象
                DrawingVisual visual = new DrawingVisual();
                DrawingLinesOnVisual(visual, BrokenLines[i], i);
                canvas.AddVisual(visual);
            }
        }
Пример #8
0
        public MarksLayer(DrawingCanvas MarksLayer, DrawingCanvas PriceLine, Action <MarksLayer> act)
        {
            ChartVisual = new DrawingVisual(); MarksLayer.AddVisual(ChartVisual);
            PriceVisual = new DrawingVisual(); PriceLine.AddVisual(PriceVisual);

            var lm = new ObservableCollection <PriceMark>();

            Marks = lm; Act = null;

            var x = this;

            Act = () => act(x);
            lm.CollectionChanged += (s, e) => act(x);
        }
Пример #9
0
        public PaintingModule(View chart, DrawingCanvas PrototypeCanvas, DrawingCanvas PrototPCanvas,
                              DrawingCanvas PrototTCanvas, Action <HookElement> AddElement) : base(chart)
        {
            this.PrototypeCanvas      = PrototypeCanvas;     PrototypeCanvas.AddVisual(PrototypeVisual);
            this.PrototypePriceCanvas = PrototPCanvas;  PrototPCanvas.AddVisual(PrototypePriceVisual);
            this.PrototypeTimeCanvas  = PrototTCanvas;   PrototTCanvas.AddVisual(PrototypeTimeVisual);

            this.AddElement = AddElement;

            Chart.ChartGrid.MouseEnter += (s, e) =>
            {
                PrototypeCanvas.Visibility      = Visibility.Visible;
                PrototypePriceCanvas.Visibility = Visibility.Visible;
                PrototypeTimeCanvas.Visibility  = Visibility.Visible;
            };
            Chart.ChartGrid.MouseLeave += (s, e) =>
            {
                PrototypeCanvas.Visibility      = Visibility.Hidden;
                PrototypePriceCanvas.Visibility = Visibility.Hidden;
                PrototypeTimeCanvas.Visibility  = Visibility.Hidden;
            };
            Chart.Shell.PrepareInstrument += PrepareInstrument;
            Chart.DrawPrototype            = () => DrawPrototype?.Invoke(Chart,
                                                                         PrototypeVisual, PrototypePriceVisual, PrototypeTimeVisual);
            this.SetMenuAct = chart.Shell.SetMenu;

            this.ResetInstrument = Chart.Shell.ResetInstrument;

            Chart.PaintingLevel = PaintingLevel;

            ////////////////////
            Task.Run(() =>
            {
                Dispatcher.Invoke(() =>
                {
                    AddElement(new Level(208.99, Brushes.White, Brushes.Black, Brushes.Yellow, 5, 5, 2));
                    AddElement(new Level(206.95, Brushes.Black, Brushes.Azure, Brushes.Azure, 4, 6, 3));
                    AddElement(new Level(204.90, Brushes.Lime, Brushes.Black, Brushes.Lime, 3, 7, 4));
                });
            });
        }
Пример #10
0
        /// <summary>
        /// 在画板上绘制折线
        /// </summary>
        private void DrawingLinesOnCanvas(DrawingCanvas drawingCanvas)
        {
            drawingCanvas.ClearVisual();

            List <BrokenLine> newLines = new List <BrokenLine>();

            foreach (var line in BrokenLines)
            {
                newLines.Add(line.DeepClone());
            }

            //获取拉伸过的曲线
            GetStretchLines(newLines);
            //遍历曲线
            for (int i = 0; i < newLines.Count; ++i)
            {
                //每条线作为一个visual对象
                DrawingVisual visual = new DrawingVisual();
                DrawingLinesOnVisual(visual, newLines[i], i);
                drawingCanvas.AddVisual(visual);
            }
        }
Пример #11
0
        public Indicator(View Chart, bool Twin = false) : base(Chart)
        {
            this.Twin = Twin;

            Grid.SetColumn(ScaleGrd, 2);

            pixelsPerDip = VisualTreeHelper.GetDpi(ScaleVisual).PixelsPerDip;
            IndicatorCanvasBase.AddVisual(IndicatorVisualBase);
            GridCanvas.AddVisual(GridVisual);
            ScaleCanvas.AddVisual(ScaleVisual);

            BaseGrd.MouseEnter += (s, e) => Chart.Interaction = ShoWMenu;
            BaseGrd.MouseLeave += (s, e) => { if (Chart.Interaction == ShoWMenu)
                                              {
                                                  Chart.Interaction = null;
                                              }
            };
            BaseGrd.MouseEnter  += CursorShow;
            BaseGrd.MouseLeave  += CursorLeave;
            BaseGrd.MouseMove   += CursorRedraw;
            BaseGrd.MouseEnter  += (s, e) => Chart.SetMoving(s, e);
            BaseGrd.MouseLeave  += (s, e) => Chart.BreakMoving(s, e);
            BaseGrd.SizeChanged += BaseGrd_SizeChanged;

            BaseGrd.Children.Add(Selector);
            BaseGrd.Children.Add(GridCanvas);
            BaseGrd.ClipToBounds = true;
            BaseGrd.Background   = CursorGrabber;
            BaseGrd.Cursor       = Cursors.None;
            {
                var L2grd = new Grid();
                {
                    var L3grd = new Grid
                    {
                        RenderTransformOrigin = new Point(1, 0.5),
                        RenderTransform       = ScX
                    };
                    {
                        var L4grd = new Grid {
                            RenderTransformOrigin = new Point(0.5, 0.5)
                        };
                        {
                            var tgr = new TransformGroup();
                            {
                                tgr.Children.Add(new RotateTransform(180));
                                tgr.Children.Add(Translate);
                                tgr.Children.Add(ScY);
                            }
                            L4grd.RenderTransform = tgr;
                            L4grd.Children.Add(IndicatorCanvasBase);
                        }
                        L3grd.Children.Add(L4grd);
                    }
                    L2grd.Children.Add(L3grd);
                }
                BaseGrd.Children.Add(L2grd);
            }
            if (Twin)
            {
                IndicatorCanvasSecond = new DrawingCanvas();
                IndicatorVisualSecond = new DrawingVisual();
                IndicatorCanvasSecond.AddVisual(IndicatorVisualSecond);
                BaseGrd.Children.Add(IndicatorCanvasSecond);
            }
            BaseGrd.Children.Add(CursorLayer);

            ScaleGrd.ClipToBounds = true;
            ScaleGrd.Background   = CursorGrabber;
            ScaleGrd.Children.Add(ScaleCanvas);
            ScaleGrd.Children.Add(ValueMarkLayer);

            CursorLinesTransform        = (TranslateTransform)Chart.CursorLinesLayer.RenderTransform;
            CursorLayer.RenderTransform = CursorTransform;

            Chart.CandlesChanged     += ac => Redraw();
            Chart.AllHorizontalReset += HorizontalReset;
            Chart.NewXScale          += sc => Task.Run(() => Dispatcher.Invoke(() => ScaleX = sc));
            Chart.NewXTrans          += tr => Task.Run(() => Dispatcher.Invoke(() => Translate.X = tr));
            if (Twin)
            {
                Chart.AllHorizontalReset += ac => SecondReset();
                Chart.NewXScale          += sc => SecondReset();
                Chart.NewXTrans          += sc => SecondReset();
            }
            Chart.NewFSF += fsf => RedrawScale();
        }
Пример #12
0
        private void AddTempLine(int index)
        {
            Dispatcher.Invoke(() =>
            {
                {
                    Grid grd = new Grid();
                    grd.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(35)
                    });
                    grd.ColumnDefinitions.Add(new ColumnDefinition());
                    grd.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(30)
                    });
                    {
                        Viewbox vb1 = new Viewbox {
                            Height = 20
                        };
                        Grid.SetColumn(vb1, 0);
                        {
                            Label l = new Label
                            {
                                ContentStringFormat = "0.00",
                                FontSize            = 12,
                                FontWeight          = FontWeights.Bold,
                                Foreground          = Brushes.Lime
                            };
                            l.SetBinding(Label.ContentProperty, $"Hashrates[{index}]");
                            vb1.Child = l;
                        }

                        Viewbox vb2 = new Viewbox {
                            Height = 16, Stretch = Stretch.Fill
                        };
                        Grid.SetColumn(vb2, 1);
                        {
                            DrawingCanvas DC = new DrawingCanvas
                            {
                                Width  = 100,
                                Height = 20
                            };

                            var DV = new DrawingVisual {
                                Effect = new BlurEffect {
                                    Radius = 5
                                }
                            };

                            DC.AddVisual(DV);
                            DVs.Add(DV);
                            vb2.Child = DC;
                        }

                        Viewbox vb3 = new Viewbox {
                            Height = 20
                        };
                        Grid.SetColumn(vb3, 2);
                        {
                            Label l = new Label
                            {
                                ContentStringFormat = "0℃",
                                FontSize            = 12,
                                FontWeight          = FontWeights.Bold,
                                Foreground          = Brushes.Yellow
                            };
                            l.SetBinding(Label.ContentProperty, $"Temperatures[{index}]");
                            vb3.Child = l;
                        }

                        grd.Children.Add(vb1);
                        grd.Children.Add(vb2);
                        grd.Children.Add(vb3);
                    }
                    DetaledTemperaturesControl.Items.Add(grd);
                }
            });
        }
Пример #13
0
        /// <summary>
        /// Draws graph with doubled and split edges.
        /// </summary>
        /// <param name="graph"></param>
        private void DrawGraph(Graph graph)
        {
            double x0  = modifiedGraph.ActualWidth / 2;
            double y0  = modifiedGraph.ActualHeight / 2;
            double rad = 100;
            int    n   = graph.splitVertices.Count;

            graph.drawn = true;

            double[] x_coords = new double[n];
            double[] y_coords = new double[n];
            for (int i = 0; i < n; i++)
            {
                double cos = Math.Cos((i + 1) * 2 * Math.PI / n);
                double sin = Math.Sin((i + 1) * 2 * Math.PI / n);
                x_coords[i] = x0 + rad * cos;
                y_coords[i] = y0 + rad * sin;
                Point         current = new Point(x_coords[i], y_coords[i]);
                DrawingVisual visual  = new DrawingVisual();
                using (DrawingContext dc = visual.RenderOpen())
                {
                    SolidColorBrush brush   = new SolidColorBrush(Colors.ForestGreen);
                    SolidColorBrush contour = new SolidColorBrush(Colors.Black);
                    Pen             pen     = new Pen(contour, 2);
                    dc.DrawEllipse(brush, pen, current, 7, 7);
                }
                modifiedCanvas.AddVisual(visual);
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (graph.AreNeighboursInSplit(i, j))
                    {
                        Point       p1    = new Point(x_coords[i], y_coords[i]);
                        Point       p2    = new Point(x_coords[j], y_coords[j]);
                        List <Edge> edges = graph.GetEdgesInSplit(graph.splitVertices[i], graph.splitVertices[j]);
                        if (edges.Count == 1)
                        {
                            DrawingVisual visual = new DrawingVisual();
                            using (DrawingContext dc = visual.RenderOpen())
                            {
                                SolidColorBrush contour = new SolidColorBrush(Colors.Black);
                                Pen             pen     = new Pen(contour, 2);

                                dc.DrawLine(pen, p1, p2);
                            }
                            modifiedCanvas.AddVisual(visual);
                            DrawArrow(p1, p2);
                        }
                        else
                        {
                            ArcSegment as1 = new ArcSegment();
                            as1.Point          = p2;
                            as1.Size           = new Size(200, 300);
                            as1.SweepDirection = SweepDirection.Clockwise;
                            as1.IsLargeArc     = false;

                            PathFigure figure1 = new PathFigure();
                            figure1.StartPoint = p1;
                            figure1.Segments.Add(as1);

                            PathGeometry geometry1 = new PathGeometry();
                            geometry1.Figures.Add(figure1);

                            System.Windows.Shapes.Path path1 = new System.Windows.Shapes.Path();
                            path1.Data            = geometry1;
                            path1.Stroke          = new SolidColorBrush(Colors.Black);
                            path1.StrokeThickness = 1;

                            modifiedGraph.Children.Add(path1);

                            ArcSegment as2 = new ArcSegment();
                            as2.Point          = p2;
                            as2.Size           = new Size(200, 300);
                            as2.SweepDirection = SweepDirection.Counterclockwise;
                            as2.IsLargeArc     = false;

                            PathFigure figure2 = new PathFigure();
                            figure2.StartPoint = p1;
                            figure2.Segments.Add(as2);

                            PathGeometry geometry2 = new PathGeometry();
                            geometry1.Figures.Add(figure2);

                            System.Windows.Shapes.Path path2 = new System.Windows.Shapes.Path();
                            path2.Data            = geometry2;
                            path2.Stroke          = new SolidColorBrush(Colors.Black);
                            path2.StrokeThickness = 1;

                            modifiedGraph.Children.Add(path2);
                        }
                    }
                }
            }
        }