
#include <oslib/oslib.h>

extern OSL_FONT *maFonte , *maFonte2;

OSL_IMAGE *Fond, *fond_menu;
int Menu = 1;

int NbMenu = 0;

//deplacement en cor progressif
int IconeVoulue = 0;
//deplacement en cour
int Deplacement_actuel = 0;
int Deplacement_prevue = 0;


extern void exemple();
extern void fenetre01();
extern void texte02();
extern void textecouleur03();
extern void particule04();
extern void menuCercle_05();
extern void Menucercle2_06();
extern void FichierIni_07();
extern void Fxcube08();
extern void fxmasque09();
extern void animation10();
extern void collisionsprirtes();
extern void Collision12();
extern void Intro13();
extern void ClavierVirtuel();
extern void image_Manip();
extern void mapscrool();
extern void MapScrool2();
extern void Mapexterne18();
extern void Getpixel();
extern void CocciGrouille();
extern void PetoBulle01();
extern void PetoBulle02();
extern void fxdivers();
extern void Pong24();
extern void BalleRebond();
extern void clavier2_26();


typedef struct TEXTEMENU 		{
	char *Titre;
	void (*Fonction)();//pointeur ver la fonction adapter au menu
	OSL_IMAGE *img;
	char *file;
	int PossX;			//Possition X du texte
	int PossY;			//Possition X du Texte
	int Selectionner; //menu selectionner
} TEXTEMENU;


void Vide()
{

}

TEXTEMENU Objet_Menu[]=		{
	{"00-template",&exemple,NULL,"media/screenshot/00.png",0,136,0},
	{"01-fenetre_warning",&fenetre01,NULL,"media/screenshot/01.png",0,0,0},
	{"02-Texte",&texte02,NULL,"media/screenshot/02.png",0,0,0},
	{"03-TexteCouleur",&textecouleur03,NULL,"media/screenshot/03.png",0,0,0},
	{"04-particule",&particule04,NULL,"media/screenshot/04.png",0,0,0},
	{"05-MenuCercle",&menuCercle_05,NULL,"media/screenshot/05.png",0,0,0},
	{"06-MenuCercle2",&Menucercle2_06,NULL,"media/screenshot/06.png",0,0,0},
	{"07-FichierINI",&FichierIni_07,NULL,"media/screenshot/07.png",0,0},
	{"08-fxCube",&Fxcube08,NULL,"media/screenshot/08.png",0,0,0},
	{"09-fxmasque",&fxmasque09,NULL,"media/screenshot/09.png",0,0,0},
	{"10-annimation",&animation10,NULL,"media/screenshot/10.png",0,0,0},
	{"11-collision_sprite",&collisionsprirtes,NULL,"media/screenshot/11.png",0,0,0},
	{"12-collision_map",&Collision12,NULL,"media/screenshot/12.png",0,0,0},
	{"13-intro",&Intro13,NULL,"media/screenshot/13.png",0,0,0},
	{"14-ClavierVirtuel01",&ClavierVirtuel,NULL,"media/screenshot/14.png",0,0,0},
	{"15-Image_Manipulation",&image_Manip,NULL,"media/screenshot/15.png",0,0},
	{"16-Map+scrool_Part 1",&mapscrool,NULL,"media/screenshot/16.png",0,0,0},
	{"17-Map+scrool_Part 2",&MapScrool2,NULL,"media/screenshot/17.png",0,0,0},
	{"18-Map externe",&Mapexterne18,NULL,"media/screenshot/18.png",0,0,0},
	{"19-Get Pixel",&Getpixel,NULL,"media/screenshot/19.png",0,0,0},
	{"20-Cocci-Grouille",&CocciGrouille,NULL,"media/screenshot/20.png",0,0,0},
	{"21-PetoBulle Part 1",&PetoBulle01,NULL,"media/screenshot/21.png",0,0,0},
	{"22-PetoBulle Part 2",&PetoBulle02,NULL,"media/screenshot/22.png",0,0,0},
	{"23-fxDivers",&fxdivers,NULL,"media/screenshot/23.png",0,0,0},
	{"24-pong",&Pong24,NULL,"media/screenshot/24.png",0,0,0},
	{"25-balleRebond",&BalleRebond,NULL,"media/screenshot/25.png",0,0,0},
	{"26-clavier 2",&clavier2_26,NULL,"media/screenshot/26.png",0,0,0},	
	{"vide",&Vide,NULL,"media/screenshot/25.png",0,0,-1},
};


int Possition = 0;//Possition du depard du menu
int PosYInitial = 100;
int PossIncremente = 0;



