public static void DrawFormattedText(this Graphics g,
                                             float x, float y,
                                             BrushesStorage brushes,
                                             Color colorMain,
                                             string text, FontStorage fonts)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            var lines       = text.Split(lineSeparator, StringSplitOptions.RemoveEmptyEntries);
            var totalHeight = 0f;

            foreach (var line in lines)
            {
                FontStyle fontStyle;
                Color?    fontColor;

                var pureLine = GetLineModifiers(line, out fontStyle, out fontColor);
                var font     = fonts.GetFont(fontStyle);

                g.DrawString(pureLine, font, brushes.GetBrush(fontColor ?? colorMain), x, y + totalHeight);

                var dH = font.GetHeight(g);
                totalHeight += dH;
            }
        }
Example #2
0
        public QuotePartButton(float scaleX, float scaleY, BrushesStorage brushes, PenStorage pens, bool isLeft = true)
        {
            brushesStor = brushes;
            pensStor = pens;
            colorScheme.Add(ButtonFigureColorScheme.Normal, Color.FromArgb(255, 180, 247, 180));
            colorScheme.Add(ButtonFigureColorScheme.Pressed, Color.FromArgb(255, 200, 247, 210));
            colorScheme.Add(ButtonFigureColorScheme.Light, Color.FromArgb(255, 160, 195, 180));

            currentBrush = brushesStor.GetBrush(colorScheme[ButtonFigureColorScheme.Normal]) as SolidBrush;

            ScaleX = scaleX;
            ScaleY = scaleY;
            this.isLeft = isLeft;
            translateMatrix = new Matrix();

            string buySellIndicatorHaderText;
            if (isLeft)
            {
                translateMatrix.Translate(paddingLeftRightProportion / 2, PaddingTopProportion);
                buySellIndicatorHaderText = "Bid";
            }
            else
            {
                translateMatrix.Translate(QuotePartButtonFigure.OriginalWidth * 2 + paddingLeftRightProportion / 2, PaddingTopProportion);
                translateMatrix.Scale(-1, 1);
                buySellIndicatorHaderText = "Ask";
            }

            buySellIndicator = new BuySellIndicator
                                   {
                                       ScaleX = scaleX,
                                       ScaleY = scaleY,
                                       OriginalLocation = isLeft
                                            ?
                                            new Point(
                                                Convert.ToInt32(paddingLeftRightProportion),
                                                Convert.ToInt32(PaddingTopProportion + PaddingTopBuySellIndicator))
                                            :
                                            new Point(
                                                Convert.ToInt32(QuotePartButtonFigure.OriginalWidth + paddingLeftRightProportion),
                                                Convert.ToInt32(PaddingTopProportion + PaddingTopBuySellIndicator)),
                                       HaderText = buySellIndicatorHaderText,
                                       Volume = null
                                   };

            arrowTrend = new ArrowTrend
                             {
                                 Sx = ScaleX,
                                 Sy = ScaleY,
                                 Brushes = brushes,
                                 Pens = pens,
                                 OriginalLocation = isLeft ? new PointF(QuotePartButtonFigure.OriginalWidth - paddingLeftRightProportion - 2, PaddingTopArrow) :
                                                             new PointF(QuotePartButtonFigure.OriginalWidth * 2 - paddingLeftRightProportion - 2, PaddingTopArrow)
                             };
        }
 public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 {
     if (data.Count == 0) return;
     base.Draw(g, worldRect, canvasRect);
     using (var pens = new PenStorage())
     using (var brushes = new BrushesStorage())
     {
         foreach (var span in data)
         {
             span.Draw(g, pens, brushes, worldRect, canvasRect, Chart.Font);
         }
     }
 }
 public void Draw(Graphics g, PenStorage penStorage, BrushesStorage brushStorage)
 {
     var pen = penStorage.GetPen(Color.Black);
     var brush = brushStorage.GetBrush(Color.White);
     if (action == MarkerAction.Move)
     {
         var points = new[]
                             {
                                 new Point((int) centerScreen.X - Size2, (int) centerScreen.Y),
                                 new Point((int) centerScreen.X, (int) centerScreen.Y - Size2),
                                 new Point((int) centerScreen.X + Size2, (int) centerScreen.Y),
                                 new Point((int) centerScreen.X, (int) centerScreen.Y + Size2)
                             };
         g.FillPolygon(brush, points);
         g.DrawPolygon(pen, points);
         return;
     }
     g.FillRectangle(brush, (float)centerScreen.X - Size2, (float)centerScreen.Y - Size2, Size, Size);
     g.DrawRectangle(pen, (float) centerScreen.X - Size2, (float) centerScreen.Y - Size2, Size, Size);
 }
        /// <summary>
        /// прорисовка на кнопке
        /// </summary>
        public void Draw(Graphics graphic, BrushesStorage brushes)
        {
            var textSize = ScaleY < ScaleX ? TextSizeOriginal * ScaleY : TextSizeOriginal * ScaleX;

            graphic.DrawString(HaderText, new Font("Open Sans", textSize), brushes.GetBrush(Color.Black),
                new PointF(OriginalLocation.X * ScaleX, OriginalLocation.Y * ScaleY));

            graphic.DrawString(volumeTop, new Font("Open Sans", textSize * 0.7f, FontStyle.Bold), brushes.GetBrush(Color.DarkBlue),
                new PointF((OriginalLocation.X + MarginLeft) * ScaleX, (OriginalLocation.Y + MarginText) * ScaleY));

            //Прорисовка центральной части
            var sizeTop = graphic.MeasureString(volumeTop,
                                              new Font("Open Sans", textSize * 0.7f, FontStyle.Bold));
            graphic.DrawString(volumeCentr, new Font("Open Sans", textSize * 1.25f, FontStyle.Bold), brushes.GetBrush(Color.DarkBlue),
                new PointF((OriginalLocation.X + 4 * MarginLeft) * ScaleX, (OriginalLocation.Y + MarginText) * ScaleY + 4 * sizeTop.Height / 5));

            //Прорисовка нижней части
            var sizeMiddle = graphic.MeasureString(volumeCentr, new Font("Open Sans", textSize * 1.25f, FontStyle.Bold));
            graphic.DrawString(volumeBotton, new Font("Open Sans", textSize * 0.7f, FontStyle.Bold), brushes.GetBrush(Color.DarkBlue),
                new PointF((OriginalLocation.X +  4 * MarginLeft) * ScaleX + sizeMiddle.Height,
                    (OriginalLocation.Y + MarginText) * ScaleY + 2 * sizeTop.Height / 3 + 2 * sizeMiddle.Height / 3));
        }
