#include <GL/glut.h>
#include <string>
#include <strstream>
#include <vector>

#include "parametres.h"
#include "CPointChaud.h"
#include "globale.h"
#include "CWinStream.h"

float NewTemp;
CPointChaud LePoint;



void keyboard(unsigned char, int, int);
void mouse(int, int, int, int);
void display(void);
void run(void);

void TermineRajoute(void)
{
	LePoint.LaTemperature = NewTemp;
	LesPoints.push_back(LePoint);
	glutKeyboardFunc(keyboard);
	glutMouseFunc(mouse);
	glutDisplayFunc(display);
	glutIdleFunc(run);
}


void displayrajoute(void)
{
	wout.Begin();
	
		// Clear d'une petite région de l'écran
		glColor3f(1,1,1);
		glBegin(GL_QUADS);
			glVertex2i((WIN_X >> 2), (WIN_Y >> 2));
			glVertex2i(3*(WIN_X >> 2), (WIN_Y >> 2));
			glVertex2i(3*(WIN_X >> 2), 3*(WIN_Y >> 2));
			glVertex2i((WIN_X >> 2), 3*(WIN_Y >> 2));
		glEnd();

		wout.SetCouleur(0,0,0,1);
		wout.SetPos((WIN_X >> 2) + 10, (WIN_Y >> 1));
		//wout.SetPos(20, 20);
		wout << "Temperature: " << NewTemp;
	wout.End();

	glutSwapBuffers();
}


void keyboardrajouteS(int key, int x, int y)
{
	float Inc = 1.0f;
	switch (key)
	{
	case (GLUT_KEY_UP):
		if(glutGetModifiers() & GLUT_ACTIVE_SHIFT)
			Inc *= 10.0f;
		else if (glutGetModifiers() & GLUT_ACTIVE_CTRL)
			Inc /= 10.0f;
		 glutPostRedisplay();
		
		NewTemp += Inc;
		break;
	case (GLUT_KEY_DOWN):
		if(glutGetModifiers() & GLUT_ACTIVE_SHIFT)
			Inc *= 10.0f;
		else if (glutGetModifiers() & GLUT_ACTIVE_CTRL)
			Inc /= 10.0f;
		
		NewTemp -= Inc;
		glutPostRedisplay();
		break;
	}
}

void keyboardrajoute(unsigned char key, int x, int y)
{
	switch (key)
	{
	case (13):
		TermineRajoute(); break;
	case (27):
		glutKeyboardFunc(keyboard);
		glutMouseFunc(mouse);
		glutDisplayFunc(display);
		glutIdleFunc(run);
		break;
	}
}







void RajoutePoint(int x, int y)
{
	NewTemp = MILIEU;
	LePoint.x = x;
	LePoint.y = y;
	glutDisplayFunc(displayrajoute);
	glutIdleFunc(0);
	glutKeyboardFunc(keyboardrajoute);
	glutSpecialFunc(keyboardrajouteS);
	glutMouseFunc(0);

	glutPostRedisplay();
}
