//+------------------------------------------------------------------+
//|                                     ReferenceLineRenderer.mqh    |
//|                    Draws horizontal analytical threshold lines   |
//+------------------------------------------------------------------+
#ifndef REFERENCE_LINE_RENDERER_MQH
#define REFERENCE_LINE_RENDERER_MQH

#include <Canvas\Canvas.mqh>
#include "ChartScaler.mqh"

//+------------------------------------------------------------------+
//| Draws a single dashed horizontal reference level with a label    |
//+------------------------------------------------------------------+
class CReferenceLineRenderer
  {
public:
                     CReferenceLineRenderer(void);
                    ~CReferenceLineRenderer(void);

   void              DrawLine(CCanvas &canvas, const CChartScaler &scaler,
                              const double value, const int plot_left, const int plot_right,
                              const uint line_color, const string label);
  };

//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CReferenceLineRenderer::CReferenceLineRenderer(void)
  {
  }

//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CReferenceLineRenderer::~CReferenceLineRenderer(void)
  {
  }

//+-------------------------------------------------------------------+
//| DrawLine                                                          |
//| Draw one horizontal analytical reference level                    |
//| Parameters: canvas     - target canvas to draw onto               |
//|             scaler     - configured scaler for value-to-pixel     |
//|             value      - the Profit Factor value to mark          |
//|             plot_left, plot_right - horizontal extent of the plot |
//|             line_color - line and label color                     |
//|             label      - text label drawn to the right of the line|
//+-------------------------------------------------------------------+
void CReferenceLineRenderer::DrawLine(CCanvas &canvas, const CChartScaler &scaler,
                                      const double value, const int plot_left, const int plot_right,
                                      const uint line_color, const string label)
  {
   int y = scaler.ValueToY(value);

//--- canvases created with COLOR_FORMAT_ARGB_NORMALIZE require an explicit
//--- alpha channel; a raw 'color' value has alpha = 0 and would be fully
//--- transparent, so every draw call below uses the opaque ARGB form
   uint opaque_color = ::ColorToARGB((color)line_color, 255);

//--- draw a dashed line so reference levels remain distinguishable from the data series
   int dash_length = 6;
   int gap_length  = 4;
   int x = plot_left;
   while(x < plot_right)
     {
      int segment_end = MathMin(x + dash_length, plot_right);
      canvas.Line(x, y, segment_end, y, opaque_color);
      x = segment_end + gap_length;
     }

   canvas.TextOut(plot_right + 6, y - 6, label, opaque_color);
  }

#endif // REFERENCE_LINE_RENDERER_MQH
//+------------------------------------------------------------------+