Canvas is cool! - page 28

 
Evgeny Potapov:

Thank you! This option looks quite realistic!

Thank you for your question, because in answering it I realised one very important thing I didn't know.
I'd be surprised if anyone knew about it at all.

If you resize a canvas or its position using ObjectSetInteger, you don't need to redraw it.

  • Even if we resize the generated kanvas and then resize it back, the kanvas data is retained by the original drawing.
  • If you increase the size of the shaped kanvas, the data will disappear, but reappear when you resize it back to its original size.
  • When resizing or changing the kanvas' position it's not even necessary to do Update() or ChartRedraw(), it will be updated with a new tick or window change.

This indicator demonstrates it. The canvas is generated only once. But its size and location can be changed, and the array of values is retained. Simply move the mouse across the screen

#property indicator_chart_window

#define protected public  // увы, это необходимо, чтобы расширить наши возможности 
#include <Canvas\Canvas.mqh> 
#undef protected
CCanvas C;
int OnInit()
  {
   if(!C.CreateBitmapLabel(0,0,"_Canvas",100,100,600,400,COLOR_FORMAT_ARGB_NORMALIZE))
      Print("Error creating canvas: ",GetLastError());
   DrawCanvas(600,400);
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   C.Destroy();
  }
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,       
                 const int prev_calculated,   
                 const int begin,             
                 const double& price[])       
  {
    return prev_calculated;               
  }

void OnChartEvent(const int id,          
                  const long& lparam,   
                  const double& dparam, 
                  const string& sparam) 
  {
   if (id==CHARTEVENT_MOUSE_MOVE)  DrawCanvas((int)lparam,(int)dparam);
  }
//+------------------------------------------------------------------+
void DrawCanvas(int x, int y)
{
 static bool first=true;
 //Comment(string(x)+"   " +string(y));
 ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_XDISTANCE,x/5);
 ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_YDISTANCE,y/5);
 ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_XSIZE,x);
 ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_YSIZE,y);  
 if(first) // канвас формируется только один раз
 {
   C.Erase();
   C.FillCircle(100,100,70,ColorToARGB(clrViolet,200));
   C.FillCircle(300,200,100,ColorToARGB(clrLightBlue,100));
   C.Rectangle(140,50,250,150,ColorToARGB(clrAqua));
   C.Update(); 
   first=false;
 }
 ChartRedraw(); // можно обойтись и без этого, но тогда перерисовка будет только с каждым тиком или изменением чарта
}
Files:
 
is it possible to save to video?
 
Andrey Dik:
can you save to a video?
you can
 
Nikolai Semko:
you can

cool! hopefully not by creating a million images and then assembling them into a video in some video editor?))

if you don't mind, please elaborate

 
Andrey Dik:

cool! hopefully not by creating a million images and then assembling them into a video in some video editor?))

if you don't mind, please elaborate

No, of course not.
It will.

 
Nikolai Semko:

No, of course it doesn't.
It's a hassle.

you don't need the code, give me a hint how to do it.

 
Nikolai Semko:
  • When resizing or changing position of canvas, you don't even need to do Update() or ChartRedraw(), it will be updated with a new tick or window change.

Well, the terminal calls ChartRedraw() by itself according to these events;)

 
Andrey Dik:

no code needed, hint how to do it

There are a lot of options depending on what kind of video you want to capture. Just what happens in the window in real time with mouse pointer, indicators, objects, GUI ? Or something else?

 
What is the real utility of this chip? Does it help to find patterns on the price chart that would help trading?
 
Andrey Khatimlianskii:

Well, the terminal itself calls ChartRedraw() on these events;)

I understand it, I just did not want to go into details.
I drew your attention to it because the chartRedraw() does not redraw the canvas object, it is redrawn only duringUpdate(). And if you use ObjectSetInteger to redraw the canvas object it is enough to force ChartRedraw() or wait for the change of chart or arrival of a new tick, when ChartRedraw() occurs.