Example #6
0
        /// <summary>
        /// Прорисовать индикатор - пририсовка квадритика и надписи в соответствии с установлеными для них размеров и положения
        /// </summary>
        /// <param name="graphic">Объект типа "Graphics" контрола типа QuoteTradeControl на котором будем рисовать индикатор</param>
        /// <param name="brushes">Кисть</param>
        public void Draw(Graphics graphic, BrushesStorage brushes)
        {
            graphic.FillRectangle(brushes.GetBrush(Color.FromArgb(255, 192, 255, 192)), spreadPointRectangle);
            graphic.DrawRectangle(new Pen(Color.FromArgb(255, 90, 188, 90), 1), spreadPointRectangle);
            var pipsStr = (Value*precisionPower).ToString("N1");

            // Устанавливаем стандартный размер шрифта
            var textSize = spreadPointRectangle.Height / 1.5f > spreadPointRectangle.Width / 3f ? spreadPointRectangle.Width / 3f : spreadPointRectangle.Height / 1.5f;
            var rectSize = graphic.MeasureString(pipsStr, new Font("Open Sans", textSize, FontStyle.Bold));

            // Если при стандарном размере шрифта текст полкостью не влезает, то смотрим насколько не влезло и высчитаваем подходящий размер шрифта
            if (rectSize.Height > spreadPointRectangle.Height || rectSize.Width > spreadPointRectangle.Width)
            {
                textSize = rectSize.Height > rectSize.Width
                               ? textSize * spreadPointRectangle.Height / rectSize.Height - 0.5f
                               : textSize * spreadPointRectangle.Width / rectSize.Width - 0.5f;
                rectSize = graphic.MeasureString(pipsStr, new Font("Open Sans", textSize, FontStyle.Bold));
            }

            var px = (spreadPointRectangle.Width - rectSize.Width) / 2;
            var py = (spreadPointRectangle.Height - rectSize.Height) / 2;
            graphic.DrawString(pipsStr, new Font("Open Sans", textSize, FontStyle.Bold),
                      brushes.GetBrush(Color.Black), spreadPointRectangle.X + px, spreadPointRectangle.Y + py);
        }
 public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 {
     base.Draw(g, worldRect, canvasRect);
     using (var penDic = new PenStorage())
     using (var brushStorage = new BrushesStorage())
     foreach (var channel in data)
     {
         try
         {
             channel.Draw(g, worldRect, canvasRect, Chart.Font, penDic, brushStorage);
         }
         catch (Exception ex)
         {
             logNoFlood.LogMessageFormatCheckFlood(LogEntryType.Error,
                 LogMsgErrorDrawChannel, "SeriesFiboChannel darawing error: {0}", ex);
         }
     }
 }
Example #8
0
 public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 {
     base.Draw(g, worldRect, canvasRect);
     using (var pens = new PenStorage())
     using (var brushes = new BrushesStorage())
     {
         foreach (TrendLine line in data)
         {
             line.Draw(g, worldRect, canvasRect, pens, brushes);
         }
     }
 }
Example #9
0
        public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect)
        {
            base.Draw(g, worldRect, canvasRect);

            using (var penStorage = new PenStorage())
            using (var brushStorage = new BrushesStorage())
            foreach (var marker in data)
            {
                var ptScreen = Conversion.WorldToScreen(new PointD(marker.candleIndex, marker.Price),
                                                        worldRect, canvasRect);
                marker.Draw(g, ptScreen, Chart.Font);

                if (marker.exitPair.HasValue)
                {
                    var pairId = marker.exitPair;
                    var pair = data.FirstOrDefault(m => m.id == pairId);
                    if (pair != null)
                    {
                        var ptPair = Conversion.WorldToScreen(new PointD(pair.candleIndex, pair.Price),
                                                        worldRect, canvasRect);
                        // соединить две точки
                        var pen = penStorage.GetPen(Color.DarkSlateBlue, 1,
                                                    DashStyle.Dash);
                        g.DrawLine(pen, ptScreen.ToPointF(), ptPair.ToPointF());
                    }
                }
                if (marker.Selected) marker.DrawMarker(g, worldRect, canvasRect, penStorage, brushStorage);
            }
        }
        public void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect, Font font,
            PenStorage penDic, BrushesStorage brushStorage)
        {
            spansInScreenCoords.Clear();
            Draw(g, worldRect, canvasRect, penDic, brushStorage);

            if (linePoints.Count == 2)
            {// сохранить экранные координаты задающего отрезка
                spansInScreenCoords.Add(new Cortege2<Point, Point>(
                                            new Point((int) screenPointA.X, (int) screenPointA.Y),
                                            new Point((int) screenPointB.X, (int) screenPointB.Y)));
            }
            if (!Point3.HasValue) return;

            PointD oldPoint0 = linePoints[0], oldPoint1 = linePoints[1];
            // параллельно перенести прямую по уровням
            var pointC = ProjectDotOnSpan(worldRect, canvasRect);
            var vector = new PointD(Point3.Value.X - pointC.X, Point3.Value.Y - pointC.Y);

            // начальная прямая
            linePoints[0] = oldPoint0 + vector;
            linePoints[1] = oldPoint1 + vector;
            Draw(g, worldRect, canvasRect, penDic, brushStorage);
            spansInScreenCoords.Add(new Cortege2<Point, Point>(
                                            new Point((int)screenPointA.X, (int)screenPointA.Y),
                                            new Point((int)screenPointB.X, (int)screenPointB.Y)));

            // нормаль
            var vectorScale = series.Count == 0 ? 1.0 : series[series.Count - 1] + 1;
            var pointC2 = pointC + vector * vectorScale;
            var pointArrow = Conversion.WorldToScreen(pointC + vector, worldRect, canvasRect);
            var screenC = Conversion.WorldToScreen(pointC, worldRect, canvasRect);
            var screenC2 = Conversion.WorldToScreen(pointC2, worldRect, canvasRect);
            using (var pen = new Pen(LineColor) { DashStyle = DashStyle.Dot })
            {
                g.DrawLine(pen, screenC.ToPointF(), screenC2.ToPointF());
                g.DrawPolygon(pen, GetArrowPoints(screenC, pointArrow));
                // сохранить экранные координаты нормали
                spanNormalScreenCoords = new Cortege2<Point, Point>(screenC.ToPoint(), screenC2.ToPoint());
            }

            // ряд прямых
            var rectPen = penDic.GetPen(LineColor);
            foreach (var level in series)
            {
                var vectorScaled = vector * (1 + level);
                linePoints[0] = oldPoint0 + vectorScaled;
                linePoints[1] = oldPoint1 + vectorScaled;
                Draw(g, worldRect, canvasRect, penDic, brushStorage);
                // сохранить координаты (для проверки попадания)
                spansInScreenCoords.Add(new Cortege2<Point, Point>(
                                            new Point((int)screenPointA.X, (int)screenPointA.Y),
                                            new Point((int)screenPointB.X, (int)screenPointB.Y)));
                // вывести подпись в рамке
                if (DrawText)
                {
                    var whiteBrush = brushStorage.GetBrush(Color.White);
                    var brush = brushStorage.GetBrush(LineColor);

                    var ptText = pointC + vectorScaled;
                    ptText = Conversion.WorldToScreen(ptText, worldRect, canvasRect);
                    var textSz = g.MeasureString(level.ToString(), font);
                    var textRect = new Rectangle((int) (ptText.X - textSz.Width/2 - 2),
                                                    (int) (ptText.Y - textSz.Height/2 - 2),
                                                    (int) textSz.Width + 4, (int) textSz.Height + 4);
                    g.FillRectangle(whiteBrush, textRect);
                    g.DrawRectangle(rectPen, textRect);
                    g.DrawString(level.ToString(), font, brush, (float) ptText.X, (float) ptText.Y,
                                    new StringFormat
                                        {
                                            Alignment = StringAlignment.Center,
                                            LineAlignment = StringAlignment.Center
                                        });
                }
            }

            // восстановить начальные точки
            linePoints[0] = oldPoint0;
            linePoints[1] = oldPoint1;
        }
Example #11
0
        private void DrawTangent(List<PointD> screenPoints, Rectangle canvasRect, Graphics g, PenStorage penStorage,
                                 BrushesStorage brushStorage, Font font)
        {
            var ptLeft = points[0].X < points[1].X ? points[0] : points[1];
            var ptRight = points[0].X < points[1].X ? points[1] : points[0];
            var m1 = new PointD(cx + b * Math.Sin(angle), cy + b * Math.Cos(angle));
            var m2 = new PointD(cx + b * Math.Sin(angle + Math.PI), cy + b * Math.Cos(angle + Math.PI));
            var m = ptLeft.Y > ptRight.Y
                        ? m1.Y < m2.Y ? m1 : m2 // нижняя касательная для растущего эллипса
                        : m1.Y < m2.Y ? m2 : m1; // верхняя для падающего

            var o = new PointD(cx, cy);
            var r = new PointD(m.X - o.X, m.Y - o.Y);

            var pen = penStorage.GetPen(TangentColor);

            foreach (var level in tangentFiboLevels)
            {
                // нарисовать касательную или параллельную ей линию
                var A = new PointD(screenPoints[0].X + r.X * (level + 1), screenPoints[0].Y + r.Y * (level + 1));
                var B = new PointD(screenPoints[1].X + r.X * (level + 1), screenPoints[1].Y + r.Y * (level + 1));
                if (TangentType == EllipseTangentType.Прямая) StretchSpanToScreen(ref A, ref B, canvasRect);
                g.DrawLine(pen, A.ToPointF(), B.ToPointF());
                if (level == 0) continue;
                // нарисовать текстовую отметку
                var ptText = new PointD(o.X + r.X * (level + 1), o.Y + r.Y * (level + 1));
                var textSz = g.MeasureString(level.ToString(), font);
                var textRect = new Rectangle((int) (ptText.X - textSz.Width / 2 - 2),
                                             (int) (ptText.Y - textSz.Height / 2 - 2),
                                             (int) textSz.Width + 4, (int) textSz.Height + 4);
                var brushWhite = brushStorage.GetBrush(Color.FromArgb(60, pen.Color));
                g.FillRectangle(brushWhite, textRect);
                g.DrawRectangle(pen, textRect);
                var brushText = brushStorage.GetBrush(pen.Color);
                g.DrawString(level.ToString(), font, brushText, (float) ptText.X, (float) ptText.Y,
                             new StringFormat
                                 {
                                     Alignment = StringAlignment.Center,
                                     LineAlignment = StringAlignment.Center
                                 });
            }
        }
Example #12
0
 public void DrawMarker(Graphics g, RectangleD worldRect, Rectangle canvasRect, 
     PenStorage penStorage, BrushesStorage brushStorage)
 {
     editMarkers[0].CalculateScreenCoords(worldRect, canvasRect);
     editMarkers[0].Draw(g, penStorage, brushStorage);
 }
Example #13
0
 public void DrawComments(Graphics g, RectangleD worldRect, Rectangle canvasRect,
     PenStorage penStorage, BrushesStorage brushStorage)
 {
     foreach (var marker in markers)
     {
         marker.CalculateScreenCoords(worldRect, canvasRect);
         marker.Draw(g, penStorage, brushStorage);
     }
 }
Example #14
0
 public void DrawMarkers(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 {
     using (var penStorage = new PenStorage())
     using (var brushStorage = new BrushesStorage())
     foreach (var marker in markers)
     {
         marker.CalculateScreenCoords(worldRect, canvasRect);
         marker.Draw(g, penStorage, brushStorage);
     }
 }
Example #15
0
        private void DrawDragScaleMarks(Graphics g, BrushesStorage brushes)
        {
            if (!startDragPoint.HasValue) return;

            // найти X-координату (точно в центре области, занимаемой отметками оси)
            var xCoord = startDragPoint.Value.X;
            if (Chart.YAxisAlignment == YAxisAlignment.Left)
                xCoord = (int)(LeftAxisRect.Left + LeftAxisRect.Width * 0.5);
            else if (Chart.YAxisAlignment == YAxisAlignment.Right)
                xCoord = (int)(RightAxisRect.Left + RightAxisRect.Width * 0.5);
            else
            {
                var left = (int)(LeftAxisRect.Left + LeftAxisRect.Width * 0.5);
                var right = (int)(RightAxisRect.Left + RightAxisRect.Width * 0.5);
                var deltaLeft = Math.Abs(xCoord - left);
                var deltaRight = Math.Abs(xCoord - right);
                xCoord = deltaLeft < deltaRight ? left : right;
            }

            // нарисовать отметку начала перетягивания
            const int pointStartR = 5, pointStartD = 10;
            var brush = brushes.GetBrush(Chart.visualSettings.SeriesForeColor);
            var ptCenter = new Point(xCoord, startDragPoint.Value.Y);
            g.FillEllipse(brush, ptCenter.X - pointStartR, ptCenter.Y - pointStartR, pointStartD, pointStartD);

            // нарисовать отметку текущей позиции курсора
            if (!currentDragPoint.HasValue) return;
            const int shapeWd2 = 5, shapeHt2 = 4, shapeHt = 7;

            var x = currentDragPoint.Value.X;
            var y = currentDragPoint.Value.Y;
            var dir = y > startDragPoint.Value.Y ? 1 : -1;

            var points = new []
                             {
                                 new Point(x - shapeWd2, y - shapeHt2 * dir),
                                 new Point(x + shapeWd2, y - shapeHt2 * dir),
                                 new Point(x, y + shapeHt * dir)
                             };
            g.FillPolygon(brush, points);
        }
Example #16
0
        private void DrawComments(Graphics g, RectangleD worldRect, Rectangle canvasRect)
        {
            List<Rectangle> areasDrawn = null;
            // контроль перекрывающихся комментов
            if (hideSpannedComments)
                areasDrawn = new List<Rectangle>();

            using (var fonts = new FontStorage(new Font(Chart.Font.FontFamily, fontSize,
                FontBold ? FontStyle.Bold : FontStyle.Regular)))
            using (var penStorage = new PenStorage())
            using (var brushStorage = new BrushesStorage())
            {

                for (var i = data.Count - 1; i >= 0; i--)
                {
                    data[i].DrawComment(g, fonts, worldRect, canvasRect, penStorage, brushStorage, areasDrawn);
                    if (!hideSpannedComments) continue;
                }
            }
        }
Example #17
0
 private void DrawBackground(Graphics g, BrushesStorage brushes,
     Rectangle axisRect, YAxisAlignment alignment)
 {
     var brush = brushes.GetBrush(BackColor);
     var pen = new Pen(ForeColor);
     g.FillRectangle(brush, axisRect);
     using (pen)
     {
         if (alignment == YAxisAlignment.Left)
         {
             g.DrawLine(pen, axisRect.Right - 1, axisRect.Top, axisRect.Right - 1, axisRect.Bottom - 1);
         }
         else if (alignment == YAxisAlignment.Right)
         {
             g.DrawLine(pen, axisRect.Left, axisRect.Top, axisRect.Left, axisRect.Bottom - 1);
         }
     }
 }
Example #18
0
        internal override void Draw(Graphics g)
        {
            if (Owner.CanvasRect.Height == 0) return;

            using (var brushes = new BrushesStorage())
            {
                if (Chart.YAxisAlignment == YAxisAlignment.Left)
                {
                    DrawBackground(g, brushes, LeftAxisRect, YAxisAlignment.Left);
                    DrawGrid(g, brushes);
                    DrawTicks(g, LeftAxisRect, YAxisAlignment.Left);
                    DrawLabels(g, brushes, LeftAxisRect, YAxisAlignment.Left);
                }
                else if (Chart.YAxisAlignment == YAxisAlignment.Right)
                {
                    DrawBackground(g, brushes, RightAxisRect, YAxisAlignment.Right);
                    DrawGrid(g, brushes);
                    DrawTicks(g, RightAxisRect, YAxisAlignment.Right);
                    DrawLabels(g, brushes, RightAxisRect, YAxisAlignment.Right);
                }
                else
                {
                    DrawBackground(g, brushes, RightAxisRect, YAxisAlignment.Right);
                    DrawTicks(g, RightAxisRect, YAxisAlignment.Right);
                    DrawLabels(g, brushes, RightAxisRect, YAxisAlignment.Right);
                    DrawBackground(g, brushes, LeftAxisRect, YAxisAlignment.Left);
                    DrawGrid(g, brushes);
                    DrawTicks(g, LeftAxisRect, YAxisAlignment.Left);
                    DrawLabels(g, brushes, LeftAxisRect, YAxisAlignment.Left);
                }
                // нарисовать точки, откуда пользователь начал "перетягивать" курсором масштаб
                DrawDragScaleMarks(g, brushes);
            }
        }
Example #19
0
 private void DrawEllipses(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 {
     using (var brushStorage = new BrushesStorage())
     using (var penStorage = new PenStorage())
     foreach (var ellipse in data)
     {
         ellipse.DrawEllipse(g, worldRect, canvasRect, brushStorage, penStorage,Chart.Font);
     }
 }
        private void DrawCandles(Graphics g, RectangleD worldRect, Rectangle canvasRect,
            int left, int right)
        {
            var barWidth = (int)(Conversion.WorldToScreen(new SizeD(BarWidthPercent / 100.0, 0.0),
                                                 worldRect, canvasRect).Width);
            if (barWidth < 3) barWidth = 1;

            using (var brushStorage = new BrushesStorage())
            using (var brushUp = new SolidBrush(UpFillColor))
            using (var brushDown = new SolidBrush(DownFillColor))
            using (var penBarUp = new Pen(UpLineColor, BarLineWidth)
            {
                Alignment = PenAlignment.Center,
                DashCap = DashCap.Flat,
                StartCap = LineCap.Flat,
                EndCap = LineCap.Flat
            })
            using (var penBarDown = new Pen(DownLineColor, BarLineWidth)
            {
                Alignment = PenAlignment.Center,
                DashCap = DashCap.Flat,
                StartCap = LineCap.Flat,
                EndCap = LineCap.Flat
            })
            {
                for (var i = left; i <= right; i++)
                {
                    double close;
                    double open;
                    Brush brush;
                    var candle = Data[i];
                    var isGrowing = candle.close >= candle.open;

                    if (isGrowing)
                    {
                        close = candle.close;
                        open = candle.open;
                        brush = brushUp;
                    }
                    else
                    {
                        close = candle.open;
                        open = candle.close;
                        brush = brushDown;
                    }
                    double xValue = i;
                    if (candle.customColor.HasValue)
                        brush = brushStorage.GetBrush(candle.customColor.Value);

                    // рисовать отрезочек
                    if (barWidth == 1)
                    {
                        var pointA = PointD.Round(Conversion.WorldToScreen(
                                         new PointD(xValue, close), worldRect, canvasRect));

                        var pointB = PointD.Round(Conversion.WorldToScreen(
                                    new PointD(xValue, open), worldRect, canvasRect));

                        DrawLine(g, isGrowing ? penBarUp : penBarDown, pointA, pointB);
                        continue;
                    }

                    var point1 = PointD.Round(Conversion.WorldToScreen(
                                         new PointD(xValue - 0.45, close), worldRect, canvasRect));

                    var point2 = PointD.Round(Conversion.WorldToScreen(
                                new PointD(xValue + 0.45, open), worldRect, canvasRect));

                    var point3 = PointD.Round(Conversion.WorldToScreen(
                                new PointD(xValue, Data[i].low), worldRect, canvasRect));

                    var point4 = PointD.Round(Conversion.WorldToScreen(
                                new PointD(xValue, Data[i].high), worldRect, canvasRect));

                    // свеча...
                    DrawCandle(g, barWidth, close, open, isGrowing ? penBarUp : penBarDown,
                                       point3, point1, point4, point2, brush);
                }
            }
        }
Example #21
0
        public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect)
        {
            base.Draw(g, worldRect, canvasRect);

            using (var font = new Font(Chart.Font.FontFamily, fontSize))
            using (var penStorage = new PenStorage())
            using (var brushStorage = new BrushesStorage())
            {
                var brush = brushStorage.GetBrush(Color.White);

                foreach (var span in data)
                {
                    DrawSpan(g, worldRect, canvasRect, span, brush, penStorage);
                }

                foreach (var proj in projections)
                {
                    DrawProjection(g, worldRect, canvasRect, proj, brush, font,
                        penStorage, brushStorage);
                }
            }
        }
        private void TrendLineTypeDialogLoad(object sender, EventArgs e)
        {
            // заполнить список линий
            var w = imageListLarge.ImageSize.Width;
            var h = imageListLarge.ImageSize.Height;
            var rectWorld = new RectangleD(0, 0, w, h);
            var rectCanvas = new Rectangle(0, 0, w, h);

            var colors = new [] {Color.BlanchedAlmond, Color.GreenYellow, Color.PaleTurquoise};
            var colorIndex = 0;

            foreach (TrendLine.TrendLineStyle lineType in Enum.GetValues(typeof(TrendLine.TrendLineStyle)))
            {
                var bmp = new Bitmap(w, h);
                var line = new TrendLine();
                line.AddPoint(h * 0.23, w - 5);
                line.AddPoint(h * 0.77, 5);
                if (lineType == TrendLine.TrendLineStyle.Отрезок
                    || lineType == TrendLine.TrendLineStyle.Окружность || lineType == TrendLine.TrendLineStyle.ЛинияСМаркерами
                    || lineType == TrendLine.TrendLineStyle.ОтрезокСМаркерами)
                {
                    line.linePoints[1] = new PointD(h * 0.32, w - 16);
                    line.linePoints[0] = new PointD(h * 0.68, 16);
                }

                line.LineColor = Color.Black;
                line.ShapeFillColor = colors[colorIndex];
                line.LineStyle = lineType;
                colorIndex++;
                if (colorIndex == colors.Length)
                    colorIndex = 0;

                using (var gr = Graphics.FromImage(bmp))
                using (var brushes = new BrushesStorage())
                using (var pens = new PenStorage())
                {
                    gr.SmoothingMode = SmoothingMode.AntiAlias;
                    line.Draw(gr, rectWorld, rectCanvas, pens, brushes);
                }

                imageListLarge.Images.Add(bmp);
                var item = listView.Items.Add(lineType.ToString(),
                                              EnumFriendlyName<TrendLine.TrendLineStyle>.GetString(lineType),
                                              imageListLarge.Images.Count - 1);
                item.Tag = lineType;
                if (lineType == selectedStyle)
                    item.Selected = true;
            }

            // привязать картинки к списку
            listView.LargeImageList = imageListLarge;
            listView.SmallImageList = imageListLarge;
        }
Example #23
0
 public Image CreateSample(Size sizeHint)
 {
     var originalPoints = new List<PointF>(points);
     points.Clear();
     var centerx = sizeHint.Width / 2;
     var centery = sizeHint.Height / 2;
     var dx = sizeHint.Width / 2;
     var dy = sizeHint.Height / 2;
     var left = centerx - dx;
     var top = centery - dy;
     var width = sizeHint.Width;
     var height = sizeHint.Height;
     points.Add(new PointF(left, top));
     points.Add(new PointF(left + width, top + height));
     points.Add(new PointF(left + width / 2, top + height));
     var worldRect = new RectangleD(left - 50, top - 50, width + 100, height + 100);
     var result = new Bitmap(sizeHint.Width, sizeHint.Height);
     var brushStorage = new BrushesStorage();
     var penStorage = new PenStorage();
     DrawEllipse(Graphics.FromImage(result), worldRect, new Rectangle(new Point(0, 0), sizeHint), brushStorage,
                 penStorage, new Font(FontFamily.GenericSansSerif, 8));
     points.Clear();
     points.AddRange(originalPoints);
     return result;
 }
Example #24
0
 private void DrawGrid(Graphics g, BrushesStorage brushes)
 {
     DrawYAxisGrid(g, brushes);
     DrawXAxisGrid(g, brushes);
 }
Example #25
0
 public void DrawEllipse(Graphics g, RectangleD worldRect, Rectangle canvasRect,
     BrushesStorage brushStorage, PenStorage penStorage, Font font)
 {
     const int markerSize = 3;
     var pen = penStorage.GetPen(Color, Selected ? 3f : 1f);
     var screenPoints = new List<PointD>();
     foreach (var pt in points)
     {
         screenPoints.Add(Conversion.WorldToScreen(new PointD(pt.X, pt.Y),
                                                     worldRect, canvasRect));
     }
     foreach (var pt in screenPoints)
     {
         g.DrawRectangle(pen, (float)pt.X - markerSize, (float)pt.Y - markerSize,
                         markerSize * 2F, markerSize * 2F);
     }
     if (screenPoints.Count == 2)
     {
         g.DrawLine(pen, screenPoints[0].ToPointF(), screenPoints[1].ToPointF());
     }
     if (screenPoints.Count == 3)
     {
         // нарисовать собственно эллипс
         double newAngle;
         float newCx, newCy, newA, newB;
         correctEllipse = Geometry.GetEllipseParams(screenPoints[0].ToPointF(),
                                                         screenPoints[1].ToPointF(),
                                                         screenPoints[2].ToPointF(),
                                                         out newAngle, out newA, out newB, out newCx, out newCy);
         if (correctEllipse) // можно построить эллипс - рисуем его
         {
             a = newA;
             b = newB;
             angle = newAngle;
             cx = newCx;
             cy = newCy;
             var ellipseBezierPoints = Geometry.GetEllipseBezierPoints(newAngle, newA, newB, newCx, newCy);
             g.DrawBeziers(pen, ellipseBezierPoints);
             if (BrushAlpha > 0)
             {
                 var brush = brushStorage.GetBrush(Color.FromArgb(BrushAlpha, BrushColor));
                 g.FillClosedCurve(brush, ellipseBezierPoints);
             }
             // строить касательную
             if (BuildTangent)
                 DrawTangent(screenPoints, canvasRect, g,
                     penStorage, brushStorage, font);
         }
         else // построить эллипс по указанным координатам невозможно
         {
             g.DrawLine(pen, screenPoints[1].ToPointF(), screenPoints[2].ToPointF());
             g.DrawLine(pen, screenPoints[0].ToPointF(), screenPoints[2].ToPointF());
         }
     }
     // маркеры
     if (Selected)
         DrawComments(g, worldRect, canvasRect, penStorage, brushStorage);
 }
Example #26
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            using (var pens = new PenStorage())
            using (var brushes = new BrushesStorage())
            {
                var str = MakeDisplayedString();

                // залить прямоугольник и отрисовать границу
                var outerRectColor = Selected ? clOutlineSel[blinkCounter] : clOutline;
                var pen = pens.GetPen(outerRectColor, BookmarkDrawState == DrawState.Pressed ||
                    DragState != DragDropState.Normal ? 2 : 1);

                var brColor = brushColor[BookmarkDrawState];
                if (IsBlinking)
                    brColor = brushColor[(DrawState)blinkCounter];
                var brush = brushes.GetBrush(brColor);
                var area = new Rectangle(new Point(0, 0), new Size(Width - 1, Height - 1));
                e.Graphics.FillRectangle(brush, area);
                e.Graphics.DrawRectangle(pen, area);

                // нарисовать "тень"
                if (Selected || DragState == DragDropState.InFrame)
                {
                    var penSelected = pens.GetPen(clOutlineSel[blinkCounter]);
                    e.Graphics.DrawLine(penSelected, 1, 1, Width - 1, 1);
                    e.Graphics.DrawLine(penSelected, 1, 1, 1, Bottom - 1);
                }

                // нарисовать крестик контрастным
                if (modeEdit)
                {
                    var brushCross = brushes.GetBrush(closeBtnVisible ? clOutline : MakeContrastColor(brColor, 26));
                    var points =
                        pointsCross.Select(p => new PointF(p.X + areaCross.Left, p.Y + areaCross.Top)).ToArray();
                    e.Graphics.FillPolygon(brushCross, points);
                }

                // нарисовать картинку
                var left = TilePad;
                if (Bookmark.ShouldDrawImage && ImageList.Images.Count > Bookmark.ImageIndex && Bookmark.ImageIndex >= 0)
                {
                    e.Graphics.DrawImage(ImageList.Images[Bookmark.ImageIndex], left, (TileH - ImageSize) / 2);
                    left += (ImageSize + TilePad);
                }

                // нарисовать текст
                if (Bookmark.ShouldDrawText && str.Length > 0)
                    e.Graphics.DrawString(str,
                        Selected ? fontSelected : Font,
                        brushes.GetBrush(clOutline),
                        left, TileH/2, new StringFormat
                        {
                            LineAlignment = StringAlignment.Center
                        });
            }
        }
