Canvas is cool! - page 73

 
Vitaliy Kuznetsov #:

Can someone please advise if there is any ready code for Edit Box to canvas.

I am making a rubber panel and need such an element. When you click on it, you need to enter and delete numbers and see a blinking cursor.

If not, I'll make a normal substitution when clicking on it.

Someone did it, and there were problems not with graphics, but with input - MetaTrader "dragged/processed" the usual buttons (Enter/Tab) and KeyPress/Repeate/Release in general.

It's easier to take a DLL and embed the Windows Control window, or Notepad.exe.

A few days of mate about the lack of information (low-level things are hard to find nowadays, there are few of them), but in the end the code will be two orders of magnitude less and will work better.

 
Vitaliy Kuznetsov #:

Can someone please advise if there is any ready code for Edit Box to canvas.

...

EasyAndFastGUI - library for creating graphical interfaces >>>

See TextBox.mqh file

EasyAndFastGUI - библиотека для создания графических интерфейсов
EasyAndFastGUI - библиотека для создания графических интерфейсов
  • www.mql5.com
Библиотека EasyAndFastGUI дает возможность создавать графические интерфейсы для своих MQL-программ.
 
Thank you all, I'll try different options
 
Maxim Kuznetsov #:

someone did, there were problems not with graphics, but with input - MetaTrader "dragged/processed" the usual buttons (Enter/Tab) and KeyPress/Repeate/Release in general.

It's easier to take a DLL and embed the Windows Control window, or Notepad.exe.

A few days of mate about the lack of information (low-level things are hard to find nowadays, there are few of them), but in the end the code will be two orders of magnitude less and will work better.

by the way about "zambed" and remembering different experiments: windows are embedded, but there are problems with redrawing and input. It's just not usable, I stopped at "the fact that potentially works"

But it's not surprising - EAs work in one track, GUI of chart in another and there are also different things there apparently.
It's necessary to explain Windows somehow so that all required messages are sent and rendering is processed correctly. Not quite a typical GUI design when there is a control (in terms of win, it's a window after all) which has everything in another track.

Of course, I'm at a bit of a dead end here, Linux practice is not favourable. it is necessary to set some (what?) flags to the Expert process (in OS terms, it is not a GUI-tread, as it seems, and some part of it just doesn't fly to it) and/or pull AttachThreadInput.

If such a problem is solved, the prospects are bright for those who are not afraid of DLLs:

- It will be possible to use Gtk/Qt/Lazarus with their designers and really good graphics, for "dialogues inside the chart" (and toplevel are done, but it is not always convenient, still the user works with the chart)

- it will be possible to make your own "tabs" - inside MDI and from "draw a window in the chart" to "make a tab in MT" half a step. All sorts of boards/boards won't require opening a new chart

Yes, at the hack level :-)

 
Vitaliy Kuznetsov #:

Can someone please advise if there is any ready code for Edit Box to canvas.

I am making a rubber panel and need such an element. When you click on it, you need to enter and delete numbers and see a blinking cursor.

If not, I'll make a normal substitution when clicking on it.

Sample code of such EditCtrl (base)

