Discussion of article "Graphical Interfaces X: The Standard Chart Control (build 4)"

 

New article Graphical Interfaces X: The Standard Chart Control (build 4) has been published:

This time we will consider the Standard chart control. It will allow to create arrays of subcharts with the ability to synchronize horizontal scrolling. In addition, we will continue to optimize the library code to reduce the CPU load.

The library for creating graphical interfaces at the current stage of development looks like in the schematic below.

 Fig. 6. Structure of the library at the current stage of development.

Author: Anatoli Kazharski

 
Если к этому прибавить ещё перемещение курсора мыши в области графика и активное взаимодействие с графическим интерфейсом MQL-приложения, то потребление вырастет ещё больше. Задача состоит в том, чтобы ограничить работу таймера движка библиотеки и исключить перерисовку графика по приходу события перемещения курсора мыши.

For OBJ_CHART scrolling, why use a timer? And for interaction with the interface - a similar question. It seems that mouse events should always suffice.

 
fxsaber:

For OBJ_CHART scrolling, why use a timer? And for interaction with the interface - a similar question. After all, it seems that mouse events should always suffice.

What you quoted refers not to OBJ_CHART, but to the timer of the library engine as a whole. That's why the solution of this problem was put in a separate section of the article "Optimisation of the timer and event handler of the library engine" as an addition to the main topic.

The timer is used to change the colour of controls on mouseover, as well as accelerated scrolling of lists, tables, calendar and values in input fields.

//---

P.S. And OBJ_CHART scrolling is just carried out by the mouse cursor movement event - CHARTEVENT_MOUSE_MOVE. In the listing below is the code of the handler (shortened version) of events of the "Standard Chart" element (class CStandardChart):

//+------------------------------------------------------------------+
//| Event handling|
//+------------------------------------------------------------------+
void CStandardChart::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
//--- Handling of cursor movement event
   if(id==CHARTEVENT_MOUSE_MOVE)
     {
      //--- Exit if the item is hidden
      if(!CElement::IsVisible())
         return;
      //--- Exit if in subwindow resizing mode
      if(CheckDragBorderWindowMode())
         return;
      //--- Exit if subwindow numbers do not match
      if(CElement::m_subwin!=CElement::m_mouse.SubWindowNumber())
         return;
      //--- Exit if the form is blocked by another element
      if(m_wnd.IsLocked() && m_wnd.IdActivatedElement()!=CElement::Id())
         return;
      //--- Focus check
      CElement::MouseFocus(m_mouse.X()>X() && m_mouse.X()<X2() && m_mouse.Y()>Y() && m_mouse.Y()<Y2());
      //--- If there is a focus
      if(CElement::MouseFocus())
         //--- Horizontal scrolling of the graph
         HorizontalScroll();
      //--- If there is no focus and the left mouse button is released
      else if(!m_mouse.LeftButtonState())
        {
         //--- Hide horizontal scroll pointer
         m_x_scroll.Hide();
         //--- Unlock the form
         if(m_wnd.IdActivatedElement()==CElement::Id())
           {
            m_wnd.IsLocked(false);
            m_wnd.IdActivatedElement(WRONG_VALUE);
           }
        }
      //---
      return;
     }
//...
  }
 
Anatoli Kazharski:

Timer-based colour change of control elements on mouseover is arranged

Why couldn't the mouse be used here?
 
fxsaber:
Why can't I use the mouse here?

Because there is a smooth colour change (the number of steps is set by the user).

This also applies to the scrolling of lists. If you use the method as it is implemented in SB, you will have jagged (uneven) scrolling.

 
Anatoli Kazharski:

Because a smooth colour change is provided (the number of steps is set by the user).

This also applies to the scrolling of lists. If you use the method as it is implemented in SB, you will get jagged (uneven) scrolling.

Why is there no jagged scrolling for OBJ_CHART?
 
fxsaber:
Why then for OBJ_CHART tearing does not come out ?

In what case (relative to the test Expert Advisor from the article) ?

  1. In the case when scrolling through the calendar is performed?
  2. In case of manual scrolling by CHARTEVENT_MOUSE_MOVE event in the item event handler(CStandardChart) ?

