forked from dingmaotu/mql4-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadOnlyLabel.mqh
77 lines (74 loc) · 3.07 KB
/
ReadOnlyLabel.mqh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//+------------------------------------------------------------------+
//| UI/ReadOnlyLabel.mqh |
//| Copyright 2017, Bear Two Technologies Co., Ltd. |
//+------------------------------------------------------------------+
#property strict
//+------------------------------------------------------------------+
//| A label representing read only content |
//+------------------------------------------------------------------+
class ReadOnlyLabel
{
private:
const long m_chart;
const string m_id;
const int m_ox,m_oy;
const int m_color;
int m_currentColor;
protected:
void ensureCreated();
public:
ReadOnlyLabel(string id,int x,int y,color c,long chart=0):m_chart(chart==0?ChartID():chart),m_id(id),m_ox(x),m_oy(y),m_color(c)
{
ensureCreated();
}
~ReadOnlyLabel() {ObjectDelete(m_chart,m_id);}
void render(string content,string tooltip="",color optColor=clrNONE);
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ReadOnlyLabel::ensureCreated(void)
{
if(ObjectFind(m_chart,m_id)>=0) return;
ObjectCreate(m_chart,m_id,OBJ_LABEL,0,0,0);
ObjectSetInteger(m_chart,m_id,OBJPROP_CORNER,CORNER_RIGHT_LOWER);
ObjectSetInteger(m_chart,m_id,OBJPROP_ANCHOR,ANCHOR_RIGHT_LOWER);
ObjectSetInteger(m_chart,m_id,OBJPROP_XDISTANCE,m_ox);
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");
ObjectSetInteger(m_chart,m_id,OBJPROP_SELECTABLE,0);
ObjectSetInteger(m_chart,m_id,OBJPROP_SELECTED,0);
ObjectSetInteger(m_chart,m_id,OBJPROP_HIDDEN,1);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+