forked from dingmaotu/mql4-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFreeFormElement.mqh
123 lines (116 loc) · 5.68 KB
/
FreeFormElement.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//+------------------------------------------------------------------+
//| UI/FreeFormElement.mqh |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Li Ding"
#property link "dingmaotu@hotmail.com"
#property strict
#include "BaseElement.mqh"
//+------------------------------------------------------------------+
//| The following elements are not anchored to price/time |
//| OBJ_LABEL |
//| OBJ_BUTTON |
//| OBJ_BITMAP_LABEL |
//| OBJ_EDIT |
//| OBJ_RECTANGLE_LABEL |
//+------------------------------------------------------------------+
class FreeFormElement: public BaseElement
{
protected:
bool createElement(ENUM_OBJECT type)
{
return ObjectCreate(m_root.getChartId(),getName(),type,m_root.getSubwindowIndex(), 0, 0);
}
FreeFormElement(UIElement *parent,string name,ENUM_OBJECT type):BaseElement(parent,name){createElement(type);}
public:
~FreeFormElement() {deleteSelf();}
//--- Position and Shape
virtual int getX() const {return(int)getInteger(OBJPROP_XDISTANCE);}
virtual bool setX(int value) {return setInteger(OBJPROP_XDISTANCE,value);}
virtual int getY() const {return(int)getInteger(OBJPROP_YDISTANCE);}
virtual bool setY(int value) {return setInteger(OBJPROP_YDISTANCE,value);}
int getRelativeX() const {return getX()-getParent().getX();}
int getRelativeY() const {return getY()-getParent().getY();}
bool setRelativeX(int value) {return setX(getParent().getX()+value);}
bool setRelativeY(int value) {return setY(getParent().getY()+value);}
bool setPosition(int x,int y) {return setX(x) && setY(y);}
bool setRelativePosition(int x,int y) {return setRelativeX(x) && setRelativeY(y);}
bool move(int dx,int dy) {return setX(getX()+dx) && setY(getY()+dy);}
virtual int getWidth() const {return(int)getInteger(OBJPROP_XSIZE);}
virtual bool setWidth(int value) {return setInteger(OBJPROP_XSIZE,value);}
virtual int getHeight() const {return(int)getInteger(OBJPROP_YSIZE);}
virtual bool setHeight(int value) {return setInteger(OBJPROP_YSIZE,value);}
bool setSize(int width,int height) {return setWidth(width) && setHeight(height);}
};
//+------------------------------------------------------------------+
//| Parent for free form container elements |
//+------------------------------------------------------------------+
class Panel: public FreeFormElement
{
public:
Panel(UIRoot *parent,string name,int x=-1,int y=-1,int w=-1,int h=-1);
Panel(Panel *parent,string name)
:FreeFormElement(parent,name,OBJ_RECTANGLE_LABEL){}
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Panel::Panel(UIRoot *parent,string name,int x,int y,int w,int h)
:FreeFormElement(parent,name,OBJ_RECTANGLE_LABEL)
{
if(x>=0) setX(x);
if(y>=0) setY(y);
if(w>=0) setWidth(w);
if(h>=0) setHeight(h);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class Label: public FreeFormElement
{
public:
Label(Panel *parent,string name,string text)
:FreeFormElement(parent,name,OBJ_LABEL)
{
setText(text);
}
bool setWidth(int value) {return false;} // read only, thus do nothing
bool setHeight(int value) {return false;} // read only, thus do nothing
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class Bitmap: public FreeFormElement
{
Bitmap(Panel *parent,string name)
:FreeFormElement(parent,name,OBJ_BITMAP_LABEL)
{}
bool setWidth(int value) {return false;} // read only, thus do nothing
bool setHeight(int value) {return false;} // read only, thus do nothing
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class Edit: public FreeFormElement
{
public:
Edit(Panel *parent,string name,string text)
:FreeFormElement(parent,name,OBJ_EDIT)
{
setText(text);
}
bool setAlign(ENUM_ALIGN_MODE value) {return setInteger(OBJPROP_ALIGN,value);}
bool setReadOnly(bool value) {return setInteger(OBJPROP_READONLY,value?1:0);}
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class Button: public FreeFormElement
{
public:
Button(Panel *parent,string name,string text)
:FreeFormElement(parent,name,OBJ_BUTTON)
{
setText(text);
}
};
//+------------------------------------------------------------------+