Making a crowdsourced project on Canvas - page 32

 
Алексей Барбашин:

That's exactly how I built it. Basically, I took the standard library as a basis, because it has very well worked out moments of events transfer and some other things. Anatoly creates grouping for each different class of elements, in the standard one everything is reduced to one base object.

...

In his examples Nikolay shows that it's not necessary to bother storing all the data of local areas because repaint of the whole canvas is so fast, that it doesn't need to go down to details and it's enough to redraw the whole canvas at once.
It is not that simple. Imagine that you have a large (full-size) table where one of the cells changes value 20 times per second. If you redraw the whole canvas, the load on the processor will increase up to 40% or more. Absolutely wrong way of working with a canvas. You need to redraw separate elements, otherwise tables, glass and various local animations will overload the processor and slow down execution of other functions (if they are in a common thread).
 
Реter Konow:
It is not that simple. Imagine, you have drawn a large (entire chart) table, where one of the cells changes value 20 times per second. If you redraw the entire canvas, the load on the processor will increase up to 40% or more. Absolutely wrong way of working with a canvas. You need to redraw separate elements, otherwise tables, glass and different local animations will overload the processor and slow down execution of other functions (if they are in a common thread).

Nikolay's experiments so far prove the opposite. He redraws all the contents of the canvas in one go, and it's clearly visible in the code.

But I'm still in favor of local changes. But this approach has its own difficulties, which I have not yet solved.

 
Алексей Барбашин:

Nikolay's experiments so far prove the opposite. He redraws all the contents of the canvas in one go, and it's clearly visible in the code.

But I'm still in favor of local changes. But this approach has its own difficulties that I have not yet solved.

I consider Nikolay my friend and he's reached some great heights in working with canvas, but still he hasn't performed full-fledged experiments with controls. Particularly with tables and glass. At any rate, I'm not aware of any.

The bottom line is this: A canvas is an array of data. The data is changed and re-saved at change events. If the array includes all pixels of the chart space - then its size = height*width of the chart. If there is a local change of pixel values inside the array, there is no need to do a full loop on the whole array and reset all the values. You need to do a loop on the changed area, set the values and exit the loop. Otherwise, no matter how you slice it, it's a waste of resources and time.

And there are a lot of difficulties with this approach. The main one is to create own fully functional objects, find and process them on one's own canvas. In-house CCanvas is not suitable for that. It would not "see" your elements and you can't access them through it. It has no such functionality.

 
Реter Konow:

I consider Nikolai a friend of mine, and he has achieved great heights with canvas, but still he has not done full-fledged experiments with the controls. Particularly with tables and a tumbler. At any rate, I'm not aware of any.

The bottom line is this: A canvas is an array of data. The data is changed and re-saved at change events. If the array includes all pixels of the chart space - then its size = height*width of the chart. If there is a local change of pixel values inside the array, there is no need to do a full loop on the whole array and reset all the values. You need to do a loop on the changed area, set the values and exit the loop. Otherwise, no matter how you slice it, it's a waste of resources and time.

And there are a lot of difficulties with this approach. The main one is to create own fully functional objects, find and process them on one's own canvas. In-house CCanvas is not suitable for that. It would not "see" your elements and you can't access them through it. There is no such a functionality there.

I understand all this very well and am well aware of it. I have created my own object classes and it all works fine.

 
Алексей Барбашин:

I understand all of this very well and am very aware of it. I have my object classes created and it all works fine.

In this case, you can check by creating a table and updating it in two ways - locally (each cell separately) and all at once the whole table.

 

Nikolai's animations mostly have a low refresh rate, and so, simultaneously redrawing the whole canvas doesn't come out as an overlap. But if you increase the refresh rate up to 5 times per second, you can see an increase in CPU resource consumption. If you need to redraw the whole animation - no way out, but if a single, small area inside - better just that one.

The frequency itself - 5 times per second - can occur in a table where values change asynchronously. This situation occurred to me on MT4, when I connected the table to the tester via resources. There, at speed 31 all parameters are changing so fast that an incorrect redraw of the table caused CPU load of 50% or more. Even local redrawing of elements didn't save it completely. I came up with the idea of slowing down the speed at which the values were displayed. The values themselves were changing at a natural rate, but they were output to the cells several times less frequently. This solved the problem.

Here's an example. 1000 cells should change values at a rate of 25ms. In fact, the cells change values about once every 500ms and the CPU load is about 50%. (This is MT4 and the table is drawn).

https://www.mql5.com/ru/forum/293630/page160


Here is an example with the tester. The table is drawn, but it doesn't save the processor from overload. :) (tester speed 31, cell update full (no pin skipping)).

https://www.mql5.com/ru/forum/293630/page148

 
Реter Konow:
It's not that simple. Imagine that you have a large (for the whole chart) table where one of the cells changes values 20 times per second. If you redraw the whole canvas, the load on the processor will increase up to 40% or more. Absolutely wrong way of working with a canvas. You need to redraw separate elements, otherwise tables, glass and different local animations will overload the processor and slow down execution of other functions (if they are in a common thread).

I'm not quite sure where you are getting your figures from. Look at Nikolai's perfectly simple example https://www.mql5.com/ru/forum/227736/page44#comment_13445909. On a kanvas the size of a graph, several objects are generated which can be dragged and dropped on the graph (on the kanvas). The entire kanvas is redrawn. There is no slowdown at all.

Canvas - это круто!
Canvas - это круто!
  • 2019.09.20
  • www.mql5.com
Поставил себе задачу: коротким кодом эффектно продемонстрировать возможности пользовательской графики через класс CCanvas...
 
Алексей Барбашин:

I'm not quite sure where you are getting your figures from. Look at Nikolai's perfectly simple example https://www.mql5.com/ru/forum/227736/page44#comment_13445909. On a kanvas the size of a graph, several objects are generated which can be dragged and dropped on the graph (on the kanvas). The entire kanvas is redrawn. There is no any slowdowns.

Look at the examples above.

Inserted the links to the hyphae.
 

Here is an example of slowing down the output of values to cells and reducing the load on the processor:


https://www.mql5.com/ru/forum/293630/page148

 
Алексей Барбашин:

I'm not quite sure where you are getting your figures from. Look at Nikolai's perfectly simple example https://www.mql5.com/ru/forum/227736/page44#comment_13445909. On a kanvas the size of a graph, several objects are generated which can be dragged and dropped on the graph (on the kanvas). The entire kanvas is redrawn. There is no slowdown at all.

The refresh rate in that example is normal. Therefore, there is no slowdown.

Reason: