domingo, dezembro 03, 2006

Entrada de dados

Este foi mais fácil ainda: a biblioteca PALib tem um teclado pronto e um interpretador Graffiti. Este programa usa o botão select para escolher qual método de entrada o usuário prefere.

Link para download no rapidshare

Código-fonte:
// Includes
#include // Include for PA_Lib

// Function: main()
int main(int argc, char ** argv)
{
  //variaveis
  s32 nletra = 0;
  char letra = 0;
  char texto[600];
  int grafitti = 0;

  //programa
  PA_Init(); // Initializes PA_Lib
  PA_InitVBL(); // Initializes a standard VBL

  PA_InitText(0, 0);
  PA_InitText(1, 0);
  PA_InitKeyboard(2);
  PA_KeyboardIn(20, 100);
  PA_OutputSimpleText(1, 0, 0, "Texto: ");
  PA_OutputSimpleText(0,0,0,"O que for digitado no teclado, ira' ser digitado
no texto. O enter é inserido no texto como Enter, mas apresentado na tela como um
espaço. As teclas A,B,X,Y trocam a cor do teclado. Select altera entre o modo teclado
e o modo graffiti.");

  // Infinite loop to keep the program running
  while (1)
  {
    if (Pad.Newpress.A) PA_SetKeyboardColor(0, 1); // Blue and Red
    if (Pad.Newpress.B) PA_SetKeyboardColor(1, 0); // Red and Blue
    if (Pad.Newpress.X) PA_SetKeyboardColor(2, 1); // Green and Red
    if (Pad.Newpress.Y) PA_SetKeyboardColor(0, 2); // Blue and Green
    if (Pad.Newpress.Select) {
      if (grafitti) {
        PA_KeyboardIn(20,100);
        grafitti = 0;
      } else {
        PA_KeyboardIn(20,199);
        grafitti = 1;
      }
    }
    if (grafitti) {
      letra = PA_CheckLetter();
    } else {
      letra = PA_CheckKeyboard();
    }

    if (letra > 31 || letra == '\n') { // nova letra
      texto[nletra] = letra;
      nletra++;
    } else if ((letra == PA_BACKSPACE)&&nletra) { // Retrocesso
      nletra--;
      texto[nletra] = ' '; // Apaga a ultima letra
    }

    PA_OutputSimpleText(1, 7, 0, texto); // escreve o texto na tela de cima
    PA_WaitForVBL();
  }

  return 0;
} // End of main()

Nenhum comentário: