Exemplo n.º 1
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)
                             };
        }
Exemplo n.º 2
0
 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);
         }
     }
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
        public virtual void Draw(Graphics g, BrushesStorage brushes, PenStorage pens)
        {
            var images = buttonImage[key];

            // нарисовать подложку и обводку
            if (State == ImageState.Pressed)
            {
                var brush =
                    brushes.GetBrush(Color.FromArgb(128, ColorThemeIndex == 0 ? Color.Black : Color.White));
                g.FillRectangle(brush, Position.X, Position.Y, Size.Width - 1, Size.Height - 1);
            }
            if (State == ImageState.Highlighted || State == ImageState.Pressed)
            {
                var pen = pens.GetPen(ColorThemeIndex == 0 ? Color.Black : Color.White);
                g.DrawRectangle(pen, Position.X, Position.Y, Size.Width - 1, Size.Height - 1);
            }

            // нарисовать картинку
            var img = images.images[ColorThemeIndex, imageIndex];
            var padding = (Size.Width - img.Width) / 2;
            g.DrawImage(img, Position.X + padding, Position.Y + padding, img.Width, img.Height);
        }
Exemplo n.º 5
0
 public void Draw(Graphics g, PenStorage penDic, float penWidth)
 {
     foreach (Polyline poly in lines)
     {
         if (poly.GetType() == typeof(Polygone))
         {
             g.FillPolygon(new SolidBrush(Color.FromArgb(alpha, ((Polygone)poly).FillColor)),
                           poly.points);
             g.DrawPolygon(penDic.GetPen(poly.LineColor, penWidth), poly.points);
         }
         else
             g.DrawLines(penDic.GetPen(poly.LineColor, penWidth), poly.points);
     }
 }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// нарисовать заголовочек и контрол - содержимое
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // заголовочек
            var rectHr = new Rectangle(0, 0, Width, HeaderHeight);
            e.Graphics.FillRectangle(SystemBrushes.ButtonFace, rectHr);
            e.Graphics.DrawLine(SystemPens.ButtonShadow, 0, HeaderHeight - 1, Width - 1, HeaderHeight - 1);
            e.Graphics.DrawLine(SystemPens.ButtonShadow, Width - 1, HeaderHeight - 1, Width - 1, 0);
            e.Graphics.DrawLine(SystemPens.ButtonHighlight, 0, 0, Width - 1, 0);
            e.Graphics.DrawLine(SystemPens.ButtonHighlight, 0, 0, 0, HeaderHeight - 1);

            // текст заголовка
            var textWidth = pictograms[0].area.Left - PaddingPictogram - PaddingText;
            if (textWidth > 0)
            {
                e.Graphics.DrawString(Title, fontTitle, SystemBrushes.ControlText, PaddingText, HeaderHeight / 2,
                    new StringFormat { LineAlignment = StringAlignment.Center });
            }

            // пиктограммы
            using (var pens = new PenStorage())
            foreach (var pict in pictograms)
            {
                pict.Draw(e.Graphics, pens);
            }
        }
Exemplo n.º 10
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);
     }
 }
Exemplo n.º 11
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);
     }
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
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
                                 });
            }
        }
Exemplo n.º 14
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);
     }
 }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
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);
         }
     }
 }
