Download MetaTrader 5
To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
mar
1143
mar 2015.10.17 10:22 

Hi coders,

I use the color red for a rectangle. If a predefined event happens I would like to make this red a bit darker. Mathematically spoken I would like to subtract C'50,50,50' from the normal color.

Is that somehow possible without setting a new color? Sometimes I don't know about the color of a rectangle and so I can't use absolute color values. I only want to make the current color a bit darker, whatever color it originally is.

Thanks! 

Gordon Gekko
649
Gordon Gekko 2015.10.17 12:22  
mar:

Hi coders,

I use the color red for a rectangle. If a predefined event happens I would like to make this red a bit darker. Mathematically spoken I would like to subtract C'50,50,50' from the normal color.

Is that somehow possible without setting a new color? Sometimes I don't know about the color of a rectangle and so I can't use absolute color values. I only want to make the current color a bit darker, whatever color it originally is.

Thanks! 

I made this, not tested:

color darken(color mycolor,int c_offset)
  {
  int R=(mycolor%65536)%256;
  int G=((mycolor-R)%65536)/256;
  int B=(mycolor-(256*G)-R)/65536;
  
   if(R-c_offset>0) R-=c_offset;
   else R=0;
   if(G-c_offset>0) G-=c_offset;
   else G=0;
   if(B-c_offset>0) B-=c_offset;
   else B=0;

   return color(B*65536+G*256+R);
  }
mar
1143
mar 2015.10.17 13:15  
Works perfect! Thank you very much! 
Gordon Gekko
649
Gordon Gekko 2015.10.17 14:04  
mar:
Works perfect! Thank you very much! 
You are welcome!
/
To add comments, please log in or register