//+------------------------------------------------------------------+ //| Hor.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_HOR_MQH_BY_LEO #define GRAPHICS_HISTOGRAM_EJES_HIST_HOR_MQH_BY_LEO #include "Base.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CHistogramEjeHorizontal : 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 CHistogramEjeHorizontal::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(y2 - y1); m_histogram_eje = new CHistogramEjeLineHorizontal(); if(mode == HIST_LINE_MODE_IZQUIERDA) { m_histogram_eje.Init(c, m_x1, m_y1, size_line, clr_line_eje_simple, mode); } else { m_histogram_eje.Init(c, m_x2, m_y1, size_line, clr_line_eje_simple, mode); } m_histogram_eje.CleanColor(clr_clean); //--- Eje simple m_histogram_eje_2.init = m_y2; m_histogram_eje_2.c1 = m_x1; m_histogram_eje_2.c2 = m_x2; m_canvas.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_histogram_eje_2.clr); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CHistogramEjeHorizontal::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 + ((m_x2 - m_x1) >> 1); int y = m_y2 + gap_eje; m_eje_2_text.Create(m_canvas, x, y, txt, clr, TA_TOP | TA_CENTER, fontsize, font, flagtext); m_eje_2_text.CleanColor(m_clr_clean); m_eje_2_text_gap = gap_eje; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CHistogramEjeHorizontal::ChangeAnclaje1(int x1, int y1, bool redraw = false) { //--- const bool aument = x1 > m_x1; if(aument) 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_histogram_eje_2.c1 = m_x1; m_canvas.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_histogram_eje_2.clr); //--- const int x = m_x1 + ((m_x2 - m_x1) >> 1); m_eje_2_text.X(x); //--- const int size_line = fabs(m_y2 - m_y1); // Nuevo ancho const int real_x = (m_mode_line == HIST_LINE_MODE_IZQUIERDA) ? m_x1 : m_x2; // X Real m_histogram_eje.SetCordinates(real_x, m_y1, size_line, redraw); // Cambiamos } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CHistogramEjeHorizontal::ChangeAnclaje2(int x2, int y2, bool redraw = false) { //--- const bool reduce = x2 < m_x2; if(reduce) m_canvas.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_clr_clean); //--- m_x2 = x2; m_y2 = y2; //--- m_histogram_eje_2.init = m_y2; m_histogram_eje_2.c2 = m_x2; m_canvas.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_histogram_eje_2.clr); //--- const int x = m_x1 + ((m_x2 - m_x1) >> 1); const int y = m_y2 + m_eje_2_text_gap; m_eje_2_text.ChangeYAndX(x,y); //--- const int size_line = fabs(m_y2 - m_y1); // Nuevo ancho const int real_x = (m_mode_line == HIST_LINE_MODE_IZQUIERDA) ? m_x1 : m_x2; // X Real m_histogram_eje.SetCordinates(real_x, m_y1, size_line, redraw); // Cambiamos } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CHistogramEjeHorizontal::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_y2; m_histogram_eje_2.c1 = m_x1; m_histogram_eje_2.c2 = m_x2; m_canvas.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_histogram_eje_2.clr); //--- const int x = m_x1 + ((m_x2 - m_x1) >> 1); const int y = m_y2 + m_eje_2_text_gap; m_eje_2_text.ChangeYAndX(x,y); //--- const int size_line = fabs(m_y2 - m_y1); // Nuevo ancho const int real_x = (m_mode_line == HIST_LINE_MODE_IZQUIERDA) ? m_x1 : m_x2; // X Real m_histogram_eje.SetCordinates(real_x, m_y1, size_line, redraw); // Cambiamos } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CHistogramEjeHorizontal::EjeSimpleColor(uint new_value, bool redraw = false) { m_histogram_eje_2.clr = new_value; m_canvas.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_histogram_eje_2.clr); if(redraw) m_canvas.Update(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CHistogramEjeHorizontal::EjeSimpleSize(uint new_value, bool redraw = false) { if(m_mode_line == HIST_LINE_MODE_IZQUIERDA) { 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.LineHorizontal(m_histogram_eje_2.c1, m_histogram_eje_2.c2, m_histogram_eje_2.init, m_histogram_eje_2.clr); if(redraw) m_canvas.Update(); } //+------------------------------------------------------------------+ #endif //+------------------------------------------------------------------+