// ScrollingProfile.cpp: implementation of the CScrollingProfile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "6046dryend.h"
#include "ScrollingProfile.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CScrollingProfile::CScrollingProfile()
{
	m_fPointSize = 2;
}

CScrollingProfile::~CScrollingProfile()
{

}


DWORD CScrollingProfile::Render(BOOL flag)
{
  if(!m_bInit)
    return 1;

  wglMakeCurrent(m_hDC, m_hRC);

  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glLoadIdentity();			

  //glTranslatef(-0.5f,-0.5f, -1.2f);
   
  glEnable(GL_LINE_SMOOTH);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glPointSize(m_fPointSize);

  //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  
  DraxAxis();

  DrawProfile(flag);


  glDisable(GL_LINE_SMOOTH);
  glDisable(GL_BLEND);
  glFlush();

  return 1;
}

DWORD CScrollingProfile::DraxAxis()
{
  char label[128];
  float offset, text_width, text_height, distance_steps, depth_steps, swath_half;
  int i;

  gl_setcolor(GLWHITE);

  sprintf(label, "Depth [m]");
  text_width = glGetTextWidth(label);
  glRasterPos2f(-text_width - 0.01f, 0.999f);
  glPrint(label);
  
  sprintf(label, "Swath [m]");
  glRasterPos2f(1.0f, -0.02f);
  glPrint(label);
  
  // Axis
  gl_line(0.0f, 0.0f, 0.0f, 1.0f);
  gl_line(0.0f, 0.0f, 1.0f, 0.0f);

  gl_line(0.0f, 1.0f, 0.01f, 0.99f);
  gl_line(0.0f, 1.0f, -0.01f, 0.99f);
  gl_line(1.0f, 0.0f, 0.99f, 0.01f);
  gl_line(1.0f, 0.0f, 0.99f, -0.01f);

  /*
  depth_steps = (float)((m_dMaxDepth - m_dMinDepth) / 8.0);
  // Y
  for(i=0;i<9;i++)
  {
    sprintf(label, "-%.0lf", (double)m_dMaxDepth - i*depth_steps);
    text_width = glGetTextWidth(label);
    text_height = glGetTextHeight();
    
    offset = (float)(i * 0.1 + 0.1);
    gl_line(-0.02f, offset, 0.02f, offset);

    glRasterPos3f(-text_width - 0.01f, offset - text_height/2.0f, .06f);
    glPrint(label);
  }

  distance_steps = (float)((m_dMaxDistance - m_dMinDistance) / 8.0);
  swath_half = (float)((m_dMaxDistance - m_dMinDistance) * 0.5);
  // X
  for(i=0;i<9;i++)
  {
    sprintf(label, "%.0lf", (double)-swath_half + i*distance_steps);
    text_width = glGetTextWidth(label);

    offset = (float)(i * 0.1 + 0.1);
    gl_line(offset, -0.02f, offset, 0.02f);

    glRasterPos3f(offset - text_width/(float)2.0, -0.01f - text_height, .06f);
    glPrint(label);
  
  }
  */

  return 1;

}

DWORD CScrollingProfile::DrawProfile(BOOL skipMemMove)
{

	return 1;
}