#include "Scrollbar.h"

Scrollbar::Scrollbar()
{
	state = 0;
	caption = NULL;
	nb = 0;
	value = 10;
}

Scrollbar::~Scrollbar()
{
	free(caption);
}


void Scrollbar::setState(int s)
{
	state = s;
}

int  Scrollbar::getState()
{
	return state;
}

void Scrollbar::setValue(char v)
{
	value = v;
}

char  Scrollbar::getValue()
{
	return value;
}


void Scrollbar::print()
{
	printf("Etat du bouton : %d\n",state);
}

void Scrollbar::setCaption(char * c,int n)
{
	caption = (char*) realloc(caption,n*sizeof(char));
	int i;
	for(i=0;i<n;i++)
	{
		*(caption+i)=*(c+i);
	}
	nb = n;
}
int  Scrollbar::getCaption(char * c)
{
	int i;
	for(i=0;i<nb;i++)
	{
		*(c+i)=*(caption+i);
	}
	return nb;
}

#define bw  3
#define bh  6

void Scrollbar::draw()
{
	glColor3ub(52,54,184);
	glBegin(GL_QUADS);
	glVertex2d(x,y);
	glVertex2d(x+bw,y);
	glColor3ub(91,191,224);
	glVertex2d(x+bw,y+value);
	glVertex2d(x,y+value);
	glEnd();
	glFlush();
}


int Scrollbar::isOver(int mousex,int mousey)
{
	if (x<=mousex && (x+bw)> mousex && y<=mousey && (y+bh)> mousey) return 1;
	else return 0;
};
