Gallery of UIs written in MQL - page 77

 
To understand it a little better, this is the base class for any EA or indicator after implementation. 

class CEAMain : public CObject
   {
   public: CEAMain()
      {
      m_classname="CEAMain";
      SubscribeToCycle(EA_CYCLE_LOAD);
      SubscribeToCycle(EA_CYCLE_PARAMS);   
      SubscribeToCycle(EA_CYCLE_INIT);   
      SubscribeToCycle(EA_CYCLE_ACTIVATE);
      SubscribeToCycle(EA_CYCLE_TICK);
      SubscribeToCycle(EA_CYCLE_DEINIT);
      SubscribeToCycle(EA_CYCLE_UNLOAD);
      }
      //+------------------------------------------------------------------+
      //| Cycles handler                                                   |
      //+------------------------------------------------------------------+
      public: virtual void OnEACycle(CEACycleParams * cpm)
         {
         switch (cpm.Cycle)
            {
            case EA_CYCLE_LOAD:        cpm.CycleResult(OnEALoad(PTR(cpm.Init))); break;
            case EA_CYCLE_PARAMS:      cpm.CycleResult(OnEAParams()); break;
            case EA_CYCLE_INIT:        cpm.CycleResult(OnEAInit(PTR(cpm.Init))); break;
            case EA_CYCLE_ACTIVATE:    OnEAActivate(); break;
            case EA_CYCLE_DEINIT:      OnEADeinit(PTR(cpm.Deinit)); break;
            case EA_CYCLE_UNLOAD:      OnEAUnload(PTR(cpm.Deinit)); break;
            case EA_CYCLE_BOOKEVENT:   OnEABookEvent(PTR(cpm.BookEvent)); break;
            }
         }
      //+------------------------------------------------------------------+
      //| Cycles override                                                  |
      //+------------------------------------------------------------------+
      protected: virtual bool OnEALoad(CEAInitParams * ipm)                   { return true; }
      protected: virtual bool OnEAParams(void)                                { return true; }
      protected: virtual bool OnEAInit(CEAInitParams * ipm)                   { return true; } 
      protected: virtual void OnEAActivate(void)                              {}
      protected: virtual void OnEADeinit(CEADeinitParams * dpm)               {}
      protected: virtual void OnEAUnload(CEADeinitParams * dpm)               {}
      protected: virtual void OnEAChartEvent(CEAChartEventParams * cep)       {}
      protected: virtual void OnEABookEvent(CEABookEventParams * cpm)         {}
         
   };
And a final EA looks like this then:

class CMain : public CEAMain
   {
      public: CMain()
         {
         m_classname="MainEA";
         }
      public: ~CMain()
         {
         }         

      //+------------------------------------------------------------------+
      //| Load                                                             |
      //+------------------------------------------------------------------+
      protected: virtual bool OnEALoad(CEAInitParams * ipm)
         {
         Print("Welcome :)");
         return true;
         }
      //+------------------------------------------------------------------+
      //| Expert initialization function                                   |
      //+------------------------------------------------------------------+
      protected: virtual bool OnEAInit(CEAInitParams * ipm)
         { 
         if (ipm.IsFirstInit) return true;
         //--- Account changed init
         if (ipm.IsAccountChanged)
            {
            }
         //--- Symbol change init
         else if (ipm.IsSymbolChanged)    
            {
            }
         return true;
        }
        
      //+------------------------------------------------------------------+
      //| Expert deinitialization function                                 |
      //+------------------------------------------------------------------+
      protected: virtual void OnEADeinit(CEADeinitParams * dpm)
        {
        }
      protected: virtual void OnEAUnload(CEADeinitParams * dpm)
         {
         DeInit();
         Print("Bye.");
         }  
      ...
      ...
};

// Create the main EA object on a global scope. 
CMain __MainEA;
 
Of course, Load/Unload/Activate etc. are custom, but since you have this event-core, you have way more flexibility than without and way more control over absolutely everything. 
If I´d had the time, I would write an article and provide the sources. Its not a secret, no magic at all. 
 
Doerk Hilger control over absolutely everything.
Watched the GUI you created. I like it a lot. Tell me, did you write it yourself or did you use some MQL libraries?
 
Реter Konow #:
Watched the GUI you created. I like it a lot. Tell me, did you write it yourself or did you use some MQL libraries?

Thank you.
No, no libraries. Designed from the scratch by myself. Actually only CCanvas from the original ones is adapted, nothing else.  

 
Doerk Hilger #:

Thank you.
No, no libraries. I developed it from scratch myself. Actually, only CCanvas is adapted from the original ones, nothing else.

It's not easy to make something like this. )

As far as I know, in the standard Ccanvas class there is no functionality for drawing a colour gradient, how did you solve the problem with a gradient in your GUI?
 
Реter Konow #:
It's not easy to make something like this. )

As far as I know, in the standard Ccanvas class there is no functionality for drawing a colour gradient, how did you solve the problem with a gradient in your GUI?

You mean the light-effects? Well, added light :D As described, CCanvas is also only adapted in its basics and its structure, not in its details. 

