Graphics in MetaTrader 5: Canvas - drawing inside the buffer with the object snap

 

The new ResourceCreate function has appeared in build 619 for creation of dynamic graphical resources on the fly.

With this function, you can now create any complex images in 32 bit color (including the alpha channel) and attach them to chart objects.

How can developers benefit from that:

  • programs can quickly create beautiful interfaces without the need to carry lots of files

  • additional resource files (not just BMP and WAV) can be added directly to EX5 files using the # Resource "file name" directive, read at runtime, modified and applied to objects

    ResourceLoad() function will be available in the nearest build. It will allow to read the resources that had been attached to EX5 file some time before

  • it is possible to apply any analytical constructions over a chart managing transparency with the use of alpha-channels

    for example, we can draw a semi-transparent cloud with the prediction of possible market directions by managing color and saturation

  • draw anything on a chart

Soon we will add CCanvas class to the standard library. This class will allow to easily manipulate the images by drawing them in its own buffer with the output to a bound object.

Here is a simple script showing the operation of this class (the files are attached):

#include "Canvas.mqh"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   CCanvas can;
//---
   can.Create("MySpace",0,0,512,512,COLOR_FORMAT_ARGB_RAW);
   MathSrand(0);
//---
   for(int i=0;i<10000;i++)
     {
      can.FillRect(MathRand()&255,MathRand()&255,256+(MathRand()&255),256+(MathRand()&255),XRGB(MathRand(),MathRand(),MathRand()));
      can.Circle(MathRand()&511,MathRand()&511,MathRand()&127,XRGB(MathRand(),MathRand(),MathRand()));
      can.Triangle(MathRand()&511,MathRand()&511,MathRand()&511,MathRand()&511,MathRand()&511,MathRand()&511,XRGB(MathRand(),MathRand(),MathRand()));
      //---
      can.Update();
     }
//---
  }




Files:
Canvas.mqh  14 kb
 

good job


Reason: