Beispiel #1
0
        public PriceMarksModule(View chart, DrawingCanvas MarksCanvas, DrawingCanvas PriceLine) : base(chart)
        {
            this.MarksCanvas = MarksCanvas;
            this.PriceLine   = PriceLine;

            #region Слои отметок
            {
                Levels = new MarksLayer(MarksCanvas, PriceLine, RedrawMarks); MarksLayers.Add(Levels);
            }
            #endregion
        }
Beispiel #2
0
        private void RedrawMarks(MarksLayer Layer)
        {
            var marksData = new List <RedrawData>();

            {   // get redraw data
                if (Layer.Marks != null)
                {
                    var pricesMax = (Chart.PricesMin + Chart.PricesDelta) * Chart.TickSize;
                    foreach (var mark in Layer.Marks)
                    {
                        if (mark.Price > Chart.PricesMin * Chart.TickSize && mark.Price < pricesMax)
                        {
                            var height = Chart.PriceToHeight(mark.Price);

                            var ft = new FormattedText
                                     (
                                mark.Price.ToString(Chart.TickPriceFormat),
                                CultureInfo.CurrentCulture,
                                FlowDirection.LeftToRight,
                                Chart.FontNumeric,
                                Chart.BaseFontSize,
                                mark.TextBrush,
                                VisualTreeHelper.GetDpi(Layer.PriceVisual).PixelsPerDip
                                     );

                            var linpen = new Pen(mark.LineBrush, mark.LineThikness); linpen.Freeze();
                            var geopen = new Pen(mark.LineBrush, 2); geopen.Freeze();

                            var linps = new List <Point>();
                            if (mark.LineIndent == 0)
                            {
                                linps.Add(new Point(0, height));
                                linps.Add(new Point(4096, height));
                            }
                            else
                            {
                                double s = 0;
                                while (s < 4096)
                                {
                                    linps.Add(new Point(s, height)); s += mark.LineDash;
                                    linps.Add(new Point(s, height)); s += mark.LineIndent;
                                }
                            }

                            var geo = new PathGeometry(new[] { new PathFigure(new Point(0, height),
                                                                              new[]
                                {
                                    new LineSegment(new Point(Chart.PriceShift, height + ft.Height / 2), true),
                                    new LineSegment(new Point(Chart.PriceLineWidth - 2, height + ft.Height / 2), true),
                                    new LineSegment(new Point(Chart.PriceLineWidth - 2, height - ft.Height / 2), true),
                                    new LineSegment(new Point(Chart.PriceShift, height - ft.Height / 2), true)
                                },
                                                                              true) }); geo.Freeze();

                            marksData.Add(new RedrawData(
                                              new Point(0, height),
                                              new Point(Chart.ChWidth + 2, height),
                                              ft, mark.MarkFill,
                                              new Point(Chart.PriceShift + 1, height - ft.Height / 2),
                                              linpen, linps, geopen, geo));
                        }
                    }
                }
            } // get redraw data

            if (marksData.Count > 0)
            {
                СlearedSpace = false;
                Dispatcher.Invoke(() =>
                {
                    using var dcCH = Layer.ChartVisual.RenderOpen();
                    using var dcP  = Layer.PriceVisual.RenderOpen();

                    foreach (var rd in marksData)
                    {
                        for (int i = 0; i < rd.LinPoints.Count; i += 2)
                        {
                            dcCH.DrawLine(rd.Linpen, rd.LinPoints[i], rd.LinPoints[i + 1]);
                        }

                        dcP.DrawGeometry(rd.Fill, rd.Geopen, rd.Geo);
                        dcP.DrawText(rd.Ft, rd.T);
                    }
                });
            }
            else if (!СlearedSpace)
            {
                СlearedSpace = true;
                Dispatcher.Invoke(() =>
                {
                    Layer.ChartVisual.RenderOpen().Close();
                    Layer.PriceVisual.RenderOpen().Close();
                });
            }
        }