Libraries: Easy Canvas - page 12

 
Nikolai Semko:

Does this apply to the normal mode or the tester?

Normal mode, Nikolai.

 
Nikolai Semko:

Thank you!

Is this function not suitable?

Unfortunately not. It moves the bitmap object itself, I need a function that moves the content x points. I know that internally the memory consists of an x, y array but there is no memmove or something in mql. I don't know how to move the memory quickly.

 
Владислав Качило :

Normal mode, Nikolai.

I usually follow the following scheme:

  1. I perform all drawing, tied to bars or time, in a single function, for example void Draw()
  2. in OnChartEvent I add the line
    if (id == CHARTEVENT_CHART_CHANGE ) Draw (); 
    tracking the chart change event (a new bar is also a chart change event).
  3. in OnCalculate for test mode I add a line for redrawing for example when a new bar occurs, because OnChartEvent does not work:
    .
     if(rate_total-prev_calculated == 1) if (Canvas.tester) {ChartChanged (); Draw ();}

If it doesn't work in MT4, then something is wrong with the CHARTEVENT_CHART_CHANGE event. I can't check it now, there are no quotes yet.

 
Nikolai Semko:

I usually do the following:

  1. I do all drawing, tied to bars or time, in one function, for example void Draw()
  2. I add a line to OnChartEvent to track the chart change event (a new bar is also a chart change event).
  3. In OnCalculate for the test mode I add a line for redrawing, for example, when a new bar occurs, because OnChartEvent does not work:

If it doesn't work in MT4, then something is wrong with the CHARTEVENT_CHART_CHANGE event. I can't check it now, there are no quotes yet.

Nicholas, so that you don't waste your time, I wrote above a solution that solved my problem, namely, as you correctly noticed, the following code inserted into OnCalcucate():

if(rates_total - prev_calculated == 1)ChartChanged();

 
Mighty7:

Unfortunately not. It moves the bitmap object itself, I need a function that moves the content x points. I know that internally the memory consists of an x, y array but there is no memmove or something in mql. I don't know how to move the memory quickly.

I didn't get it, do you need to move the rectangular area inside the entire canvas?

 
Vladyslav Katsylo:

Nicholas, so that you don't waste your time I wrote above a solution that solved my problem, namely, as you correctly noticed, the following code inserted into OnCalcucate():

In normal non-test mode you should not do this, because the ChartChanged() function will be executed twice in a row, which is not reasonable. After all, it is executed when the CHARTEVENT_CHART_CHANGE event occurs inside the iCanvas.mqh file.
It is correct to redraw your canvas bound to bars or time in OnChartEvent when the window change event ( CHARTEVENT_CHART_CHANGE) occurs without using ChartChanged().

 
Vladyslav Katsylo:

Nicholas, so that you don't waste your time, I wrote above a solution that solved my problem, namely, as you correctly noticed, the following code inserted into OnCalcucate():

You need to take the following into consideration:

  • ChartChanged() is executed each time the CHARTEVENT_CHART_CHANGE event occurs in OnChartEvent inside the iCanvas class
  • The OnChartEvent inside the iCanvas class is executed first , and then the OnChartEvent of your code is executed .

Your problem was because OnCalculate is apparently executed before OnChartEvent is executed and therefore ChartChanged() has not been executed yet.
That's why it is reasonable to implement the redraw handler exactly in OnChartEvent and not in On
Calculate. Especially it should be done because the user can change the size of the window at any time. The CHARTEVENT_CHART_CHANGE event is responsible for all this

 
Nikolai Semko:

I didn't get it, do you need to move the rectangular area inside the whole canvas?

Yes. Example: I draw a circle in the middle of the full screen canvas and want to move the circle to the left, but I don't want to delete the entire area and repaint the circle with every movement, but simply scroll the memory to the left.

The CCanvas is simply an x/y Array of points.

   uint              m_pixels[];               // array of pixels
//+------------------------------------------------------------------+
//| Get pixel colour|
//+------------------------------------------------------------------+
uint CCanvas::PixelGet(const int x,const int y) const
  {
//--- check coordinates
   if(x>=0 && x<m_width && y>=0 && y<m_height)
      return(m_pixels[y*m_width+x]);
//--- error
   return(0);
  }

I mean a function which moves the m_pixels to the left, right, up, down.

 
Mighty7:

Yes. Example: I draw a circle in the middle of the full screen canvas and want to move the circle to the left, but I don't want to delete the entire area and repaint the circle with every movement, but simply scroll the memory to the left.

The CCanvas is simply an x/y Array of points.

I mean a function which moves the m_pixels to the left, right, up, down.

Yes, it's a reasonable wish.
All the more it is not difficult to implement it.
I thought about it, but I came to the conclusion that if there is a need to move the rectangular part of the common canvas, there is an easier way to implement it:

  • Create a new smaller canvas. In this case, you don't have to worry about filling the background of the part to be moved.

Yes, a well-founded desire.
Moreover, it is not difficult to implement it.
I thought about it, but came to the conclusion that if there is a need to move the rectangular part of the common canvas, then there is an easier way to implement it:
  • Create a new, smaller canvas. In this case, you don't have to worry about filling the background of the moving part.
 
Nikolai Semko:

Yes, quite a reasonable desire.
All the more it is not difficult to implement it.
I thought about it, but came to the conclusion that if there is a need to move the rectangular part of the general canvas, there is an easier way to implement it:

  • Create a new smaller canvas. In this case, you don't have to worry about filling the background of the part to be moved.

Yes, a well-founded desire.
Moreover, it is not difficult to implement it.
I thought about it, but came to the conclusion that if there is a need to move the rectangular part of the common canvas, then there is an easier way to implement it:
  • Create a new, smaller canvas. In this case, you don't have to worry about filling the background of the moving part.

That's not working because my Canvas is the fullscreen. It's like a tick chart but it cost too much time to erase the complete background and construcht and paint everything new so I need to move the content to the left (eg. 8 pixels) and draw only the new 8 pixels (8 px in x direction and full height) with new data. I tried to move the Canvas 8 px to the left with MoveCanvas and this is working but I can't resize it the way that from the left 8 px width are removed and on the right 8 px are added. I hope you understand...