Add files via upload
This commit is contained in:
@@ -0,0 +1,805 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Colors.mqh |
|
||||
//| Copyright 2015, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
//+------------------------------------------------------------------+
|
||||
//| Êëàññ äëÿ ðàáîòû ñ öâåòîì |
|
||||
//+------------------------------------------------------------------+
|
||||
class CColors
|
||||
{
|
||||
private:
|
||||
double Arctan2(const double x,const double y);
|
||||
double Hue_To_RGB(double v1,double v2,double vH);
|
||||
public:
|
||||
CColors();
|
||||
~CColors();
|
||||
//--- Ñïèñîê ôóíêöèé ñ ñàéòà > http://www.easyrgb.com/index.php?X=MATH
|
||||
// start of list <
|
||||
void RGBtoXYZ(const double aR,const double aG,const double aB,double &oX,double &oY,double &oZ);
|
||||
void XYZtoRGB(const double aX,const double aY,const double aZ,double &oR,double &oG,double &oB);
|
||||
void XYZtoYxy(const double aX,const double aY,const double aZ,double &oY,double &ox,double &oy);
|
||||
void YxyToXYZ(const double aY,const double ax,const double ay,double &oX,double &oY,double &oZ);
|
||||
void XYZtoHunterLab(const double aX,const double aY,const double aZ,double &oL,double &oa,double &ob);
|
||||
void HunterLabToXYZ(const double aL,const double aa,const double ab,double &oX,double &oY,double &oZ);
|
||||
void XYZtoCIELab(const double aX,const double aY,const double aZ,double &oCIEL,double &oCIEa,double &oCIEb);
|
||||
void CIELabToXYZ(const double aCIEL,const double aCIEa,const double aCIEb,double &oX,double &oY,double &oZ);
|
||||
void CIELabToCIELCH(const double aCIEL,const double aCIEa,const double aCIEb,double &oCIEL,double &oCIEC,double &oCIEH);
|
||||
void CIELCHtoCIELab(const double aCIEL,const double aCIEC,const double aCIEH,double &oCIEL,double &oCIEa,double &oCIEb);
|
||||
void XYZtoCIELuv(const double aX,const double aY,const double aZ,double &oCIEL,double &oCIEu,double &oCIEv);
|
||||
void CIELuvToXYZ(const double aCIEL,const double aCIEu,const double aCIEv,double &oX,double &oY,double &oZ);
|
||||
void RGBtoHSL(const double aR,const double aG,const double aB,double &oH,double &oS,double &oL);
|
||||
void HSLtoRGB(const double aH,const double aS,const double aL,double &oR,double &oG,double &oB);
|
||||
void RGBtoHSV(const double aR,const double aG,const double aB,double &oH,double &oS,double &oV);
|
||||
void HSVtoRGB(const double aH,const double aS,const double aV,double &oR,double &oG,double &oB);
|
||||
void RGBtoCMY(const double aR,const double aG,const double aB,double &oC,double &oM,double &oY);
|
||||
void CMYtoRGB(const double aC,const double aM,const double aY,double &oR,double &oG,double &oB);
|
||||
void CMYtoCMYK(const double aC,const double aM,const double aY,double &oC,double &oM,double &oY,double &oK);
|
||||
void CMYKtoCMY(const double aC,const double aM,const double aY,const double aK,double &oC,double &oM,double &oY);
|
||||
//--- > end of list
|
||||
//
|
||||
void ColorToRGB(const color aColor,double &aR,double &aG,double &aB);
|
||||
double GetR(const color aColor);
|
||||
double GetG(const color aColor);
|
||||
double GetB(const color aColor);
|
||||
color RGBToColor(const double aR,const double aG,const double aB);
|
||||
color MixColors(const color aCol1,const color aCol2,const double aK);
|
||||
void Gradient(color &aColors[],color &aOut[],int aOutCount,bool aCycle=false);
|
||||
void RGBtoXYZsimple(double aR,double aG,double aB,double &oX,double &oY,double &oZ);
|
||||
void XYZtoRGBsimple(const double aX,const double aY,const double aZ,double &oR,double &oG,double &oB);
|
||||
color Negative(const color aColor);
|
||||
color StandardColor(const color aColor,int &aIndex);
|
||||
double RGBtoGray(double aR,double aG,double aB);
|
||||
double RGBtoGraySimple(double aR,double aG,double aB);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CColors::CColors(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CColors::~CColors(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Arctan2 |
|
||||
//+------------------------------------------------------------------+
|
||||
double CColors::Arctan2(const double x,const double y)
|
||||
{
|
||||
if(y==0)
|
||||
{
|
||||
if(x<0)
|
||||
return(M_PI);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(x>0)
|
||||
return(::MathArctan(y/x));
|
||||
//---
|
||||
if(x<0)
|
||||
{
|
||||
if(y>0)
|
||||
return(::MathArctan(y/x)+M_PI);
|
||||
//---
|
||||
return(::MathArctan(y/x)-M_PI);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(y<0)
|
||||
return(-M_PI_2);
|
||||
//---
|
||||
return(M_PI_2);
|
||||
}
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Hue_To_RGB |
|
||||
//+------------------------------------------------------------------+
|
||||
double CColors::Hue_To_RGB(double v1,double v2,double vH)
|
||||
{
|
||||
if(vH<0)
|
||||
vH+=1.0;
|
||||
if(vH>1.0)
|
||||
vH-=1;
|
||||
if((6.0*vH)<1.0)
|
||||
return(v1+(v2-v1)*6.0*vH);
|
||||
if((2.0*vH)<1.0)
|
||||
return(v2);
|
||||
if((3.0*vH)<2.0)
|
||||
return(v1+(v2-v1)*((2.0/3.0)-vH)*6.0);
|
||||
//---
|
||||
return(v1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå RGB â XYZ |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::RGBtoXYZ(const double aR,const double aG,const double aB,double &oX,double &oY,double &oZ)
|
||||
{
|
||||
double var_R=aR/255;
|
||||
double var_G=aG/255;
|
||||
double var_B=aB/255;
|
||||
//---
|
||||
if(var_R>0.04045)
|
||||
var_R=::MathPow((var_R+0.055)/1.055,2.4);
|
||||
else
|
||||
var_R=var_R/12.92;
|
||||
//---
|
||||
if(var_G>0.04045)
|
||||
var_G=::MathPow((var_G+0.055)/1.055,2.4);
|
||||
else
|
||||
var_G=var_G/12.92;
|
||||
//---
|
||||
if(var_B>0.04045)
|
||||
var_B=::MathPow((var_B+0.055)/1.055,2.4);
|
||||
else
|
||||
var_B=var_B/12.92;
|
||||
//---
|
||||
var_R =var_R*100.0;
|
||||
var_G =var_G*100.0;
|
||||
var_B =var_B*100.0;
|
||||
oX =var_R*0.4124+var_G*0.3576+var_B*0.1805;
|
||||
oY =var_R*0.2126+var_G*0.7152+var_B*0.0722;
|
||||
oZ =var_R*0.0193+var_G*0.1192+var_B*0.9505;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå XYZ â RGB |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::XYZtoRGB(const double aX,const double aY,const double aZ,double &oR,double &oG,double &oB)
|
||||
{
|
||||
double var_X =aX/100;
|
||||
double var_Y =aY/100;
|
||||
double var_Z =aZ/100;
|
||||
double var_R =var_X*3.2406+var_Y*-1.5372+var_Z*-0.4986;
|
||||
double var_G =var_X*(-0.9689)+var_Y*1.8758+var_Z*0.0415;
|
||||
double var_B =var_X*0.0557+var_Y*(-0.2040)+var_Z*1.0570;
|
||||
//---
|
||||
if(var_R>0.0031308)
|
||||
var_R=1.055*(::MathPow(var_R,1.0/2.4))-0.055;
|
||||
else
|
||||
var_R=12.92*var_R;
|
||||
//---
|
||||
if(var_G>0.0031308)
|
||||
var_G=1.055*(::MathPow(var_G,1.0/2.4))-0.055;
|
||||
else
|
||||
var_G=12.92*var_G;
|
||||
//---
|
||||
if(var_B>0.0031308)
|
||||
var_B=1.055*(::MathPow(var_B,1.0/2.4))-0.055;
|
||||
else
|
||||
var_B=12.92*var_B;
|
||||
//---
|
||||
oR =var_R*255.0;
|
||||
oG =var_G*255.0;
|
||||
oB =var_B*255.0;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå XYZ â Yxy |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::XYZtoYxy(const double aX,const double aY,const double aZ,double &oY,double &ox,double &oy)
|
||||
{
|
||||
oY =aY;
|
||||
ox =aX/(aX+aY+aZ);
|
||||
oy =aY/(aX+aY+aZ);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå Yxy â XYZ |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::YxyToXYZ(const double aY,const double ax,const double ay,double &oX,double &oY,double &oZ)
|
||||
{
|
||||
oX =ax*(aY/ay);
|
||||
oY =aY;
|
||||
oZ =(1.0-ax-ay)*(aY/ay);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå XYZ â HunterLab |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::XYZtoHunterLab(const double aX,const double aY,const double aZ,double &oL,double &oa,double &ob)
|
||||
{
|
||||
oL =10.0*::MathSqrt(aY);
|
||||
oa =17.5*(((1.02*aX)-aY)/::MathSqrt(aY));
|
||||
ob =7.0*((aY-(0.847*aZ))/::MathSqrt(aY));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå HunterLab â XYZ |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::HunterLabToXYZ(const double aL,const double aa,const double ab,double &oX,double &oY,double &oZ)
|
||||
{
|
||||
double var_Y =aL/10.0;
|
||||
double var_X =aa/17.5*aL/10.0;
|
||||
double var_Z =ab/7.0*aL/10.0;
|
||||
//---
|
||||
oY =::MathPow(var_Y,2);
|
||||
oX =(var_X+oY)/1.02;
|
||||
oZ =-(var_Z-oY)/0.847;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå XYZ â CIELab |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::XYZtoCIELab(const double aX,const double aY,const double aZ,double &oCIEL,double &oCIEa,double &oCIEb)
|
||||
{
|
||||
double ref_X =95.047;
|
||||
double ref_Y =100.0;
|
||||
double ref_Z =108.883;
|
||||
double var_X =aX/ref_X;
|
||||
double var_Y =aY/ref_Y;
|
||||
double var_Z =aZ/ref_Z;
|
||||
//---
|
||||
if(var_X>0.008856)
|
||||
var_X=::MathPow(var_X,1.0/3.0);
|
||||
else
|
||||
var_X=(7.787*var_X)+(16.0/116.0);
|
||||
//---
|
||||
if(var_Y>0.008856)
|
||||
var_Y=::MathPow(var_Y,1.0/3.0);
|
||||
else
|
||||
var_Y=(7.787*var_Y)+(16.0/116.0);
|
||||
//---
|
||||
if(var_Z>0.008856)
|
||||
var_Z=::MathPow(var_Z,1.0/3.0);
|
||||
else
|
||||
var_Z=(7.787*var_Z)+(16.0/116.0);
|
||||
//---
|
||||
oCIEL =(116.0*var_Y)-16.0;
|
||||
oCIEa =500.0*(var_X-var_Y);
|
||||
oCIEb =200*(var_Y-var_Z);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå CIELab â ToXYZ |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::CIELabToXYZ(const double aCIEL,const double aCIEa,const double aCIEb,double &oX,double &oY,double &oZ)
|
||||
{
|
||||
double var_Y =(aCIEL+16.0)/116.0;
|
||||
double var_X =aCIEa/500.0+var_Y;
|
||||
double var_Z =var_Y-aCIEb/200.0;
|
||||
//---
|
||||
if(::MathPow(var_Y,3)>0.008856)
|
||||
var_Y=::MathPow(var_Y,3);
|
||||
else
|
||||
var_Y=(var_Y-16.0/116.0)/7.787;
|
||||
//---
|
||||
if(::MathPow(var_X,3)>0.008856)
|
||||
var_X=::MathPow(var_X,3);
|
||||
else
|
||||
var_X=(var_X-16.0/116.0)/7.787;
|
||||
//---
|
||||
if(::MathPow(var_Z,3)>0.008856)
|
||||
var_Z=::MathPow(var_Z,3);
|
||||
else
|
||||
var_Z=(var_Z-16.0/116.0)/7.787;
|
||||
//---
|
||||
double ref_X =95.047;
|
||||
double ref_Y =100.0;
|
||||
double ref_Z =108.883;
|
||||
//---
|
||||
oX =ref_X*var_X;
|
||||
oY =ref_Y*var_Y;
|
||||
oZ =ref_Z*var_Z;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå CIELab â CIELCH |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::CIELabToCIELCH(const double aCIEL,const double aCIEa,const double aCIEb,double &oCIEL,double &oCIEC,double &oCIEH)
|
||||
{
|
||||
double var_H=this.Arctan2(aCIEb,aCIEa);
|
||||
//---
|
||||
if(var_H>0)
|
||||
var_H=(var_H/M_PI)*180.0;
|
||||
else
|
||||
var_H=360.0-(::MathAbs(var_H)/M_PI)*180.0;
|
||||
//---
|
||||
oCIEL =aCIEL;
|
||||
oCIEC =::MathSqrt(::MathPow(aCIEa,2)+::MathPow(aCIEb,2));
|
||||
oCIEH =var_H;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå CIELCH â CIELab |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::CIELCHtoCIELab(const double aCIEL,const double aCIEC,const double aCIEH,double &oCIEL,double &oCIEa,double &oCIEb)
|
||||
{
|
||||
//--- Àðãóìåíòû from 0 to 360°
|
||||
oCIEL =aCIEL;
|
||||
oCIEa =::MathCos(M_PI*aCIEH/180.0)*aCIEC;
|
||||
oCIEb =::MathSin(M_PI*aCIEH/180)*aCIEC;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå XYZ â CIELuv |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::XYZtoCIELuv(const double aX,const double aY,const double aZ,double &oCIEL,double &oCIEu,double &oCIEv)
|
||||
{
|
||||
double var_U =(4.0*aX)/(aX+(15.0*aY)+(3.0*aZ));
|
||||
double var_V =(9.0*aY)/(aX+(15.0*aY)+(3.0*aZ));
|
||||
double var_Y =aY/100.0;
|
||||
//---
|
||||
if(var_Y>0.008856)
|
||||
var_Y=::MathPow(var_Y,1.0/3.0);
|
||||
else
|
||||
var_Y=(7.787*var_Y)+(16.0/116.0);
|
||||
//---
|
||||
double ref_X =95.047;
|
||||
double ref_Y =100.000;
|
||||
double ref_Z =108.883;
|
||||
double ref_U =(4.0*ref_X)/(ref_X+(15.0*ref_Y)+(3.0*ref_Z));
|
||||
double ref_V =(9.0*ref_Y)/(ref_X+(15.0*ref_Y)+(3.0*ref_Z));
|
||||
//---
|
||||
oCIEL =(116.0*var_Y)-16.0;
|
||||
oCIEu =13.0*oCIEL*(var_U-ref_U);
|
||||
oCIEv =13.0*oCIEL*(var_V-ref_V);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå CIELuv â XYZ |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::CIELuvToXYZ(const double aCIEL,const double aCIEu,const double aCIEv,double &oX,double &oY,double &oZ)
|
||||
{
|
||||
double var_Y=(aCIEL+16.0)/116.0;
|
||||
//---
|
||||
if(::MathPow(var_Y,3)>0.008856)
|
||||
var_Y=::MathPow(var_Y,3);
|
||||
else
|
||||
var_Y=(var_Y-16.0/116.0)/7.787;
|
||||
//---
|
||||
double ref_X =95.047;
|
||||
double ref_Y =100.000;
|
||||
double ref_Z =108.883;
|
||||
double ref_U =(4.0*ref_X)/(ref_X+(15.0*ref_Y)+(3.0*ref_Z));
|
||||
double ref_V =(9.0*ref_Y)/(ref_X+(15.0*ref_Y)+(3.0*ref_Z));
|
||||
double var_U =aCIEu/(13.0*aCIEL)+ref_U;
|
||||
double var_V =aCIEv/(13.0*aCIEL)+ref_V;
|
||||
//---
|
||||
oY=var_Y*100.0;
|
||||
oX=-(9.0*oY*var_U)/((var_U-4.0)*var_V-var_U*var_V);
|
||||
oZ=(9.0*oY-(15.0*var_V*oY)-(var_V*oX))/(3.0*var_V);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå RGB â HSL |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::RGBtoHSL(const double aR,const double aG,const double aB,double &oH,double &oS,double &oL)
|
||||
{
|
||||
double var_R =(aR/255);
|
||||
double var_G =(aG/255);
|
||||
double var_B =(aB/255);
|
||||
double var_Min =::MathMin(var_R,::MathMin(var_G,var_B));
|
||||
double var_Max =::MathMax(var_R,::MathMax(var_G,var_B));
|
||||
double del_Max =var_Max-var_Min;
|
||||
//---
|
||||
oL=(var_Max+var_Min)/2;
|
||||
//---
|
||||
if(del_Max==0)
|
||||
{
|
||||
oH=0;
|
||||
oS=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(oL<0.5)
|
||||
oS=del_Max/(var_Max+var_Min);
|
||||
else
|
||||
oS=del_Max/(2.0-var_Max-var_Min);
|
||||
//---
|
||||
double del_R =(((var_Max-var_R)/6.0)+(del_Max/2.0))/del_Max;
|
||||
double del_G =(((var_Max-var_G)/6.0)+(del_Max/2.0))/del_Max;
|
||||
double del_B =(((var_Max-var_B)/6.0)+(del_Max/2.0))/del_Max;
|
||||
//---
|
||||
if(var_R==var_Max)
|
||||
oH=del_B-del_G;
|
||||
else if(var_G==var_Max)
|
||||
oH=(1.0/3.0)+del_R-del_B;
|
||||
else if(var_B==var_Max)
|
||||
oH=(2.0/3.0)+del_G-del_R;
|
||||
//---
|
||||
if(oH<0)
|
||||
oH+=1.0;
|
||||
//---
|
||||
if(oH>1)
|
||||
oH-=1.0;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå HSL â RGB |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::HSLtoRGB(const double aH,const double aS,const double aL,double &oR,double &oG,double &oB)
|
||||
{
|
||||
if(aS==0)
|
||||
{
|
||||
oR=aL*255;
|
||||
oG=aL*255;
|
||||
oB=aL*255;
|
||||
}
|
||||
else
|
||||
{
|
||||
double var_2=0.0;
|
||||
//---
|
||||
if(aL<0.5)
|
||||
var_2=aL*(1.0+aS);
|
||||
else
|
||||
var_2=(aL+aS)-(aS*aL);
|
||||
//---
|
||||
double var_1=2.0*aL-var_2;
|
||||
oR =255.0*Hue_To_RGB(var_1,var_2,aH+(1.0/3.0));
|
||||
oG =255.0*Hue_To_RGB(var_1,var_2,aH);
|
||||
oB =255.0*Hue_To_RGB(var_1,var_2,aH-(1.0/3.0));
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå RGB â HSV |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::RGBtoHSV(const double aR,const double aG,const double aB,double &oH,double &oS,double &oV)
|
||||
{
|
||||
const double var_R =(aR/255.0);
|
||||
const double var_G =(aG/255.0);
|
||||
const double var_B =(aB/255.0);
|
||||
const double var_Min =::MathMin(var_R,::MathMin(var_G, var_B));
|
||||
const double var_Max =::MathMax(var_R,::MathMax(var_G,var_B));
|
||||
const double del_Max =var_Max-var_Min;
|
||||
//---
|
||||
oV=var_Max;
|
||||
//---
|
||||
if(del_Max==0)
|
||||
{
|
||||
oH=0;
|
||||
oS=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
oS=del_Max/var_Max;
|
||||
const double del_R =(((var_Max-var_R)/6.0)+(del_Max/2))/del_Max;
|
||||
const double del_G =(((var_Max-var_G)/6.0)+(del_Max/2))/del_Max;
|
||||
const double del_B =(((var_Max-var_B)/6.0)+(del_Max/2))/del_Max;
|
||||
//---
|
||||
if(var_R==var_Max)
|
||||
oH=del_B-del_G;
|
||||
else if(var_G==var_Max)
|
||||
oH=(1.0/3.0)+del_R-del_B;
|
||||
else if(var_B==var_Max)
|
||||
oH=(2.0/3.0)+del_G-del_R;
|
||||
//---
|
||||
if(oH<0)
|
||||
oH+=1.0;
|
||||
//---
|
||||
if(oH>1.0)
|
||||
oH-=1.0;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå HSV â RGB |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::HSVtoRGB(const double aH,const double aS,const double aV,double &oR,double &oG,double &oB)
|
||||
{
|
||||
if(aS==0)
|
||||
{
|
||||
oR =aV*255.0;
|
||||
oG =aV*255.0;
|
||||
oB =aV*255.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
double var_h=aH*6.0;
|
||||
//---
|
||||
if(var_h==6)
|
||||
var_h=0;
|
||||
//---
|
||||
int var_i =int(var_h);
|
||||
double var_1 =aV*(1.0-aS);
|
||||
double var_2 =aV*(1.0-aS*(var_h-var_i));
|
||||
double var_3 =aV*(1.0-aS*(1.0-(var_h-var_i)));
|
||||
double var_r =0.0;
|
||||
double var_g =0.0;
|
||||
double var_b =0.0;
|
||||
//---
|
||||
if(var_i==0)
|
||||
{
|
||||
var_r =aV;
|
||||
var_g =var_3;
|
||||
var_b =var_1;
|
||||
}
|
||||
else if(var_i==1.0)
|
||||
{
|
||||
var_r=var_2;
|
||||
var_g=aV;
|
||||
var_b=var_1;
|
||||
}
|
||||
else if(var_i==2.0)
|
||||
{
|
||||
var_r=var_1;
|
||||
var_g=aV;
|
||||
var_b=var_3;
|
||||
}
|
||||
else if(var_i==3)
|
||||
{
|
||||
var_r=var_1;
|
||||
var_g=var_2;
|
||||
var_b=aV;
|
||||
}
|
||||
else if(var_i==4)
|
||||
{
|
||||
var_r=var_3;
|
||||
var_g=var_1;
|
||||
var_b=aV;
|
||||
}
|
||||
else
|
||||
{
|
||||
var_r=aV;
|
||||
var_g=var_1;
|
||||
var_b=var_2;
|
||||
}
|
||||
//---
|
||||
oR =var_r*255.0;
|
||||
oG =var_g*255.0;
|
||||
oB =var_b*255.0;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå RGB â CMY |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::RGBtoCMY(const double aR,const double aG,const double aB,double &oC,double &oM,double &oY)
|
||||
{
|
||||
oC =1.0-(aR/255.0);
|
||||
oM =1.0-(aG/255.0);
|
||||
oY =1.0-(aB/255.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå CMY â RGB |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::CMYtoRGB(const double aC,const double aM,const double aY,double &oR,double &oG,double &oB)
|
||||
{
|
||||
oR =(1.0-aC)*255.0;
|
||||
oG =(1.0-aM)*255.0;
|
||||
oB =(1.0-aY)*255.0;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå CMY â CMYK |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::CMYtoCMYK(const double aC,const double aM,const double aY,double &oC,double &oM,double &oY,double &oK)
|
||||
{
|
||||
double var_K=1;
|
||||
//---
|
||||
if(aC<var_K)
|
||||
var_K=aC;
|
||||
if(aM<var_K)
|
||||
var_K=aM;
|
||||
if(aY<var_K)
|
||||
var_K=aY;
|
||||
//---
|
||||
if(var_K==1.0)
|
||||
{
|
||||
oC =0;
|
||||
oM =0;
|
||||
oY =0;
|
||||
}
|
||||
else
|
||||
{
|
||||
oC =(aC-var_K)/(1.0-var_K);
|
||||
oM =(aM-var_K)/(1.0-var_K);
|
||||
oY =(aY-var_K)/(1.0-var_K);
|
||||
}
|
||||
//---
|
||||
oK=var_K;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå CMYK â CMY |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::CMYKtoCMY(const double aC,const double aM,const double aY,const double aK,double &oC,double &oM,double &oY)
|
||||
{
|
||||
oC =(aC*(1.0-aK)+aK);
|
||||
oM =(aM*(1.0-aK)+aK);
|
||||
oY =(aY*(1.0-aK)+aK);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîëó÷åíèå çíà÷åíèé êîìïîíåíòîâ RGB |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::ColorToRGB(const color aColor,double &aR,double &aG,double &aB)
|
||||
{
|
||||
aR =GetR(aColor);
|
||||
aG =GetG(aColor);
|
||||
aB =GetB(aColor);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîëó÷åíèå çíà÷åíèÿ êîìïîíåíòà R |
|
||||
//+------------------------------------------------------------------+
|
||||
double CColors::GetR(const color aColor)
|
||||
{
|
||||
return(aColor&0xff);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîëó÷åíèå çíà÷åíèÿ êîìïîíåíòà G |
|
||||
//+------------------------------------------------------------------+
|
||||
double CColors::GetG(const color aColor)
|
||||
{
|
||||
return((aColor>>8)&0xff);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîëó÷åíèå çíà÷åíèÿ êîìïîíåíòà B |
|
||||
//+------------------------------------------------------------------+
|
||||
double CColors::GetB(const color aColor)
|
||||
{
|
||||
return((aColor>>16)&0xff);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå RGB â const color |
|
||||
//+------------------------------------------------------------------+
|
||||
color CColors::RGBToColor(const double aR,const double aG,const double aB)
|
||||
{
|
||||
int int_r =(int)::MathRound(aR);
|
||||
int int_g =(int)::MathRound(aG);
|
||||
int int_b =(int)::MathRound(aB);
|
||||
int Color =0;
|
||||
//---
|
||||
Color=int_b;
|
||||
Color<<=8;
|
||||
Color|=int_g;
|
||||
Color<<=8;
|
||||
Color|=int_r;
|
||||
//---
|
||||
return((color)Color);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîëó÷åíèå çíà÷åíè ïðîìåæóòî÷íîãî öâåòà ìåæäó äâóõ öâåòîâ |
|
||||
//+------------------------------------------------------------------+
|
||||
color CColors::MixColors(const color aCol1,const color aCol2,const double aK)
|
||||
{
|
||||
//--- aK - îò 0 äî 1
|
||||
double R1=0.0,G1=0.0,B1=0.0,R2=0.0,G2=0.0,B2=0.0;
|
||||
//---
|
||||
ColorToRGB(aCol1,R1,G1,B1);
|
||||
ColorToRGB(aCol2,R2,G2,B2);
|
||||
//---
|
||||
R1+=(int)::MathRound(aK*(R2-R1));
|
||||
G1+=(int)::MathRound(aK*(G2-G1));
|
||||
B1+=(int)::MathRound(aK*(B2-B1));
|
||||
//---
|
||||
return(RGBToColor(R1,G1,B1));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîëó÷åíèå ìàññèâà çàäàííîãî ðàçìåðà ñ öâåòîâûì ãðàäèåíòîì |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::Gradient(color &aColors[], // Ñïèñîê öâåòîâ
|
||||
color &aOut[], // Âîçâðàùàåìûé ìàññèâ
|
||||
int aOutCount, // Óñòàíîâêà ðàçìåðà âîçâðàùàåìîãî ìàññèâà
|
||||
bool aCycle=false) // Çàìêíóòûé öèêë. Âîçâðàùàåìûé ìàññèâ çàêàí÷èâàåòñÿ òàêèì æå öâåòîì, ñ êîòîðîãî íà÷èíàåòñÿ
|
||||
{
|
||||
::ArrayResize(aOut,aOutCount);
|
||||
//---
|
||||
int InCount =::ArraySize(aColors)+aCycle;
|
||||
int PrevJ =0;
|
||||
int nci =0;
|
||||
double K =0.0;
|
||||
//---
|
||||
for(int i=1; i<InCount; i++)
|
||||
{
|
||||
int J=(aOutCount-1)*i/(InCount-1);
|
||||
//---
|
||||
for(int j=PrevJ; j<=J; j++)
|
||||
{
|
||||
if(aCycle && i==InCount-1)
|
||||
{
|
||||
nci =0;
|
||||
K =1.0*(j-PrevJ)/(J-PrevJ+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
nci =i;
|
||||
K =1.0*(j-PrevJ)/(J-PrevJ);
|
||||
}
|
||||
aOut[j]=MixColors(aColors[i-1],aColors[nci],K);
|
||||
}
|
||||
PrevJ=J;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Åùå îäèí âàðèàíò ïðåîáðàçîâàíèÿ RGB â XYZ è |
|
||||
//| ñîîòâåòñòâóþùåå åìó ïðåîáðàçîâàíèå XYZ â RGB |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::RGBtoXYZsimple(double aR,double aG,double aB,double &oX,double &oY,double &oZ)
|
||||
{
|
||||
aR/=255;
|
||||
aG/=255;
|
||||
aB/=255;
|
||||
aR*=100;
|
||||
aG*=100;
|
||||
aB*=100;
|
||||
//---
|
||||
oX=0.431*aR+0.342*aG+0.178*aB;
|
||||
oY=0.222*aR+0.707*aG+0.071*aB;
|
||||
oZ=0.020*aR+0.130*aG+0.939*aB;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| XYZtoRGBsimple |
|
||||
//+------------------------------------------------------------------+
|
||||
void CColors::XYZtoRGBsimple(const double aX,const double aY,const double aZ,double &oR,double &oG,double &oB)
|
||||
{
|
||||
oR=3.063*aX-1.393*aY-0.476*aZ;
|
||||
oG=-0.969*aX+1.876*aY+0.042*aZ;
|
||||
oB=0.068*aX-0.229*aY+1.069*aZ;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Íåãàòèâíûé öâåò |
|
||||
//+------------------------------------------------------------------+
|
||||
color CColors::Negative(const color aColor)
|
||||
{
|
||||
double R=0.0,G=0.0,B=0.0;
|
||||
ColorToRGB(aColor,R,G,B);
|
||||
//---
|
||||
return(RGBToColor(255-R,255-G,255-B));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïîèñê íàèáîëåå ïîõîæåãî öâåòà |
|
||||
//| â íàáîðå ñòàíäàðòíûõ öâåòîâ òåðìèíàëà |
|
||||
//+------------------------------------------------------------------+
|
||||
color CColors::StandardColor(const color aColor,int &aIndex)
|
||||
{
|
||||
color m_c[]=
|
||||
{
|
||||
clrBlack,clrDarkGreen,clrDarkSlateGray,clrOlive,clrGreen,clrTeal,clrNavy,clrPurple,clrMaroon,clrIndigo,
|
||||
clrMidnightBlue,clrDarkBlue,clrDarkOliveGreen,clrSaddleBrown,clrForestGreen,clrOliveDrab,clrSeaGreen,
|
||||
clrDarkGoldenrod,clrDarkSlateBlue,clrSienna,clrMediumBlue,clrBrown,clrDarkTurquoise,clrDimGray,
|
||||
clrLightSeaGreen,clrDarkViolet,clrFireBrick,clrMediumVioletRed,clrMediumSeaGreen,clrChocolate,clrCrimson,
|
||||
clrSteelBlue,clrGoldenrod,clrMediumSpringGreen,clrLawnGreen,clrCadetBlue,clrDarkOrchid,clrYellowGreen,
|
||||
clrLimeGreen,clrOrangeRed,clrDarkOrange,clrOrange,clrGold,clrYellow,clrChartreuse,clrLime,clrSpringGreen,
|
||||
clrAqua,clrDeepSkyBlue,clrBlue,clrFuchsia,clrRed,clrGray,clrSlateGray,clrPeru,clrBlueViolet,clrLightSlateGray,
|
||||
clrDeepPink,clrMediumTurquoise,clrDodgerBlue,clrTurquoise,clrRoyalBlue,clrSlateBlue,clrDarkKhaki,clrIndianRed,
|
||||
clrMediumOrchid,clrGreenYellow,clrMediumAquamarine,clrDarkSeaGreen,clrTomato,clrRosyBrown,clrOrchid,
|
||||
clrMediumPurple,clrPaleVioletRed,clrCoral,clrCornflowerBlue,clrDarkGray,clrSandyBrown,clrMediumSlateBlue,
|
||||
clrTan,clrDarkSalmon,clrBurlyWood,clrHotPink,clrSalmon,clrViolet,clrLightCoral,clrSkyBlue,clrLightSalmon,
|
||||
clrPlum,clrKhaki,clrLightGreen,clrAquamarine,clrSilver,clrLightSkyBlue,clrLightSteelBlue,clrLightBlue,
|
||||
clrPaleGreen,clrThistle,clrPowderBlue,clrPaleGoldenrod,clrPaleTurquoise,clrLightGray,clrWheat,clrNavajoWhite,
|
||||
clrMoccasin,clrLightPink,clrGainsboro,clrPeachPuff,clrPink,clrBisque,clrLightGoldenrod,clrBlanchedAlmond,
|
||||
clrLemonChiffon,clrBeige,clrAntiqueWhite,clrPapayaWhip,clrCornsilk,clrLightYellow,clrLightCyan,clrLinen,
|
||||
clrLavender,clrMistyRose,clrOldLace,clrWhiteSmoke,clrSeashell,clrIvory,clrHoneydew,clrAliceBlue,clrLavenderBlush,
|
||||
clrMintCream,clrSnow,clrWhite,clrDarkCyan,clrDarkRed,clrDarkMagenta,clrAzure,clrGhostWhite,clrFloralWhite
|
||||
};
|
||||
//---
|
||||
double m_rv=0.0,m_gv=0.0,m_bv=0.0;
|
||||
//---
|
||||
ColorToRGB(aColor,m_rv,m_gv,m_bv);
|
||||
//---
|
||||
double m_md=0.3*::MathPow(255,2)+0.59*::MathPow(255,2)+0.11*::MathPow(255,2)+1;
|
||||
aIndex=0;
|
||||
//---
|
||||
for(int i=0; i<138; i++)
|
||||
{
|
||||
double m_d=0.3*::MathPow(GetR(m_c[i])-m_rv,2)+0.59*::MathPow(GetG(m_c[i])-m_gv,2)+0.11*::MathPow(GetB(m_c[i])-m_bv,2);
|
||||
//---
|
||||
if(m_d<m_md)
|
||||
{
|
||||
m_md =m_d;
|
||||
aIndex =i;
|
||||
}
|
||||
}
|
||||
//---
|
||||
return(m_c[aIndex]);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðåîáðàçîâàíèå â ñåðûé öâåò |
|
||||
//+------------------------------------------------------------------+
|
||||
double CColors::RGBtoGray(double aR,double aG,double aB)
|
||||
{
|
||||
aR/=255;
|
||||
aG/=255;
|
||||
aB/=255;
|
||||
//---
|
||||
aR=::MathPow(aR,2.2);
|
||||
aG=::MathPow(aG,2.2);
|
||||
aB=::MathPow(aB,2.2);
|
||||
//---
|
||||
double rY=0.21*aR+0.72*aG+0.07*aB;
|
||||
rY=::MathPow(rY,1.0/2.2);
|
||||
//---
|
||||
return(rY);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Ïðîñòîå ïðåîáðàçîâàíèå â ñåðûé öâåò |
|
||||
//+------------------------------------------------------------------+
|
||||
double CColors::RGBtoGraySimple(double aR,double aG,double aB)
|
||||
{
|
||||
aR/=255;
|
||||
aG/=255;
|
||||
aB/=255;
|
||||
double rY=0.3*aR+0.59*aG+0.11*aB;
|
||||
//---
|
||||
return(rY);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,21 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Defines.mqh |
|
||||
//| Copyright 2015, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
//--- Class name
|
||||
#define CLASS_NAME ::StringSubstr(__FUNCTION__,0,::StringFind(__FUNCTION__,"::"))
|
||||
//--- Program name
|
||||
#define PROGRAM_NAME ::MQLInfoString(MQL_PROGRAM_NAME)
|
||||
//--- Program type
|
||||
#define PROGRAM_TYPE (ENUM_PROGRAM_TYPE)::MQLInfoInteger(MQL_PROGRAM_TYPE)
|
||||
//--- Prevention of exceeding the array size
|
||||
#define PREVENTING_OUT_OF_RANGE __FUNCTION__," > Prevention of exceeding the array size."
|
||||
|
||||
//--- Font
|
||||
#define FONT ("Calibri")
|
||||
#define FONT_SIZE (8)
|
||||
|
||||
//--- Timer step (milliseconds)
|
||||
#define TIMER_STEP_MSC (16)
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,243 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Element.mqh |
|
||||
//| Copyright 2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include "Objects.mqh"
|
||||
#include "Colors.mqh"
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Base class of control |
|
||||
//+------------------------------------------------------------------+
|
||||
class CElement
|
||||
{
|
||||
protected:
|
||||
//--- Class instance for working with the color
|
||||
CColors m_clr;
|
||||
//--- (1) Name of class and (2) program, (3) program type
|
||||
string m_class_name;
|
||||
string m_program_name;
|
||||
ENUM_PROGRAM_TYPE m_program_type;
|
||||
//--- Identifier and window number of the chart
|
||||
long m_chart_id;
|
||||
int m_subwin;
|
||||
//--- Identifier and index of control
|
||||
int m_id;
|
||||
int m_index;
|
||||
//--- Coordinates and boundaries
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_x2;
|
||||
int m_y2;
|
||||
int m_x_size;
|
||||
int m_y_size;
|
||||
int m_x_gap;
|
||||
int m_y_gap;
|
||||
//--- Control states
|
||||
bool m_is_visible;
|
||||
bool m_is_dropdown;
|
||||
int m_is_object_tabs;
|
||||
//--- Focus
|
||||
bool m_mouse_focus;
|
||||
//--- Chart corner and anchor point of objects
|
||||
ENUM_BASE_CORNER m_corner;
|
||||
ENUM_ANCHOR_POINT m_anchor;
|
||||
//--- Number of colors in the gradient
|
||||
int m_gradient_colors_total;
|
||||
//--- Common array of pointers to all objects in this control
|
||||
CChartObject *m_objects[];
|
||||
//---
|
||||
public:
|
||||
CElement(void);
|
||||
~CElement(void);
|
||||
//--- (1) Obtaining and setting the class name, (2) obtaining the program name,
|
||||
// (3) obtaining the program type, (4) setting the number of the chart window
|
||||
string ClassName(void) const { return(m_class_name); }
|
||||
void ClassName(const string class_name) { m_class_name=class_name; }
|
||||
string ProgramName(void) const { return(m_program_name); }
|
||||
ENUM_PROGRAM_TYPE ProgramType(void) const { return(m_program_type); }
|
||||
void SubwindowNumber(const int number) { m_subwin=number; }
|
||||
//--- Obtaining the object pointer by the specified index
|
||||
CChartObject *Object(const int index);
|
||||
//--- (1) Obtaining the number of the control objects, (2) emptying the object array
|
||||
int ObjectsElementTotal(void) const { return(::ArraySize(m_objects)); }
|
||||
void FreeObjectsArray(void) { ::ArrayFree(m_objects); }
|
||||
//--- Setting and obtaining the control identifier
|
||||
void Id(const int id) { m_id=id; }
|
||||
int Id(void) const { return(m_id); }
|
||||
//--- Setting and obtaining the control index
|
||||
void Index(const int index) { m_index=index; }
|
||||
int Index(void) const { return(m_index); }
|
||||
//--- Boundaries
|
||||
int X(void) const { return(m_x); }
|
||||
void X(const int x) { m_x=x; }
|
||||
int Y(void) const { return(m_y); }
|
||||
void Y(const int y) { m_y=y; }
|
||||
int X2(void) const { return(m_x+m_x_size); }
|
||||
int Y2(void) const { return(m_y+m_y_size); }
|
||||
//--- Size
|
||||
int XSize(void) const { return(m_x_size); }
|
||||
void XSize(const int x_size) { m_x_size=x_size; }
|
||||
int YSize(void) const { return(m_y_size); }
|
||||
void YSize(const int y_size) { m_y_size=y_size; }
|
||||
//--- Indents from the edge point (xy)
|
||||
int XGap(void) const { return(m_x_gap); }
|
||||
void XGap(const int x_gap) { m_x_gap=x_gap; }
|
||||
int YGap(void) const { return(m_y_gap); }
|
||||
void YGap(const int y_gap) { m_y_gap=y_gap; }
|
||||
//--- Control states
|
||||
void IsVisible(const bool flag) { m_is_visible=flag; }
|
||||
bool IsVisible(void) const { return(m_is_visible); }
|
||||
void IsDropdown(const bool flag) { m_is_dropdown=flag; }
|
||||
bool IsDropdown(void) const { return(m_is_dropdown); }
|
||||
void IsObjectTabs(const int index) { m_is_object_tabs=index; }
|
||||
int IsObjectTabs(void) const { return(m_is_object_tabs); }
|
||||
//--- (1) Focus, (2) setting the gradient size
|
||||
bool MouseFocus(void) const { return(m_mouse_focus); }
|
||||
void MouseFocus(const bool focus) { m_mouse_focus=focus; }
|
||||
void GradientColorsTotal(const int total) { m_gradient_colors_total=total; }
|
||||
//---
|
||||
public:
|
||||
//--- Chart event handler
|
||||
virtual void OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam) {}
|
||||
//--- Timer
|
||||
virtual void OnEventTimer(void) {}
|
||||
//--- Moving the control
|
||||
virtual void Moving(const int x,const int y) {}
|
||||
//--- (1) Showing, (2) hiding, (3) resetting, (4) deleting
|
||||
virtual void Show(void) {}
|
||||
virtual void Hide(void) {}
|
||||
virtual void Reset(void) {}
|
||||
virtual void Delete(void) {}
|
||||
//--- (1) Setting, (2) resetting of priorities for left clicking on mouse
|
||||
virtual void SetZorders(void) {}
|
||||
virtual void ResetZorders(void) {}
|
||||
//---
|
||||
protected:
|
||||
//--- Method to add pointers of primitive objects to the common array
|
||||
void AddToArray(CChartObject &object);
|
||||
//--- Initializing the array gradient
|
||||
void InitColorArray(const color outer_color,const color hover_color,color &color_array[]);
|
||||
//--- Changing the object color
|
||||
void ChangeObjectColor(const string name,const bool mouse_focus,const ENUM_OBJECT_PROPERTY_INTEGER property,
|
||||
const color outer_color,const color hover_color,const color &color_array[]);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CElement::CElement(void) : m_x(0),
|
||||
m_y(0),
|
||||
m_x2(0),
|
||||
m_y2(0),
|
||||
m_x_size(0),
|
||||
m_y_size(0),
|
||||
m_x_gap(0),
|
||||
m_y_gap(0),
|
||||
m_is_visible(true),
|
||||
m_is_dropdown(false),
|
||||
m_mouse_focus(false),
|
||||
m_id(WRONG_VALUE),
|
||||
m_index(WRONG_VALUE),
|
||||
m_gradient_colors_total(3),
|
||||
m_is_object_tabs(WRONG_VALUE),
|
||||
m_corner(CORNER_LEFT_UPPER),
|
||||
m_anchor(ANCHOR_LEFT_UPPER),
|
||||
m_program_name(PROGRAM_NAME),
|
||||
m_program_type(PROGRAM_TYPE),
|
||||
m_class_name("")
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CElement::~CElement(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Returns the object pointer of the control by index |
|
||||
//+------------------------------------------------------------------+
|
||||
CChartObject *CElement::Object(const int index)
|
||||
{
|
||||
int array_size=::ArraySize(m_objects);
|
||||
//--- Verifying the size of the object array
|
||||
if(array_size<1)
|
||||
{
|
||||
::Print(__FUNCTION__," > No ("+m_class_name+") objects in this control!");
|
||||
return(NULL);
|
||||
}
|
||||
//--- Correction in case the size was exceeded
|
||||
int i=(index>=array_size)? array_size-1 :(index<0)? 0 : index;
|
||||
//--- Return the object pointer
|
||||
return(m_objects[i]);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Adds object pointer to an array |
|
||||
//+------------------------------------------------------------------+
|
||||
void CElement::AddToArray(CChartObject &object)
|
||||
{
|
||||
int size=ObjectsElementTotal();
|
||||
::ArrayResize(m_objects,size+1);
|
||||
m_objects[size]=::GetPointer(object);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialization of the gradient array |
|
||||
//+------------------------------------------------------------------+
|
||||
void CElement::InitColorArray(const color outer_color,const color hover_color,color &color_array[])
|
||||
{
|
||||
//--- Array of the gradient colors
|
||||
color colors[2];
|
||||
colors[0]=outer_color;
|
||||
colors[1]=hover_color;
|
||||
//--- Formation of the color array
|
||||
m_clr.Gradient(colors,color_array,m_gradient_colors_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Changing of object color when hovering the cursor over it |
|
||||
//+------------------------------------------------------------------+
|
||||
void CElement::ChangeObjectColor(const string name,const bool mouse_focus,const ENUM_OBJECT_PROPERTY_INTEGER property,
|
||||
const color outer_color,const color hover_color,const color &color_array[])
|
||||
{
|
||||
if(::ArraySize(color_array)<1)
|
||||
return;
|
||||
//--- Obtain the current object color
|
||||
color current_color=(color)::ObjectGetInteger(m_chart_id,name,property);
|
||||
//--- If the cursor is over the object
|
||||
if(mouse_focus)
|
||||
{
|
||||
//--- Leave, if the specified color has been reached
|
||||
if(current_color==hover_color)
|
||||
return;
|
||||
//--- Move from the first to the last one
|
||||
for(int i=0; i<m_gradient_colors_total; i++)
|
||||
{
|
||||
//--- If colors do not match, move to the following
|
||||
if(color_array[i]!=current_color)
|
||||
continue;
|
||||
//---
|
||||
color new_color=(i+1==m_gradient_colors_total)? color_array[i]: color_array[i+1];
|
||||
//--- Change color
|
||||
::ObjectSetInteger(m_chart_id,name,property,new_color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//--- If the cursor is not in the area of the object
|
||||
else
|
||||
{
|
||||
//--- Leave, if the specified color has been reached
|
||||
if(current_color==outer_color)
|
||||
return;
|
||||
//--- Move from the last to the first one
|
||||
for(int i=m_gradient_colors_total-1; i>=0; i--)
|
||||
{
|
||||
//--- If colors do not match, move to the following
|
||||
if(color_array[i]!=current_color)
|
||||
continue;
|
||||
//---
|
||||
color new_color=(i-1<0)? color_array[i]: color_array[i-1];
|
||||
//--- Change color
|
||||
::ObjectSetInteger(m_chart_id,name,property,new_color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,306 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Objects.mqh |
|
||||
//| Copyright 2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include "Enums.mqh"
|
||||
#include "Defines.mqh"
|
||||
#include <ChartObjects/ChartObjectsBmpControls.mqh>
|
||||
#include <ChartObjects/ChartObjectsTxtControls.mqh>
|
||||
//--- List of classes in file for a quick navigation (Alt+G)
|
||||
class CRectLabel;
|
||||
class CEdit;
|
||||
class CLabel;
|
||||
class CBmpLabel;
|
||||
class CButton;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class with additional properties for the Rectangle Label object |
|
||||
//+------------------------------------------------------------------+
|
||||
class CRectLabel : public CChartObjectRectLabel
|
||||
{
|
||||
protected:
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_x2;
|
||||
int m_y2;
|
||||
int m_x_gap;
|
||||
int m_y_gap;
|
||||
int m_x_size;
|
||||
int m_y_size;
|
||||
bool m_mouse_focus;
|
||||
public:
|
||||
CRectLabel(void);
|
||||
~CRectLabel(void);
|
||||
//--- Coordinates
|
||||
int X(void) { return(m_x); }
|
||||
void X(const int x) { m_x=x; }
|
||||
int Y(void) { return(m_y); }
|
||||
void Y(const int y) { m_y=y; }
|
||||
int X2(void) { return(m_x+m_x_size); }
|
||||
int Y2(void) { return(m_y+m_y_size); }
|
||||
//--- Indents from the edge point (xy)
|
||||
int XGap(void) { return(m_x_gap); }
|
||||
void XGap(const int x_gap) { m_x_gap=x_gap; }
|
||||
int YGap(void) { return(m_y_gap); }
|
||||
void YGap(const int y_gap) { m_y_gap=y_gap; }
|
||||
//--- Sizes
|
||||
int XSize(void) { return(m_x_size); }
|
||||
void XSize(const int x_size) { m_x_size=x_size; }
|
||||
int YSize(void) { return(m_y_size); }
|
||||
void YSize(const int y_size) { m_y_size=y_size; }
|
||||
//--- Focus
|
||||
bool MouseFocus(void) { return(m_mouse_focus); }
|
||||
void MouseFocus(const bool focus) { m_mouse_focus=focus; }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CRectLabel::CRectLabel(void) : m_x(0),
|
||||
m_y(0),
|
||||
m_x2(0),
|
||||
m_y2(0),
|
||||
m_x_gap(0),
|
||||
m_y_gap(0),
|
||||
m_x_size(0),
|
||||
m_y_size(0),
|
||||
m_mouse_focus(false)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CRectLabel::~CRectLabel(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class with additional properties for the Edit object |
|
||||
//+------------------------------------------------------------------+
|
||||
class CEdit : public CChartObjectEdit
|
||||
{
|
||||
protected:
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_x2;
|
||||
int m_y2;
|
||||
int m_x_gap;
|
||||
int m_y_gap;
|
||||
int m_x_size;
|
||||
int m_y_size;
|
||||
bool m_mouse_focus;
|
||||
public:
|
||||
CEdit(void);
|
||||
~CEdit(void);
|
||||
//--- Coordinates
|
||||
int X(void) { return(m_x); }
|
||||
void X(const int x) { m_x=x; }
|
||||
int Y(void) { return(m_y); }
|
||||
void Y(const int y) { m_y=y; }
|
||||
int X2(void) { return(m_x+m_x_size); }
|
||||
int Y2(void) { return(m_y+m_y_size); }
|
||||
//--- Indents from the edge point (xy)
|
||||
int XGap(void) { return(m_x_gap); }
|
||||
void XGap(const int x_gap) { m_x_gap=x_gap; }
|
||||
int YGap(void) { return(m_y_gap); }
|
||||
void YGap(const int y_gap) { m_y_gap=y_gap; }
|
||||
//--- Sizes
|
||||
int XSize(void) { return(m_x_size); }
|
||||
void XSize(const int x_size) { m_x_size=x_size; }
|
||||
int YSize(void) { return(m_y_size); }
|
||||
void YSize(const int y_size) { m_y_size=y_size; }
|
||||
//--- Focus
|
||||
bool MouseFocus(void) { return(m_mouse_focus); }
|
||||
void MouseFocus(const bool focus) { m_mouse_focus=focus; }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CEdit::CEdit(void) : m_x(0),
|
||||
m_y(0),
|
||||
m_x2(0),
|
||||
m_y2(0),
|
||||
m_x_gap(0),
|
||||
m_y_gap(0),
|
||||
m_x_size(0),
|
||||
m_y_size(0),
|
||||
m_mouse_focus(false)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CEdit::~CEdit(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class with additional properties for the Label object |
|
||||
//+------------------------------------------------------------------+
|
||||
class CLabel : public CChartObjectLabel
|
||||
{
|
||||
protected:
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_x2;
|
||||
int m_y2;
|
||||
int m_x_gap;
|
||||
int m_y_gap;
|
||||
int m_x_size;
|
||||
int m_y_size;
|
||||
public:
|
||||
CLabel(void);
|
||||
~CLabel(void);
|
||||
//--- Coordinates
|
||||
int X(void) { return(m_x); }
|
||||
void X(const int x) { m_x=x; }
|
||||
int Y(void) { return(m_y); }
|
||||
void Y(const int y) { m_y=y; }
|
||||
int X2(void) { return(m_x+m_x_size); }
|
||||
int Y2(void) { return(m_y+m_y_size); }
|
||||
//--- Indents from the edge point (xy)
|
||||
int XGap(void) { return(m_x_gap); }
|
||||
void XGap(const int x_gap) { m_x_gap=x_gap; }
|
||||
int YGap(void) { return(m_y_gap); }
|
||||
void YGap(const int y_gap) { m_y_gap=y_gap; }
|
||||
//--- Sizes
|
||||
int XSize(void) { return(m_x_size); }
|
||||
void XSize(const int x_size) { m_x_size=x_size; }
|
||||
int YSize(void) { return(m_y_size); }
|
||||
void YSize(const int y_size) { m_y_size=y_size; }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CLabel::CLabel(void) : m_x(0),
|
||||
m_y(0),
|
||||
m_x2(0),
|
||||
m_y2(0),
|
||||
m_x_gap(0),
|
||||
m_y_gap(0),
|
||||
m_x_size(0),
|
||||
m_y_size(0)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CLabel::~CLabel(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class with additional properties for the Bmp Label object |
|
||||
//+------------------------------------------------------------------+
|
||||
class CBmpLabel : public CChartObjectBmpLabel
|
||||
{
|
||||
protected:
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_x2;
|
||||
int m_y2;
|
||||
int m_x_gap;
|
||||
int m_y_gap;
|
||||
int m_x_size;
|
||||
int m_y_size;
|
||||
bool m_mouse_focus;
|
||||
public:
|
||||
CBmpLabel(void);
|
||||
~CBmpLabel(void);
|
||||
//--- Coordinates
|
||||
int X(void) { return(m_x); }
|
||||
void X(const int x) { m_x=x; }
|
||||
int Y(void) { return(m_y); }
|
||||
void Y(const int y) { m_y=y; }
|
||||
int X2(void) { return(m_x+m_x_size); }
|
||||
int Y2(void) { return(m_y+m_y_size); }
|
||||
//--- Indents from the edge point (xy)
|
||||
int XGap(void) { return(m_x_gap); }
|
||||
void XGap(const int x_gap) { m_x_gap=x_gap; }
|
||||
int YGap(void) { return(m_y_gap); }
|
||||
void YGap(const int y_gap) { m_y_gap=y_gap; }
|
||||
//--- Sizes
|
||||
int XSize(void) { return(m_x_size); }
|
||||
void XSize(const int x_size) { m_x_size=x_size; }
|
||||
int YSize(void) { return(m_y_size); }
|
||||
void YSize(const int y_size) { m_y_size=y_size; }
|
||||
//--- Focus
|
||||
bool MouseFocus(void) { return(m_mouse_focus); }
|
||||
void MouseFocus(const bool focus) { m_mouse_focus=focus; }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CBmpLabel::CBmpLabel(void) : m_x(0),
|
||||
m_y(0),
|
||||
m_x2(0),
|
||||
m_y2(0),
|
||||
m_x_gap(0),
|
||||
m_y_gap(0),
|
||||
m_x_size(0),
|
||||
m_y_size(0),
|
||||
m_mouse_focus(false)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CBmpLabel::~CBmpLabel(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class with additional properties for the Edit object |
|
||||
//+------------------------------------------------------------------+
|
||||
class CButton : public CChartObjectButton
|
||||
{
|
||||
protected:
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_x2;
|
||||
int m_y2;
|
||||
int m_x_gap;
|
||||
int m_y_gap;
|
||||
int m_x_size;
|
||||
int m_y_size;
|
||||
bool m_mouse_focus;
|
||||
public:
|
||||
CButton(void);
|
||||
~CButton(void);
|
||||
//--- Coordinates
|
||||
int X(void) { return(m_x); }
|
||||
void X(const int x) { m_x=x; }
|
||||
int Y(void) { return(m_y); }
|
||||
void Y(const int y) { m_y=y; }
|
||||
int X2(void) { return(m_x+m_x_size); }
|
||||
int Y2(void) { return(m_y+m_y_size); }
|
||||
//--- Indents from the edge point (xy)
|
||||
int XGap(void) { return(m_x_gap); }
|
||||
void XGap(const int x_gap) { m_x_gap=x_gap; }
|
||||
int YGap(void) { return(m_y_gap); }
|
||||
void YGap(const int y_gap) { m_y_gap=y_gap; }
|
||||
//--- Sizes
|
||||
int XSize(void) { return(m_x_size); }
|
||||
void XSize(const int x_size) { m_x_size=x_size; }
|
||||
int YSize(void) { return(m_y_size); }
|
||||
void YSize(const int y_size) { m_y_size=y_size; }
|
||||
//--- Focus
|
||||
bool MouseFocus(void) { return(m_mouse_focus); }
|
||||
void MouseFocus(const bool focus) { m_mouse_focus=focus; }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CButton::CButton(void) : m_x(0),
|
||||
m_y(0),
|
||||
m_x2(0),
|
||||
m_y2(0),
|
||||
m_x_gap(0),
|
||||
m_y_gap(0),
|
||||
m_x_size(0),
|
||||
m_y_size(0),
|
||||
m_mouse_focus(false)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CButton::~CButton(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user