Discussion of article "Studying the CCanvas Class. How to Draw Transparent Objects" - page 4

 
Artyom Trishkin:
MQL4 ;)

I do not welcome MQL4. All examples are only in MQL5.

//+------------------------------------------------------------------+
//|Test.mq5 |
//|Copyright © 2016, Vladimir Karputov |
//| http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#include <Canvas\Canvas.mqh>
CCanvas     m_canvas;           // the canvas object
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
   datetime arr_time[];
   double   arr_open[];
   double   arr_close[];
   if(CopyTime(Symbol(),Period(),0,2,arr_time)==-1)
      return;
   if(CopyClose(Symbol(),Period(),0,2,arr_close)==-1)
      return;
   if(CopyOpen(Symbol(),Period(),0,2,arr_open)==-1)
      return;
   int x1,y1,x2,y2;
   if(!ChartTimePriceToXY(0,0,arr_time[0],arr_open[0],x1,y1))
      Print("Error ",GetLastError());
   if(!ChartTimePriceToXY(0,0,arr_time[1],arr_close[0],x2,y2))
      Print("Error ",GetLastError());
//x1 = Time[1];
//y1 = Open[1];
//x2 = Time[0];
//y2 = Close[1];
   Print("arr_time[0]=",arr_time[0],", arr_open[0]=",arr_open[0]);
   m_canvas.CreateBitmapLabel("COLOR_FORMAT_ARGB_NORMALIZE",x1,y1,MathAbs(x2-x1),MathAbs(y2-y1),COLOR_FORMAT_ARGB_NORMALIZE);
   m_canvas.Erase(ColorToARGB(clrBlue,200));
   m_canvas.Update();
   Sleep(10000);
   m_canvas.Destroy();
  }
//+------------------------------------------------------------------+
//| Gets the width of chart (in pixels)|
//+------------------------------------------------------------------+
int ChartWidthInPixels(const long chart_ID=0)
  {
//--- prepare the variable to get the property value
   long result=-1;
//--- reset the error value
   ResetLastError();
//--- receive the property value
   if(!ChartGetInteger(chart_ID,CHART_WIDTH_IN_PIXELS,0,result))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
   return((int)result);
  }
//+------------------------------------------------------------------+
//| Gets the height of chart (in pixels) ||
//+------------------------------------------------------------------+
int ChartHeightInPixelsGet(const long chart_ID=0,const int sub_window=0)
  {
//--- prepare the variable to get the property value
   long result=-1;
//--- reset the error value
   ResetLastError();
//--- receive the property value
   if(!ChartGetInteger(chart_ID,CHART_HEIGHT_IN_PIXELS,sub_window,result))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
   return((int)result);
  }
//+------------------------------------------------------------------+

And the result of the script:

result

 

Vladimir, a question for you as an expert.

There is a panel in the form of a canvas. And then trend lines are drawn on the chart. How to hide them behind the canvas?

Screenshots of the MetaTrader trading platform

RTS Splice, H1, 2016.10.16

JSC &#39;&#39;Otkritie Broker&#39;&#39;, MetaTrader 5, Demo

RTS Splice, H1, 2016.10.16, JSC ''Otkritie Broker'', MetaTrader 5, Demo


 
Dennis Kirichenko:

Vladimir, a question for you as an expert.

There is a panel in the form of a canvas. And then trend lines are drawn on the chart. How to hide them behind the canvas?


For example, destroy the panel and draw them again....
 
Yeah, thanks. So far I've come up with the idea of just putting objects in the background....
[Deleted]  
Vladimir Karputov:
Thanks for the article. Unfortunately, all the links to documentation in it are broken.
 
Alexey Kozitsyn:
Thanks for the article. Unfortunately all the documentation links in it are broken.

Thanks for the message - the help has been rebuilt, hence the errors. We will correct the links.

 
Vladimir Karputov:

By means of the class CCanvas?

P.S. Use CCanvas.CreateBitmap:

Creates a graphical resource bound to a chart object.

1. Creates a graphical resource in the main window of the current chart.

bool CreateBitmap(
const string name, // name
const datetimetime, // time
const doubleprice, // price
constintwidth, // width
const int height, // height
ENUM_COLOR_FORMAT clrfmt=COLOR_FORMAT_XRGB_NOALPHA// format
);

Thus you will be able to bind one corner of a Canvas. But width and height, all the same, will be set in pixels.


Can I write in Russian here?

Because you give instructions to one, but in reality you profess double standards.

 
Alexey Kozitsyn:
Thanks for the article. Unfortunately, all the links to the documentation in it are broken.
The links have been corrected. Thanks for the message.
 
Alexey Petrov:
The links have been corrected. Thanks for the message.

Errors remain.

Introduction paragraph:

...

Before you start drawing directly with the CCanvas class, you need to learn some definitions related to colour handling. For example, what is transparency and what is an alpha channel.

...


Item "5.1 Create a script "Illusion.mq5""

...

Draw a painted circle. The circle will be drawn over the colour we filled the canvas with (canvas_XRGB_NOALPHA.Erase(ColorToARGB(colr,alpha));).

canvas_XRGB_NOALPHA.CreateBitmapLabel - Here we have created a graphic resource bound to the chart object.

Fill the whole canvas with colour in ARGB format with transparency alpha

Output text - type of image processing for this canvas. Text colour in ARGB format with alpha channel equal to 255, i.e. the colour of the output text.

If we want everything drawn to be displayed on the screen, we need to refresh the screen.

Since we created the graphic resource with a binding to the chart object ( CreateBitmapLabel method), we will delete the resource using the Destroy() method.

...

 

Greetings, guys, can you tell me how to make the information panel so that the icons of deals are not superimposed on top.

It seems to be in the foreground, everything is drawn behind it, but the deals are overlaid on top.

void CreateEdit(long             chart_id,         // chart id
                int              sub_window,       // window (subwindow) number
                string           name,             // object name
                color            font_color,       // font colour
                int              x_size,           // width
                int              y_size,           // height
                int              x_distance,       // X-axis coordinate
                int              y_distance,       // Y-axis coordinate
                long             z_order,          // priority
                color            background_color) // background colour 
  {
// If the object was created successfully, then...
   if(ObjectCreate(chart_id,name,OBJ_RECTANGLE_LABEL,sub_window,0,0))
     {
      // ...set its properties
      ObjectSetInteger(chart_id,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);  // setting the angle of the graph
      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,font_color);         // font colour
      ObjectSetInteger(chart_id,name,OBJPROP_BGCOLOR,background_color); // background colour
      ObjectSetInteger(chart_id,name,OBJPROP_XSIZE,x_size);             // width
      ObjectSetInteger(chart_id,name,OBJPROP_YSIZE,y_size);             // height
      ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,x_distance);     // set X coordinate
      ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,y_distance);     // setting the Y coordinate
      ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,false);         // object cannot be selected if FALSE
      ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,z_order);           // object priority
      ObjectSetInteger(chart_id,name,OBJPROP_READONLY,true);            // read-only
      ObjectSetInteger(chart_id,name,OBJPROP_ALIGN,ALIGN_LEFT);         // left alignment
      //--- display in foreground (false) or background (true) 
    ObjectSetInteger(chart_id,name,OBJPROP_BACK,false); 
      ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,"\n");              // no tooltip if "\n".
     }
  }