Guest
Public paste!

Keyboard

By: a guest | Mar 8th, 2010 | Syntax: C | Size: 4.88 KB | Hits: 274 | Expires: Never
Copy text to clipboard
  1. /*Tuto clavier pour XtreamLua par Leo (TheGecko)*/
  2. /*-------------------------------------------------------*/
  3. /* Includes*/
  4. #include <string.h>
  5. #include <pspkernel.h>
  6. #include <libge/libge.h>
  7.  
  8. PSP_MODULE_INFO("Clavier", PSP_MODULE_USER, 0, 1);
  9. PSP_HEAP_SIZE_KB(2048);
  10.  
  11.  
  12. //-------------------Prototypes des fonctions-------------------
  13. void KeyBoard( char* chaineY, ge_Image * fond, char * Desc, ge_Font* Police);
  14.  
  15. //-------------------Main-------------------
  16. int main(int args, char** argc)
  17. {
  18.         geInit();//Initialise la LibGE
  19.         SceCtrlData pad;//Variable pour les touches
  20.         SceCtrlData oldpad;//Seconde variable pour les touches, pour pouvoir faire des comparaisons
  21.         sceCtrlReadBufferPositive(&oldpad, 1);//On remplie une fois le oldpad, pour pouvoir faire les premieres comparaisons
  22.         ge_Image *fond = geCreateSurface(480, 272, RGB(255, 255, 355));//On charge l'image de fond
  23.         char Desc[100] = "Entrez votre nom";//Description pour le clavier
  24.         char nom[100];//Chaine qui va contenir notre nom
  25.        
  26.         ge_Font* Police = geLoadFont("./DejaVuSans.ttf");//On charge la police
  27.        
  28. //-------------------Boucle principale-------------------
  29.         for(;;)//Boucle infinie
  30.         {
  31.                 KeyBoard( &*nom, fond, Desc, Police);//On lance le clavier
  32.                 geBlitImage( 0, 0, fond, 0, 0, fond->width, fond->height, 1);//On affiche l'image de fond
  33.                 geFontPrintScreen(10, 10, Police, nom, RGB(0,0,0));//On affiche le nom
  34.                 geSwapBuffers();//On swap les buffers
  35.                 oldpad = pad;//On attribue la valeur de pad a oldpad
  36.                 do
  37.                 {
  38.                         sceCtrlReadBufferPositive(&pad, 1);
  39.                 }
  40.                 while(!(pad.Buttons & PSP_CTRL_CROSS));//Tant que l'on appuie pas sur croix
  41.         }
  42. }
  43.  
  44. //------------------Fonctions-------------------
  45. void KeyBoard( char * chaineY, ge_Image * fond, char * Desc, ge_Font* Police )
  46. {
  47.         SceCtrlData pad;//Variables pour les touches
  48.         SceCtrlData oldpad;
  49.         sceCtrlReadBufferPositive(&oldpad, 1);//On remplie une fois le oldpad, pour pouvoir faire les premieres comparaisons
  50.         geFontSize(Police, 18);//On definit la taille de la police a 18 pxl
  51.         strcpy(chaineY,"");//On vide la chaine
  52.         //Code pour le clavier
  53.         char clavier[6][13][2]=
  54.         {
  55.                 {"~","!","@","#","$","%","^","&","*","(",")","_","+"},
  56.                 {"`","1","2","3","4","5","6","7","8","9","0","-","="},
  57.                 {"q","w","e","r","t","y","u","i","o","p","[","]","|"},
  58.                 {"a","s","d","f","g","h","j","k","l",";","'","{","}"},
  59.                 {"z","x","c","v","b","n","m",",",".","/","<",">","?"},
  60.                 {":"," "," "," "," "," "," "," "," "," "," "," "," "}//Vous pouvez remplir les blancs avec d'autres caracteres
  61.         };
  62.         int i, j;//variables pour les for
  63.         ge_Image * ImgClavier = geLoadImage("image.jpg");//image de fond d'une touche
  64.         ge_Image * ImgchaineY = geLoadImage("image2.jpg");//image de fond de la saisie
  65.         int x=0;//coordonnées x du selecteur
  66.         int y=0;//coordonnées y du selecteur
  67.        
  68.         while (1)
  69.         {
  70.                 //----Calculs----
  71.                 sceCtrlReadBufferPositive(&pad, 1);
  72.                 //Deplacements du curseur
  73.                 if((pad.Buttons & PSP_CTRL_UP) && !(oldpad.Buttons & PSP_CTRL_UP) && (y > 0))
  74.                         {y--;}
  75.                 else if((pad.Buttons & PSP_CTRL_DOWN) && !(oldpad.Buttons & PSP_CTRL_DOWN) && (y < 5))
  76.                         {y++;}
  77.                 else if((pad.Buttons & PSP_CTRL_LEFT) && !(oldpad.Buttons & PSP_CTRL_LEFT) && (x > 0))
  78.                         {x--;}
  79.                 else if((pad.Buttons & PSP_CTRL_RIGHT) && !(oldpad.Buttons & PSP_CTRL_RIGHT) && (x < 12))
  80.                         {x++;}
  81.                 //Ajout d'un caractere si : croix
  82.                 if ((pad.Buttons & PSP_CTRL_CROSS) && !(oldpad.Buttons & PSP_CTRL_CROSS))
  83.                 {
  84.                         strcat(chaineY,clavier[y][x]);
  85.                 }
  86.                 //Ajout d'un espace si : Triangle
  87.                 if ((pad.Buttons & PSP_CTRL_TRIANGLE) && !(oldpad.Buttons & PSP_CTRL_TRIANGLE))
  88.                 {
  89.                         strcat(chaineY," ");//Espace
  90.                 }
  91.                 //Valider si : START
  92.                 else if ((pad.Buttons & PSP_CTRL_START) && !(oldpad.Buttons & PSP_CTRL_START))
  93.                 {
  94.                         break;
  95.                 }
  96.                 //Supression d'un caractere si : Carré
  97.                 else if ((pad.Buttons & PSP_CTRL_SQUARE) && !(oldpad.Buttons & PSP_CTRL_SQUARE))//simulation de la touche DEL lorsqu'on appuie sur []
  98.                 {
  99.                         chaineY[strlen(chaineY) - 1] = 0;
  100.                 }
  101.                 //----Affichage----
  102.                
  103.                 geBlitImage( 0, 0, fond, 0, 0, fond->width, fond->height, 1);//On affiche l'image de fond
  104.                 for ( i = 0; i < 6 ; i++)
  105.                 {
  106.                         for ( j = 0; j < 13; j++)
  107.                         {
  108.                                 geBlitImage(j*30+20,i*30+20, ImgClavier, 0, 0, ImgClavier->width, ImgClavier->height, 1);
  109.                                 geFontPrintScreen(j*30+26, i*30+25, Police, clavier[i][j], RGB(0,0,0));
  110.                         }
  111.                        
  112.                 }
  113.                 geBlitImageNegative(x*30+20,y*30+20, ImgClavier, 0, 0, ImgClavier->width, ImgClavier->height);//On affiche la touche selectionnée en negatif
  114.                 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
  115.                 geFontPrintScreen(1, 1, Police, Desc, RGB(0,0,0));//On affiche la description
  116.                 geBlitImage(2, 200, ImgchaineY, 0, 0, ImgchaineY->width, ImgchaineY->height,1);//On affiche le fond de la saisie
  117.                 geFontPrintScreen(12, 205, Police, chaineY, RGB(0,0,0));//on affiche la saisie
  118.                 oldpad = pad;
  119.                 geSwapBuffers();
  120.         }
  121.         return;
  122. }