Ejemplo n.º 1
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            //Allow user to change ZOrder when manually drawn on chart
            if (!hasSetZOrder && !StartAnchor.IsNinjaScriptDrawn)
            {
                ZOrderType   = DrawingToolZOrder.Normal;
                ZOrder       = ChartPanel.ChartObjects.Min(z => z.ZOrder) - 1;
                hasSetZOrder = true;
            }
            RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
            OutlineStroke.RenderTarget = RenderTarget;
            ChartPanel chartPanel = chartControl.ChartPanels[PanelIndex];

            // recenter region anchors to always be onscreen/centered
            double middleX = chartPanel.X + chartPanel.W / 2d;
            double middleY = chartPanel.Y + chartPanel.H / 2d;

            if (Mode == RegionHighlightMode.Price)
            {
                StartAnchor.UpdateXFromPoint(new Point(middleX, 0), chartControl, chartScale);
                EndAnchor.UpdateXFromPoint(new Point(middleX, 0), chartControl, chartScale);
            }
            else
            {
                StartAnchor.UpdateYFromDevicePoint(new Point(0, middleY), chartScale);
                EndAnchor.UpdateYFromDevicePoint(new Point(0, middleY), chartScale);
            }

            Point  startPoint = StartAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point  endPoint   = EndAnchor.GetPoint(chartControl, chartPanel, chartScale);
            double width      = endPoint.X - startPoint.X;

            AnchorLineStroke.RenderTarget = RenderTarget;
            OutlineStroke.RenderTarget    = RenderTarget;

            if (!IsInHitTest && AreaBrush != null)
            {
                if (areaBrushDevice.Brush == null)
                {
                    Brush brushCopy = areaBrush.Clone();
                    brushCopy.Opacity     = areaOpacity / 100d;
                    areaBrushDevice.Brush = brushCopy;
                }
                areaBrushDevice.RenderTarget = RenderTarget;
            }
            else
            {
                areaBrushDevice.RenderTarget = null;
                areaBrushDevice.Brush        = null;
            }

            // align to full pixel to avoid unneeded aliasing
            float strokePixAdjust = Math.Abs(OutlineStroke.Width % 2d).ApproxCompare(0) == 0 ? 0.5f : 0f;

            SharpDX.RectangleF rect = Mode == RegionHighlightMode.Time ?
                                      new SharpDX.RectangleF((float)startPoint.X + strokePixAdjust, ChartPanel.Y - OutlineStroke.Width + strokePixAdjust,
                                                             (float)width, chartPanel.Y + chartPanel.H + OutlineStroke.Width * 2) :
                                      new SharpDX.RectangleF(chartPanel.X - OutlineStroke.Width + strokePixAdjust, (float)startPoint.Y + strokePixAdjust,
                                                             chartPanel.X + chartPanel.W + OutlineStroke.Width * 2, (float)(endPoint.Y - startPoint.Y));

            if (!IsInHitTest && areaBrushDevice.BrushDX != null)
            {
                RenderTarget.FillRectangle(rect, areaBrushDevice.BrushDX);
            }

            SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : OutlineStroke.BrushDX;
            RenderTarget.DrawRectangle(rect, tmpBrush, OutlineStroke.Width, OutlineStroke.StrokeStyle);

            if (IsSelected)
            {
                tmpBrush = IsInHitTest ? chartControl.SelectionBrush : AnchorLineStroke.BrushDX;
                RenderTarget.DrawLine(startPoint.ToVector2(), endPoint.ToVector2(), tmpBrush, AnchorLineStroke.Width, AnchorLineStroke.StrokeStyle);
            }
        }