If the former, then the chart scrolling is timed, as the calendar scrolling is timed. That is, generation of the calendar date change event(ON_CHANGE_DATE) is timed at 16 ms interval.

If the second, the shift is calculated and is not always equal to 1 bar. So it only seems that manual scrolling by CHARTEVENT_MOUSE_MOVE event is smooth.

 
Anatoli Kazharski:

If the second, the shift is calculated and is not always equal to 1 bar. So it just seems that scrolling manually by CHARTEVENT_MOUSE_MOVE event is smooth.

Got it, thanks!

 
Thank you for the article. Was looking forward to it. Not disappointed :)
 

Anatoly, tell me what the cause of the error is

2016.10.19 03:09:04.993 TestTable (EURUSD,H1)   invalid pointer access in 'Scrolls.mqh' (698,10)

Everything worked fine before this update. Now when building the CTable table this error pops up.

Please tell me where it is wrong - I have already printed every line - the interface is built, but after somewhere stumbles, and .... error.

File with an example in the archive.

Files:
TestTable.zip  734 kb
 

Found it.

Take your example from MQL4\Experts\Article07\TestLibrary02\TestLibrary02.mq4.

From your example above:

Make the number of columns and the number of visible columns the same , compile, run, and get an error.

//+------------------------------------------------------------------+
//|| Creates a table|
//+------------------------------------------------------------------+
bool CProgram::CreateTable(void)
  {
//#define COLUMNS1_TOTAL (100)
//#define ROWS1_TOTAL (1000)
#define COLUMNS1_TOTAL (6)
#define ROWS1_TOTAL    (1000)
//--- Save the pointer to the form
   m_table.WindowPointer(m_window1);
//--- Coordinates
   int x=m_window1.X()+TABLE1_GAP_X;
   int y=m_window1.Y()+TABLE1_GAP_Y;
//--- Number of visible columns and rows
   int visible_columns_total =6;
   int visible_rows_total    =15;
//--- Set properties before creation
   m_table.XSize(600);
   m_table.RowYSize(20);
   m_table.FixFirstRow(true);
   m_table.FixFirstColumn(true);
   m_table.LightsHover(true);
   m_table.SelectableRow(true);
   m_table.TextAlign(ALIGN_CENTER);
   m_table.HeadersColor(C'255,244,213');
   m_table.HeadersTextColor(clrBlack);
   m_table.CellColorHover(clrGold);
   m_table.TableSize(COLUMNS1_TOTAL,ROWS1_TOTAL);
   m_table.VisibleTableSize(visible_columns_total,visible_rows_total);
//--- Create a control
   if(!m_table.CreateTable(m_chart_id,m_subwin,x,y))
      return(false);
//--- Let's fill in the table:
// The first cell is empty
   m_table.SetValue(0,0,"-");
//--- Headings for columns
   for(int c=1; c<COLUMNS1_TOTAL; c++)
     {
      for(int r=0; r<1; r++)
         m_table.SetValue(c,r,"SYMBOL "+string(c));
     }
//--- Headings for rows, text alignment method - to the right
   for(int c=0; c<1; c++)
     {
      for(int r=1; r<ROWS1_TOTAL; r++)
        {
         m_table.SetValue(c,r,"PARAMETER "+string(r));
         m_table.TextAlign(c,r,ALIGN_RIGHT);
        }
     }
//--- Data and table formatting (background colour and cell colour)
   for(int c=1; c<COLUMNS1_TOTAL; c++)
     {
      for(int r=1; r<ROWS1_TOTAL; r++)
        {
         m_table.SetValue(c,r,string(c)+":"+string(r));
         m_table.TextColor(c,r,(c%2==0)? clrRed : clrRoyalBlue);
         m_table.CellColor(c,r,(r%2==0)? clrWhiteSmoke : clrWhite);
        }
     }
//--- Refresh the table to show changes
   m_table.UpdateTable();
//--- Add the object to the common array of object groups
   CWndContainer::AddToElementsArray(0,m_table);
   return(true);
  }
//+------------------------------------------------------------------+
Actually, if you make the number of rows and the number of visible rows the same, you get the same error.
This website uses cookies. Learn more about our Cookies Policy.