/// <summary>
        /// Control points selection rectangle is rendered in absolute size, ignoring scaling.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="pen">Pass null to use default control point pen.</param>
        protected void DrawControlPoints(GraphicsWrapper g)
        {
            float xMargin = 0.5f * Math.Abs(_defaultAbsoluteControlPointSelectionRectanglesSize / g.DrawingSpaceTransform.Elements[0]);
            float yMargin = 0.5f * Math.Abs(_defaultAbsoluteControlPointSelectionRectanglesSize / g.DrawingSpaceTransform.Elements[3]);

            for (int i = 0; i < _controlPoints.Count; i++)
            {
                PointF point = _controlPoints[i];
                if (_selectedControlPoints.Contains(i))
                {
                    g.DrawRectangle(_defaultSelectedControlPointPen, point.X - xMargin, point.Y - yMargin, xMargin * 2, yMargin * 2);
                }
                else
                {
                    g.DrawRectangle(_defaultControlPointPen, point.X - xMargin, point.Y - yMargin, xMargin * 2, yMargin * 2);
                }
            }
        }
Esempio n. 2
0
        protected void DrawIcon(GraphicsWrapper g, Pen pen, Brush fill, Rectangle rectangle)
        {
            if (Visible == false)
            {
                return;
            }

            if (fill != null)
            {
                g.FillRectangle(fill, rectangle);
            }

            if (pen != null)
            {
                g.DrawRectangle(pen, rectangle);
            }
        }
