GrapichsByLeo/Histogram/EjeHist/Ver.mqh

245 lines
8.2 KiB
MQL5
Raw Permalink Normal View History

2025-10-13 22:07:20 -05:00
//+------------------------------------------------------------------+
//| Ver.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
2025-10-14 07:28:22 -05:00
#ifndef GRAPHICS_HISTOGRAM_EJES_HIST_VER_MQH_BY_LEO
#define GRAPHICS_HISTOGRAM_EJES_HIST_VER_MQH_BY_LEO
2025-10-13 22:07:20 -05:00
#include "Base.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CHistogramEjeVertical : public CHistogramEje
{
public:
2025-10-14 07:28:22 -05:00
void Init(CCanvasCustom* c, int x1, int x2, int y1, int y2, int mode, uint clr_line_eje_simple, uint clr_line_eje_fij, uint clr_clean) override;
2025-10-14 14:25:54 -05:00
void CreateTituloEje2(int gap_eje, const string& txt, uint clr, int fontsize = 0, string font = NULL, uint flagtext = UINT_MAX) override;
2025-10-14 07:28:22 -05:00
//--- SImple eje
//- Color
void EjeSimpleColor(uint new_value, bool redraw = false) override final;
//- Ancho
void EjeSimpleSize(uint new_value, bool redraw = false) override final;
__forceinline uint EjeSimpleSize() const override final { return (m_histogram_eje_2.c2 - m_histogram_eje_2.c1); }
//--- Cordenadas
void ChangeCordinates(int x1, int x2, int y1, int y2, bool redraw = false)override final;
void ChangeAnclaje2(int x2, int y2, bool redraw = false) override final;
void ChangeAnclaje1(int x1, int y1, bool redraw = false) override final;
2025-10-13 22:07:20 -05:00
};
2025-10-14 07:28:22 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CHistogramEjeVertical::Init(CCanvasCustom *c, int x1, int x2, int y1, int y2, int mode, uint clr_line_eje_simple, uint clr_line_eje_fij, uint clr_clean)
{
if(m_init)
return;
//---
m_init = true;
//---
2025-10-14 10:58:09 -05:00
m_canvas = c;
2025-10-14 07:28:22 -05:00
m_x1 = x1;
m_y1 = y1;
m_x2 = x2;
m_y2 = y2;
/*
x1 x2
y1 y1
y2 x2
x1 y2
*/
//---
m_histogram_eje_2.clr = clr_line_eje_fij;
//---
const int size_line = fabs(m_x2 - m_x1);
m_histogram_eje = new CHistogramEjeLineVertical();
if(mode == HIST_LINE_MODE_ARRIBA)
{
m_histogram_eje.Init(c, m_x1, m_y1, size_line, clr_line_eje_simple, mode);
}
else
{
m_histogram_eje.Init(c, m_x1, m_y2, size_line, clr_line_eje_simple, mode);
}
m_histogram_eje.CleanColor(clr_clean);
//--- Eje simple
m_histogram_eje_2.init = m_x1;
m_histogram_eje_2.c1 = m_y1;
m_histogram_eje_2.c2 = m_y2;
2025-10-14 10:58:09 -05:00
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.clr);
2025-10-14 07:28:22 -05:00
}
2025-10-14 14:25:54 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CHistogramEjeVertical::CreateTituloEje2(int gap_eje, const string &txt, uint clr, int fontsize = 0, string font = NULL, uint flagtext = UINT_MAX)
{
if(m_eje_2_text != NULL)
return;
m_eje_2_text = new CTextCanvas();
int x = m_x1 - gap_eje;
int y = m_y1 + ((m_y2 - m_y1) >> 1);
m_eje_2_text.Create(m_canvas, x, y, txt, clr, TA_TOP | TA_CENTER, fontsize, font, flagtext, 900);
2025-10-14 14:25:54 -05:00
m_eje_2_text.CleanColor(m_clr_clean);
m_eje_2_text_gap = gap_eje;
}
2025-10-14 07:28:22 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Solo mueve x1, y1, lo demas constante no se modifica
2025-10-14 10:58:09 -05:00
void CHistogramEjeVertical::ChangeAnclaje1(int x1, int y1, bool redraw = false)
2025-10-14 07:28:22 -05:00
{
//---
const bool aument = y1 > m_y1;
if(aument)
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_clr_clean);
//---
m_x1 = x1;
m_y1 = y1;
//---
m_histogram_eje_2.init = m_x1;
m_histogram_eje_2.c1 = m_y1;
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.clr);
2025-10-14 14:25:54 -05:00
//---
const int y = m_y1 + ((m_y2 - m_y1) >> 1);
const int x = m_x1 - m_eje_2_text_gap;
m_eje_2_text.ChangeYAndX(x, y);
2025-10-14 07:28:22 -05:00
//---
const int size_line = fabs(m_x2 - m_x1);
const int real_y = (m_mode_line == HIST_LINE_MODE_ARRIBA) ? m_y1 : m_y2; // Y Real
m_histogram_eje.SetCordinates(m_x1, real_y, size_line, redraw); // Cambiamos
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2025-10-14 10:58:09 -05:00
void CHistogramEjeVertical::ChangeAnclaje2(int x2, int y2, bool redraw = false)
2025-10-14 07:28:22 -05:00
{
//---
const bool reduce = y2 < m_y2;
if(reduce)
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_clr_clean);
//---
m_x2 = x2;
m_y2 = y2;
//---
m_histogram_eje_2.c2 = m_y2;
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.clr);
2025-10-14 14:25:54 -05:00
//---
const int y = m_y1 + ((m_y2 - m_y1) >> 1);
m_eje_2_text.Y(y);
2025-10-14 07:28:22 -05:00
//---
const int size_line = fabs(m_x2 - m_x1);
const int real_y = (m_mode_line == HIST_LINE_MODE_ARRIBA) ? m_y1 : m_y2; // Y Real
m_histogram_eje.SetCordinates(m_x1, real_y, size_line, redraw); // Cambiamos
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2025-10-14 10:58:09 -05:00
void CHistogramEjeVertical::ChangeCordinates(int x1, int x2, int y1, int y2, bool redraw = false)
2025-10-14 07:28:22 -05:00
{
//---
m_canvas.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_clr_clean);
//---
m_x1 = x1;
m_y1 = y1;
m_x2 = x2;
m_y2 = y2;
//--- Eje simple
m_histogram_eje_2.init = m_x1;
m_histogram_eje_2.c1 = m_y1;
m_histogram_eje_2.c2 = m_y2;
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.clr);
2025-10-14 14:25:54 -05:00
//---
const int y = m_y1 + ((m_y2 - m_y1) >> 1);
const int x = m_x1 - m_eje_2_text_gap;
m_eje_2_text.ChangeYAndX(x, y);
2025-10-14 07:28:22 -05:00
//---
const int size_line = fabs(m_x2 - m_x1);
const int real_y = (m_mode_line == HIST_LINE_MODE_ARRIBA) ? m_y1 : m_y2; // Y Real
m_histogram_eje.SetCordinates(m_x1, real_y, size_line, redraw); // Cambiamos
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CHistogramEjeVertical::EjeSimpleColor(uint new_value, bool redraw = false)
{
m_histogram_eje_2.clr = new_value;
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.clr);
if(redraw)
m_canvas.Update();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
/*
x1
c1
|
|
|
|
|
c2
*/
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CHistogramEjeVertical::EjeSimpleSize(uint new_value, bool redraw = false)
{
if(m_mode_line == HIST_LINE_MODE_ARRIBA)
{
m_histogram_eje_2.c2 = m_histogram_eje_2.c1 + (int)new_value;
}
else
{
m_histogram_eje_2.c1 = m_histogram_eje_2.c2 - (int)new_value;
}
m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.clr);
if(redraw)
m_canvas.Update();
}
2025-10-13 22:07:20 -05:00
//+------------------------------------------------------------------+
2025-10-14 14:25:54 -05:00
#endif
//+------------------------------------------------------------------+