Canvas is cool! - page 94

 

I've had a serious problem with flicker in mql4 whilst using canvas.

My fist thought was hardware, but after testing I pretty much ruled this out. Then I checked chart-events as I've a lot going on and have duplicated calls to draw the canvas in the past. This also seems OK.

I found the problem is Resize... Specifically:  ArrayInitialize(m_pixels, 0 );  On a light BG it flashes black before Erase resets the light color.


I think I've solved this(It seems to work) but I'm a newbie with oop.


class MyCanvas : public CCanvas
{
public:
        CCanvas(void);
       ~CCanvas(void);
   
   bool Resize_Erase(const int width, const int height, const uint clr)
   {
      if(m_rcname!=NULL && width>0 && height>0)
         if(ArrayResize(m_pixels,width*height)>0)
         {
            m_width =width;
            m_height=height;
            ArrayInitialize(m_pixels, clr);
            if(ResourceCreate(m_rcname,m_pixels,m_width,m_height,0,0,0,m_format))
            {
               if(m_objname!=NULL && ObjectSetString(m_chart_id,m_objname,OBJPROP_BMPFILE,m_rcname))
                  return(true);
            }
         }
//--- error - destroy object
      Destroy();
      return(false);
   }
};
 
Jon_G #:

I have a serious flickering problem in mql4 when using canvas.

My first thought was hardware, but after testing I pretty much ruled out that possibility. I then checked chart-events, as I have a lot of events and in the past I have duplicated calls to draw canvas. There seems to be nothing wrong with that either.

I found that the problem lies in the resizing..... Specifically: ArrayInitialize(m_pixels, 0) ; On a light BG it flashes black before Erase resets the light colour.


I think I've solved this problem (it seems to work), but I'm new to oop.

It's bad practice to recreate the canvas object every time. This is a very expensive procedure, so flickering is inevitable.
I suggest you consider creating the canvas object once at initialisation for the whole chart and resize it only when the chart window itself is resized.
If you don't need the whole window size, create the largest possible size and don't change it, only move it.
It's much more convenient and productive to work with this class:

https://www.mql5.com/ru/code/22164 - MT5
https://www.mql5.com/en/code/23840 - MT4

 

Sorry, the construcror/destructor isn't supposed to be there. I must of made a C&P mistake.

 
Jon_G #:

Sorry, the construct/destructor shouldn't be there. I must have made a mistake in C&P.

The constructor/destructor has nothing to do with it.
 
Nikolai Semko #:


I suggest you consider creating the canvas object once at initialisation for the whole chart and resize it only when the chart window itself is resized.


This is exactly what I've been doing. 


" create the largest possible size and don't change it, only move it. "

Thanks, I'll think on that.

 
Jon_G #:


This is exactly what I've been doing. 


" create the largest possible size and don't change it, only move it. "

Thanks, I'll think on that.


bool iCanvas::MoveCanvas(const int x,const int y) {
   if(ObjectSetInteger(m_chart_id,m_objname,OBJPROP_XDISTANCE,x) && ObjectSetInteger(m_chart_id,m_objname,OBJPROP_YDISTANCE,y))  return(true);
   else return(false);
}
 
Nikolai,
Affine transform indicator https://www.mql5.com/ru/code/9378 converts price data in a diffrent dimension.Can you combine the canvas channels with affine transform? So we can. view the price data in diffrent dimensions?
 
невозможно #:
Nicholas,
The affine transformation indicator https://www.mql5.com/ru/code/9378 transforms price data in different dimensions. Is it possible to merge canvas channels with affine transformation? Can we. view price data in different dimensions?

Of course it is possible

For example, in this video, Fourier approximations and extrapolation are calculated after such transformations in each parabolic channel:


After the Fourier calculation, an inverse transformation is performed to output the Fourier line to the graph.
 
Just a demonstration of Canvas capabilities.
Video is not accelerated, everything works without lags.
OpenCL and DirectX were not used.
If you use OpenCL, the processor will not be loaded at all.
But even with the use of a simple processor the time of forming one frame is on average 5 -15 milliseconds.


 
Nikolai Semko #:
Just a demonstration of Canvas capabilities.
Video is not accelerated, everything works without lags.
OpenCL and DirectX were not used.
If you use OpenCL, the processor will not be loaded at all.
But even with the use of a simple processor the time of forming one frame is on average 5 -15 milliseconds.


.

Is the onTimer() in onTimer()? If so, what Event in milliseconds is set?

Reason: