/*Tuto clavier pour XtreamLua par Leo (TheGecko)*/
/*-------------------------------------------------------*/
/* Includes*/
#include <string.h>
#include <pspkernel.h>
#include <libge/libge.h>
PSP_MODULE_INFO("Clavier", PSP_MODULE_USER, 0, 1);
PSP_HEAP_SIZE_KB(2048);
//-------------------Prototypes des fonctions-------------------
void KeyBoard( char* chaineY, ge_Image * fond, char * Desc, ge_Font* Police);
//-------------------Main-------------------
int main(int args, char** argc)
{
geInit();//Initialise la LibGE
SceCtrlData pad;//Variable pour les touches
SceCtrlData oldpad;//Seconde variable pour les touches, pour pouvoir faire des comparaisons
sceCtrlReadBufferPositive(&oldpad, 1);//On remplie une fois le oldpad, pour pouvoir faire les premieres comparaisons
ge_Image *fond = geCreateSurface(480, 272, RGB(255, 255, 355));//On charge l'image de fond
char Desc[100] = "Entrez votre nom";//Description pour le clavier
char nom[100];//Chaine qui va contenir notre nom
ge_Font* Police = geLoadFont("./DejaVuSans.ttf");//On charge la police
//-------------------Boucle principale-------------------
for(;;)//Boucle infinie
{
KeyBoard( &*nom, fond, Desc, Police);//On lance le clavier
geBlitImage( 0, 0, fond, 0, 0, fond->width, fond->height, 1);//On affiche l'image de fond
geFontPrintScreen(10, 10, Police, nom, RGB(0,0,0));//On affiche le nom
geSwapBuffers();//On swap les buffers
oldpad = pad;//On attribue la valeur de pad a oldpad
do
{
sceCtrlReadBufferPositive(&pad, 1);
}
while(!(pad.Buttons & PSP_CTRL_CROSS));//Tant que l'on appuie pas sur croix
}
}
//------------------Fonctions-------------------
void KeyBoard( char * chaineY, ge_Image * fond, char * Desc, ge_Font* Police )
{
SceCtrlData pad;//Variables pour les touches
SceCtrlData oldpad;
sceCtrlReadBufferPositive(&oldpad, 1);//On remplie une fois le oldpad, pour pouvoir faire les premieres comparaisons
geFontSize(Police, 18);//On definit la taille de la police a 18 pxl
strcpy(chaineY,"");//On vide la chaine
//Code pour le clavier
char clavier[6][13][2]=
{
{"~","!","@","#","$","%","^","&","*","(",")","_","+"},
{"`","1","2","3","4","5","6","7","8","9","0","-","="},
{"q","w","e","r","t","y","u","i","o","p","[","]","|"},
{"a","s","d","f","g","h","j","k","l",";","'","{","}"},
{"z","x","c","v","b","n","m",",",".","/","<",">","?"},
{":"," "," "," "," "," "," "," "," "," "," "," "," "}//Vous pouvez remplir les blancs avec d'autres caracteres
};
int i, j;//variables pour les for
ge_Image * ImgClavier = geLoadImage("image.jpg");//image de fond d'une touche
ge_Image * ImgchaineY = geLoadImage("image2.jpg");//image de fond de la saisie
int x=0;//coordonnées x du selecteur
int y=0;//coordonnées y du selecteur
while (1)
{
//----Calculs----
sceCtrlReadBufferPositive(&pad, 1);
//Deplacements du curseur
if((pad.Buttons & PSP_CTRL_UP) && !(oldpad.Buttons & PSP_CTRL_UP) && (y > 0))
{y--;}
else if((pad.Buttons & PSP_CTRL_DOWN) && !(oldpad.Buttons & PSP_CTRL_DOWN) && (y < 5))
{y++;}
else if((pad.Buttons & PSP_CTRL_LEFT) && !(oldpad.Buttons & PSP_CTRL_LEFT) && (x > 0))
{x--;}
else if((pad.Buttons & PSP_CTRL_RIGHT) && !(oldpad.Buttons & PSP_CTRL_RIGHT) && (x < 12))
{x++;}
//Ajout d'un caractere si : croix
if ((pad.Buttons & PSP_CTRL_CROSS) && !(oldpad.Buttons & PSP_CTRL_CROSS))
{
strcat(chaineY,clavier[y][x]);
}
//Ajout d'un espace si : Triangle
if ((pad.Buttons & PSP_CTRL_TRIANGLE) && !(oldpad.Buttons & PSP_CTRL_TRIANGLE))
{
strcat(chaineY," ");//Espace
}
//Valider si : START
else if ((pad.Buttons & PSP_CTRL_START) && !(oldpad.Buttons & PSP_CTRL_START))
{
break;
}
//Supression d'un caractere si : Carré
else if ((pad.Buttons & PSP_CTRL_SQUARE) && !(oldpad.Buttons & PSP_CTRL_SQUARE))//simulation de la touche DEL lorsqu'on appuie sur []
{
chaineY[strlen(chaineY) - 1] = 0;
}
//----Affichage----
geBlitImage( 0, 0, fond, 0, 0, fond->width, fond->height, 1);//On affiche l'image de fond
for ( i = 0; i < 6 ; i++)
{
for ( j = 0; j < 13; j++)
{
geBlitImage(j*30+20,i*30+20, ImgClavier, 0, 0, ImgClavier->width, ImgClavier->height, 1);
geFontPrintScreen(j*30+26, i*30+25, Police, clavier[i][j], RGB(0,0,0));
}
}
geBlitImageNegative(x*30+20,y*30+20, ImgClavier, 0, 0, ImgClavier->width, ImgClavier->height);//On affiche la touche selectionnée en negatif
geFontPrintScreen(x*30+26, y*30+25, Police, clavier[y][x], RGB(255,255,255));//On affiche les texte de la touche selectionné en blanc
geFontPrintScreen(1, 1, Police, Desc, RGB(0,0,0));//On affiche la description
geBlitImage(2, 200, ImgchaineY, 0, 0, ImgchaineY->width, ImgchaineY->height,1);//On affiche le fond de la saisie
geFontPrintScreen(12, 205, Police, chaineY, RGB(0,0,0));//on affiche la saisie
oldpad = pad;
geSwapBuffers();
}
return;
}