Libraries: EasyAndFastGUI library for creating graphical interfaces - page 14

 

Hello.

//+------------------------------------------------------------------+
//| Creating a canvas for drawing an element |
//+------------------------------------------------------------------+
bool CElement::CreateCanvas(const string name,const int x,const int y,
                            const int x_size,const int y_size,ENUM_COLOR_FORMAT clr_format=COLOR_FORMAT_ARGB_NORMALIZE)
  {
//--- Size adjustment
   int xsize =(x_size<1)? 50 : x_size;
   int ysize =(y_size<1)? 20 : y_size;
//--- Reset last error
   ::ResetLastError();
//--- Creating an object
   if(!m_canvas.CreateBitmapLabel(m_chart_id,m_subwin,name,x,y,xsize,ysize,clr_format))
     {
      ::Print(__FUNCTION__," > Failed to create a canvas to draw the item (""+m_class_name+"): ",::GetLastError());
      return(false);
     }
//--- Reset last error
   ::ResetLastError();
//--- Get a pointer to the base class
   if(!m_canvas.Attach(m_chart_id,name,clr_format))
     {
      ::Print(__FUNCTION__," > Failed to attach a drawing canvas to the chart: ",::GetLastError());
      return(false);
     }
//--- Properties
   ::ObjectSetString(m_chart_id,m_canvas.ChartObjectName(),OBJPROP_TOOLTIP,"\n");
   ::ObjectSetInteger(m_chart_id,m_canvas.ChartObjectName(),OBJPROP_CORNER,m_corner);
   ::ObjectSetInteger(m_chart_id,m_canvas.ChartObjectName(),OBJPROP_SELECTABLE,false);
//--- All elements except the form have a higher priority than the main element
   Z_Order((dynamic_cast<CWindow*>(&this)!=NULL)? 0 : m_main.Z_Order()+1);
//--- Coordinates
   m_canvas.X(x);
   m_canvas.Y(y);
//--- Dimensions
   m_canvas.XSize(x_size);
   m_canvas.YSize(y_size);
//--- Indents from the end point
   m_canvas.XGap(CalculateXGap(x));
   m_canvas.YGap(CalculateYGap(y));
   return(true);
  }

CreateBitmapLabel - create a graphic resource

Attach - read the same resource and write to the same resource again.

Or do I understand something wrong?

 

Hello again :)

class CMouse
  {

...............

   //--- (1) Returns the number of the window where the cursor is located, (2) the time corresponding to the X coordinate, 
   // (3) level (price) corresponding to the Y coordinate
   int               SubWindowNumber(void) const { return(m_subwin);                        }
   datetime          Time(void)            const { return(m_time);                          }
   double            Level(void)           const { return(m_level);                         }

Is Time and Level even used anywhere? Couldn't find it anywhere...

What is SubWindowNumber used for?

My point is that ChartXYToTimePrice is quite a costly operation to perform on every mouse movement...

 
Oleksii Chepurnyi:

It's all in the comments. There's nothing to add.

 
Anatoli Kazharski:

It's all in the comments. There is nothing to add.

If you mean comments in the code, everything is clear there, but that's not what the questions are about :)

 
Oleksii Chepurnyi:

...

My point is that ChartXYToTimePrice is quite a costly operation to perform on every mouse movement...

To get the relative coordinate if the GUI is not in the main window.

 
Anatoli Kazharski:

To get relative coordinate when GUI is not in main window.

So maybe calculate only when GUI is not in the main window? :)


I'm more interested in why Attach? As far as I understand, it repeats the actions of CreateBitmapLabel

 
Oleksii Chepurnyi:
So maybe only calculate when the GUI is not in the main window? :)

There are also variants when the main GUI window is in the subwindow of the chart, and the dialogues are in the main window.

I'm more interested in why Attach? As far as I understand, it repeats the actions of CreateBitmapLabel

There is a code of CCanvas::Attach() method:

//+------------------------------------------------------------------+
//| Attach new object with bitmap resource |
//+------------------------------------------------------------------+
bool CCanvas::Attach(const long chart_id,const string objname,ENUM_COLOR_FORMAT clrfmt=COLOR_FORMAT_XRGB_NOALPHA)
  {
   if(OBJ_BITMAP_LABEL==ObjectGetInteger(chart_id,objname,OBJPROP_TYPE))
     {
      string rcname=ObjectGetString(chart_id,objname,OBJPROP_BMPFILE);
      rcname=StringSubstr(rcname,StringFind(rcname,"::"));
      if(ResourceReadImage(rcname,m_pixels,m_width,m_height))
        {
         m_chart_id=chart_id;
         m_objname=objname;
         m_rcname=rcname;
         m_format=clrfmt;
         m_objtype=OBJ_BITMAP_LABEL;
         //--- success
         return(true);
        }
     }
//--- failed
   return(false);
  }
 
Anatoli Kazharski:


There is the code of the CCanvas::Attach() method:

Yes, and above CreateBitmapLabel. I've been looking at them. And as far as I understood, CreateBitmapLabel creates an empty resource, and Attach reads the resource (any) and writes it to m_pixels. And as I wrote above, we create a resource (CreateBitmapLabel) with the name name, then read the same resource (Attach) and again write the read into the same m_pixels

Or do I understand something wrong?

PS Experimentally without Attach everything works :)

 
Oleksii Chepurnyi:

...

PS Experimentally without Attach everything works :)

Really? So there's been some changes again. Something didn't work before for sure.

And after deleting GUI from the chart objects are deleted?

 
Anatoli Kazharski:

Really? So there's been another change. Something definitely wasn't working before.

And after removing the GUI from the graph, are the objects deleted?

Everything seems to be clean :)

Files:
35.png  11 kb
36.png  6 kb