Exemple #1
0
        public Task Redraw()
        {
            return(Task.Run(() =>
            {
                if (Chart.ChHeight == 0)
                {
                    return;
                }
                PricesDelta = (Chart.ChHeight / Chart.CurrentScale.Y);
                PricesMin = LastMin - (LastY - Chart.CurrentTranslate.Y) + (LastDelta - PricesDelta) / 2;
                var pixelsPerDip = VisualTreeHelper.GetDpi(PricesVisual).PixelsPerDip;

                double count = Math.Floor((Chart.ChHeight / (Chart.BaseFontSize * 6)));
                if (count == 0)
                {
                    return;
                }
                var step = (PricesDelta * Chart.TickSize) / count;
                double n = 1;
                int d = 0;
                while (step > 10)
                {
                    step /= 10;
                    n *= 10;
                }
                while (step < 1)
                {
                    step *= 10;
                    n /= 10;
                    d += 1;
                }

                if (step > 5)
                {
                    step = 5 * n;
                }
                else if (step > 4)
                {
                    step = 4 * n;
                }
                else if (step > 2.5)
                {
                    step = 2.5 * n; d += 1;
                }
                else if (step > 2)
                {
                    step = 2 * n;
                }
                else if (step > 1)
                {
                    step = 1 * n;
                }

                double maxP;
                if (PricesMin < 0 && (PricesMin + PricesDelta) < Math.Abs(PricesMin) * 10)
                {
                    maxP = Math.Abs(PricesMin) * 10 * Chart.TickSize;
                }
                else
                {
                    maxP = (PricesMin + PricesDelta) * Chart.TickSize;
                }

                var raz = 1;
                while (maxP > 10)
                {
                    maxP /= 10;
                    raz *= 10;
                }
                Fsf = Chart.TickPriceFormat;
                if (raz > 10)
                {
                    for (int i = Convert.ToInt32(Math.Log10(raz)); i > 0; i--)
                    {
                        Fsf = "0" + Fsf;
                    }
                }

                var fsfFT = new FormattedText
                            (
                    Fsf,
                    CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight,
                    Chart.FontNumeric,
                    Chart.BaseFontSize,
                    Chart.FontBrush,
                    pixelsPerDip
                            );

                var price = Math.Round(step * Math.Ceiling((PricesMin * Chart.TickSize) / step), d);
                var coordiate = Chart.PriceToHeight(price);
                var pricesToDraw = new List <(FormattedText price, Point coor,
                                              Point A, Point B, Point G, Point H)>();

                do
                {
                    var ft = new FormattedText
                             (
                        price.ToString(Chart.TickPriceFormat),
                        CultureInfo.CurrentCulture,
                        FlowDirection.LeftToRight,
                        Chart.FontNumeric,
                        Chart.BaseFontSize,
                        Chart.FontBrush,
                        pixelsPerDip
                             );
                    var Y = coordiate - ft.Height / 2;
                    pricesToDraw.Add((ft, new Point(Chart.PriceShift, Y),
                                      new Point(0, coordiate), new Point(3, coordiate),
                                      new Point(0, coordiate), new Point(4096, coordiate)));
                    price = Math.Round(price + step, d);
                    coordiate = Chart.PriceToHeight(price);
                }while (coordiate > 0);

                PriceLineWidth = fsfFT.Width + Chart.PriceShift + 4;
                ScaleWidthChanged.Invoke(PriceLineWidth, Fsf);
                Dispatcher.Invoke(() =>
                {
                    using var pvc = PricesVisual.RenderOpen();
                    using var pgvc = PriceGridVisual.RenderOpen();
                    foreach (var pr in pricesToDraw)
                    {
                        pvc.DrawText(pr.price, pr.coor);
                        pvc.DrawLine(Chart.LinesPen, pr.A, pr.B);
                        pgvc.DrawLine(Chart.LinesPen, pr.G, pr.H);
                    }
                });
                PriceMarksModule.Redraw();
                VerticalСhanges?.Invoke();
            }));
        }
