Canvas is cool! - page 27

 
Aлександр Антошкин:
The eagle with two heads in different shapes, colours and versions has been on our coat of arms for over five centuries - from the time of the Moscow State during Ivan III until 1918, as a consequence of genetic mutation.....
What is it that you want to correct in Peter?

I don't catch the logic. Where did you see that I want to correct something in someone?

 
Nikolai Semko:

I don't catch the logic. Where did you see me wanting to correct something from someone?

It's such subtle trolling. Hinting that I am an incorrigible consequence of genetic mutation.) I read the author's other posts and thought that he himself is an experimental AI on our forum. ))

https://www.mql5.com/ru/forum/221552/page1485#comment_12959767

От теории к практике
От теории к практике
  • 2019.08.23
  • www.mql5.com
Добрый вечер, уважаемые трейдеры! Решил было на какое-то время покинуть форум, и сразу как-то скучно стало:)))) А просто читать, увы - неинтересно...
 
Aleksey Vyazmikin:

Is this how ticks can be presented?

 
fxsaber:

I mean the ticks should be presented as bars - 5 seconds each, let's say.

 

Hello!

Is it possible to use Canvas to create panels? (CAppDialog).

Directly, with Add(), a CCanvas object obviously cannot be added to a panel.

Maybe there is a workaround, e.g. first create a resource and then, treating it as a simpler object, you can bind it to a CAppDialog?

But I'm not really even sure what functions to use to try and pull such a trick.

Anyway, help!

There's so much great stuff in this thread that my task seems quite simple against this background!

 
Evgeny Potapov:

Hello!

Is it possible to use Canvas to create panels? (CAppDialog).

Directly, with Add(), a CCanvas object obviously cannot be added to a panel.

Maybe there is a workaround, e.g. first create a resource and then, treating it as a simpler object, you can bind it to a CAppDialog?

But I'm not really even sure what functions to use to try and pull such a trick.

Anyway, help!

There's so much great stuff in this topic, that my task seems quite simple against this background!

I'm afraid it won't work.
Because CAppDialog is drawn on OBJ_RECTANGLE objects, and CCanvas is OBJ_BITMAP_LABEL object and there is no way to cross them.
But it is possible to draw a canvas on top of the panel's window and monitor the changes in the panel and redraw the canvas at the same time.

Like this:

// это эксперт
#define protected public  // увы, это необходимо, чтобы расширить наши возможности 
#include <Controls\Dialog.mqh>
#include <Canvas\Canvas.mqh> 
#undef protected
CAppDialog D;
CCanvas C;
int OnInit()
  {
   if(!D.Create(0,"AppWindow",0,100,100,400,300))
      return(INIT_FAILED);
   D.Run();
   if(!C.CreateBitmapLabel(D.m_chart_id,D.m_subwin,D.m_name+"_Canvas",D.m_rect.left,D.m_rect.top,D.m_rect.right-D.m_rect.left,D.m_rect.bottom-D.m_rect.top,COLOR_FORMAT_ARGB_NORMALIZE))
      Print("Error creating canvas: ",GetLastError());
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   D.Destroy(reason);
   C.Destroy();
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id,          
                  const long& lparam,   
                  const double& dparam, 
                  const string& sparam) 
  {
   static int X=0, Y=0;
   D.ChartEvent(id,lparam,dparam,sparam);
   if (D.m_rect.left!=X || D.m_rect.top!=Y) 
   { DrawCanvas(); X=D.m_rect.left; Y=D.m_rect.top;}
  }
//+------------------------------------------------------------------+
void DrawCanvas()
{
 // изменяем канвас в соответсвии положения и размера панели
 static int w=0, h=0, tf=0;
 int x=D.m_rect.left;
 int y=D.m_rect.top;
 int width = D.m_rect.right-x;
 int height =D.m_rect.bottom-y;
 ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_XDISTANCE,x);
 ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_YDISTANCE,y);
 if (w!=width) ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_XSIZE,width);
 if (h!=height) ObjectSetInteger(C.m_chart_id,C.m_objname,OBJPROP_YSIZE,height);
 
 if(w!=width || h!=height || tf!=_Period)
 {
   C.Erase();
// здесь формируем рисунок на панели
   C.FillCircle(50,20,30,ColorToARGB(clrViolet,200));
   C.FillCircle(100,100,50,ColorToARGB(clrLightBlue,100));
   C.Rectangle(200,50,250,150,ColorToARGB(clrAqua));
//----------------------------------
   C.Update(); 
   
   tf=_Period;
   w=width;
   h=height;
 }
}



but since a panel is a set of objects, just add another one to that set.

So, this way it works and kanvas is drawn only in one place (in this case, function DrawCanvas) in the panel's coordinates and I don't need to worry about attaching it to the panel and redrawing it.

 
   if (D.m_rect.left!=X || D.m_rect.top!=Y) DrawCanvas();
   else {X=D.m_rect.left; Y=D.m_rect.top;}
Else сработает только когда left=x и top=y , тогда зачем их присваивать ещё раз
 
Aleksei Beliakov:

Yes, thank you, Alexey. Slowed down ))
Corrected.

 
Nikolai Semko:

I'm afraid that this will not work.
Because CAppDialog is drawn using OBJ_RECTANGLE objects and CCanvas is an OBJ_BITMAP_LABEL object and there is no way to merge them.

Thank you! This variant looks quite realistic!

Is it possible to extend CAppDialog and include OBJ_BITMAP_LABEL in it?

 
Evgeny Potapov:

Thank you! This variant looks quite realistic!

Is it possible to extend CAppDialog and include OBJ_BITMAP_LABEL in it?

Of course it is possible, if you have the desire and time.