Changeset 3a180ad in mainline for uspace/app/tetris/scores.c


Ignore:
Timestamp:
2009-04-08T20:00:38Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ccf814f
Parents:
8be693b
Message:

Allow UCS in Tetris highscores.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tetris/scores.c

    r8be693b r3a180ad  
    5656/* #include <stdlib.h> */
    5757#include <string.h>
     58#include <kbd/kbd.h>
     59#include <kbd/keycode.h>
     60#include <stdlib.h>
    5861/* #include <time.h> */
    5962/* #include <term.h> */
     
    123126{
    124127        int i,j;
    125         int key;
    126 
     128        size_t off;
     129        kbd_event_t ev;
    127130       
    128131        clear_screen();
     
    130133        puts("Insert your name: ");
    131134        strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME);
    132         i = 6;
     135        i = 6; off = 6;
    133136
    134137        moveto(10 , 28);
    135138        printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
    136         key = getchar();       
    137         while(key != '\n') {
    138                 if (key == '\b') {
    139                         if (i > 0)
    140                                 scores[NUMSPOTS - 1].hs_name[--i] = '\0';       
    141                 } else {
    142                         if (i < (MAXLOGNAME - 1))
    143                                 scores[NUMSPOTS - 1].hs_name[i++] = key;       
    144                                 scores[NUMSPOTS - 1].hs_name[i] = '\0';
     139
     140        while (1) {
     141                fflush(stdout);
     142                if (kbd_get_event(&ev) != EOK)
     143                        exit(1);
     144
     145                if (ev.type == KE_RELEASE)
     146                        continue;
     147
     148                if (ev.key == KC_ENTER || ev.key == KC_NENTER)
     149                        break;
     150
     151                if (ev.key == KC_BACKSPACE) {
     152                        if (i > 0) {
     153                                wchar_t uc;
     154
     155                                --i;
     156                                while (off > 0) {
     157                                        --off;
     158                                        size_t otmp = off;
     159                                        uc = str_decode(scores[NUMSPOTS - 1].hs_name,
     160                                            &otmp, STR_BOUNDS(MAXLOGNAME) + 1);
     161                                        if (uc != U_SPECIAL)
     162                                                break;
     163                                }
     164
     165                                scores[NUMSPOTS - 1].hs_name[off] = '\0';
     166                        }
     167                } else if (ev.c != '\0') {
     168                        if (i < (MAXLOGNAME - 1)) {
     169                                if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name,
     170                                    &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) {
     171                                        ++i;
     172                                }
     173                                scores[NUMSPOTS - 1].hs_name[off] = '\0';
     174                        }
    145175                }
    146176               
    147177                moveto(10 , 28);
    148178                printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
    149        
    150                 key = getchar();       
    151179        }
    152180       
Note: See TracChangeset for help on using the changeset viewer.