97 lines
		
	
	
		
			No EOL
		
	
	
		
			7.7 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
			
		
		
	
	
			97 lines
		
	
	
		
			No EOL
		
	
	
		
			7.7 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
//+------------------------------------------------------------------+
 | 
						|
//|                                                ARGBGenerator.mqh |
 | 
						|
//|                                  Copyright 2025, Niquel Mendoza. |
 | 
						|
//|                     https://www.mql5.com/es/users/nique_372/news |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
#property copyright "Copyright 2025, Niquel Mendoza."
 | 
						|
#property link      "https://www.mql5.com/es/users/nique_372/news"
 | 
						|
#property strict
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|  Class CColorGeneratorArgb                                           |
 | 
						|
//|  Usage: class to generate ARGB colors for charts or objects      |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
class CColorGeneratorArgb
 | 
						|
  {
 | 
						|
private:
 | 
						|
   int               m_index;                // Current index
 | 
						|
   bool              m_generate;             // Flag to generate new colors
 | 
						|
   uint              m_current_palette[20];  // Working color palette (ARGB)
 | 
						|
   static const uint s_default_palette[20];  // Default base palette (ARGB)
 | 
						|
   uchar             m_alpha;                // Transparency (0–255)
 | 
						|
 | 
						|
public:
 | 
						|
                     CColorGeneratorArgb();
 | 
						|
 | 
						|
   //--- Gets the next ARGB color
 | 
						|
   uint              Next(void);
 | 
						|
   //--- Resets the generator to the original palette
 | 
						|
   void              Reset(void);
 | 
						|
   //--- Set alpha manually (0 = transparent, 255 = opaque)
 | 
						|
   void              SetAlpha(uchar alpha);
 | 
						|
  };
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//| Default palette (20 harmonious colors, ARGB format)              |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
const uint CColorGeneratorArgb::s_default_palette[20]=
 | 
						|
  {
 | 
						|
   0xFF3366CC,0xFFDC3912,0xFFFF9900,0xFF109618,0xFF990099,
 | 
						|
   0xFF3B3EAC,0xFF0099C6,0xFFDD4477,0xFF66AA00,0xFFB82E2E,
 | 
						|
   0xFF316395,0xFF994499,0xFF22AA99,0xFFAAAA11,0xFF6633CC,
 | 
						|
   0xFFE67300,0xFF8B0707,0xFF329262,0xFF5574A6,0xFF3B3EAC
 | 
						|
  };
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//| Constructor                                                      |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
CColorGeneratorArgb::CColorGeneratorArgb():
 | 
						|
   m_index(0),
 | 
						|
   m_generate(false),
 | 
						|
   m_alpha(255)
 | 
						|
  {
 | 
						|
   ArrayCopy(m_current_palette,s_default_palette);
 | 
						|
  }
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//| Generate or retrieve next color                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
uint CColorGeneratorArgb::Next(void)
 | 
						|
  {
 | 
						|
   if(m_index >= 20)
 | 
						|
     {
 | 
						|
      m_index = 0;
 | 
						|
      if(!m_generate)
 | 
						|
         m_generate = true;
 | 
						|
     }
 | 
						|
 | 
						|
   if(m_generate)
 | 
						|
     {
 | 
						|
      // Simple XOR-based variation to get a new tone
 | 
						|
      uint base1 = m_current_palette[m_index];
 | 
						|
      uint base2 = (m_index == 19 ? m_current_palette[0] : m_current_palette[m_index + 1]);
 | 
						|
      m_current_palette[m_index] = (base1 ^ base2) | (uint(m_alpha) << 24);
 | 
						|
     }
 | 
						|
 | 
						|
   // Apply alpha to ensure all colors follow current transparency
 | 
						|
   uint clr = (m_current_palette[m_index++] & 0x00FFFFFF) | (uint(m_alpha) << 24);
 | 
						|
   return clr;
 | 
						|
  }
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//| Reset the generator                                              |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
void CColorGeneratorArgb::Reset(void)
 | 
						|
  {
 | 
						|
   m_index = 0;
 | 
						|
   m_generate = false;
 | 
						|
   ArrayCopy(m_current_palette, s_default_palette);
 | 
						|
  }
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//| Set alpha transparency                                           |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
void CColorGeneratorArgb::SetAlpha(uchar alpha)
 | 
						|
  {
 | 
						|
   m_alpha = alpha;
 | 
						|
  } |