Libraries: Easy Canvas - page 13

 
Mighty7:

It would take too long to erase all the background, build and paint everything new

Not that much. It can take a lot of time to build.

We keep the state in memory (position of elements, their colour, etc.), if we need, for example, to move an element, we change its coordinates, erase the canvas and draw a new state. Visually it looks lightning fast, even with a lot of elements )

 
Mighty7:

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...

Mighty7:

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...

Ok, done. Download version 1.42.
But you need to control vertical resizing.

Ok, done. Download version 1.42 for yourself.
But you need to control the change in vertical scale.

#include <Canvas\iCanvas.mqh> //https://www.mql5.com/en/code/22164

input int shift = -1;
//+------------------------------------------------------------------+
int OnInit() {
   EventSetMillisecondTimer(100);
   Canvas.Erase(0x00FFFFFF);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnTimer() {
   Canvas.FillCircle(rand()%_Width,rand()%_Height, 10+rand()%100,Canvas.Grad(rand()/32767.0)&0x80FFFFFF);
   Canvas.ShiftCanvas(shift);
   Canvas.Update();
   
}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[]) {
   return(rates_total);
}
void              ShiftCanvas(const int _shift=-1, uint bckgr = 0x00FFFFFF) { // shift the entire canvas to the left (x is a negative value) or to
                     // the right (x is a positive value). The canvas itself remains in place, but all pixels are shifted. The bckgr is 
                     // the colour with which the newly created stripe is filled to the left or right, depending on the direction of the shift.
                        if (_shift==0) return;
                        int _Shift = Fabs(_shift);
                        if (_Shift>=m_width) { ArrayInitialize(m_pixels,bckgr); return;}
                        int start = (_shift>0)?0:-_shift;
                        int count = m_width-_Shift;
                        int offset= (_shift>0)?0:count;
                        for (; start<m_height*m_width; start+=m_width, offset+=m_width) {                        
                           ArrayCopy(m_pixels,m_pixels,start+_shift,start,count); 
                           ArrayFill(m_pixels,offset,_Shift,bckgr);
                        }                        
                     }



Files:
 
Great. Thank you very much.
 
Mighty7:
Great. Thank you very much.
No problem 😊
 
Nikolai Semko:
No problem 😊

It works like a charme but to have it complete, is it possible to implement a Shift also
at the y axis (north/south)? I need this to scroll/shift in these directions too.

 
Mighty7:

It works like a charme but to have it complete, is it possible to implement a Shift also
at the y axis (north/south)? I need this to scroll/shift in these directions too.

OK. I will do it.

 
Mighty7:

It works like a charme but to have it complete, is it possible to implement a Shift also
at the y axis (north/south)? I need this to scroll/shift in these directions too.

done

ver 1.43

Files:
 
Nikolai Semko :

getan

siehe 1.43

Absolutely brilliant. Thank you very much.

Edit: x=-1,y=0 is not shifting, so it's not working correctly.

 
Mighty7:

Absolutely brilliant. Thank you very much.

Edit: x=-1,y=0 is not shifting, so it's not working correctly.

Thank you. Fixed it.

Files:
iCanvas.mqh  52 kb
 
Nikolai Semko:

Thank you. Corrected.

I have to say thanks. Now it's perfect. Top work.