test/testime.c
changeset 3478 f7541260e89c
parent 3338 9de326b3099c
child 3581 15eea7a1fa97
     1.1 --- a/test/testime.c	Sat Nov 21 07:59:19 2009 +0000
     1.2 +++ b/test/testime.c	Sat Nov 21 08:42:42 2009 +0000
     1.3 @@ -10,7 +10,11 @@
     1.4  #endif
     1.5  
     1.6  #define DEFAULT_PTSIZE  30
     1.7 -#define DEFAULT_FONT    "/System/Library/Fonts/华文细黑.ttf"
     1.8 +#ifdef __QNXNTO__
     1.9 +    #define DEFAULT_FONT    "/usr/photon/font_repository/tt0003m_.ttf"
    1.10 +#else
    1.11 +    #define DEFAULT_FONT    "/System/Library/Fonts/华文细黑.ttf"
    1.12 +#endif
    1.13  #define MAX_TEXT_LENGTH 256
    1.14  
    1.15  SDL_Surface *screen;
    1.16 @@ -31,7 +35,7 @@
    1.17  
    1.18  void InitVideo(int argc, char *argv[])
    1.19  {
    1.20 -    int width = 500, height = 250;
    1.21 +    int width = 640, height = 480;
    1.22      int flags = SDL_HWSURFACE;
    1.23      const char *fontname = DEFAULT_FONT;
    1.24      int fullscreen = 0;
    1.25 @@ -164,6 +168,10 @@
    1.26          SDL_StopTextInput();
    1.27          return;
    1.28      }
    1.29 +    else
    1.30 +    {
    1.31 +        SDL_StartTextInput();
    1.32 +    }
    1.33  
    1.34      cursorRect = markedRect;
    1.35      cursorRect.w = 2;
    1.36 @@ -222,8 +230,51 @@
    1.37          switch (event.type)
    1.38          {
    1.39          case SDL_KEYDOWN:
    1.40 -            if (event.key.keysym.sym == SDLK_ESCAPE) {
    1.41 -                done = 1;
    1.42 +            switch (event.key.keysym.sym)
    1.43 +            {
    1.44 +                case SDLK_ESCAPE:
    1.45 +                     done = 1;
    1.46 +                     break;
    1.47 +                case SDLK_RETURN:
    1.48 +                     text[0]=0x00;
    1.49 +                     Redraw();
    1.50 +                     break;
    1.51 +                case SDLK_BACKSPACE:
    1.52 +                     {
    1.53 +                         int textlen=SDL_strlen(text);
    1.54 +
    1.55 +                         do {
    1.56 +                             if (textlen==0)
    1.57 +                             {
    1.58 +                                 break;
    1.59 +                             }
    1.60 +                             if ((text[textlen-1] & 0x80) == 0x00)
    1.61 +                             {
    1.62 +                                 /* One byte */
    1.63 +                                 text[textlen-1]=0x00;
    1.64 +                                 break;
    1.65 +                             }
    1.66 +                             if ((text[textlen-1] & 0xC0) == 0x80)
    1.67 +                             {
    1.68 +                                 /* Byte from the multibyte sequence */
    1.69 +                                 text[textlen-1]=0x00;
    1.70 +                                 textlen--;
    1.71 +                             }
    1.72 +                             if ((text[textlen-1] & 0xC0) == 0xC0)
    1.73 +                             {
    1.74 +                                 /* First byte of multibyte sequence */
    1.75 +                                 text[textlen-1]=0x00;
    1.76 +                                 break;
    1.77 +                             }
    1.78 +                         } while(1);
    1.79 +
    1.80 +                         Redraw();
    1.81 +                     }
    1.82 +                     break;
    1.83 +            }
    1.84 +
    1.85 +            if (done)
    1.86 +            {
    1.87                  break;
    1.88              }
    1.89  
    1.90 @@ -235,15 +286,15 @@
    1.91              break;
    1.92  
    1.93          case SDL_TEXTINPUT:
    1.94 -            if (strlen(event.text.text) == 0 || event.text.text[0] == '\n' ||
    1.95 +            if (SDL_strlen(event.text.text) == 0 || event.text.text[0] == '\n' ||
    1.96                  markedRect.w < 0)
    1.97                  break;
    1.98  
    1.99              fprintf(stderr, "Keyboard %d: text input \"%s\"\n",
   1.100                      event.text.which, event.text.text);
   1.101  
   1.102 -            if (strlen(text) + strlen(event.text.text) < sizeof(text))
   1.103 -                strcpy(text + strlen(text), event.text.text);
   1.104 +            if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
   1.105 +                strcpy(text + SDL_strlen(text), event.text.text);
   1.106  
   1.107              fprintf(stderr, "text inputed: %s\n", text);
   1.108