Example #27
0
        private void DrawLabels(Graphics g,
            BrushesStorage brushes,
            Rectangle axisRect, YAxisAlignment alignment)
        {
            var canvasRect = Owner.CanvasRect;
            var worldRect = Owner.WorldRect;
            var format = PrepareStringFormat(alignment);
            var provider = PrepareNumberFormat();
            var brush = brushes.GetBrush(TextColor);

            using (format)
            {
                var rect = new Rectangle(axisRect.Left + 5, 0, ((axisRect.Width - 5) - 5) - 1, Font.Height);
                for (double i = LabelInfo.Max; i > LabelInfo.Min; i -= LabelInfo.MajorStep)
                {
                    var tf = (PointF)Conversion.WorldToScreen(new PointD(0.0, i), worldRect, canvasRect);
                    rect.Y = ((int)tf.Y) - (Font.Height / 2);
                    double num2 = i / LabelInfo.Exponent;
                    if (axisRect.Contains(rect))
                    {
                        g.DrawString(num2.ToString("N", provider), Font, brush, rect, format);
                    }
                }
                if (CurrentPrice.HasValue)
                {
                    // рисуем текущую цену в шкале
                    DrawSelectedPriceLabel(CurrentPrice.Value,
                        brush, format, axisRect, worldRect, canvasRect, g);
                }

                if (SelectedLabelPrice.HasValue)
                {
                    // отметка цены для перекрестия
                    DrawSelectedPriceLabel(SelectedLabelPrice.Value,
                        brush, format, axisRect, worldRect, canvasRect, g);
                }
                ExponentLabel.Draw(g, axisRect, alignment);
            }
        }
