/****************************************************************************
 * Micah Acinapura CS382                                                    *
 * Hexagon   color chooser class                                            *
 *  Linkage flags:                                                          *
 *   -lX11 -lGL -lGLU -lglut -lXmu -L/usr/X11R6/lib                         *
 ****************************************************************************/
// Libraries on linux systems
#include <X11/X.h> // X libraries
#include <GL/gl.h> // Basic OpenGL Libraries 
#include <GL/glut.h> // GL Utility Toolkit
#include "gltypes2.h" //our gl functions
#include "component.h"

using namespace GLTYPES;

class hex_chooser
{
	
public:

	hex_chooser(GLTYPES::RealRect world=GLTYPES::RealRect(0, 1, 0, 1), 
  		 GLTYPES::RealRect viewport=GLTYPES::RealRect(0, 60, 0, 60))
  	 : Component( world, viewport)
	{
		is_white = 0;
	}
	
	//generate chooser
	
	void picker()
	{
		
		if(is_white)
		{
			glColor3f(0.0,0.0,0.0);
		}
		else						//for flipping between b & w
		{
			glColor3f(1.0,1.0,1.0);
		}
	
		glBegin(GL_TRIANGLE_FAN);

		glVertex2i(40,30);
		glColor3f(1.0,0.0,0.0); //red
		glVertex2i(10,30);
		glColor3f(1.0,1.0,0.0); //orange?
		glVertex2i(25,60);
		glColor3f(0.0,1.0,0.0); //green
		glVertex2i(55,60);
		glColor3f(0.0,1.0,1.0); //cyan
		glVertex2i(70,30);
		glColor3f(0.0,0.0,1.0); //blue
		glVertex2i(55,0);
		glColor3f(1.0,0.0,1.0); //violet
		glVertex2i(25,0);
		glColor3f(1.0,0.0,0.0); //red again
		glVertex2i(10,30);
		
		glEnd();
	
	
  	}
	
	
//expose event handler
  	void reDisplay(void)	
	{
		picker();
	}

//mouse event handler
  	GLcolor3 mouseman(int button, int state, int x, int y)
  	{
		if(button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
		{
			is_white = !is_white;
			reDisplay();
		}
		if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
		{
			GLfloat r = 0.0;
			GLfloat g = 1.0;
			GLfloat b = 1.0;  
  			return GLcolor3(r,g,b);
  		}
  	}		
	
private:

bool is_white;	

};