Exemplo n.º 17
0
 public void Draw(Graphics g, PenStorage penDic)
 {
     Draw(g, penDic, 1);
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
0
        public void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect,
            Brush brush, Font fnt, PenStorage penStorage, 
            bool doDrawText)
        {
            spansProjScreenCoords.Clear();
            rectanglesTextScreenCoords.Clear();

            var pen = penStorage.GetPen(Color, Selected ? 2f : 1f, DashStyle.Dot);
            var screenPoints = points.Select(point =>
                Conversion.WorldToScreen(new PointD(point.a, point.b), worldRect, canvasRect)).ToList();

            // сохранить координаты начального отрезка (для проверки попадания)
            if (screenPoints.Count > 1)
                spanBaseScreenCoords = new Cortege2<Point, Point>(screenPoints[0].ToPoint(), screenPoints[1].ToPoint());

            // соединить
            if (Completed && HideLine == false)
                g.DrawLine(pen, (float)screenPoints[0].X, (float)screenPoints[0].Y,
                            (float)screenPoints[1].X, (float)screenPoints[1].Y);
            // нарисовать кружки
            foreach (var point in screenPoints)
            {
                g.FillEllipse(brush, (float)point.X - 3, (float)point.Y - 3, 6, 6);
                g.DrawEllipse(pen, (float)point.X - 3, (float)point.Y - 3, 6, 6);
            }

            // нарисовать проекции
            if (points.Count < 2 || points[0].b == points[1].b || pricesProj == null) return;

            visibleParts = new List<ProjectionLinePart>();
            if (IsExtension)
            {
                foreach (var price in pricesProj)
                {
                    visibleParts.Add(new ProjectionLinePart(StartIndex,
                                                            EndIndex, price));
                }
            }
            if (IsCorrection)
            {
                foreach (var price in pricesCorr)
                {
                    visibleParts.Add(new ProjectionLinePart(StartIndex,
                                                            EndIndex, price));
                }
            }

            // скрыть "лишние" кусочки
            if (HideFarParts) DoHideFarParts(visibleParts);

            foreach (var part in visibleParts)
            {
                var ptScrLeft = Conversion.WorldToScreen(new PointD(part.left,
                                                                part.price), worldRect, canvasRect);
                var ptScrRight = Conversion.WorldToScreen(new PointD(part.right,
                                                                part.price), worldRect, canvasRect);
                part.x1 = (float)ptScrLeft.X;
                part.y1 = (float)ptScrLeft.Y;
                part.x2 = (float)ptScrRight.X;
                part.y2 = (float)ptScrRight.Y;
                g.DrawLine(pen, (float)ptScrLeft.X, (float)ptScrLeft.Y, (float)ptScrRight.X, (float)ptScrRight.Y);
                // сохранить координаты
                spansProjScreenCoords.Add(new Cortege2<Point, Point>(
                    new Point((int)ptScrLeft.X, (int)ptScrLeft.Y),
                    new Point((int)ptScrRight.X, (int)ptScrRight.Y)));
            }

            if (doDrawText)
            {
                using (var fontBrush = new SolidBrush(Color))
                {
                    var strFormat = new StringFormat { LineAlignment = StringAlignment.Center };
                    foreach (var part in visibleParts)
                    {
                        if (part.left == part.right) continue;
                        var priceStr = part.price.ToStringUniformPriceFormat(false);
                        var textSz = g.MeasureString(priceStr, fnt);
                        if (Markers == MarkerPlacement.Слева ||
                            Markers == MarkerPlacement.ДвеМетки)
                        {
                            g.DrawString(priceStr, fnt, fontBrush, part.x1 - textSz.Width - 2, part.y1, strFormat);
                            rectanglesTextScreenCoords.Add(new Rectangle((int)(part.x1 - textSz.Width - 2), (int)(part.y1 - textSz.Height / 2),
                                (int)textSz.Width, (int)textSz.Height));
                        }
                        if (Markers == MarkerPlacement.Справа ||
                            Markers == MarkerPlacement.ДвеМетки)
                        {
                            g.DrawString(priceStr, fnt, fontBrush, part.x2 + 2, part.y2, strFormat);
                            rectanglesTextScreenCoords.Add(new Rectangle((int)(part.x2 + 2), (int)(part.y2 - textSz.Height / 2),
                                (int)textSz.Width, (int)textSz.Height));
                        }
                    }
                }
            }
            if (Selected)
                DrawMarkers(g, worldRect, canvasRect);
        }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