Example #28
0
        public Image CreateSample(Size sizeHint)
        {
            if (points.Count < 2)
                return null;

            // готовим данные для миниатюры
            var rangeX = (int) Math.Round(points[1].X - points[0].X);
            if (rangeX < 1)
                rangeX = 1;
            var projections = new[]
                {
                    new FiboSpanProjection
                        {
                            AckDegree = 1,
                            Index = (int) (points[1].X + 0.5) + rangeX
                        },
                    new FiboSpanProjection
                        {
                            AckDegree = 2,
                            Index = (int) (points[1].X + 0.5) + rangeX * 2
                        },
                    new FiboSpanProjection
                        {
                            AckDegree = 3,
                            Index = (int) (points[1].X + 0.5) + rangeX * 3
                        }
                };

            // рисуем
            var minX = points.Select(p => p.X).Min();
            var minY = points.Select(p => p.Y).Min();
            var maxX = points.Select(p => p.X).Max();
            var maxY = points.Select(p => p.Y).Max();
            foreach (var projection in projections)
                if (projection.Index > maxX)
                    maxX = projection.Index;
            rangeX = (int)(maxX - minX);
            var rangeY = maxY - minY;
            minX-= rangeX / 10;
            maxX += rangeX / 10;
            minY -= rangeY / 10;
            maxY += rangeY / 10;
            var worldRect = new RectangleD(minX, minY, maxX - minX, maxY - minY);
            var brushStorage = new BrushesStorage();
            var brush = brushStorage.GetBrush(Color.White);
            var penStorage = new PenStorage();
            var canvasRect = new Rectangle(new Point(0, 0), sizeHint);
            var result = new Bitmap(sizeHint.Width, sizeHint.Height);
            var g = Graphics.FromImage(result);
            ownerSeries.DrawSpan(g, worldRect, canvasRect, this, brush, penStorage);
            foreach (var projection in projections)
            {
                ownerSeries.DrawProjection(g, worldRect, canvasRect, projection, brush,
                                           new Font(FontFamily.GenericSansSerif, 8), penStorage, brushStorage);
            }
            return result;
        }
