245 lines
		
	
	
	
		
			8.2 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
			
		
		
	
	
			245 lines
		
	
	
	
		
			8.2 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
//+------------------------------------------------------------------+
 | 
						|
//|                                                          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
 | 
						|
 | 
						|
 | 
						|
#ifndef GRAPHICS_HISTOGRAM_EJES_HIST_VER_MQH_BY_LEO
 | 
						|
#define GRAPHICS_HISTOGRAM_EJES_HIST_VER_MQH_BY_LEO
 | 
						|
 | 
						|
#include "Base.mqh"
 | 
						|
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|                                                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
class CHistogramEjeVertical : public CHistogramEje
 | 
						|
 {
 | 
						|
public:
 | 
						|
  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;
 | 
						|
  void               CreateTituloEje2(int gap_eje, const string& txt, uint clr, int fontsize = 0, string font = NULL, uint flagtext = UINT_MAX) override;
 | 
						|
 | 
						|
  //--- 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;
 | 
						|
 };
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|                                                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
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;
 | 
						|
 | 
						|
//---
 | 
						|
  m_canvas = c;
 | 
						|
  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;
 | 
						|
  m_canvas.LineVertical(m_histogram_eje_2.init, m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.clr);
 | 
						|
 }
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|                                                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
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);
 | 
						|
  m_eje_2_text.CleanColor(m_clr_clean);
 | 
						|
  m_eje_2_text_gap = gap_eje;
 | 
						|
 }
 | 
						|
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
//|                                                                  |
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
// Solo mueve x1, y1, lo demas constante no se modifica
 | 
						|
void CHistogramEjeVertical::ChangeAnclaje1(int x1, int y1, bool redraw = false)
 | 
						|
 {
 | 
						|
//---
 | 
						|
  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);
 | 
						|
 | 
						|
//---
 | 
						|
  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);
 | 
						|
 | 
						|
 | 
						|
//---
 | 
						|
  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::ChangeAnclaje2(int x2, int y2, bool redraw = false)
 | 
						|
 {
 | 
						|
//---
 | 
						|
  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);
 | 
						|
 | 
						|
//---
 | 
						|
  const int y = m_y1 + ((m_y2 - m_y1) >> 1);
 | 
						|
  m_eje_2_text.Y(y);
 | 
						|
 | 
						|
 | 
						|
 | 
						|
//---
 | 
						|
  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::ChangeCordinates(int x1, int x2, int y1, int y2, bool redraw = false)
 | 
						|
 {
 | 
						|
//---
 | 
						|
  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);
 | 
						|
 | 
						|
//---
 | 
						|
  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);
 | 
						|
 | 
						|
//---
 | 
						|
  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();
 | 
						|
 }
 | 
						|
//+------------------------------------------------------------------+
 | 
						|
#endif
 | 
						|
//+------------------------------------------------------------------+
 |