Esempio n. 3
0
        void DrawHistogramBar(GraphicsWrapper g, ref PointF drawingPoint, float[] values, Pen pen, Brush fill,
                              int index, int previousItemIndex, float itemWidth, float itemMargin)
        {
            float y = drawingPoint.Y;

            double heightSum      = 0;
            int    actualSumCount = 0;

            int unificationCount = index - previousItemIndex;

            for (int i = previousItemIndex; i <= index; i++)
            {
                if (float.IsNaN(values[i]) ||
                    float.IsInfinity(values[i]))
                {
                    continue;
                }

                heightSum += values[i];
                actualSumCount++;
            }

            if (actualSumCount == 0)
            {
                return;
            }

            float height = (float)(heightSum / actualSumCount);

            if (height < 0)
            {
                y     += height;
                height = -height;
            }

            if (fill != null)
            {
                g.FillRectangle(fill, drawingPoint.X, y, (itemWidth) * unificationCount, height);
            }

            if (pen != null)
            {
                g.DrawRectangle(pen, drawingPoint.X, y, itemWidth, height);
            }
        }
        /// <summary>
        /// Enter locked.
        /// </summary>
        void DrawCandleStick(GraphicsWrapper g, ref PointF startingPoint, BarData barData, float itemWidth, float itemMargin, int itemUnitification)
        {
            if (barData.BarIsRising || (barData.IsHigherPrev && barData.BarBodyLength == 0))
            {
                if (_risingBarFill != null)
                {
                    g.FillRectangle(_risingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.BarBodyLength);
                }

                if (_risingBarPen != null)
                {
                    if (itemWidth > 4)
                    {
                        g.DrawRectangle(_risingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.BarBodyLength);
                        // Harry -- Draw a line for open = = close
                        if ((float)barData.BarBodyLength <= 0)
                        {
                            g.DrawLine(_risingBarPen,
                                       startingPoint.X,
                                       startingPoint.Y + (float)barData.Close,
                                       startingPoint.X + itemWidth,
                                       startingPoint.Y + (float)barData.Close);
                        }
                    }
                    else
                    {
                        g.FillRectangle(Brushes.Green, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.BarBodyLength);
                    }

                    // Lower shadow
                    g.DrawLine(_risingBarPen,
                               startingPoint.X + itemWidth / 2,
                               startingPoint.Y + (float)barData.Low,
                               startingPoint.X + itemWidth / 2,
                               startingPoint.Y + (float)barData.Open);

                    // Upper shadow
                    g.DrawLine(_risingBarPen,
                               startingPoint.X + itemWidth / 2,
                               (float)(startingPoint.Y + barData.High),
                               startingPoint.X + itemWidth / 2,
                               (float)(startingPoint.Y + barData.Close));
                    //Console.WriteLine("  startingPoint.X    " + startingPoint.X + "   startingPoint.Y " + startingPoint.Y + "  (float)barData.Low " + (float)barData.Low + "  (float)barData.Close  " + (float)barData.Close + "  (float)barData.High " + (float)barData.High + "  (float)barData.Open  " + (float)barData.Open);
                }
            }
            else
            {
                if (_fallingBarFill != null)
                {
                    g.FillRectangle(_fallingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.BarBodyLength);
                    // Harry -- Draw a line for open = = close
                    if ((float)barData.BarBodyLength <= 0)
                    {
                        g.DrawLine(_fallingBarPen,
                                   startingPoint.X,
                                   startingPoint.Y + (float)barData.Close,
                                   startingPoint.X + itemWidth,
                                   startingPoint.Y + (float)barData.Close);
                    }
                }

                if (_fallingBarPen != null)
                {
                    if (itemWidth >= 4)
                    {// Only if an item is clearly visible, show the border, otherwise, hide to improver overal visibility.
                        // Showing this border adds nice detail on close zooming, but not useful otherwise.
                        g.DrawRectangle(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.BarBodyLength);
                    }

                    // Lower shadow
                    g.DrawLine(_fallingBarPen,
                               startingPoint.X + itemWidth / 2,
                               startingPoint.Y + (float)barData.Low,
                               startingPoint.X + itemWidth / 2,
                               startingPoint.Y + (float)barData.Close);

                    // Upper shadow
                    g.DrawLine(_fallingBarPen,
                               startingPoint.X + itemWidth / 2,
                               (float)(startingPoint.Y + barData.High),
                               startingPoint.X + itemWidth / 2,
                               (float)(startingPoint.Y + barData.Open));
                }
            }
        }
        void DrawHistogramBar(GraphicsWrapper g, ref PointF drawingPoint, float[] values, Pen pen, Brush fill, 
            int index, int previousItemIndex, float itemWidth, float itemMargin)
        {
            float y = drawingPoint.Y;

            double heightSum = 0;
            int actualSumCount = 0;

            int unificationCount = index - previousItemIndex;

            for (int i = previousItemIndex; i <= index; i++)
            {
                if (float.IsNaN(values[i])
                    || float.IsInfinity(values[i]))
                {
                    continue;
                }

                heightSum += values[i];
                actualSumCount++;
            }

            if (actualSumCount == 0)
            {
                return;
            }

            float height = (float)(heightSum / actualSumCount);

            if (height < 0)
            {
                y += height;
                height = -height;
            }

            if (fill != null)
            {
                g.FillRectangle(fill, drawingPoint.X, y, (itemWidth) * unificationCount, height);
            }

            if (pen != null)
            {
                g.DrawRectangle(pen, drawingPoint.X, y, itemWidth, height);
            }
        }
        protected void DrawIcon(GraphicsWrapper g, Pen pen, Brush fill, Rectangle rectangle)
        {
            if (Visible == false)
            {
                return;
            }

            if (fill != null)
            {
                g.FillRectangle(fill, rectangle);
            }

            if (pen != null)
            {
                g.DrawRectangle(pen, rectangle);
            }
        }
        void DrawOrder(GraphicsWrapper g, ref PointF updatedImageDrawingPoint, Order order, float itemWidth, float itemMargin,
                       float yToXScaling, BarData orderBarData, float lastBarX, bool drawOpening)
        {
            Image image     = _imageUp;
            Brush brush     = Brushes.Green;
            Pen   dashedPen = _buyDashedPen;
            Pen   pen       = Pens.GreenYellow;

            if (order.IsBuy == false)
            {
                image     = _imageDown;
                brush     = Brushes.Red;
                pen       = Pens.Red;
                dashedPen = _sellDashedPen;
            }

            if (drawOpening == false)
            {
                image = _imageCross;
            }

            float price = (float)order.OpenPrice;

            if (drawOpening == false)
            {
                price = (float)order.ClosePrice;
            }

            if (drawOpening && _showPendingOrdersTracing && order.IsOpen)
            {// Open orders tracking line.
                PointF point1    = new PointF(updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + price);
                float  sellPrice = (float)_dataProvider.Bid;
                if (order.IsBuy == false)
                {
                    sellPrice = (float)_dataProvider.Ask;
                }
                PointF point2 = new PointF(lastBarX - itemWidth / 2f, updatedImageDrawingPoint.Y + sellPrice);
                g.DrawLine(dashedPen, point1, point2);
            }

            //if (drawOpening && _showClosedOrdersTracing && order.IsOpen == false)
            //{// Closed order tracking.
            // Close order tracing is implemented in main draw function.
            //}

            if (_showOrderSpot)
            {
                PointF basePoint = new PointF(updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + price);
                float  height    = (yToXScaling * itemWidth);
                if (order.IsBuy == false)
                {
                    height = -height;
                }

                if (drawOpening)
                {
                    g.FillPolygon(brush, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y),
                                                        new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) });
                    g.DrawPolygon(Pens.White, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y),
                                                             new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) });

                    // Take profit level.
                    if (double.IsInfinity(order.SourceTakeProfit) == false &&
                        double.IsNaN(order.SourceTakeProfit) == false &&
                        order.SourceTakeProfit != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit,
                                   updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit);

                        g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit,
                                   updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit - height);
                    }

                    // Stop loss level.
                    if (double.IsInfinity(order.SourceStopLoss) == false &&
                        double.IsNaN(order.SourceStopLoss) == false &&
                        order.SourceStopLoss != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss,
                                   updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss);

                        g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss,
                                   updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss + height);
                    }
                }
                else
                {
                    g.DrawRectangle(Pens.White, basePoint.X, basePoint.Y,
                                    itemWidth, yToXScaling * itemWidth);
                }
            }

            float imageHeight = 2 * (yToXScaling * itemWidth);

            if (_showOrderArrow)
            {
                // Draw up image.

                g.DrawImage(image, updatedImageDrawingPoint.X - (itemWidth / 2f), updatedImageDrawingPoint.Y +
                            (float)orderBarData.Low - (yToXScaling * itemWidth), 2 * itemWidth, -imageHeight);

                updatedImageDrawingPoint.Y -= 1.2f * imageHeight;
            }
        }
        /// <summary>
        /// Control points selection rectangle is rendered in absolute size, ignoring scaling.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="pen">Pass null to use default control point pen.</param>
        protected void DrawControlPoints(GraphicsWrapper g)
        {
            float xMargin = 0.5f * Math.Abs(_defaultAbsoluteControlPointSelectionRectanglesSize / g.DrawingSpaceTransform.Elements[0]);
            float yMargin = 0.5f * Math.Abs(_defaultAbsoluteControlPointSelectionRectanglesSize / g.DrawingSpaceTransform.Elements[3]);

            for (int i = 0; i < _controlPoints.Count; i++)
            {
                PointF point = _controlPoints[i];
                if (_selectedControlPoints.Contains(i))
                {
                    g.DrawRectangle(_defaultSelectedControlPointPen, point.X - xMargin, point.Y - yMargin, xMargin * 2, yMargin * 2);
                }
                else
                {
                    g.DrawRectangle(_defaultControlPointPen, point.X - xMargin, point.Y - yMargin, xMargin * 2, yMargin * 2);
                }
            }
        }
        void DrawSelection(GraphicsWrapper g)
        {
            if (CurrentSelectionRectangle.HasValue == false)
            {
                return;
            }

            RectangleF selectionRectangle = CurrentSelectionRectangle.Value;

            if (selectionRectangle.Width > 0 && selectionRectangle.Height > 0 &&
                _lastDrawingSpaceMouseRightButtonPosition.HasValue && _currentDrawingSpaceMousePosition.HasValue)
            {
                if (_selectionPen != null)
                {
                    g.DrawRectangle(_selectionPen, selectionRectangle.X, selectionRectangle.Y, selectionRectangle.Width, selectionRectangle.Height);
                }

                if (_selectionFill != null)
                {
                    g.FillRectangle(_selectionFill, selectionRectangle);
                }
            }
        }
        void DrawDrawingSpace(GraphicsWrapper g)
        {
            RectangleF drawingSpaceClipping = _actualDrawingSpaceArea;
            drawingSpaceClipping.X -= _seriesItemMargin + _seriesItemWidth;
            drawingSpaceClipping.Y -= _seriesItemMargin + _seriesItemWidth;

            drawingSpaceClipping.Width += 2 * (_seriesItemMargin + _seriesItemWidth);
            drawingSpaceClipping.Height += 2 * (_seriesItemMargin + _seriesItemWidth);

            drawingSpaceClipping = GraphicsWrapper.ActualSpaceToDrawingSpace(drawingSpaceClipping);
            //drawingSpaceClipping.Y = DrawingSpace.Y - 10;
            //drawingSpaceClipping.Height = DrawingSpace.Height + 10;

            // Grid.
            _drawingSpaceGrid.Draw(g, drawingSpaceClipping, _drawingSpace, _seriesItemMargin + _seriesItemWidth);

            // Show clipping rectangle.
            if (ShowClippingRectangle)
            {
                Pen clippingRectanglePen = (Pen)Pens.DarkGray.Clone();
                clippingRectanglePen.DashStyle = DashStyle.Dash;

                g.DrawRectangle(clippingRectanglePen, drawingSpaceClipping.X, drawingSpaceClipping.Y, drawingSpaceClipping.Width, drawingSpaceClipping.Height);
            }

            // Draw custom objects - pre series.
            _customObjectsManager.Draw(g, drawingSpaceClipping, CustomObject.DrawingOrderEnum.PreSeries);

            // Series.
            foreach (ChartSeries series in _series)
            {
                series.Draw(g, CurrentUnitUnification, drawingSpaceClipping, _seriesItemWidth, _seriesItemMargin);
            }

            // Draw custom objects - post series.
            _customObjectsManager.Draw(g, drawingSpaceClipping, CustomObject.DrawingOrderEnum.PostSeries);
        }
        protected virtual void DrawPostActualSpaceOverlays(GraphicsWrapper g)
        {
            if (_titleFont != null && _titleFontBrush != null)
            {
                // Title
                Rectangle titleRectangle = new Rectangle(_actualDrawingSpaceArea.Left, _actualDrawingSpaceArea.Top, 0, 0);
                SizeF titleSize = g.MeasureString(_chartName, _titleFont);
                titleRectangle.Size = new Size((int)titleSize.Width, (int)titleSize.Height);
                g.DrawString(_chartName, _titleFont, _titleFontBrush, titleRectangle.Location);
            }

            if (_actualDrawingSpaceAreaBorderPen != null)
            {
                // Border
                g.DrawRectangle(_actualDrawingSpaceAreaBorderPen, _actualDrawingSpaceArea.X - 1, _actualDrawingSpaceArea.Y - 1, _actualDrawingSpaceArea.Width + 1, _actualDrawingSpaceArea.Height + 1);
            }
        }
        void DrawOrder(GraphicsWrapper g, ref PointF updatedImageDrawingPoint, Order order, float itemWidth, float itemMargin,
            float yToXScaling, BarData orderBarData, float lastBarX, bool drawOpening)
        {
            Image image = _imageUp;
            Brush brush = Brushes.Green;
            Pen dashedPen = _buyDashedPen;
            Pen pen = Pens.GreenYellow;
            if (order.IsBuy == false)
            {
                image = _imageDown;
                brush = Brushes.Red;
                pen = Pens.Red;
                dashedPen = _sellDashedPen;
            }

            if (drawOpening == false)
            {
                image = _imageCross;
            }

            float price = (float)order.OpenPrice;
            if (drawOpening == false)
            {
                price = (float)order.ClosePrice;
            }

            if (drawOpening && _showPendingOrdersTracing && order.IsOpen)
            {// Open orders tracking line.
                PointF point1 = new PointF(updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + price);
                float sellPrice = (float)_dataProvider.Bid;
                if (order.IsBuy == false)
                {
                    sellPrice = (float)_dataProvider.Ask;
                }
                PointF point2 = new PointF(lastBarX - itemWidth / 2f, updatedImageDrawingPoint.Y + sellPrice);
                g.DrawLine(dashedPen, point1, point2);
            }

            //if (drawOpening && _showClosedOrdersTracing && order.IsOpen == false)
            //{// Closed order tracking.
            // Close order tracing is implemented in main draw function.
            //}

            if (_showOrderSpot)
            {
                PointF basePoint = new PointF(updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + price);
                float height = (yToXScaling * itemWidth);
                if (order.IsBuy == false)
                {
                    height = -height;
                }

                if (drawOpening)
                {
                    g.FillPolygon(brush, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y),
                        new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) });
                    g.DrawPolygon(Pens.White, new PointF[] { basePoint, new PointF(basePoint.X + itemWidth, basePoint.Y),
                        new PointF(basePoint.X + (itemWidth / 2f), basePoint.Y + height) });

                    // Take profit level.
                    if (double.IsInfinity(order.SourceTakeProfit) == false
                        && double.IsNaN(order.SourceTakeProfit) == false
                        && order.SourceTakeProfit != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit,
                            updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit);

                        g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit,
                            updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceTakeProfit - height);
                    }

                    // Stop loss level.
                    if (double.IsInfinity(order.SourceStopLoss) == false
                        && double.IsNaN(order.SourceStopLoss) == false
                        && order.SourceStopLoss != 0)
                    {
                        g.DrawLine(pen, updatedImageDrawingPoint.X, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss,
                            updatedImageDrawingPoint.X + itemWidth, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss);

                        g.DrawLine(pen, updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss,
                            updatedImageDrawingPoint.X + itemWidth / 2f, updatedImageDrawingPoint.Y + (float)order.SourceStopLoss + height);
                    }
                }
                else
                {
                    g.DrawRectangle(Pens.White, basePoint.X, basePoint.Y,
                        itemWidth, yToXScaling * itemWidth);
                }

            }

            float imageHeight = 2 * (yToXScaling * itemWidth);
            if (_showOrderArrow)
            {
                // Draw up image.

                g.DrawImage(image, updatedImageDrawingPoint.X - (itemWidth / 2f), updatedImageDrawingPoint.Y +
                    (float)orderBarData.Low - (yToXScaling * itemWidth), 2 * itemWidth, -imageHeight);

                updatedImageDrawingPoint.Y -= 1.2f * imageHeight;
            }
        }