Exemple #2
0
        }                 //конструктор для intellisense

        public View(ChartWindow Window, ChartShell Shell)
        {
            this.Window = Window;
            this.Shell  = Shell;

            InitializeComponent();
            this.Shell.ToggleClipTime += b => Clipped = b;
            this.PreviewMouseDown     += (s, e) => this.Shell.ChartGotFocus(this);
            this.MouseEnter           += (s, e) => this.Shell.InstrumentsHandler = this;
            this.MouseLeave           += (s, e) =>
            {
                if (this.Shell.InstrumentsHandler == this)
                {
                    this.Shell.InstrumentsHandler = null;
                }
            };
            this.ShowSettings += this.Shell.ShowSettings;

            PriceMarksModule = new PriceMarksModule(this, LevelsLayer, PaintingMarksLayer);

            PriceLineModule = new PriceLineModule(this, GridLayerHorizontal, PricesLayer, PriceMarksModule);
            PriceLineModule.VerticalСhanges   += () => VerticalСhanges.Invoke();
            PriceLineModule.ScaleWidthChanged += (w, fsf) =>
            {
                Dispatcher.Invoke(() =>
                {
                    PriceLineCD.Width  = new GridLength(w);
                    PriceLineCD2.Width = new GridLength(w);
                });

                NewFSF?.Invoke(fsf);
            };

            TimeLineModule = new TimeLineModule(this, GridLayerVertical);
            TimeLineModule.HorizontalСhanges += () => HorizontalСhanges.Invoke();

            CursorModule = new CursorModule(this, CursorLayer, MagnetLayer, CursorTimeMarkLayer, CursorPriceMarkLayer);

            CandlesModule = new CandlesModule(this, CandlesLayer, PriceLineModule, TimeLineModule,
                                              Translate, ScaleX, ScaleY, TimeLine, PriceLine,
                                              new Vector(ScaleX.ScaleX, ScaleY.ScaleY));
            CandlesModule.CandlesChanged     += ac => CandlesChanged?.Invoke(ac);
            CandlesModule.AllHorizontalReset += cc => AllHorizontalReset?.Invoke(cc);
            CandlesModule.NewXScale          += sc => NewXScale?.Invoke(sc);
            CandlesModule.NewXTrans          += tr => NewXTrans?.Invoke(tr);

            BottomIndicatorManger = new BottomIndicatorsManger(this, IndicatorsGrid, IndicatorsRowRD, IndicatorsSplitterRD);
            CenterIndicatorManger = new CenterIndicatorManger(this, BackgroundIndLayer,
                                                              ForegroundIndLayer, PaintingMarksLayer, PaintingTimeLayer);

            PaintingModule = new PaintingModule(this, PrototypeLayer, PrototypePriceLayer,
                                                PrototypeTimeLayer, CenterIndicatorManger.AddElement);
            this.Shell.ClearPrototypes += PaintingModule.ClearPrototype;

            HooksModule = new HooksModule(this, HooksLayer, HookPriceLayer, HookTimeLayer,
                                          () => CursorModule.LinesPen, CenterIndicatorManger,
                                          new List <FrameworkElement>
            {
                SubLayers,
                PaintingMarksLayer,
                BackgroundIndLayer,
                ForegroundIndLayer
            });

            ChartGrid.PreviewMouseRightButtonDown += (s, e) =>
            {
                var items = HooksModule.ShowContextMenu(s, e);
                if (items == null)
                {
                    items = (new List <(string Name, Action Act)>()
                    {
                        ("Test 1", () => { Debug.WriteLine("Test 1"); }),
                        ("+++", null),
                        ("Test 2", () => { Debug.WriteLine("Test 2"); }),
                        ("+++", null),
                        ("Test 3", () => { Debug.WriteLine("Test 3"); })
                    },
                             null, null);
                }
                this.Shell.ShowContextMenu(items.Value);
            };

            CandlesModule.WheelScalled += () => CursorModule.Redraw(CursorPosition.Current);

            var DC = DataContext as ViewModel;

            DC.PropertyChanged += DC_PropertyChanged;
            DC.Inicialize();

            SetsDefinition();
        }