Example #29
0
 private void DrawXAxisGrid(Graphics g, BrushesStorage brushes)
 {
     Rectangle canvasRect = Owner.CanvasRect;
     RectangleD worldRect = Owner.WorldRect;
     GraphicsState gstate = g.Save();
     g.SetClip(canvasRect);
     if ((Chart.XAxis.GridLineVisible || Chart.XAxis.GridBandVisible) &&
         (Chart.XAxis.Grid.Count > 0))
     {
         var pen = new Pen(Chart.XAxis.GridLineColor);
         var brush = brushes.GetBrush(Chart.XAxis.GridBandColor);
         pen.DashStyle = (DashStyle)Enum.Parse(typeof(DashStyle), Chart.XAxis.GridLineStyle.ToString());
         using (pen)
         {
             bool flag = true;
             XAxisLabelInfo info;
             for (int i = 0; i < Chart.XAxis.Grid.Count; i++)
             {
                 info = (XAxisLabelInfo)Chart.XAxis.Grid[i];
                 var tf = (PointF)Conversion.WorldToScreen(new PointD(info.X, 0.0), worldRect, canvasRect);
                 if (Chart.XAxis.GridBandVisible)
                 {
                     if (flag)
                     {
                         PointF tf2;
                         if (i != (Chart.XAxis.Grid.Count - 1))
                         {
                             var info2 = (XAxisLabelInfo)Chart.XAxis.Grid[i + 1];
                             tf2 =
                                 (PointF)
                                 Conversion.WorldToScreen(new PointD(info2.X, 0.0), worldRect, canvasRect);
                         }
                         else
                         {
                             tf2 = new PointF(canvasRect.Right, canvasRect.Top);
                         }
                         g.FillRectangle(brush, tf.X, 0f, tf2.X - tf.X, canvasRect.Height);
                     }
                     else if ((i == 0) && (tf.X > canvasRect.Left))
                     {
                         g.FillRectangle(brush, canvasRect.Left, 0f, tf.X - canvasRect.Left,
                                         canvasRect.Height);
                     }
                     flag = !flag;
                 }
                 if (Chart.XAxis.GridLineVisible)
                 {
                     g.DrawLine(pen, tf.X, 0f, tf.X, (canvasRect.Height - 1));
                 }
             }
         }
     }
     g.Restore(gstate);
 }
