public static RectanglePaint operator +(RectanglePaint r1, RectanglePaint r2) { RectanglePaint res = new RectanglePaint(); res.X = r1.X < r2.X ? r1.X : r2.X; res.Y = r1.Y < r2.Y ? r1.Y : r2.Y; res.Width = r1.X + r1.Width > r2.X + r2.Width ? r1.X + r1.Width - res.X : r2.X + r2.Width - res.X; res.Height = r1.X + r1.Height > r2.Y + r2.Height ? r1.Y + r1.Height - res.Y : r2.Y + r2.Height - res.Y; return(res); }
private void PaintOneLevel(Graphics canvas, Rectangle rectPaint, decimal Value, int index) { rectPaint = RectanglePaint.DeleteRight(rectPaint, new Rectangle(0, 0, this.PanelValues.WidthBorder, 0)); int Y1 = GraphicShape.GetCoordinate(rectPaint.Height, this.Max, this.Min, Value > 0 ? Value : 0); int Y2 = GraphicShape.GetCoordinate(rectPaint.Height, this.Max, this.Min, Value < 0 ? Value : 0); int bodyX = (int)(rectPaint.Width - this.WidthOneLevel * index); int bodyY = rectPaint.Y + Y1; int bodyWidth = this.WidthOneLevel - 2; //-2 чтобы свечки не слипались int bodyHeight = Y2 - Y1; //bodyHeight = bodyHeight - bodyY; bodyHeight = bodyHeight == 0 ? bodyHeight + 1 : bodyHeight; GraphicShape.PaintRectangle(canvas, bodyX, bodyY, bodyWidth, bodyHeight, Color.Black, Value < 0 ? Color.Red : Color.Green); }
/// <summary>Отрисовка всего графика </summary> /// <param name="graphic">Полотно</param> public void Paint(Graphics graphic, Rectangle rectPaint) { this.Canvas = graphic; if (this.PanelCandels.CollectionCandle.IsNull() || this.PanelCandels.CollectionCandle.ToArray().Length == 0) { return; } this.GetMinMax(); //Гор. объемы this.CalculateHorVolumeForPanel(); ///Нижняя временная шкала var BottomRectForTimeLine = RectanglePaint.GetBottom(rectPaint, 20); RectAllTop = RectanglePaint.DeleteBottom(rectPaint, BottomRectForTimeLine); //Получение области для нижних объемов var BottomRectForVol = RectanglePaint.GetBottom(RectAllTop, 50); RectAllTop = RectanglePaint.DeleteBottom(RectAllTop, BottomRectForVol); PanelPrices.CurrentValue = PanelCandels.CollectionCandle.ElementAt(0).Close; PanelPrices.WidthBorder = 60; //Ширина области рисования PanelPrices.RectPaint = RectAllTop; //Прям. область рисования PanelPrices.minStepPrice = this.MinStepPrice; //Шаг цены //Получаем правую область для шкалы с ценами var rectForPrices = RectanglePaint.GetRight(RectAllTop, PanelPrices.WidthBorder); //Получаем область для свечек из общей верхней области. var RectCandle = RectanglePaint.DeleteRight(RectAllTop, rectForPrices); //Получаем правую область для шкалы с гор. объемами (РАЗНИЦА) var RectForDiffHVolumes = RectanglePaint.GetRight(RectCandle, 70); //Получаем область для свечек из общей верхней области. RectCandle = RectanglePaint.DeleteRight(RectCandle, RectForDiffHVolumes); //Получаем правую область для шкалы с гор. объемами var RectForHVolumes = RectanglePaint.GetRight(RectCandle, 70); //Получаем область для свечек из общей верхней области. RectCandle = RectanglePaint.DeleteRight(RectCandle, RectForHVolumes); int BorderBottomIndicator = RectForHVolumes.Width + RectForDiffHVolumes.Width + rectForPrices.Width; //BottomRectForVol.Width = RectCandle.Width; //Получение прямоугольника для области временных меток BottomRectForTimeLine = RectanglePaint.AttachBottom(RectCandle, BottomRectForTimeLine); //Получение области для рисования временных линий и меток BottomRectForTimeLine = RectanglePaint.AttachBottom(BottomRectForTimeLine, BottomRectForVol); //Ширина свечки int WidthOneCandle = PanelCandels.GetWidthOne(RectCandle); //Настройки для объемов PanelVolumes.WidthOneLevel = WidthOneCandle; PanelVolumes.PanelValues.WidthBorder = BorderBottomIndicator;// PanelPrices.WidthBorder; PanelVolumes.PanelValues.CountBorderPrice = 4; PanelDiffHorVolumes.PanelValues.CountBorderPrice = 3; PanelHorVolumes.PanelValues.CountBorderPrice = 3; PanelTimes.WidthOneCandle = WidthOneCandle; PanelTimes.CollectionCandle = PanelCandels.CollectionCandle; this.Canvas.Clear(Color.White); //Рисуем линии времени PanelTimes.PaintTimeFrame(this.Canvas, BottomRectForTimeLine); //Рисуем линии цен PanelPrices.PaintPrices(this.Canvas, this.MaxPrice, this.MinPrice); //Рисуем объемы PanelVolumes.PaintLevels(this.Canvas, BottomRectForVol); //Рисуем объемы горизонтальные PanelHorVolumes.PaintLevels(this.Canvas, RectForHVolumes, this.MaxPrice, this.MinPrice); //Рисуем объемы горизонтальные РАЗНИЦА PanelDiffHorVolumes.PaintLevels(this.Canvas, RectForDiffHVolumes, this.MaxPrice, this.MinPrice); //Рисуем область свечей PanelCandels.PaintCandles(this.Canvas, RectCandle, this.MaxPrice, this.MinPrice, this.MinStepPrice); //Рисуем линию последней цены PanelPrices.PaintCurrentValue(this.Canvas, this.MaxPrice, this.MinPrice); //Рисуем заявки Orders.PaintOrders(this.Canvas, RectAllTop, this.MaxPrice, this.MinPrice, this.MinStepPrice); }