//+------------------------------------------------------------------+
//| Macro to generate color                                          |
//+------------------------------------------------------------------+
#define XRGB(r,g,b)    (0xFF000000|(uchar(r)<<16)|(uchar(g)<<8)|uchar(b))
#define ARGB(a,r,g,b)  ((uchar(a)<<24)|(uchar(r)<<16)|(uchar(g)<<8)|uchar(b))
#define TRGB(a,rgb)    ((uchar(a)<<24)|(rgb))
#define GETRGB(clr)    ((clr)&0xFFFFFF)
#define GETRGBA(clr)   uchar((clr)>>24)
#define GETRGBR(clr)   uchar((clr)>>16)
#define GETRGBG(clr)   uchar((clr)>>8)
#define GETRGBB(clr)   uchar(clr)
#define COLOR2RGB(clr) (0xFF000000|(uchar(clr)<<16)|(uchar((clr)>>8)<<8)|uchar((clr)>>16))
#define RGB2COLOR(rgb) ((uchar(rgb)<<16)|(uchar((rgb)>>8)<<8)|uchar((rgb)>>16))


//+------------------------------------------------------------------+
//| Add light to rectangular area                                    |
//+------------------------------------------------------------------+
void CCanvasExt::AddLight(int x1, int y1, int x2, int y2, bool updown=true, double intensity=.5, int isoftedge=20, color lightcolor=C'255,255,255')
   {
   if (intensity==0)
      return;
      
   int tmp;
//--- sort vertexes
   if(x2<x1)
     {
      tmp=x1;
      x1 =x2;
      x2 =tmp;
     }
   if(y2<y1)
     {
      tmp=y1;
      y1 =y2;
      y2 =tmp;
     }
//--- out of screen boundaries
   if(x2<0 || y2<0 || x1>=m_width || y1>=m_height)
      return;
//--- stay withing screen boundaries
   if(x1<0)
      x1=0;
   if(y1<0)
      y1=0;
   if(x2>=m_width)
      x2=m_width -1;
   if(y2>=m_height)
      y2=m_height-1;


//--- calculate softedge
   isoftedge=MIN(100,isoftedge);
   int softedge=isoftedge>0 ? isoftedge*(y2-y1)/100 : 0;

//--- correct height
   y2-=(y2-y1)/2;
   y2+=(softedge/2);
   y2++;
   y2=MIN(m_height-1,y2);   
   
//--- prepare 
   COLOR_RGBA rgb=_ColorLumaMult(lightcolor,ABS(intensity));
   double r=(int)GETRGBR(rgb);
   double g=(int)GETRGBG(rgb);
   double b=(int)GETRGBB(rgb);  
   
   if (intensity<0)
      {
      r=0-r;
      g=0-g;
      b=0-b;
      }
   uint pixel;     
   int istart;
   int iend;
   int i;

//--- check direction
   if (updown)
      {
   //--- add main light   
      for(;y1<y2-softedge;y1++)
         {
         istart=y1*m_width+x1;
         iend=istart+(x2-x1);
         for (i=istart;i<=iend;i++)
            {
            pixel=m_pixels[i];
            m_pixels[i]=ARGB(GETRGBA(pixel),MIN(GETRGBR(pixel)+r,0xFF),MIN(GETRGBG(pixel)+g,0xFF),MIN(GETRGBB(pixel)+b,0xFF));// m_pixels[i]+=XRGB(r,g,b);
            //m_pixels[i]|=rgb;
            }
         }
      if (softedge==0)
         return;
   
   //-- Add soft edge 
      double decr=r/softedge;
      double decg=g/softedge;
      double decb=b/softedge;
   
   //--- Loop rows separate and adjust color each row   
      for (;y1<=y2;y1++)
         {
         r-=decr; r=MAX(0,r); 
         g-=decg; g=MAX(0,g); 
         b-=decb; b=MAX(0,b); 
         
         istart=y1*m_width+x1;
         iend=istart+(x2-x1);
         for (i=istart;i<=iend;i++)
            {
            pixel=m_pixels[i];
            m_pixels[i]=ARGB(GETRGBA(pixel),MIN(GETRGBR(pixel)+r,0xFF),MIN(GETRGBG(pixel)+g,0xFF),MIN(GETRGBB(pixel)+b,0xFF));// m_pixels[i]+=XRGB(r,g,b);
            }
         }
      }   
  }   
 
Doerk Hilger #: You mean the lighting effects? Well, added light :D As said, CCanvas is also adapted only in the basics and structure, but not in the details.
I see, thanks. )
 
Реter Konow #:
I see, thanks. )

Feel free to use it :) 
PS: updown is actually useless, as I see. Anyway, light comes from above anyway usually

 
Doerk Hilger #:

Feel free to use it :)
PS: updown is actually useless as far as I can see. In any case, the light usually comes from above.

Yes, you have an interesting option, I'll try it :)

I have the light distribution working the other way round - from a given original colour to a lighter one. Let me explain: the colour partitioning algorithm itself works correctly and writes 256 shades to the array. That is, the full range for each colour that the function accepts. But the painting algorithm puts the gradient on the surfaces of elements only in one direction. For a long time I wanted to add features, and make multidirectional gradient, which would give volume and complex plane elements. In principle, this is not a difficult task. However, there are many more important tasks ahead).

 
friend, If you can figure out how to use the GUI when backtesting your EA, I would be grateful.