void UpdateMenu()
{

//	if (Deplacement_actuel < (IconeVoulue * (18 + Objet_Menu[0].img->sizeY)))
//		Deplacement_actuel --;
	if (Deplacement_actuel < (IconeVoulue * (18 + Objet_Menu[0].img->sizeY)))
		Deplacement_actuel +=12;
	//100

	//Objet_Menu[e].PossY

	else if (Deplacement_actuel > (IconeVoulue * (18 + Objet_Menu[0].img->sizeY)))
		Deplacement_actuel -=12;

	else if (Deplacement_actuel == (IconeVoulue * (18 + Objet_Menu[0].img->sizeY)))
		;

}


//gestion des touches
void Touche_Menu()
{
 oslReadKeys();


	if (osl_keys->pressed.down){
		if (Possition >= 0 && Possition <= (NbMenu-2))
		{
		Possition += 1;//Possition du depard du menu
		//PosYInitial -= 18 + Objet_Menu[0].img->sizeY;
			IconeVoulue ++;
		}
	}


	if (osl_keys->pressed.up){
		if (Possition >= 1 && Possition <= NbMenu)
		{
		Possition -= 1;//Possition du depard du menu
		//PosYInitial += 18 + Objet_Menu[0].img->sizeY;
			IconeVoulue --;
		}
	}

	if (osl_keys->pressed.cross){
		Objet_Menu[Possition].Fonction();
		oslCls();
	}


}


void MenuAffiche()
{

	Fond = oslLoadImageFile("media/menu.png", OSL_IN_RAM, OSL_PF_8888);
	Fond->x = (OSL_SCREEN_WIDTH/2) -(Fond->sizeX/2);

	fond_menu  = oslLoadImageFile("media/fond_menu.png", OSL_IN_RAM, OSL_PF_8888);

	//initialise les immage du menu
	int i =0;
	while ( Objet_Menu[i].Selectionner != -1)
	{

		NbMenu++;
		Objet_Menu[i].img = oslLoadImageFile(Objet_Menu[i].file, OSL_IN_RAM, OSL_PF_5551);
		i++;

	}


	while (Menu)
		{
		oslStartDrawing();
		oslCls();

		//gestion des touche de l'avent menu
		Touche_Menu();





		oslDrawImage(fond_menu);
		oslDrawImage(Fond);



		oslSetScreenClipping(Fond->x + 5, Fond->y + 15, Fond->x + Fond->sizeX - 5, Fond->y + Fond->sizeY - 22);//de la taille du rectangle

		PossIncremente = 0;
		int e = 0;
		while ( Objet_Menu[e].Selectionner != -1)
		{
			//Deplacement_actuel
			Objet_Menu[e].PossY = PosYInitial + PossIncremente - Deplacement_actuel; 
			//Objet_Menu[e].PossY = PosYInitial + PossIncremente; 

			//dessine l'image
			Objet_Menu[e].img->x = 240 - (Objet_Menu[e].img->sizeX/2);
			Objet_Menu[e].img->y =  Objet_Menu[e].PossY;
			oslDrawImage(Objet_Menu[e].img);

			if (e == Possition)
			{
				//oslDrawFillRect(Objet_Menu[e].img->x - 5, Objet_Menu[e].img->x - 2, Objet_Menu[e].img->sizeX, Objet_Menu[e].img->sizeY + 15, RGB(255,255,255));
				//oslDrawImage(Objet_Menu[e].img);
				oslPrintColorShadow(240 - (oslStringLength(Objet_Menu[e].Titre)/2), Objet_Menu[e].PossY + Objet_Menu[e].img->sizeY + 2 ,RGBA(255, 255, 0, 192),Objet_Menu[e].Titre, 0);
			}
			else
			{
				//oslDrawImage(Objet_Menu[e].img);
				oslPrintColorShadow(240 - (oslStringLength(Objet_Menu[e].Titre)/2), Objet_Menu[e].PossY + Objet_Menu[e].img->sizeY + 2,RGBA(0, 255, 0, 192),Objet_Menu[e].Titre, 0);
			}
			
			PossIncremente += 18 + Objet_Menu[e].img->sizeY;

			e++;
		}

		oslResetScreenClipping();

		UpdateMenu();

	
/*		//affichage du degrader
		oslDrawGradientRect(0, 20, OSL_SCREEN_WIDTH, 140, RGB(34,61,67), RGB(12,66,120), RGB(12,66,120), RGB(34,61,67));
		oslDrawLine(0, 19, OSL_SCREEN_WIDTH, 19, RGB(255,255,255));
		oslDrawLine(0, 141, OSL_SCREEN_WIDTH, 141, RGB(255,255,255));
*/

		oslSetFont(maFonte2);
		oslPrintColorShadow(240  -(oslStringLength("Creer par PJEFF pour PSP-GENERATION et DEVSGEN")/2),272-12,BLANC,"Creer par PJEFF pour PSP-GENERATION et DEVSGEN",0);
	

		//oslSetTextColor(RGBA(255, 255, 255, 255));
		//oslPrintf_xy(10, 20,"%d",IconeVoulue);



		oslSynchronization();

	}

	oslDeleteImage(Fond);

}




