Skip to content

Commit

Permalink
Feature: add the ability to change label color on every update
Browse files Browse the repository at this point in the history
  • Loading branch information
dingmaotu committed Apr 7, 2019
1 parent 78847e6 commit d98327c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions UI/ReadOnlyLabel.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
};
//+------------------------------------------------------------------+
//| |
Expand All @@ -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");

Expand All @@ -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);
}
Expand Down

0 comments on commit d98327c

Please sign in to comment.