Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5786 in orxonox.OLD


Ignore:
Timestamp:
Nov 26, 2005, 9:56:11 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: key-repeat in the Shell is smoother now

Location:
trunk/src/lib
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/Makefile.am

    r5463 r5786  
    44noinst_LIBRARIES = libORXevent.a
    55
    6 libORXevent_a_SOURCES = event.cc \
    7                         event_handler.cc \
     6libORXevent_a_SOURCES = event_handler.cc \
    87                        event_listener.cc \
    98                        key_mapper.cc \
  • trunk/src/lib/event/event.h

    r5391 r5786  
    2727
    2828//! An abstract event class
    29 class Event {
    30 
    31  public:
    32   Event();
    33 
    34   int      offset;                      //!< offset in the event type array
     29struct Event {
    3530  int      type;                        //!< the type field
    3631  bool     bPressed;                    //!< is true, if the button/mouse was pressed, false if released
  • trunk/src/lib/event/event_handler.cc

    r5553 r5786  
    4646  /* now initialize them all to zero */
    4747  this->flush(ES_ALL);
     48  this->withUNICODE(false);
    4849
    4950  this->state = ES_GAME;
    5051  this->keyMapper = NULL;
    5152  this->stateStack = NULL;
     53
    5254}
    5355
     
    247249
    248250
     251void EventHandler::withUNICODE(bool enableUNICODE)
     252{
     253  SDL_EnableUNICODE(enableUNICODE);
     254  this->bUNICODE = enableUNICODE;
     255}
     256
     257
    249258/**
    250259 *  core function of event handler: receives all events from SDL
     
    264273          ev.bPressed = true;
    265274          ev.type = event.key.keysym.sym;
     275          if (unlikely(this->bUNICODE))
     276              ev.x = event.key.keysym.unicode;
    266277          break;
    267278        case SDL_KEYUP:
    268279          ev.bPressed = false;
    269280          ev.type = event.key.keysym.sym;
     281          if (unlikely(this->bUNICODE))
     282            ev.x = event.key.keysym.unicode;
    270283          break;
    271284        case SDL_MOUSEMOTION:
  • trunk/src/lib/event/event_handler.h

    r5776 r5786  
    4141  inline bool isSubscribed(elState state, int eventType) { return(listeners[state][eventType] == NULL)?false:true; };
    4242
     43
     44  void withUNICODE(bool enableUNICODE);
     45
    4346  void process();
    4447
     
    5861  KeyMapper*                 keyMapper;                       //!< reference to the key mapper.
    5962
     63  bool                       bUNICODE;                        //!< If unicode should be enabled.
    6064};
    6165
  • trunk/src/lib/shell/shell.cc

    r5783 r5786  
    129129
    130130  EventHandler::getInstance()->pushState(ES_SHELL);
     131  EventHandler::getInstance()->withUNICODE(true);
     132
    131133  this->setRelCoorSoft2D(0, 0, 1, 5);
    132134
     
    149151  this->bActive = false;
    150152
     153  EventHandler::getInstance()->withUNICODE(false);
    151154  EventHandler::getInstance()->popState();
    152155
  • trunk/src/lib/shell/shell_input.cc

    r5785 r5786  
    317317  {
    318318    this->delayed = this->repeatRate;
    319     if (this->pressedKey == SDLK_BACKSPACE)
    320       this->removeCharacters(1);
    321     else if (pressedKey < 127)
    322       this->addCharacter(this->pressedKey);
     319    switch (this->pressedKey )
     320    {
     321      case SDLK_BACKSPACE:
     322        this->removeCharacters(1);
     323        break;
     324      case SDLK_UP:
     325        this->historyMoveUp();
     326        break;
     327      case SDLK_DOWN:
     328        this->historyMoveDown();
     329        break;
     330      default:
     331      {
     332        if (likely(pressedKey < 127))
     333          this->addCharacter(this->pressedKey);
     334      }
     335    }
    323336  }
    324337}
     
    336349      this->help();
    337350    else if (event.type == SDLK_F2)
     351    {
    338352      ;//this->debug();
     353    }
    339354    else if (event.type == SDLK_UP)
     355    {
    340356      this->historyMoveUp();
     357      this->pressedKey = event.type;
     358    }
    341359    else if (event.type == SDLK_DOWN)
     360    {
    342361      this->historyMoveDown();
     362      this->pressedKey = event.type;
     363    }
    343364    else if (event.type == SDLK_TAB)
    344365      this->completion->autoComplete();
     
    350371    }
    351372    else if (event.type == SDLK_RETURN)
     373    {
    352374      this->executeCommand();
     375      this->pressedKey = event.type;
     376    }
    353377    // any other keyboard key
    354378    else if (likely(event.type < 127))
    355379    {
    356       Uint8 *keystate = SDL_GetKeyState(NULL);
    357       this->delayed = this->repeatDelay;
    358       if (unlikely( keystate[SDLK_LSHIFT] || keystate[SDLK_RSHIFT] ))
    359       {
    360         this->pressedKey = event.type-32;
    361         this->addCharacter(event.type-32);
    362       }
    363       else
    364       {
    365         this->pressedKey = event.type;
    366         this->addCharacter(event.type);
    367       }
    368     }
     380      this->addCharacter(event.x);
     381      this->pressedKey = event.x;
     382    }
     383    this->delayed = this->repeatDelay;
    369384  }
    370385  else // if(!event.bPressed)
    371386  {
    372     if (this->pressedKey == event.type || (this->pressedKey == event.type - 32))
    373     {
    374       this->pressedKey = SDLK_FIRST;
     387    if (this->pressedKey == event.x)
     388    {
     389      this->pressedKey = 0;
    375390      this->delayed = 0.0;
    376391    }
  • trunk/src/lib/shell/shell_input.h

    r5784 r5786  
    6060   float                       repeatDelay;            //!< The delay of the first Character of a given Character.
    6161   float                       delayed;                //!< how much of the delay is remaining.
    62    int                         pressedKey;             //!< the pressed key that will be repeated.
     62   Uint16                      pressedKey;             //!< the pressed key that will be repeated.
    6363
    6464   std::list<char*>            history;                //!< The history of given commands.
Note: See TracChangeset for help on using the changeset viewer.