//+------------------------------------------------------------------+
//|                                                     EditCtrl.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Canvas/Canvas.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CControl : protected CCanvas
  {
public:

   bool              Create(int x,int y,int w,int h)
     {
      if(!CCanvas::CreateBitmapLabel("TEST_EDIT",x,y,w,h,COLOR_FORMAT_ARGB_NORMALIZE))
         return(false);
      if(!OnCreate())
         return(false);

      Update();
      return(true);
     }

   void              TimerSet(uint msec)
     {
      if(msec)
         EventSetMillisecondTimer(msec);
      else
         EventKillTimer();
     }

   void              Update(void)
     {
      OnDraw(this);
      CCanvas::Update();
     }

   virtual bool      OnCreate(void) { return(true); }
   virtual void      OnKeyDown(int key,uint flags) { }
   virtual void      OnTimer(void) { }
   virtual void      OnDraw(CCanvas &canvas) { }
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CEditCtrl : public CControl
  {
protected:
   string            m_text;
   uint              m_cursor_pos;
   bool              m_cursor_visible;

public:
   virtual bool      OnCreate(void)
     {
      m_cursor_pos    =0;
      m_cursor_visible=true;
      m_text          ="";
      TimerSet(500);
      return(true);
     }

   virtual void      OnKeyDown(int key,uint flags)
     {
      short code;

      switch(key)
        {
         case 35: // END
            if(m_cursor_pos==m_text.Length())
               return;
            m_cursor_pos=m_text.Length();
            break;
         case 36: // HOME
            if(m_cursor_pos==0)
               return;
            m_cursor_pos=0;
            break;
         case 37: // LEFT
            if(m_cursor_pos==0)
               return;
            m_cursor_pos--;
            break;
         case 39: // RIGHT
            if(m_cursor_pos>=m_text.Length())
               return;
            m_cursor_pos++;
            break;
         default:
            if((code=TranslateKey(key))==-1)
               return;

            if(code<32)
              {
               if(code==8 && m_cursor_pos)
                 {
                  m_text=m_text.Substr(0,m_cursor_pos-1) + m_text.Substr(m_cursor_pos,-1);

                  if(--m_cursor_pos>m_text.Length())
                     m_cursor_pos=m_text.Length();
                     
                  break;
                 }

               return;
              }

            if(m_cursor_pos!=m_text.Length())
               m_text = m_text.Substr(0,m_cursor_pos) + "\xFFFF" + m_text.Substr(m_cursor_pos,m_text.Length());

            m_text.SetChar(m_cursor_pos,code);
            m_cursor_pos++;
            break;
        }

      Update();
     }

   virtual void      OnTimer(void)
     {
      m_cursor_visible=!m_cursor_visible;
      Update();
     }

   virtual void      OnDraw(CCanvas &canvas)
     {
      CCanvas::Erase(ARGB(255,255,255,255));

      if(m_text.Length())
         canvas.TextOut(0,0,m_text,ARGB(255,0,0,0));

      if(m_cursor_visible)
        {
         int x=0,y;

         if(m_cursor_pos)
            canvas.TextSize(m_text.Substr(0,m_cursor_pos),x,y);

         canvas.FillRectangle(x,0,x,canvas.Height(),ARGB(255,0,0,0));
        }
     }
  };

CEditCtrl ExtEditCtrl;
CControl *ExtInputFocus=&ExtEditCtrl;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   ExtEditCtrl.Create(100,100,200,20);

   ChartSetInteger(0,CHART_QUICK_NAVIGATION,false);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer(void)
  {
   ExtInputFocus.OnTimer();
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id==CHARTEVENT_KEYDOWN)
      ExtInputFocus.OnKeyDown((int)lparam,(uint)sparam);
  }
//+------------------------------------------------------------------+
 
Ilyas #:

Sample code of such EditCtrl (base)

Thank you. I will try it on MT5 a little later.

 
Ilyas #:

Sample code of such EditCtrl (base)

Thanks, Ilyas, for a good tutorial example of quality code
 
Ilyas #:

Sample code of such EditCtrl (base)

Is there any way to disable backspace so that the object is not deleted?

 
Aleksei Beliakov #:

Is there any way to disable backspace so that the object is not deleted?

int OnInit()
  {
   ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id==CHARTEVENT_OBJECT_CREATE)
     {
      ObjectSetInteger(0,sparam,OBJPROP_HIDDEN,true);
      ChartRedraw();
      Print(sparam);
     }
  }
 
Ilyas #:
Even if I set this property the object is deleted by backspace, maybe it is because it is selected?
Is there any way to place an object on top of another object if the creation time is shorter?
For example I create a bitmap label object then any other object, bitmaplabel is under the objects that are created after it
Question is there any way to put bitmap label on top of objects created after it except delete and create again?
Reason: