From d98327cfd9a721a8c7b47dbe069788c683e3846a Mon Sep 17 00:00:00 2001 From: Ding Li Date: Sun, 7 Apr 2019 11:03:46 +0800 Subject: [PATCH] Feature: add the ability to change label color on every update --- UI/ReadOnlyLabel.mqh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/UI/ReadOnlyLabel.mqh b/UI/ReadOnlyLabel.mqh index e366374..5cb5aad 100644 --- a/UI/ReadOnlyLabel.mqh +++ b/UI/ReadOnlyLabel.mqh @@ -13,6 +13,7 @@ private: const string m_id; const int m_ox,m_oy; const int m_color; + int m_currentColor; protected: void ensureCreated(); public: @@ -21,7 +22,7 @@ public: ensureCreated(); } ~ReadOnlyLabel() {ObjectDelete(m_chart,m_id);} - void render(string content,string tooltip=""); + void render(string content,string tooltip="",color optColor=clrNONE); }; //+------------------------------------------------------------------+ //| | @@ -37,6 +38,7 @@ void ReadOnlyLabel::ensureCreated(void) ObjectSetInteger(m_chart,m_id,OBJPROP_YDISTANCE,m_oy); ObjectSetInteger(m_chart,m_id,OBJPROP_COLOR,m_color); + m_currentColor=m_color; ObjectSetInteger(m_chart,m_id,OBJPROP_FONTSIZE,12); ObjectSetString(m_chart,m_id,OBJPROP_FONT,"Monospace"); @@ -47,12 +49,28 @@ void ReadOnlyLabel::ensureCreated(void) //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ -void ReadOnlyLabel::render(string content,string tooltip) +void ReadOnlyLabel::render(string content,string tooltip,color optColor) { ensureCreated(); ObjectSetString(m_chart,m_id,OBJPROP_TEXT,content); if(tooltip!="") ObjectSetString(m_chart,m_id,OBJPROP_TOOLTIP,tooltip); + if(optColor!=clrNONE) + { + if(optColor!=m_currentColor) + { + ObjectSetInteger(m_chart,m_id,OBJPROP_COLOR,optColor); + m_currentColor=optColor; + } + } + else + { + if(m_color!=m_currentColor) + { + ObjectSetInteger(m_chart,m_id,OBJPROP_COLOR,m_color); + m_currentColor=m_color; + } + } //--- no need to force redraw as the chart will redraw itself on next tick //--- ChartRedraw(m_chart); }