#include "VMenuStarter.h"
#include <iostream>
#include <GL/glew.h>
#include <GL/glut.h>

using namespace std;

VMenuStarter::VMenuStarter(int* width,int*height,unsigned int* fps,vector<GUIelement*> elements) :
	GUIelement(width,height,fps) {
	if(elements.size() != 4)
		cerr << "Error: Wrong number of GUI elements" << endl;
	this->elements = elements;
    this->active = true;
	this->width = 0;
	this->height = 0;
	this->offset = 10;
 }

void VMenuStarter::motion(int xm,int ym) {
	if(xm < offset && ym < offset) {
		if(!elements[0]->isActive())
			elements[0]->setBlend(true);
		//cout << "linke obere ecke" << endl;
	} else if(xm > *wwidth-offset && ym < offset) {
		if(!elements[1]->isActive())
			elements[1]->setBlend(true);
		//cout << "rechte obere ecke" << endl;
	} else if(xm < offset && ym > *wheight-offset) {
		if(!elements[2]->isActive())
			elements[2]->setBlend(true);
		//cout << "linke untere ecke" << endl;
	} else if(xm > *wwidth-offset && ym > *wheight-offset) {
		if(!elements[3]->isActive())
			elements[3]->setBlend(true);
		//cout << "reckte untere ecke" << endl;
	}
}

bool VMenuStarter::isInside(int xm, int ym) {
	return (xm < offset && ym < offset) || (xm > *wwidth-offset && ym < offset)
			|| (xm < offset && ym > *wheight-offset) || (xm > *wwidth-offset && ym > *wheight-offset);
}

void VMenuStarter::render() {
	glColor3f(1.0,1.0,1.0);
	glRasterPos3f(30, 10, 0.0);
	for(char * ch= "<- Transferfunktion"; *ch; ch++) {
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, (int)*ch);
	}
	glRasterPos3f((*this->wwidth)-95, 10, 0.0);
	for(char * ch= "Rendermode ->"; *ch; ch++) {
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, (int)*ch);
	}
	glRasterPos3f((*this->wwidth)-70, (*this->wheight)-10, 0.0);
	for(char * ch= "Slicing ->"; *ch; ch++) {
		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, (int)*ch);
	}
}
