~ubuntu-branches/ubuntu/natty/gav/natty

« back to all changes in this revision

Viewing changes to automa/StateWithInput.h

  • Committer: Bazaar Package Importer
  • Author(s): Ari Pollak
  • Date: 2006-05-27 17:49:14 UTC
  • mfrom: (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060527174914-3hgcv8ov8y6hbqpb
Tags: 0.9.0-1
* New upstream release
  - Now saves settings between games (Closes: #261197)

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    return(std::string(s2));
43
43
  }
44
44
 
45
 
  signed char getKeyPressed(InputState *is) {
46
 
    bool typed = false;
 
45
  short getKeyPressed(InputState *is, bool blocking = true) {
47
46
    SDL_keysym keysym;
48
47
    SDL_Event event;
49
 
    while ( !typed ) {
50
 
      is->getInput();
51
 
      if ( (event = is->getEventWaiting()).type != SDL_KEYDOWN )
 
48
    while ( 1 ) {
 
49
      if (!blocking && (!SDL_PollEvent(NULL)))
 
50
        return -1;
 
51
      if ( (event = is->getEventWaiting()).type != SDL_KEYDOWN ) {
52
52
        continue;
 
53
      }
53
54
      keysym = event.key.keysym;
54
 
      do {
55
 
        is->getInput();
56
 
      } while ( is->getEventWaiting().type != SDL_KEYUP );
 
55
      while ( is->getEventWaiting().type != SDL_KEYUP );
57
56
      char *kn = SDL_GetKeyName(keysym.sym);
58
57
      // printf("\"%s\"\n", kn);
59
58
      if ( strlen(kn) == 1 )
60
59
        return((signed char)(*kn));
61
60
      else if ( !strcmp(kn, "return") )
62
 
        return(0);
 
61
        return(SDLK_RETURN);
63
62
      else if ( !strcmp(kn, "backspace") )
64
 
        return(-1);
 
63
        return(SDLK_BACKSPACE);
 
64
      else if ( !strcmp(kn, "escape") )
 
65
        return(SDLK_ESCAPE);
65
66
      else
66
67
        continue;
 
68
 
67
69
    }
68
 
    return(0);
 
70
    return -1;
69
71
  }
 
72
 
70
73
};
71
74
 
72
75
#endif