Exemplo n.º 1
0
        private void DrawLevel(LevelSeriesItem l, Graphics g, RectangleD worldRect, Rectangle canvasRect)
        {
            using (var brushFont = new SolidBrush(Color.Black))
            {
                using (var brushSign = new SolidBrush(l.Color))
                {
                    using (var pen = new Pen(l.Color))
                    {
                        int    x1 = canvasRect.Left;
                        int    x2 = canvasRect.Right;
                        PointD p1 = Conversion.WorldToScreen(new PointD(0, (double)l.Price),
                                                             worldRect, canvasRect);
                        var y       = (int)p1.Y;
                        var textSz  = g.MeasureString(l.Title, Chart.Font);
                        var textW2  = (int)textSz.Width / 2;
                        var textH2  = (int)textSz.Height / 2;
                        var centerX = (x1 + x2) / 2;

                        if (l.TextDirection == LevelSeriesItem.Direction.Left)
                        {
                            DrawRectangle(pen, g, x1, y - textH2 - 2, (int)textSz.Width + 4,
                                          (int)textSz.Height + 4);
                            g.DrawString(l.Title, Chart.Font, brushFont, x1 + 2, y - textH2);
                            g.DrawLine(pen, textSz.Width + 4, y, x2, y);
                            DrawSign(pen, brushSign, g, x2 - 6, y, l.Side);
                            return;
                        }

                        if (l.TextDirection == LevelSeriesItem.Direction.Right)
                        {
                            DrawRectangle(pen, g, x2 - (int)textSz.Width - 4, y - textH2 - 2,
                                          (int)textSz.Width + 4, (int)textSz.Height + 4);
                            g.DrawString(l.Title, Chart.Font, brushFont, x2 - textSz.Width - 2, y - textH2);
                            g.DrawLine(pen, x1, y, x2 - textSz.Width - 4, y);
                            DrawSign(pen, brushSign, g, x1 + 6, y, l.Side);
                            return;
                        }

                        if (l.TextDirection == LevelSeriesItem.Direction.Middle)
                        {
                            DrawRectangle(pen, g, centerX - textW2 - 2, y - textH2 - 2,
                                          (int)textSz.Width + 4, (int)textSz.Height + 4);
                            g.DrawString(l.Title, Chart.Font, brushFont, centerX - textW2, y - textH2);
                            g.DrawLine(pen, x1, y, centerX - textW2 - 2, y);
                            g.DrawLine(pen, centerX + textW2 + 2, y, x2, y);
                            DrawSign(pen, brushSign, g, x1 + 6, y, l.Side);
                            DrawSign(pen, brushSign, g, x2 - 6, y, l.Side);
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void DrawLevel(LevelSeriesItem l, Graphics g, RectangleD worldRect, Rectangle canvasRect)
        {
            using (var brushFont = new SolidBrush(Color.Black))
            {
                using (var brushSign = new SolidBrush(l.Color))
                {
                    using (var pen = new Pen(l.Color))
                    {
                        int x1 = canvasRect.Left;
                        int x2 = canvasRect.Right;
                        PointD p1 = Conversion.WorldToScreen(new PointD(0, (double) l.Price),
                                                             worldRect, canvasRect);
                        var y = (int) p1.Y;
                        var textSz = g.MeasureString(l.Title, Chart.Font);
                        var textW2 = (int) textSz.Width/2;
                        var textH2 = (int) textSz.Height/2;
                        var centerX = (x1 + x2)/2;

                        if (l.TextDirection == LevelSeriesItem.Direction.Left)
                        {
                            DrawRectangle(pen, g, x1, y - textH2 - 2, (int) textSz.Width + 4,
                                          (int) textSz.Height + 4);
                            g.DrawString(l.Title, Chart.Font, brushFont, x1 + 2, y - textH2);
                            g.DrawLine(pen, textSz.Width + 4, y, x2, y);
                            DrawSign(pen, brushSign, g, x2 - 6, y, l.Side);
                            return;
                        }

                        if (l.TextDirection == LevelSeriesItem.Direction.Right)
                        {
                            DrawRectangle(pen, g, x2 - (int) textSz.Width - 4, y - textH2 - 2,
                                          (int) textSz.Width + 4, (int) textSz.Height + 4);
                            g.DrawString(l.Title, Chart.Font, brushFont, x2 - textSz.Width - 2, y - textH2);
                            g.DrawLine(pen, x1, y, x2 - textSz.Width - 4, y);
                            DrawSign(pen, brushSign, g, x1 + 6, y, l.Side);
                            return;
                        }

                        if (l.TextDirection == LevelSeriesItem.Direction.Middle)
                        {
                            DrawRectangle(pen, g, centerX - textW2 - 2, y - textH2 - 2,
                                          (int) textSz.Width + 4, (int) textSz.Height + 4);
                            g.DrawString(l.Title, Chart.Font, brushFont, centerX - textW2, y - textH2);
                            g.DrawLine(pen, x1, y, centerX - textW2 - 2, y);
                            g.DrawLine(pen, centerX + textW2 + 2, y, x2, y);
                            DrawSign(pen, brushSign, g, x1 + 6, y, l.Side);
                            DrawSign(pen, brushSign, g, x2 - 6, y, l.Side);
                            return;
                        }
                    }
                }
            }
        }