1528 righe
93 KiB
MQL5
1528 righe
93 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Controls.mqh |
|
|
//| Copyright 2025, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2025, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Включаемые библиотеки |
|
|
//+------------------------------------------------------------------+
|
|
#include "Base.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Макроподстановки |
|
|
//+------------------------------------------------------------------+
|
|
#define DEF_LABEL_W 40 // Ширина текстовой метки по умолчанию
|
|
#define DEF_LABEL_H 16 // Высота текстовой метки по умолчанию
|
|
#define DEF_BUTTON_W 50 // Ширина кнопки по умолчанию
|
|
#define DEF_BUTTON_H 16 // Высота кнопки по умолчанию
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Перечисления |
|
|
//+------------------------------------------------------------------+
|
|
enum ENUM_ELEMENT_COMPARE_BY // Сравниваемые свойства
|
|
{
|
|
ELEMENT_SORT_BY_ID = 0, // Сравнение по идентификатору элемента
|
|
ELEMENT_SORT_BY_NAME, // Сравнение по наименованию элемента
|
|
ELEMENT_SORT_BY_TEXT, // Сравнение по тексту элемента
|
|
ELEMENT_SORT_BY_COLOR, // Сравнение по цвету элемента
|
|
ELEMENT_SORT_BY_ALPHA, // Сравнение по прозрачности элемента
|
|
ELEMENT_SORT_BY_STATE, // Сравнение по состоянию элемента
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| Функции |
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Классы |
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс рисования изображений |
|
|
//+------------------------------------------------------------------+
|
|
class CImagePainter : public CBaseObj
|
|
{
|
|
protected:
|
|
CCanvas *m_canvas; // Указатель на канвас, где рисуем
|
|
CBound m_bound; // Координаты и границы изображения
|
|
uchar m_alpha; // Прозрачность
|
|
|
|
//--- Проверяет валидность холста и корректность размеров
|
|
bool CheckBound(void);
|
|
|
|
public:
|
|
//--- (1) Назначает канвас для рисования, (2) устанавливает, (3) возвращает прозрачность
|
|
void CanvasAssign(CCanvas *canvas) { this.m_canvas=canvas; }
|
|
void SetAlpha(const uchar value) { this.m_alpha=value; }
|
|
uchar Alpha(void) const { return this.m_alpha; }
|
|
|
|
//--- (1) Устанавливает координаты, (2) изменяет размеры области
|
|
void SetXY(const int x,const int y) { this.m_bound.SetXY(x,y); }
|
|
void SetSize(const int w,const int h) { this.m_bound.Resize(w,h); }
|
|
//--- Устанавливает координаты и размеры области
|
|
void SetBound(const int x,const int y,const int w,const int h)
|
|
{
|
|
this.SetXY(x,y);
|
|
this.SetSize(w,h);
|
|
}
|
|
|
|
//--- Возвращает границы и размеры рисунка
|
|
int X(void) const { return this.m_bound.X(); }
|
|
int Y(void) const { return this.m_bound.Y(); }
|
|
int Right(void) const { return this.m_bound.Right(); }
|
|
int Bottom(void) const { return this.m_bound.Bottom(); }
|
|
int Width(void) const { return this.m_bound.Width(); }
|
|
int Height(void) const { return this.m_bound.Height(); }
|
|
|
|
//--- Очищает область
|
|
bool Clear(const int x,const int y,const int w,const int h,const bool update=true);
|
|
//--- Рисует закрашенную стрелку (1) вверх, (2) вниз, (3) влево, (4) вправо
|
|
bool ArrowUp(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
bool ArrowDown(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
bool ArrowLeft(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
bool ArrowRight(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
|
|
//--- Рисует (1) отмеченный, (2) неотмеченный CheckBox
|
|
bool CheckedBox(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
bool UncheckedBox(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
|
|
//--- Рисует (1) отмеченный, (2) неотмеченный RadioButton
|
|
bool CheckedRadioButton(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
bool UncheckedRadioButton(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle);
|
|
virtual bool Load(const int file_handle);
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_IMAGE_PAINTER); }
|
|
|
|
//--- Конструкторы/деструктор
|
|
CImagePainter(void) : m_canvas(NULL) { this.SetBound(1,1,DEF_BUTTON_H-2,DEF_BUTTON_H-2); this.SetName("Image Painter"); }
|
|
CImagePainter(CCanvas *canvas) : m_canvas(canvas) { this.SetBound(1,1,DEF_BUTTON_H-2,DEF_BUTTON_H-2); this.SetName("Image Painter"); }
|
|
CImagePainter(CCanvas *canvas,const int id,const string name) : m_canvas(canvas)
|
|
{
|
|
this.m_id=id;
|
|
this.SetName(name);
|
|
this.SetBound(1,1,DEF_BUTTON_H-2,DEF_BUTTON_H-2);
|
|
}
|
|
CImagePainter(CCanvas *canvas,const int id,const int dx,const int dy,const int w,const int h,const string name) : m_canvas(canvas)
|
|
{
|
|
this.m_id=id;
|
|
this.SetName(name);
|
|
this.SetBound(dx,dy,w,h);
|
|
}
|
|
~CImagePainter(void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Сравнение двух объектов |
|
|
//+------------------------------------------------------------------+
|
|
int CImagePainter::Compare(const CObject *node,const int mode=0) const
|
|
{
|
|
const CImagePainter *obj=node;
|
|
switch(mode)
|
|
{
|
|
case ELEMENT_SORT_BY_NAME : return(this.Name() >obj.Name() ? 1 : this.Name() <obj.Name() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_ALPHA : return(this.Alpha()>obj.Alpha() ? 1 : this.Alpha()<obj.Alpha()? -1 : 0);
|
|
default : return(this.ID() >obj.ID() ? 1 : this.ID() <obj.ID() ? -1 : 0);
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//|CImagePainter::Проверяет валидность холста и корректность размеров|
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::CheckBound(void)
|
|
{
|
|
if(this.m_canvas==NULL)
|
|
{
|
|
::PrintFormat("%s: Error. First you need to assign the canvas using the CanvasAssign() method",__FUNCTION__);
|
|
return false;
|
|
}
|
|
if(this.Width()==0 || this.Height()==0)
|
|
{
|
|
::PrintFormat("%s: Error. First you need to set the area size using the SetSize() or SetBound() methods",__FUNCTION__);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Очищает область |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::Clear(const int x,const int y,const int w,const int h,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
//--- Очищаем прозрачным цветом всю область изображения
|
|
this.m_canvas.FillRectangle(x,y,x+w-1,y+h-1,clrNULL);
|
|
//--- Если указано - обновляем канвас
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
//--- Всё успешно
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует закрашенную стрелку вверх |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::ArrowUp(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Рассчитываем координаты углов стрелки внутри области изображения
|
|
int hw=(int)::floor(w/2); // Половина ширины
|
|
if(hw==0)
|
|
hw=1;
|
|
|
|
int x1 = x + 1; // X. Основание (левая точка)
|
|
int y1 = y + h - 4; // Y. Левая точка основания
|
|
int x2 = x1 + hw; // X. Вершина (центральная верхняя точка)
|
|
int y2 = y + 3; // Y. Вершина (верхняя точка)
|
|
int x3 = x1 + w - 1; // X. Основание (правая точка)
|
|
int y3 = y1; // Y. Основание (правая точка)
|
|
|
|
//--- Рисуем треугольник
|
|
this.m_canvas.FillTriangle(x1, y1, x2, y2, x3, y3, ::ColorToARGB(clr, alpha));
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует закрашенную стрелку вниз |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::ArrowDown(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Рассчитываем координаты углов стрелки внутри области изображения
|
|
int hw=(int)::floor(w/2); // Половина ширины
|
|
if(hw==0)
|
|
hw=1;
|
|
|
|
int x1=x+1; // X. Основание (левая точка)
|
|
int y1=y+4; // Y. Левая точка основания
|
|
int x2=x1+hw; // X. Вершина (центральная нижняя точка)
|
|
int y2=y+h-3; // Y. Вершина (нижняя точка)
|
|
int x3=x1+w-1; // X. Основание (правая точка)
|
|
int y3=y1; // Y. Основание (правая точка)
|
|
|
|
//--- Рисуем треугольник
|
|
this.m_canvas.FillTriangle(x1, y1, x2, y2, x3, y3, ::ColorToARGB(clr, alpha));
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует закрашенную стрелку влево |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::ArrowLeft(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Рассчитываем координаты углов стрелки внутри области изображения
|
|
int hh=(int)::floor(h/2); // Половина высоты
|
|
if(hh==0)
|
|
hh=1;
|
|
|
|
int x1=x+w-4; // X. Основание (правая сторона)
|
|
int y1=y+1; // Y. Верхний угол основания
|
|
int x2=x+3; // X. Вершина (левая центральная точка)
|
|
int y2=y1+hh; // Y. Центральная точка (вершина)
|
|
int x3=x1; // X. Нижний угол основания
|
|
int y3=y1+h-1; // Y. Нижний угол основания
|
|
|
|
//--- Рисуем треугольник
|
|
this.m_canvas.FillTriangle(x1, y1, x2, y2, x3, y3, ::ColorToARGB(clr, alpha));
|
|
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует закрашенную стрелку вправо |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::ArrowRight(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Рассчитываем координаты углов стрелки внутри области изображения
|
|
int hh=(int)::floor(h/2); // Половина высоты
|
|
if(hh==0)
|
|
hh=1;
|
|
|
|
int x1=x+4; // X. Основание треугольника (левая сторона)
|
|
int y1=y+1; // Y. Верхний угол основания
|
|
int x2=x+w-3; // X. Вершина (правая центральная точка)
|
|
int y2=y1+hh; // Y. Центральная точка (вершина)
|
|
int x3=x1; // X. Нижний угол основания
|
|
int y3=y1+h-1; // Y. Нижний угол основания
|
|
|
|
//--- Рисуем треугольник
|
|
this.m_canvas.FillTriangle(x1, y1, x2, y2, x3, y3, ::ColorToARGB(clr, alpha));
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует отмеченный CheckBox |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::CheckedBox(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Координаты прямоугольника
|
|
int x1=x+1; // Левый верхний угол, X
|
|
int y1=y+1; // Левый верхний угол, Y
|
|
int x2=x+w-2; // Правый нижний угол, X
|
|
int y2=y+h-2; // Правый нижний угол, Y
|
|
|
|
//--- Рисуем прямоугольник
|
|
this.m_canvas.Rectangle(x1, y1, x2, y2, ::ColorToARGB(clr, alpha));
|
|
|
|
//--- Координаты "галочки"
|
|
int arrx[3], arry[3];
|
|
|
|
arrx[0]=x1+(x2-x1)/4; // X. Левая точка
|
|
arrx[1]=x1+w/3; // X. Центральная точка
|
|
arrx[2]=x2-(x2-x1)/4; // X. Правая точка
|
|
|
|
arry[0]=y1+1+(y2-y1)/2; // Y. Левая точка
|
|
arry[1]=y2-(y2-y1)/3; // Y. Центральная точка
|
|
arry[2]=y1+(y2-y1)/3; // Y. Правая точка
|
|
|
|
//--- Рисуем "галочку" линией двойной толщины
|
|
this.m_canvas.Polyline(arrx, arry, ::ColorToARGB(clr, alpha));
|
|
arrx[0]++;
|
|
arrx[1]++;
|
|
arrx[2]++;
|
|
this.m_canvas.Polyline(arrx, arry, ::ColorToARGB(clr, alpha));
|
|
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует неотмеченный CheckBox |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::UncheckedBox(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Координаты прямоугольника
|
|
int x1=x+1; // Левый верхний угол, X
|
|
int y1=y+1; // Левый верхний угол, Y
|
|
int x2=x+w-2; // Правый нижний угол, X
|
|
int y2=y+h-2; // Правый нижний угол, Y
|
|
|
|
//--- Рисуем прямоугольник
|
|
this.m_canvas.Rectangle(x1, y1, x2, y2, ::ColorToARGB(clr, alpha));
|
|
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует отмеченный RadioButton |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::CheckedRadioButton(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Координаты и радиус окружности
|
|
int x1=x+1; // Левый верхний угол области окружности, X
|
|
int y1=y+1; // Левый верхний угол области окружности, Y
|
|
int x2=x+w-2; // Правый нижний угол области окружности, X
|
|
int y2=y+h-2; // Правый нижний угол области окружности, Y
|
|
|
|
//--- Координаты и радиус окружности
|
|
int d=::fmin(x2-x1,y2-y1); // Диаметр по меньшей стороне (ширина или высота)
|
|
int r=d/2; // Радиус
|
|
int cx=x1+r; // Координата X центра
|
|
int cy=y1+r; // Координата Y центра
|
|
|
|
//--- Рисуем окружность
|
|
this.m_canvas.CircleWu(cx, cy, r, ::ColorToARGB(clr, alpha));
|
|
|
|
//--- Радиус "метки"
|
|
r/=2;
|
|
if(r<1)
|
|
r=1;
|
|
//--- Рисуем метку
|
|
this.m_canvas.FillCircle(cx, cy, r, ::ColorToARGB(clr, alpha));
|
|
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Рисует неотмеченный RadioButton |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::UncheckedRadioButton(const int x,const int y,const int w,const int h,const color clr,const uchar alpha,const bool update=true)
|
|
{
|
|
//--- Если область изображения не валидна - возвращаем false
|
|
if(!this.CheckBound())
|
|
return false;
|
|
|
|
//--- Координаты и радиус окружности
|
|
int x1=x+1; // Левый верхний угол области окружности, X
|
|
int y1=y+1; // Левый верхний угол области окружности, Y
|
|
int x2=x+w-2; // Правый нижний угол области окружности, X
|
|
int y2=y+h-2; // Правый нижний угол области окружности, Y
|
|
|
|
//--- Координаты и радиус окружности
|
|
int d=::fmin(x2-x1,y2-y1); // Диаметр по меньшей стороне (ширина или высота)
|
|
int r=d/2; // Радиус
|
|
int cx=x1+r; // Координата X центра
|
|
int cy=y1+r; // Координата Y центра
|
|
|
|
//--- Рисуем окружность
|
|
this.m_canvas.CircleWu(cx, cy, r, ::ColorToARGB(clr, alpha));
|
|
|
|
if(update)
|
|
this.m_canvas.Update(false);
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Сохранение в файл |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::Save(const int file_handle)
|
|
{
|
|
//--- Сохраняем данные родительского объекта
|
|
if(!CBaseObj::Save(file_handle))
|
|
return false;
|
|
|
|
//--- Сохраняем прозрачность
|
|
if(::FileWriteInteger(file_handle,this.m_alpha,INT_VALUE)!=INT_VALUE)
|
|
return false;
|
|
//--- Сохраняем данные области
|
|
if(!this.m_bound.Save(file_handle))
|
|
return false;
|
|
|
|
//--- Всё успешно
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CImagePainter::Загрузка из файла |
|
|
//+------------------------------------------------------------------+
|
|
bool CImagePainter::Load(const int file_handle)
|
|
{
|
|
//--- Загружаем данные родительского объекта
|
|
if(!CBaseObj::Load(file_handle))
|
|
return false;
|
|
|
|
//--- Загружаем прозрачность
|
|
this.m_alpha=(uchar)::FileReadInteger(file_handle,INT_VALUE);
|
|
//--- Загружаем данные области
|
|
if(!this.m_bound.Load(file_handle))
|
|
return false;
|
|
|
|
//--- Всё успешно
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс текстовой метки |
|
|
//+------------------------------------------------------------------+
|
|
class CLabel : public CCanvasBase
|
|
{
|
|
protected:
|
|
CImagePainter m_painter; // Класс рисования
|
|
ushort m_text[]; // Текст
|
|
ushort m_text_prev[]; // Прошлый текст
|
|
int m_text_x; // Координата X текста (смещение относительно левой границы объекта)
|
|
int m_text_y; // Координата Y текста (смещение относительно верхней границы объекта)
|
|
|
|
//--- (1) Устанавливает, (2) возвращает прошлый текст
|
|
void SetTextPrev(const string text) { ::StringToShortArray(text,this.m_text_prev); }
|
|
string TextPrev(void) const { return ::ShortArrayToString(this.m_text_prev);}
|
|
|
|
//--- Стирает текст
|
|
void ClearText(void);
|
|
|
|
public:
|
|
//--- Возвращает указатель на класс рисования
|
|
CImagePainter *Painter(void) { return &this.m_painter; }
|
|
|
|
//--- (1) Устанавливает, (2) возвращает текст
|
|
void SetText(const string text) { ::StringToShortArray(text,this.m_text); }
|
|
string Text(void) const { return ::ShortArrayToString(this.m_text); }
|
|
|
|
//--- Возвращает координату (1) X, (2) Y текста
|
|
int TextX(void) const { return this.m_text_x; }
|
|
int TextY(void) const { return this.m_text_y; }
|
|
|
|
//--- Устанавливает координату (1) X, (2) Y текста
|
|
void SetTextShiftH(const int x) { this.m_text_x=x; }
|
|
void SetTextShiftV(const int y) { this.m_text_y=y; }
|
|
|
|
//--- (1) Устанавливает координаты, (2) изменяет размеры области изображения
|
|
void SetImageXY(const int x,const int y) { this.m_painter.SetXY(x,y); }
|
|
void SetImageSize(const int w,const int h) { this.m_painter.SetSize(w,h); }
|
|
//--- Устанавливает координаты и размеры области изображения
|
|
void SetImageBound(const int x,const int y,const int w,const int h)
|
|
{
|
|
this.SetImageXY(x,y);
|
|
this.SetImageSize(w,h);
|
|
}
|
|
//--- Возвращает координату (1) X, (2) Y, (3) ширину, (4) высоту, (5) правую, (6) нижнюю границу области изображения
|
|
int ImageX(void) const { return this.m_painter.X(); }
|
|
int ImageY(void) const { return this.m_painter.Y(); }
|
|
int ImageWidth(void) const { return this.m_painter.Width(); }
|
|
int ImageHeight(void) const { return this.m_painter.Height(); }
|
|
int ImageRight(void) const { return this.m_painter.Right(); }
|
|
int ImageBottom(void) const { return this.m_painter.Bottom(); }
|
|
|
|
//--- Выводит текст
|
|
void DrawText(const int dx, const int dy, const string text, const bool chart_redraw);
|
|
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle);
|
|
virtual bool Load(const int file_handle);
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_LABEL); }
|
|
|
|
//--- Конструкторы/деструктор
|
|
CLabel(void);
|
|
CLabel(const string object_name, const string text, const int x, const int y, const int w, const int h);
|
|
CLabel(const string object_name, const string text, const int wnd, const int x, const int y, const int w, const int h);
|
|
CLabel(const string object_name, const long chart_id, const int wnd, const string text, const int x, const int y, const int w, const int h);
|
|
~CLabel(void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Конструктор по умолчанию. Строит метку в главном окне |
|
|
//| текущего графика в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CLabel::CLabel(void) : CCanvasBase("Label",::ChartID(),0,0,0,DEF_LABEL_W,DEF_LABEL_H), m_text_x(0), m_text_y(0)
|
|
{
|
|
//--- Объекту рисования назначаем канвас переднего плана и
|
|
//--- обнуляем координаты и размеры, что делает его неактивным
|
|
this.m_painter.CanvasAssign(this.GetForeground());
|
|
this.m_painter.SetXY(0,0);
|
|
this.m_painter.SetSize(0,0);
|
|
//--- Устанавливаем текущий и предыдущий текст
|
|
this.SetText("Label");
|
|
this.SetTextPrev("");
|
|
//--- Фон - прозрачный, передний план - нет
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Конструктор параметрический. Строит метку в главном окне |
|
|
//| текущего графика с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CLabel::CLabel(const string object_name, const string text,const int x,const int y,const int w,const int h) :
|
|
CCanvasBase(object_name,::ChartID(),0,x,y,w,h), m_text_x(0), m_text_y(0)
|
|
{
|
|
//--- Объекту рисования назначаем канвас переднего плана и
|
|
//--- обнуляем координаты и размеры, что делает его неактивным
|
|
this.m_painter.CanvasAssign(this.GetForeground());
|
|
this.m_painter.SetXY(0,0);
|
|
this.m_painter.SetSize(0,0);
|
|
//--- Устанавливаем текущий и предыдущий текст
|
|
this.SetText(text);
|
|
this.SetTextPrev("");
|
|
//--- Фон - прозрачный, передний план - нет
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
}
|
|
//+-------------------------------------------------------------------+
|
|
//| CLabel::Конструктор параметрический. Строит метку в указанном окне|
|
|
//| текущего графика с указанными текстом, координами и размерами |
|
|
//+-------------------------------------------------------------------+
|
|
CLabel::CLabel(const string object_name, const string text,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CCanvasBase(object_name,::ChartID(),wnd,x,y,w,h), m_text_x(0), m_text_y(0)
|
|
{
|
|
//--- Объекту рисования назначаем канвас переднего плана и
|
|
//--- обнуляем координаты и размеры, что делает его неактивным
|
|
this.m_painter.CanvasAssign(this.GetForeground());
|
|
this.m_painter.SetXY(0,0);
|
|
this.m_painter.SetSize(0,0);
|
|
//--- Устанавливаем текущий и предыдущий текст
|
|
this.SetText(text);
|
|
this.SetTextPrev("");
|
|
//--- Фон - прозрачный, передний план - нет
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
}
|
|
//+-------------------------------------------------------------------+
|
|
//| CLabel::Конструктор параметрический. Строит метку в указанном окне|
|
|
//| указанного графика с указанными текстом, координами и размерами |
|
|
//+-------------------------------------------------------------------+
|
|
CLabel::CLabel(const string object_name,const long chart_id,const int wnd,const string text,const int x,const int y,const int w,const int h) :
|
|
CCanvasBase(object_name,chart_id,wnd,x,y,w,h), m_text_x(0), m_text_y(0)
|
|
{
|
|
//--- Объекту рисования назначаем канвас переднего плана и
|
|
//--- обнуляем координаты и размеры, что делает его неактивным
|
|
this.m_painter.CanvasAssign(this.GetForeground());
|
|
this.m_painter.SetXY(0,0);
|
|
this.m_painter.SetSize(0,0);
|
|
//--- Устанавливаем текущий и предыдущий текст
|
|
this.SetText(text);
|
|
this.SetTextPrev("");
|
|
//--- Фон - прозрачный, передний план - нет
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Сравнение двух объектов |
|
|
//+------------------------------------------------------------------+
|
|
int CLabel::Compare(const CObject *node,const int mode=0) const
|
|
{
|
|
const CLabel *obj=node;
|
|
switch(mode)
|
|
{
|
|
case ELEMENT_SORT_BY_NAME : return(this.Name() >obj.Name() ? 1 : this.Name() <obj.Name() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_TEXT : return(this.Text() >obj.Text() ? 1 : this.Text() <obj.Text() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_COLOR : return(this.ForeColor()>obj.ForeColor() ? 1 : this.ForeColor()<obj.ForeColor() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_ALPHA : return(this.AlphaFG() >obj.AlphaFG() ? 1 : this.AlphaFG() <obj.AlphaFG() ? -1 : 0);
|
|
default : return(this.ID() >obj.ID() ? 1 : this.ID() <obj.ID() ? -1 : 0);
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Стирает текст |
|
|
//+------------------------------------------------------------------+
|
|
void CLabel::ClearText(void)
|
|
{
|
|
int w=0, h=0;
|
|
string text=this.TextPrev();
|
|
//--- Получаем размеры прошлого текста
|
|
if(text!="")
|
|
this.m_foreground.TextSize(text,w,h);
|
|
//--- Если размеры получены - рисуем на месте текста прозрачный прямоугольник, стирая текст
|
|
if(w>0 && h>0)
|
|
this.m_foreground.FillRectangle(this.AdjX(this.m_text_x),this.AdjY(this.m_text_y),this.AdjX(this.m_text_x+w),this.AdjY(this.m_text_y+h),clrNULL);
|
|
//--- Иначе - очищаем полностью весь передний план
|
|
else
|
|
this.m_foreground.Erase(clrNULL);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Выводит текст |
|
|
//+------------------------------------------------------------------+
|
|
void CLabel::DrawText(const int dx,const int dy,const string text,const bool chart_redraw)
|
|
{
|
|
//--- Очищаем прошлый текст и устанавливаем новый
|
|
this.ClearText();
|
|
this.SetText(text);
|
|
//--- Выводим установленный текст
|
|
this.m_foreground.TextOut(this.AdjX(dx),this.AdjY(dy),this.Text(),::ColorToARGB(this.ForeColor(),this.AlphaFG()));
|
|
|
|
//--- Если текст выходит за правую границу объекта
|
|
if(this.Width()-dx<this.m_foreground.TextWidth(text))
|
|
{
|
|
//--- Получаем размеры текста "троеточие"
|
|
int w=0,h=0;
|
|
this.m_foreground.TextSize("... ",w,h);
|
|
if(w>0 && h>0)
|
|
{
|
|
//--- Стираем текст у правой границы объекта по размеру текста "троеточие" и заменяем троеточием окончание текста метки
|
|
this.m_foreground.FillRectangle(this.AdjX(this.Width()-w),this.AdjY(this.m_text_y),this.AdjX(this.Width()),this.AdjY(this.m_text_y+h),clrNULL);
|
|
this.m_foreground.TextOut(this.AdjX(this.Width()-w),this.AdjY(dy),"...",::ColorToARGB(this.ForeColor(),this.AlphaFG()));
|
|
}
|
|
}
|
|
//--- Обновляем канвас переднего плана и запоминаем новые координаты текста
|
|
this.m_foreground.Update(chart_redraw);
|
|
this.m_text_x=dx;
|
|
this.m_text_y=dy;
|
|
//--- Запоминаем нарисованный текст как прошлый
|
|
this.SetTextPrev(text);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CLabel::Draw(const bool chart_redraw)
|
|
{
|
|
this.DrawText(this.m_text_x,this.m_text_y,this.Text(),chart_redraw);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Сохранение в файл |
|
|
//+------------------------------------------------------------------+
|
|
bool CLabel::Save(const int file_handle)
|
|
{
|
|
//--- Сохраняем данные родительского объекта
|
|
if(!CCanvasBase::Save(file_handle))
|
|
return false;
|
|
|
|
//--- Сохраняем текст
|
|
if(::FileWriteArray(file_handle,this.m_text)!=sizeof(this.m_text))
|
|
return false;
|
|
//--- Сохраняем предыдущий текст
|
|
if(::FileWriteArray(file_handle,this.m_text_prev)!=sizeof(this.m_text_prev))
|
|
return false;
|
|
//--- Сохраняем координату X текста
|
|
if(::FileWriteInteger(file_handle,this.m_text_x,INT_VALUE)!=INT_VALUE)
|
|
return false;
|
|
//--- Сохраняем координату Y текста
|
|
if(::FileWriteInteger(file_handle,this.m_text_y,INT_VALUE)!=INT_VALUE)
|
|
return false;
|
|
|
|
//--- Всё успешно
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CLabel::Загрузка из файла |
|
|
//+------------------------------------------------------------------+
|
|
bool CLabel::Load(const int file_handle)
|
|
{
|
|
//--- Загружаем данные родительского объекта
|
|
if(!CCanvasBase::Load(file_handle))
|
|
return false;
|
|
|
|
//--- Загружаем текст
|
|
if(::FileReadArray(file_handle,this.m_text)!=sizeof(this.m_text))
|
|
return false;
|
|
//--- Загружаем предыдущий текст
|
|
if(::FileReadArray(file_handle,this.m_text_prev)!=sizeof(this.m_text_prev))
|
|
return false;
|
|
//--- Загружаем координату X текста
|
|
this.m_text_x=::FileReadInteger(file_handle,INT_VALUE);
|
|
//--- Загружаем координату Y текста
|
|
this.m_text_y=::FileReadInteger(file_handle,INT_VALUE);
|
|
|
|
//--- Всё успешно
|
|
return true;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс простой кнопки |
|
|
//+------------------------------------------------------------------+
|
|
class CButton : public CLabel
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CLabel::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CLabel::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_BUTTON); }
|
|
|
|
//--- Конструкторы/деструктор
|
|
CButton(void);
|
|
CButton(const string object_name, const string text, const int x, const int y, const int w, const int h);
|
|
CButton(const string object_name, const string text, const int wnd, const int x, const int y, const int w, const int h);
|
|
CButton(const string object_name, const long chart_id, const int wnd, const string text, const int x, const int y, const int w, const int h);
|
|
~CButton (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CButton::Конструктор по умолчанию. Строит кнопку в главном окне |
|
|
//| текущего графика в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CButton::CButton(void) : CLabel("Button",::ChartID(),0,"Button",0,0,DEF_BUTTON_W,DEF_BUTTON_H)
|
|
{
|
|
this.SetState(ELEMENT_STATE_DEF);
|
|
this.SetAlpha(255);
|
|
}
|
|
//+-------------------------------------------------------------------+
|
|
//| CButton::Конструктор параметрический. Строит кнопку в главном окне|
|
|
//| текущего графика с указанными текстом, координами и размерами |
|
|
//+-------------------------------------------------------------------+
|
|
CButton::CButton(const string object_name,const string text,const int x,const int y,const int w,const int h) :
|
|
CLabel(object_name,::ChartID(),0,text,x,y,w,h)
|
|
{
|
|
this.SetState(ELEMENT_STATE_DEF);
|
|
this.SetAlpha(255);
|
|
}
|
|
//+---------------------------------------------------------------------+
|
|
//| CButton::Конструктор параметрический. Строит кнопку в указанном окне|
|
|
//| текущего графика с указанными текстом, координами и размерами |
|
|
//+---------------------------------------------------------------------+
|
|
CButton::CButton(const string object_name,const string text,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CLabel(object_name,::ChartID(),wnd,text,x,y,w,h)
|
|
{
|
|
this.SetState(ELEMENT_STATE_DEF);
|
|
this.SetAlpha(255);
|
|
}
|
|
//+---------------------------------------------------------------------+
|
|
//| CButton::Конструктор параметрический. Строит кнопку в указанном окне|
|
|
//| указанного графика с указанными текстом, координами и размерами |
|
|
//+---------------------------------------------------------------------+
|
|
CButton::CButton(const string object_name,const long chart_id,const int wnd,const string text,const int x,const int y,const int w,const int h) :
|
|
CLabel(object_name,chart_id,wnd,text,x,y,w,h)
|
|
{
|
|
this.SetState(ELEMENT_STATE_DEF);
|
|
this.SetAlpha(255);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButton::Сравнение двух объектов |
|
|
//+------------------------------------------------------------------+
|
|
int CButton::Compare(const CObject *node,const int mode=0) const
|
|
{
|
|
const CButton *obj=node;
|
|
switch(mode)
|
|
{
|
|
case ELEMENT_SORT_BY_NAME : return(this.Name() >obj.Name() ? 1 : this.Name() <obj.Name() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_TEXT : return(this.Text() >obj.Text() ? 1 : this.Text() <obj.Text() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_COLOR : return(this.BackColor()>obj.BackColor() ? 1 : this.BackColor()<obj.BackColor() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_ALPHA : return(this.AlphaBG() >obj.AlphaBG() ? 1 : this.AlphaBG() <obj.AlphaBG() ? -1 : 0);
|
|
default : return(this.ID() >obj.ID() ? 1 : this.ID() <obj.ID() ? -1 : 0);
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButton::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CButton::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс двухпозиционной кнопки |
|
|
//+------------------------------------------------------------------+
|
|
class CButtonTriggered : public CButton
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Обработчик событий нажатий кнопок мышки (Press)
|
|
virtual void OnPressEvent(const int id, const long lparam, const double dparam, const string sparam);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CButton::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CButton::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_BUTTON_TRIGGERED); }
|
|
|
|
//--- Инициализация цветов объекта по умолчанию
|
|
virtual void InitColors(void);
|
|
|
|
//--- Конструкторы/деструктор
|
|
CButtonTriggered(void);
|
|
CButtonTriggered(const string object_name, const string text, const int x, const int y, const int w, const int h);
|
|
CButtonTriggered(const string object_name, const string text, const int wnd, const int x, const int y, const int w, const int h);
|
|
CButtonTriggered(const string object_name, const long chart_id, const int wnd, const string text, const int x, const int y, const int w, const int h);
|
|
~CButtonTriggered (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Конструктор по умолчанию. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CButtonTriggered::CButtonTriggered(void) : CButton("Button",::ChartID(),0,"Button",0,0,DEF_BUTTON_W,DEF_BUTTON_H)
|
|
{
|
|
this.InitColors();
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Конструктор параметрический. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonTriggered::CButtonTriggered(const string object_name,const string text,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),0,text,x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonTriggered::CButtonTriggered(const string object_name,const string text,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),wnd,text,x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне указанного графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonTriggered::CButtonTriggered(const string object_name,const long chart_id,const int wnd,const string text,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,chart_id,wnd,text,x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Сравнение двух объектов |
|
|
//+------------------------------------------------------------------+
|
|
int CButtonTriggered::Compare(const CObject *node,const int mode=0) const
|
|
{
|
|
const CButtonTriggered *obj=node;
|
|
switch(mode)
|
|
{
|
|
case ELEMENT_SORT_BY_NAME : return(this.Name() >obj.Name() ? 1 : this.Name() <obj.Name() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_TEXT : return(this.Text() >obj.Text() ? 1 : this.Text() <obj.Text() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_COLOR : return(this.BackColor()>obj.BackColor() ? 1 : this.BackColor()<obj.BackColor() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_ALPHA : return(this.AlphaBG() >obj.AlphaBG() ? 1 : this.AlphaBG() <obj.AlphaBG() ? -1 : 0);
|
|
case ELEMENT_SORT_BY_STATE : return(this.State() >obj.State() ? 1 : this.State() <obj.State() ? -1 : 0);
|
|
default : return(this.ID() >obj.ID() ? 1 : this.ID() <obj.ID() ? -1 : 0);
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Инициализация цветов объекта по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
void CButtonTriggered::InitColors(void)
|
|
{
|
|
//--- Инициализируем цвета заднего плана для обычного и активированного состояний и делаем его текущим цветом фона
|
|
this.InitBackColors(clrWhiteSmoke);
|
|
this.InitBackColorsAct(clrLightBlue);
|
|
this.BackColorToDefault();
|
|
|
|
//--- Инициализируем цвета переднего плана для обычного и активированного состояний и делаем его текущим цветом текста
|
|
this.InitForeColors(clrBlack);
|
|
this.InitForeColorsAct(clrBlack);
|
|
this.ForeColorToDefault();
|
|
|
|
//--- Инициализируем цвета рамки для обычного и активированного состояний и делаем его текущим цветом рамки
|
|
this.InitBorderColors(clrDarkGray);
|
|
this.InitBorderColorsAct(clrGreen);
|
|
this.BorderColorToDefault();
|
|
|
|
//--- Инициализируем цвет рамки и цвет переднего плана для заблокированного элемента
|
|
this.InitBorderColorBlocked(clrLightGray);
|
|
this.InitForeColorBlocked(clrSilver);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CButtonTriggered::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonTriggered::Обработчик событий нажатий кнопок мышки (Press)|
|
|
//+------------------------------------------------------------------+
|
|
void CButtonTriggered::OnPressEvent(const int id,const long lparam,const double dparam,const string sparam)
|
|
{
|
|
//--- Устанавливаем состояние кнопки, обратное уже установленному
|
|
ENUM_ELEMENT_STATE state=(this.State()==ELEMENT_STATE_DEF ? ELEMENT_STATE_ACT : ELEMENT_STATE_DEF);
|
|
this.SetState(state);
|
|
|
|
//--- Вызываем обработчик родительского объекта с указанием идентификатора в lparam и состояния в dparam
|
|
CCanvasBase::OnPressEvent(id,this.m_id,this.m_state,sparam);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс кнопки со стрелкой вверх |
|
|
//+------------------------------------------------------------------+
|
|
class CButtonArrowUp : public CButton
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CButton::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CButton::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_BUTTON_ARROW_UP);}
|
|
|
|
//--- Конструкторы/деструктор
|
|
CButtonArrowUp(void);
|
|
CButtonArrowUp(const string object_name, const int x, const int y, const int w, const int h);
|
|
CButtonArrowUp(const string object_name, const int wnd, const int x, const int y, const int w, const int h);
|
|
CButtonArrowUp(const string object_name, const long chart_id, const int wnd, const int x, const int y, const int w, const int h);
|
|
~CButtonArrowUp (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowUp::Конструктор по умолчанию. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowUp::CButtonArrowUp(void) : CButton("Arrow Up Button",::ChartID(),0,"",0,0,DEF_BUTTON_W,DEF_BUTTON_H)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowUp::Конструктор параметрический. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowUp::CButtonArrowUp(const string object_name,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),0,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowUp::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowUp::CButtonArrowUp(const string object_name,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowUp::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне указанного графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowUp::CButtonArrowUp(const string object_name,const long chart_id,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,chart_id,wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowUp::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CButtonArrowUp::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
//--- Очищаем область рисунка
|
|
this.m_painter.Clear(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),false);
|
|
//--- Задаём цвет стрелки для обычного и заблокированного состояний кнопки и рисуем стрелку вверх
|
|
color clr=(!this.IsBlocked() ? this.GetForeColorControl().NewColor(this.ForeColor(),90,90,90) : this.ForeColor());
|
|
this.m_painter.ArrowUp(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),clr,this.AlphaFG(),true);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс кнопки со стрелкой вниз |
|
|
//+------------------------------------------------------------------+
|
|
class CButtonArrowDown : public CButton
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CButton::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CButton::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_BUTTON_ARROW_DOWN); }
|
|
|
|
//--- Конструкторы/деструктор
|
|
CButtonArrowDown(void);
|
|
CButtonArrowDown(const string object_name, const int x, const int y, const int w, const int h);
|
|
CButtonArrowDown(const string object_name, const int wnd, const int x, const int y, const int w, const int h);
|
|
CButtonArrowDown(const string object_name, const long chart_id, const int wnd, const int x, const int y, const int w, const int h);
|
|
~CButtonArrowDown (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowDown::Конструктор по умолчанию. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowDown::CButtonArrowDown(void) : CButton("Arrow Up Button",::ChartID(),0,"",0,0,DEF_BUTTON_W,DEF_BUTTON_H)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowDown::Конструктор параметрический. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowDown::CButtonArrowDown(const string object_name,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),0,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowDown::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowDown::CButtonArrowDown(const string object_name,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowDown::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне указанного графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowDown::CButtonArrowDown(const string object_name,const long chart_id,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,chart_id,wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowDown::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CButtonArrowDown::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
//--- Очищаем область рисунка
|
|
this.m_painter.Clear(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),false);
|
|
//--- Задаём цвет стрелки для обычного и заблокированного состояний кнопки и рисуем стрелку вниз
|
|
color clr=(!this.IsBlocked() ? this.GetForeColorControl().NewColor(this.ForeColor(),90,90,90) : this.ForeColor());
|
|
this.m_painter.ArrowDown(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),clr,this.AlphaFG(),true);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс кнопки со стрелкой влево |
|
|
//+------------------------------------------------------------------+
|
|
class CButtonArrowLeft : public CButton
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CButton::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CButton::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_BUTTON_ARROW_DOWN); }
|
|
|
|
//--- Конструкторы/деструктор
|
|
CButtonArrowLeft(void);
|
|
CButtonArrowLeft(const string object_name, const int x, const int y, const int w, const int h);
|
|
CButtonArrowLeft(const string object_name, const int wnd, const int x, const int y, const int w, const int h);
|
|
CButtonArrowLeft(const string object_name, const long chart_id, const int wnd, const int x, const int y, const int w, const int h);
|
|
~CButtonArrowLeft (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowLeft::Конструктор по умолчанию. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowLeft::CButtonArrowLeft(void) : CButton("Arrow Up Button",::ChartID(),0,"",0,0,DEF_BUTTON_W,DEF_BUTTON_H)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowLeft::Конструктор параметрический. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowLeft::CButtonArrowLeft(const string object_name,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),0,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowLeft::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowLeft::CButtonArrowLeft(const string object_name,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowLeft::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне указанного графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowLeft::CButtonArrowLeft(const string object_name,const long chart_id,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,chart_id,wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowLeft::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CButtonArrowLeft::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
//--- Очищаем область рисунка
|
|
this.m_painter.Clear(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),false);
|
|
//--- Задаём цвет стрелки для обычного и заблокированного состояний кнопки и рисуем стрелку влево
|
|
color clr=(!this.IsBlocked() ? this.GetForeColorControl().NewColor(this.ForeColor(),90,90,90) : this.ForeColor());
|
|
this.m_painter.ArrowLeft(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),clr,this.AlphaFG(),true);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс кнопки со стрелкой вправо |
|
|
//+------------------------------------------------------------------+
|
|
class CButtonArrowRight : public CButton
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CButton::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CButton::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_BUTTON_ARROW_DOWN); }
|
|
|
|
//--- Конструкторы/деструктор
|
|
CButtonArrowRight(void);
|
|
CButtonArrowRight(const string object_name, const int x, const int y, const int w, const int h);
|
|
CButtonArrowRight(const string object_name, const int wnd, const int x, const int y, const int w, const int h);
|
|
CButtonArrowRight(const string object_name, const long chart_id, const int wnd, const int x, const int y, const int w, const int h);
|
|
~CButtonArrowRight (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowRight::Конструктор по умолчанию. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowRight::CButtonArrowRight(void) : CButton("Arrow Up Button",::ChartID(),0,"",0,0,DEF_BUTTON_W,DEF_BUTTON_H)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowRight::Конструктор параметрический. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowRight::CButtonArrowRight(const string object_name,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),0,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowRight::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowRight::CButtonArrowRight(const string object_name,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,::ChartID(),wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowRight::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне указанного графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CButtonArrowRight::CButtonArrowRight(const string object_name,const long chart_id,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButton(object_name,chart_id,wnd,"",x,y,w,h)
|
|
{
|
|
this.InitColors();
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CButtonArrowRight::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CButtonArrowRight::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
//--- Очищаем область рисунка
|
|
this.m_painter.Clear(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),false);
|
|
//--- Задаём цвет стрелки для обычного и заблокированного состояний кнопки и рисуем стрелку вправо
|
|
color clr=(!this.IsBlocked() ? this.GetForeColorControl().NewColor(this.ForeColor(),90,90,90) : this.ForeColor());
|
|
this.m_painter.ArrowRight(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),clr,this.AlphaFG(),true);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс элемента управления Checkbox |
|
|
//+------------------------------------------------------------------+
|
|
class CCheckBox : public CButtonTriggered
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CButton::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CButton::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_CHECKBOX); }
|
|
|
|
//--- Инициализация цветов объекта по умолчанию
|
|
virtual void InitColors(void);
|
|
|
|
//--- Конструкторы/деструктор
|
|
CCheckBox(void);
|
|
CCheckBox(const string object_name, const string text, const int x, const int y, const int w, const int h);
|
|
CCheckBox(const string object_name, const string text, const int wnd, const int x, const int y, const int w, const int h);
|
|
CCheckBox(const string object_name, const long chart_id, const int wnd, const string text, const int x, const int y, const int w, const int h);
|
|
~CCheckBox (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CCheckBox::Конструктор по умолчанию. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CCheckBox::CCheckBox(void) : CButtonTriggered("CheckBox",::ChartID(),0,"CheckBox",0,0,DEF_BUTTON_W,DEF_BUTTON_H)
|
|
{
|
|
//--- Устанавливаем цвета по умолчанию, прозрачность для фона и переднего плана,
|
|
//--- и координаты и границы области рисунка значка кнопки
|
|
this.InitColors();
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CCheckBox::Конструктор параметрический. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CCheckBox::CCheckBox(const string object_name,const string text,const int x,const int y,const int w,const int h) :
|
|
CButtonTriggered(object_name,::ChartID(),0,text,x,y,w,h)
|
|
{
|
|
//--- Устанавливаем цвета по умолчанию, прозрачность для фона и переднего плана,
|
|
//--- и координаты и границы области рисунка значка кнопки
|
|
this.InitColors();
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CCheckBox::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CCheckBox::CCheckBox(const string object_name,const string text,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CButtonTriggered(object_name,::ChartID(),wnd,text,x,y,w,h)
|
|
{
|
|
//--- Устанавливаем цвета по умолчанию, прозрачность для фона и переднего плана,
|
|
//--- и координаты и границы области рисунка значка кнопки
|
|
this.InitColors();
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CCheckBox::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне указанного графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CCheckBox::CCheckBox(const string object_name,const long chart_id,const int wnd,const string text,const int x,const int y,const int w,const int h) :
|
|
CButtonTriggered(object_name,chart_id,wnd,text,x,y,w,h)
|
|
{
|
|
//--- Устанавливаем цвета по умолчанию, прозрачность для фона и переднего плана,
|
|
//--- и координаты и границы области рисунка значка кнопки
|
|
this.InitColors();
|
|
this.SetAlphaBG(0);
|
|
this.SetAlphaFG(255);
|
|
this.SetImageBound(1,1,this.Height()-2,this.Height()-2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CCheckBox::Сравнение двух объектов |
|
|
//+------------------------------------------------------------------+
|
|
int CCheckBox::Compare(const CObject *node,const int mode=0) const
|
|
{
|
|
return CButtonTriggered::Compare(node,mode);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CCheckBox::Инициализация цветов объекта по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
void CCheckBox::InitColors(void)
|
|
{
|
|
//--- Инициализируем цвета заднего плана для обычного и активированного состояний и делаем его текущим цветом фона
|
|
this.InitBackColors(clrNULL);
|
|
this.InitBackColorsAct(clrNULL);
|
|
this.BackColorToDefault();
|
|
|
|
//--- Инициализируем цвета переднего плана для обычного и активированного состояний и делаем его текущим цветом текста
|
|
this.InitForeColors(clrBlack);
|
|
this.InitForeColorsAct(clrBlack);
|
|
this.InitForeColorFocused(clrNavy);
|
|
this.InitForeColorActFocused(clrNavy);
|
|
this.ForeColorToDefault();
|
|
|
|
//--- Инициализируем цвета рамки для обычного и активированного состояний и делаем его текущим цветом рамки
|
|
this.InitBorderColors(clrNULL);
|
|
this.InitBorderColorsAct(clrNULL);
|
|
this.BorderColorToDefault();
|
|
|
|
//--- Инициализируем цвет рамки и цвет переднего плана для заблокированного элемента
|
|
this.InitBorderColorBlocked(clrNULL);
|
|
this.InitForeColorBlocked(clrSilver);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CCheckBox::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CCheckBox::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
|
|
//--- Очищаем область рисунка
|
|
this.m_painter.Clear(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),false);
|
|
//--- Рисуем отмеченный значок для активного состояния кнопки,
|
|
if(this.m_state)
|
|
this.m_painter.CheckedBox(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),this.ForeColor(),this.AlphaFG(),true);
|
|
//--- и неотмеченный - для неактивного
|
|
else
|
|
this.m_painter.UncheckedBox(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),this.ForeColor(),this.AlphaFG(),true);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Класс элоемента управления Radio Button |
|
|
//+------------------------------------------------------------------+
|
|
class CRadioButton : public CCheckBox
|
|
{
|
|
public:
|
|
//--- Рисует внешний вид
|
|
virtual void Draw(const bool chart_redraw);
|
|
|
|
//--- Обработчик событий нажатий кнопок мышки (Press)
|
|
virtual void OnPressEvent(const int id, const long lparam, const double dparam, const string sparam);
|
|
|
|
//--- Виртуальные методы (1) сравнения, (2) сохранения в файл, (3) загрузки из файла, (4) тип объекта
|
|
virtual int Compare(const CObject *node,const int mode=0) const;
|
|
virtual bool Save(const int file_handle) { return CButton::Save(file_handle); }
|
|
virtual bool Load(const int file_handle) { return CButton::Load(file_handle); }
|
|
virtual int Type(void) const { return(ELEMENT_TYPE_RADIOBUTTON); }
|
|
|
|
//--- Конструкторы/деструктор
|
|
CRadioButton(void);
|
|
CRadioButton(const string object_name, const string text, const int x, const int y, const int w, const int h);
|
|
CRadioButton(const string object_name, const string text, const int wnd, const int x, const int y, const int w, const int h);
|
|
CRadioButton(const string object_name, const long chart_id, const int wnd, const string text, const int x, const int y, const int w, const int h);
|
|
~CRadioButton (void) {}
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| CRadioButton::Конструктор по умолчанию. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| в координатах 0,0 с размерами по умолчанию |
|
|
//+------------------------------------------------------------------+
|
|
CRadioButton::CRadioButton(void) : CCheckBox("RadioButton",::ChartID(),0,"",0,0,DEF_BUTTON_H,DEF_BUTTON_H)
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CRadioButton::Конструктор параметрический. |
|
|
//| Строит кнопку в главном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CRadioButton::CRadioButton(const string object_name,const string text,const int x,const int y,const int w,const int h) :
|
|
CCheckBox(object_name,::ChartID(),0,text,x,y,w,h)
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CRadioButton::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне текущего графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CRadioButton::CRadioButton(const string object_name,const string text,const int wnd,const int x,const int y,const int w,const int h) :
|
|
CCheckBox(object_name,::ChartID(),wnd,text,x,y,w,h)
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CRadioButton::Конструктор параметрический. |
|
|
//| Строит кнопку в указанном окне указанного графика |
|
|
//| с указанными текстом, координами и размерами |
|
|
//+------------------------------------------------------------------+
|
|
CRadioButton::CRadioButton(const string object_name,const long chart_id,const int wnd,const string text,const int x,const int y,const int w,const int h) :
|
|
CCheckBox(object_name,chart_id,wnd,text,x,y,w,h)
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CRadioButton::Сравнение двух объектов |
|
|
//+------------------------------------------------------------------+
|
|
int CRadioButton::Compare(const CObject *node,const int mode=0) const
|
|
{
|
|
return CCheckBox::Compare(node,mode);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CRadioButton::Рисует внешний вид |
|
|
//+------------------------------------------------------------------+
|
|
void CRadioButton::Draw(const bool chart_redraw)
|
|
{
|
|
//--- Заливаем кнопку цветом фона, рисуем рамку и обновляем канвас фона
|
|
this.Fill(this.BackColor(),false);
|
|
this.m_background.Rectangle(this.AdjX(0),this.AdjY(0),this.AdjX(this.Width()-1),this.AdjY(this.Height()-1),::ColorToARGB(this.BorderColor(),this.AlphaBG()));
|
|
this.m_background.Update(false);
|
|
//--- Выводим текст кнопки
|
|
CLabel::Draw(false);
|
|
|
|
//--- Очищаем область рисунка
|
|
this.m_painter.Clear(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),false);
|
|
//--- Рисуем отмеченный значок для активного состояния кнопки,
|
|
if(this.m_state)
|
|
this.m_painter.CheckedRadioButton(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),this.ForeColor(),this.AlphaFG(),true);
|
|
//--- и неотмеченный - для неактивного
|
|
else
|
|
this.m_painter.UncheckedRadioButton(this.AdjX(this.m_painter.X()),this.AdjY(this.m_painter.Y()),this.m_painter.Width(),this.m_painter.Height(),this.ForeColor(),this.AlphaFG(),true);
|
|
|
|
//--- Если указано - обновляем график
|
|
if(chart_redraw)
|
|
::ChartRedraw(this.m_chart_id);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| CRadioButton::Обработчик событий нажатий кнопок мышки (Press) |
|
|
//+------------------------------------------------------------------+
|
|
void CRadioButton::OnPressEvent(const int id,const long lparam,const double dparam,const string sparam)
|
|
{
|
|
//--- Если кнопка уже отмечена - уходим
|
|
if(this.m_state)
|
|
return;
|
|
//--- Устанавливаем состояние кнопки, обратное уже установленному
|
|
ENUM_ELEMENT_STATE state=(this.State()==ELEMENT_STATE_DEF ? ELEMENT_STATE_ACT : ELEMENT_STATE_DEF);
|
|
this.SetState(state);
|
|
|
|
//--- Вызываем обработчик родительского объекта с указанием идентификатора в lparam и состояния в dparam
|
|
CCanvasBase::OnPressEvent(id,this.m_id,this.m_state,sparam);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|