/* Meter.cpp
 *
 * Definition of the Meter class.
 */

#include "Meter.h"
#include <GL/glut.h>

Meter::Meter(double value)
: value_(value)
{
	// Nothing (more) to do
}

Meter::~Meter()
{
	// Nothing to do
}

void Meter::draw(bool light)
{
	// draw power bar in ortho 2d mode
	// set up ortho -- but save current projection matrix
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(-1,1,-1,1);
	//set up modelview -- but save current modelview matrix
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	// disable the depth test -- draw on top of everything
	glDisable(GL_DEPTH_TEST);
	// draw red power bar
	if (light)
	{
		GLfloat color[] = {1.0, value_ / 2.0, value_, 1.0};
		glBegin(GL_QUADS);
			glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,color);
			glNormal3f(0.0,0.0,-1.0);
			glVertex2f(0.75f,-0.5f);
			glVertex2f(0.8f,-0.5f);
			glVertex2f(0.8f,-0.5f+(float)value_);
			glVertex2f(0.75,-0.5f+(float)value_);
		glEnd();
	}
	else
	{
		glBegin(GL_QUADS);
			glColor3f(1,0,0);
			glVertex2f(0.75f,-0.5f);
			glVertex2f(0.8f,-0.5f);
			glVertex2f(0.8f,-0.5f+(float)value_);
			glVertex2f(0.75,-0.5f+(float)value_);
		glEnd();
	}
	// restore modelview matrix
	glPopMatrix();
	// restore projection matrix
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	// return to modelview mode --
	glMatrixMode(GL_MODELVIEW);
	// enable depth buffering again
	glEnable(GL_DEPTH_TEST);
}