Example #30
0
        public void DrawProjection(Graphics g, RectangleD worldRect, Rectangle canvasRect, FiboSpanProjection proj, 
            Brush brushWhite, Font font, PenStorage penStorage, BrushesStorage brushes)
        {
            // нижняя точка
            var projLow = Conversion.WorldToScreen(new PointD(proj.Index, 0), worldRect, canvasRect);
            projLow.Y = canvasRect.Bottom;
            // верхняя точка
            PointD projHigh = proj.UpperPrice.HasValue
                ? Conversion.WorldToScreen(new PointD(proj.Index, proj.UpperPrice.Value), worldRect, canvasRect)
                : new PointD(projLow.X, canvasRect.Top);

            var dashStyle = proj.AckDegree == 1 ? DashStyle.Dash : DashStyle.Solid;
            var pen = penStorage.GetPen(proj.Color, 1, dashStyle);

            g.DrawLine(pen, (float)projLow.X, (float)projLow.Y, (float)projHigh.X, (float)projHigh.Y);

            if (proj.AckDegree > 1)
            {// показать степень подтверждения
                const int textOffset = 37;
                const int textSize = 18, textSize2 = 9;
                g.FillEllipse(brushWhite, (float)projLow.X - textSize2, (float)projLow.Y - textOffset - textSize2,
                    textSize, textSize);
                g.DrawEllipse(pen, (float)projLow.X - textSize2, (float)projLow.Y - textOffset - textSize2,
                    textSize, textSize);
                var text = proj.AckDegree.ToString();
                var textSz = g.MeasureString(text, Chart.Font);
                var textLeft = (float) projLow.X - textSz.Width/2;
                var textTop = (float) projLow.Y - textSz.Height/2 - textOffset;

                var brush = brushes.GetBrush(proj.Color);
                g.DrawString(text, font, brush, textLeft, textTop);

                textTop += (textSize + 4);
                var timeStr = Chart.StockSeries.GetCandleOpenTimeByIndex(proj.Index).ToString("dd MMM HH:ss");
                textSz = g.MeasureString(timeStr, Chart.Font);
                textLeft = (float) projLow.X - textSz.Width/2;

                g.FillRectangle(brushWhite, textLeft - 2, textTop - 2, textSz.Width + 4, textSz.Height + 3);
                g.DrawRectangle(pen, textLeft - 2, textTop - 2, textSz.Width + 4, textSz.Height + 3);
                g.DrawString(timeStr, Chart.Font, brush, textLeft, textTop);
            }
        }
Example #31
0
 private void DrawYAxisGrid(Graphics g, BrushesStorage brushes)
 {
     if (GridLineVisible || GridBandVisible)
     {
         Rectangle canvasRect = Owner.CanvasRect;
         RectangleD worldRect = Owner.WorldRect;
         var pen = new Pen(GridLineColor);
         var brush = brushes.GetBrush(GridBandColor);
         pen.DashStyle = (DashStyle)Enum.Parse(typeof(DashStyle), GridLineStyle.ToString());
         using (pen)
         {
             var ef =
                 (SizeF)Conversion.WorldToScreen(new SizeD(0.0, LabelInfo.MajorStep), worldRect, canvasRect);
             float left = canvasRect.Left;
             float right = canvasRect.Right;
             right = (right < left) ? left : right;
             double max = LabelInfo.Max;
             bool flag = true;
             while (max > LabelInfo.Min)
             {
                 var tf = (PointF)Conversion.WorldToScreen(new PointD(0.0, max), worldRect, canvasRect);
                 if ((GridBandVisible && (GridBandColor != Color.Empty)) && flag)
                 {
                     g.FillRectangle(brush, canvasRect.Left, tf.Y, canvasRect.Width, ef.Height);
                 }
                 if (GridLineVisible)
                 {
                     g.DrawLine(pen, left, tf.Y, right, tf.Y);
                 }
                 flag = !flag;
                 max -= LabelInfo.MajorStep;
             }
         }
     }
 }