From 405291234028cc86b23401cee5673f3bf0da9e70 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Wed, 18 Dec 2024 09:24:41 -0800 Subject: [PATCH] Add cell background color parameter to News indicator --- indicators/news/News.cs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/indicators/news/News.cs b/indicators/news/News.cs index 90f31e3..590a94e 100644 --- a/indicators/news/News.cs +++ b/indicators/news/News.cs @@ -47,6 +47,7 @@ namespace NinjaTrader.NinjaScript.Indicators HorizontalPadding = 20; VerticalPadding = 5; YOffset = 0; + CellBackgroundColor = Brushes.Transparent; } else if (State == State.Configure) { @@ -199,20 +200,21 @@ namespace NinjaTrader.NinjaScript.Indicators var currencySize = MeasureString(newsEvent.Currency, eventTextFormat); var titleSize = MeasureString(newsEvent.Title, eventTextFormat); + // Draw cell backgrounds RectangleF timeRect = new RectangleF(x, y, maxColWidth, rowHeight); + RenderTarget.FillRectangle(timeRect, CellBackgroundColor.ToDxBrush(RenderTarget)); + + RectangleF currencyRect = new RectangleF(x + maxColWidth, y, maxColWidth, rowHeight); + RenderTarget.FillRectangle(currencyRect, CellBackgroundColor.ToDxBrush(RenderTarget)); + + RectangleF titleRect = new RectangleF(x + (2 * maxColWidth), y, maxColWidth, rowHeight); + RenderTarget.FillRectangle(titleRect, CellBackgroundColor.ToDxBrush(RenderTarget)); + + // Draw text DrawText(newsEvent.Time, x + (maxColWidth - timeSize.Width) / 2, y + (rowHeight - timeSize.Height) / 2, EventTextColor, eventTextFormat, rowHeight); + DrawText(newsEvent.Currency, x + maxColWidth + (maxColWidth - currencySize.Width) / 2, y + (rowHeight - currencySize.Height) / 2, EventTextColor, eventTextFormat, rowHeight); + DrawText(newsEvent.Title, x + (2 * maxColWidth) + (maxColWidth - titleSize.Width) / 2, y + (rowHeight - titleSize.Height) / 2, EventTextColor, eventTextFormat, rowHeight); - x += maxColWidth; - - RectangleF currencyRect = new RectangleF(x, y, maxColWidth, rowHeight); - DrawText(newsEvent.Currency, x + (maxColWidth - currencySize.Width) / 2, y + (rowHeight - currencySize.Height) / 2, EventTextColor, eventTextFormat, rowHeight); - - x += maxColWidth; - - RectangleF titleRect = new RectangleF(x, y, maxColWidth, rowHeight); - DrawText(newsEvent.Title, x + (maxColWidth - titleSize.Width) / 2, y + (rowHeight - titleSize.Height) / 2, EventTextColor, eventTextFormat, rowHeight); - - x = ChartPanel.W - (maxColWidth * 3) - HorizontalPadding; y += rowHeight; } } @@ -290,6 +292,17 @@ namespace NinjaTrader.NinjaScript.Indicators [Display(Name = "Event Font", GroupName = "News", Order = 8)] public SimpleFont EventFont { get; set; } + + [XmlIgnore] + [Display(Name = "Cell Background", GroupName = "News", Order = 9)] + public Brush CellBackgroundColor { get; set; } + + [Browsable(false)] + public string CellBackgroundColorSerialization + { + get { return Serialize.BrushToString(CellBackgroundColor); } + set { CellBackgroundColor = Serialize.StringToBrush(value); } + } #endregion } }