transparent rectangle prop ?

 

hi 

i want to add transparency to my rectangles in mql4 , which code should i use ?

 
masoodkhodayi:

hi 

i want to add transparency to my rectangles in mql4 , which code should i use ?

Hi 

In the bitmaps ? 

 
Lorentzos Roussos #:

Hi 

In the bitmaps ? 

hi


no simple rectangle object on chart

 
masoodkhodayi #:

hi


no simple rectangle object on chart

No , the OBJ_RECTANGLE has no transparency unfortunately

You can drop a canvas object though 

 
Lorentzos Roussos #:

No , the OBJ_RECTANGLE has no transparency unfortunately

You can drop a canvas object though 

oh i see , thanks

is there any color opacity control for OBJ_RECTANGLE ? like setting fill color to 50% of fullness ?

 
masoodkhodayi #:

oh i see , thanks

is there any color opacity control for OBJ_RECTANGLE ? like setting fill color to 50% of fullness ?

It was already answered. If there is not transparency what would be point of such thing.

Learn to read the documentation. All the properties are documented.

https://www.mql5.com/en/docs/constants/objectconstants/enum_object_property#enum_object_property_integer

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
  • www.mql5.com
Graphical objects can have various properties depending on the object type. Values of object properties are set up and received by corresponding...
 
masoodkhodayi #:

oh i see , thanks

is there any color opacity control for OBJ_RECTANGLE ? like setting fill color to 50% of fullness ?

you can create a custom class for rectangles with canvas too.

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Canvas - это круто!

Nikolai Semko, 2019.08.13 20:48

Если используется канвас с прозрачностью (COLOR_FORMAT_ARGB_NORMALIZE), то прозрачности двух слоев tr1 и tr2 должны смешиваться по формуле 

double tr=tr1+tr2-tr1*tr2; // где tr, tr1, tr1 меняются от нуля (абсолютная прозрачность) до 1(абсолютная непрозрачность) 

Пример скрипта со случайными кругами случайного цвета и случайной прозрачности:


#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164
#define Num 100
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
// инициализация случайных окружностей
   uint X[Num],Y[Num],sr[Num],clr[Num],Rmin[Num],Rmax[Num];
   double sx[Num],sy[Num];
   for(int i=0; i<Num; i++)
     {
      X[i]=rand()%3141;
      Y[i]=rand()%3141;
      sr[i]=rand()%3141;
      sx[i]=0.3+0.7*(double)rand()/32767.0;
      sy[i]=0.3+0.7*(double)rand()/32767.0;
      clr[i]=ARGB(rand()%256,rand()%256,rand()%256,rand()%256);
      int r2=5+rand()%100;
      int r1=5+rand()%100;
      Rmin[i]=(int)fmin(r1,r2);
      Rmax[i]=(int)fmax(r1,r2);
     }
// формирование изображения из Num (= 100) полупрозрачных кругов
   double j=0;
   while(!IsStopped())
     {
      Canvas.Erase();
      Canvas.CurentFont("Arial",30);
      Canvas.TextPosY=100;
      Canvas.Comm("Hello World!");
      for(int i=0; i<Num; i++)
        {
         Circle(W.Width/2*(1+sin((X[i]+sx[i]*j)*M_PI/1000)),
                W.Height/2*(1+sin((Y[i]+sy[i]*j)*M_PI/1000)),
                Rmin[i]+double(Rmax[i]-Rmin[i])/2*(1.0+cos((j+sr[i])*M_PI/1000)),clr[i]);
        }
      Canvas.Update();
      j+=0.3;
      Sleep(30);
     }
  }
//+------------------------------------------------------------------+

void Circle(double x,double y,double r,uint clr) 
  {
   double R2=r*r;
   for(int X=Round(x-r); X <=Round(x+r);X++)
      for(int Y=Round(y-r); Y<=Round(y+r);Y++)
         if(((x-X)*(x-X)+(y-Y)*(y-Y))<=R2) Canvas.PixelSet(X,Y,MixColor(clr,Canvas.PixelGet(X,Y)));
  }
//+------------------------------------------------------------------+

uint MixColor(uint clr,uint clrback)// смешиваем цвет и прозрачность clr c цветом и прозрачностью фона clrback
  {
   argb C,Bg;
   if(clrback==0) return clr;
   C.clr=clr;
   if(C.c[3]==255) return clr;
   Bg.clr=clrback;
   double tr=C.c[3]/255.0;
   double trb=Bg.c[3]/255.0;

   C.c[2]=uchar(Bg.c[2]+tr*(C.c[2]-Bg.c[2]));
   C.c[1]=uchar(Bg.c[1]+tr*(C.c[1]-Bg.c[1]));
   C.c[0]=uchar(Bg.c[0]+tr*(C.c[0]-Bg.c[0]));

   C.c[3]=uchar((trb+tr-trb*tr)*255.0+0.49999);
   return C.clr;
  }
//+------------------------------------------------------------------+