ForkGrapichsByLeo/General/ARGBGenerator.mqh

106 lines
8 KiB
MQL5
Raw Permalink Normal View History

2025-10-13 07:15:19 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| 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
2026-01-02 10:19:07 -05:00
#ifndef GRAPICHSBYLEO_GENERAL_ARGB_GENERATOR_MQH
#define GRAPICHSBYLEO_GENERAL_ARGB_GENERATOR_MQH
2025-10-13 07:15:19 -05:00
//+------------------------------------------------------------------+
2026-01-02 10:19:07 -05:00
//| Class CColorGeneratorArgb |
2025-10-13 07:15:19 -05:00
//| Usage: class to generate ARGB colors for charts or objects |
//+------------------------------------------------------------------+
class CColorGeneratorArgb
2026-01-02 10:19:07 -05:00
{
2025-10-13 07:15:19 -05:00
private:
2026-01-02 10:19:07 -05:00
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)
2025-10-13 07:15:19 -05:00
public:
CColorGeneratorArgb();
2025-10-13 07:15:19 -05:00
2026-01-02 10:19:07 -05:00
//--- 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);
};
2025-10-13 07:15:19 -05:00
//+------------------------------------------------------------------+
//| Default palette (20 harmonious colors, ARGB format) |
//+------------------------------------------------------------------+
2026-01-02 10:19:07 -05:00
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
};
2025-10-13 07:15:19 -05:00
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CColorGeneratorArgb::CColorGeneratorArgb():
2026-01-02 10:19:07 -05:00
m_index(0),
m_generate(false),
m_alpha(255)
{
ArrayCopy(m_current_palette, s_default_palette);
}
2025-10-13 07:15:19 -05:00
//+------------------------------------------------------------------+
//| Generate or retrieve next color |
//+------------------------------------------------------------------+
uint CColorGeneratorArgb::Next(void)
2026-01-02 10:19:07 -05:00
{
if(m_index >= 20)
{
m_index = 0;
if(!m_generate)
m_generate = true;
}
2025-10-13 07:15:19 -05:00
2026-01-02 10:19:07 -05:00
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);
}
2025-10-13 07:15:19 -05:00
2026-01-02 10:19:07 -05:00
// Apply alpha to ensure all colors follow current transparency
uint clr = (m_current_palette[m_index++] & 0x00FFFFFF) | (uint(m_alpha) << 24);
return clr;
}
2025-10-13 07:15:19 -05:00
//+------------------------------------------------------------------+
//| Reset the generator |
//+------------------------------------------------------------------+
void CColorGeneratorArgb::Reset(void)
2026-01-02 10:19:07 -05:00
{
m_index = 0;
m_generate = false;
ArrayCopy(m_current_palette, s_default_palette);
}
2025-10-13 07:15:19 -05:00
//+------------------------------------------------------------------+
//| Set alpha transparency |
//+------------------------------------------------------------------+
void CColorGeneratorArgb::SetAlpha(uchar alpha)
2026-01-02 10:19:07 -05:00
{
m_alpha = alpha;
}
//---
#endif // GRAPICHSBYLEO_GENERAL_ARGB_GENERATOR_MQH