public void Draw(Font font, Graphics g, RectangleD worldRect, Rectangle canvasRect, PenStorage penStorage, BrushesStorage brushStorage) { var strFormat = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; var pen = penStorage.GetPen(Color.FromArgb(Transparency, ColorLine), Selected ? 3f : 1f); var brush = brushStorage.GetBrush(Color.FromArgb(Transparency, ColorFill)); var brushText = brushStorage.GetBrush(Color.FromArgb(Transparency, ColorText)); var ptCenter = Conversion.WorldToScreen(new PointD(CandleIndex, Price), worldRect, canvasRect); screenX = ptCenter.X; screenY = ptCenter.Y; DrawShape(g, brush, ptCenter, pen); // значок g.DrawString(Sign, font, brushText, (float)ptCenter.X, (float)ptCenter.Y, strFormat); // маркеры if (Selected) { foreach (var marker in markers) { marker.CalculateScreenCoords(worldRect, canvasRect); marker.Draw(g, penStorage, brushStorage); } } }
public Image CreateSample(Size sizeHint) { if (sizeHint.IsEmpty) { return(null); } var result = new Bitmap(sizeHint.Width, sizeHint.Height); var g = Graphics.FromImage(result); var brushStorage = new BrushesStorage(); var penStorage = new PenStorage(); var pen = penStorage.GetPen(Color.FromArgb(Transparency, ColorLine)); var brush = brushStorage.GetBrush(Color.FromArgb(Transparency, ColorFill)); var brushText = brushStorage.GetBrush(Color.FromArgb(Transparency, ColorText)); var ptCenter = new PointD(sizeHint.Width / 2.0, sizeHint.Height / 2.0); DrawShape(g, brush, ptCenter, pen); // значок var strFormat = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; g.DrawString(Sign, new Font(FontFamily.GenericSansSerif, 8), brushText, (float)ptCenter.X, (float)ptCenter.Y, strFormat); return(result); }
/// <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); }
/// <summary> /// нарисовать на истории полоски гэпов /// </summary> private void DrawGaps(Graphics g, BrushesStorage brushes) { if (gaps.Count == 0) { return; } var widthPx = barBounds.Width - 2; if (widthPx == 0) { return; } var br = brushes.GetBrush(clHistOk); g.FillRectangle(br, barBounds.Left + 1, barBounds.Top + 1, barBounds.Width - 1, barBounds.Height - 1); // пересчитать модельные координаты в координаты времени, // заодно склеив соседние var startTick = Interval.a.Ticks; var endTick = Interval.b.Ticks; var widthTics = endTick - startTick; var intervalsPx = new List <GapIntPx>(); GapIntPx?lastPoint = null; var gapsCopy = gaps.ToArray(); foreach (var gap in gapsCopy) { var gapStartPx = (gap.start.Ticks - startTick) * widthPx / widthTics; var gapEndPx = (gap.end.Ticks - startTick) * widthPx / widthTics; var color = clGap[(int)gap.status]; if (lastPoint.HasValue) { if (lastPoint.Value.end >= gapStartPx && lastPoint.Value.color == color) { intervalsPx[intervalsPx.Count - 1] = new GapIntPx(lastPoint.Value.start, gapEndPx, color); continue; } } lastPoint = new GapIntPx(gapStartPx, gapEndPx == gapStartPx ? gapStartPx + 1 : gapEndPx, color); intervalsPx.Add(lastPoint.Value); } // отобразить foreach (var inter in intervalsPx) { var brushGap = brushes.GetBrush(inter.color); g.FillRectangle(brushGap, inter.start + barLeft + 1, barBounds.Top + 1, (inter.end - inter.start), barBounds.Height - 1); } }
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 }); } }
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; } } } }
private void DrawFrame(Graphics g, BrushesStorage brushes, PenStorage pens) { var brMain = brushes.GetBrush(SystemColors.ControlText); var cy = Height / 2; // текст (название тикера) var fmt = new StringFormat { LineAlignment = StringAlignment.Center }; g.DrawString(Ticker, font, brMain, padding, cy, fmt); // область истории var barRight = Width - padding - imageCancel.Width - padding; var barWd = barRight - barLeft; if (barWd < 0) { barWd = 0; } barBounds = new Rectangle(barLeft, cy - barHeight / 2, barWd, barHeight); if (barWd == 0) { return; } // рамка g.DrawRectangle(pens.GetPen(SystemColors.ControlText), barBounds); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); spreadIndicator.Draw(e.Graphics, brushes); leftButton.Draw(e.Graphics); rightButton.Draw(e.Graphics); Brush tickerBrush = null; //Отрисовываем шапку контрола switch (currentDragDropState) { case DragDropState.Normal: tickerBrush = brushes.GetBrush(Color.Black); break; case DragDropState.Washy: tickerBrush = brushes.GetBrush(Color.FromArgb(100, Color.DarkGray)); break; case DragDropState.InFrame: e.Graphics.DrawRectangle(pens.GetPen(Color.Black), PaddingLeftRightProportion / 2 * scaleX, PaddingBottonProportion, Width - PaddingLeftRightProportion * scaleX, CalculatedHaderHeight); tickerBrush = brushes.GetBrush(Color.Black); break; default: tickerBrush = brushes.GetBrush(Color.Black); break; } //Отрисовываем заголовок валютной пары if (tickerBrush != null) { e.Graphics.DrawString(Ticker, new Font("Times New Roman", Height < Width ? 1 + Height / 9 : Width / 9, FontStyle.Bold), tickerBrush, PaddingBottonProportion, 0); } //Отрисовываем кнопку закрытия var buttonCloseScale = scaleX < scaleY ? scaleX : scaleY; btnClose.Location = new Point(Convert.ToInt32((QuotePartButtonFigure.OriginalWidth * 2 - PaddingLeftRightProportion / 2 - PaddingRightButtonCloseProportion) * scaleX), Convert.ToInt32(2f * scaleY)); btnClose.Size = new Size(Convert.ToInt32(ButtonCloseSizeProportion * buttonCloseScale), Convert.ToInt32(ButtonCloseSizeProportion * buttonCloseScale)); }
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); } switch (ShipsDrawMode) { case ShipsDrawMode.None: break; case ShipsDrawMode.Default: DrawOrderShip(format, axisRect, worldRect, canvasRect, g); //Рисуем кораблики к открытым сделкам break; case ShipsDrawMode.Average: DrawAverageOrderShip(format, axisRect, worldRect, canvasRect, g); //Рисуем кораблики средних значений к открытым сделкам break; default: throw new ArgumentOutOfRangeException(nameof(ShipsDrawMode)); } ExponentLabel.Draw(g, axisRect, alignment); } }
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) }; }
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); }
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); }
private void DrawBackground(Graphics g, BrushesStorage brushes) { if (Chart == null || Chart.StockPane == null || Owner == null || Chart.Owner == null || brushes == null || Chart.visualSettings == null) { return; } using (var brush = brushes.GetBrush(Chart.visualSettings.PaneBackColor)) { g.FillRectangle(brush, 0, 0, Width, Height); } // нарисовать логотипчик if (bitmapBackgr != null && Math.Min(Width, Height) > MinSizeToDrawLogo) { g.DrawImage(bitmapBackgr, BackgroundShiftX, BackgroundShiftY, bitmapBackgr.Width, bitmapBackgr.Height); } // подписать окно (только для StockPane) if (this == Chart.StockPane) { var text = Chart.Symbol + " " + Chart.Owner.timeframeString; using (var brush = brushes.GetBrush(Chart.visualSettings.SeriesForeColor)) { g.DrawString(text, Chart.Font, brush, 3, 3); } } if (string.IsNullOrEmpty(BackgroundTitleText)) { return; } using (var f = new Font(FontFamily.GenericSansSerif, 16, FontStyle.Bold)) { using (var brText = brushes.GetBrush(Chart.visualSettings.PaneFrameTextColor)) { g.DrawString(BackgroundTitleText, f, brText, BackgroundTitleShiftX, BackgroundTitleShiftY); } } }
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); } } }
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); } }
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); }
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); } }
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); } } }
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); }
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); } }
/// <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)); }
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 }); } } }
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); } } }
public void DrawComment( Graphics g, FontStorage fonts, RectangleD worldRect, Rectangle canvasRect, PenStorage penStorage, BrushesStorage brushStorage, List <Rectangle> areasToCheck) { var oldMode = g.SmoothingMode; g.SmoothingMode = /*SmoothingMode.AntiAlias : */ SmoothingMode.None; try { var brush = brushStorage.GetBrush(Color.FromArgb(FillTransparency, ColorFill)); // нормализовать угол стрелки var arrowAngle = GetNormalizedArrowAngle(); while (arrowAngle < 0) { arrowAngle = Math.PI * 2 + arrowAngle; } // точка привязки PointD ptPivot = Conversion.WorldToScreen(new PointD(PivotIndex, PivotPrice), worldRect, canvasRect); // вторая точка стрелки var ptEnd = new PointD(ptPivot.X + ArrowLength * Math.Cos(arrowAngle), ptPivot.Y + ArrowLength * Math.Sin(arrowAngle)); var commentText = string.IsNullOrEmpty(Text) ? "" : Text; var color = Color; commentText = GetColorByComment(commentText, ref color); ReplaceTextPatterns(); var dashStyle = IsBeingCreated ? DashStyle.Dash : DashStyle.Solid; var pen = penStorage.GetPen(color, Selected ? 3f : 1f, dashStyle); // посчитать координаты текста float top, left, width, height; GetTextAreaLeftTop(g, fonts, commentText, arrowAngle, ptEnd, out left, out top, out width, out height); // проверить пересечение с комментом if (areasToCheck != null) { var rectOwn = new Rectangle((int)top, (int)left, (int)width, (int)height); if (areasToCheck.Any(a => a.IntersectsWith(rectOwn))) { return; } areasToCheck.Add(rectOwn); } // нарисовать область с текстом if (!HideBox) { DrawTextArea(pen, g, brush, left, top, width, height); } // .. и сам текст DrawTextOrSymbol(commentText, brushStorage, fonts, ColorText, g, left, top, width, height); TextArea = new Rectangle((int)left + canvasRect.Left, (int)top, (int)width, (int)height); // нарисовать стрелку if (!HideArrow) { PointD pointArrowEnd; List <PointF> arrowPoints = GetArrowPoints(arrowAngle, ptPivot, out pointArrowEnd); // нарисовать палку g.DrawLine(pen, (float)pointArrowEnd.X, (float)pointArrowEnd.Y, (float)ptEnd.X, (float)ptEnd.Y); // нарисовать стрелочку g.FillPolygon(brush, arrowPoints.ToArray()); g.DrawPolygon(pen, arrowPoints.ToArray()); } // маркеры if (Selected) { DrawMarkers(g, worldRect, canvasRect); } } finally { g.SmoothingMode = oldMode; } }
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); } }
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); }
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; }
private void DrawBackgr(Graphics g, BrushesStorage brushes) { var br = brushes.GetBrush(SystemColors.Control); g.FillRectangle(br, 0, 0, Width, Height); }