0
 private void DrawPairs(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 {
     using (var brush = new SolidBrush(Color.White))
     using (var fnt = new Font(Chart.Font.FontFamily, fontSize))
     using (var penStorage = new PenStorage())
     {
         foreach (var pair in data)
         {
             pair.Draw(g, worldRect, canvasRect, brush, fnt, penStorage, DrawText);
         }
     }
 }
Exemplo n.º 22
0
        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;
        }
Exemplo n.º 23
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
                        });
            }
        }
Exemplo n.º 24
0
 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);
         }
     }
 }
Exemplo n.º 25
0
            public void Draw(Graphics g, PenStorage pens)
            {
                var oldMode = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.AntiAlias;

                var pen =
                    pens.GetPen(state == DrawState.Normal
                            ? colorNormal
                            : state == DrawState.Hovered ? colorHovered : colorPressed, 0.7f);

                g.DrawPolygon(pen, figurePoints.Select(p => new Point(p.X + area.Left, p.Y + area.Top)).ToArray());

                g.SmoothingMode = oldMode;
            }
Exemplo n.º 26
0
 public Image CreateSample(Size sizeHint)
 {
     var result = new Bitmap(sizeHint.Width, sizeHint.Height);
     var g = Graphics.FromImage(result);
     var pens = new PenStorage();
     var brushes = new BrushesStorage();
     var worldRect = new RectangleD(StartIndex - 1, Price * 0.9, EndIndex + 1, Price * 1.1);
     Draw(g, pens, brushes, worldRect, new Rectangle(new Point(0, 0), sizeHint),
          new Font(FontFamily.GenericSansSerif, 8));
     return result;
 }
Exemplo n.º 27
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);
                }
            }
        }
Exemplo n.º 28
0
        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;
        }
Exemplo n.º 29
0
 public void DrawSpan(Graphics g, RectangleD worldRect, Rectangle canvasRect, 
     FiboSpan span, Brush brushWhite, PenStorage penStorage)
 {
     if (span.points.Count == 0) return;
     var pen = penStorage.GetPen(span.Color);
     var ptA = Conversion.WorldToScreen(new PointD(span.points[0].X, span.points[0].Y),
                                                         worldRect, canvasRect);
     if (span.points.Count == 2)
     {
         var ptB = Conversion.WorldToScreen(new PointD(span.points[1].X, span.points[1].Y),
                                                         worldRect, canvasRect);
         g.DrawLine(pen, ptA.ToPointF(), ptB.ToPointF());
         DrawMarker(g, pen, brushWhite, ptB);
     }
     DrawMarker(g, pen, brushWhite, ptA);
 }
Exemplo n.º 30
0
        public void Draw(Graphics g, PenStorage pens, BrushesStorage brushes,
            RectangleD worldRect, Rectangle canvasRect, Font font)
        {
            var ptA = Conversion.WorldToScreen(new PointD(StartIndex, Price),
                    worldRect, canvasRect);
            var ptB = Conversion.WorldToScreen(new PointD(EndIndex, Price),
                worldRect, canvasRect);
            // линия
            var pen = pens.GetPen(LineColor, LineWidth);
            g.DrawLine(pen, (float)ptA.X, (float)ptA.Y, (float)ptB.X, (float)ptB.Y);
            // текст
            if (string.IsNullOrEmpty(TextLeft) && string.IsNullOrEmpty(TextRight)) return;

            const int textOffsetPx = 2;
            var brush = brushes.GetBrush(LineColor);
            var fmt = new StringFormat
                       { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center };
            if (!string.IsNullOrEmpty(TextLeft))
                g.DrawString(TextLeft, font, brush, (float) ptA.X - textOffsetPx,
                                (float) ptA.Y, fmt);
            if (!string.IsNullOrEmpty(TextRight))
            {
                fmt.Alignment = StringAlignment.Near;
                g.DrawString(TextRight, font, brush, (float) ptB.X + textOffsetPx,
                                (float) ptB.Y, fmt);
            }
        }