Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7895 in orxonox.OLD for branches/gui/src/lib/event


Ignore:
Timestamp:
May 27, 2006, 5:29:48 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: fixed a bug in the EventHandler, that resulted from multiple inputs or so…

Location:
branches/gui/src/lib/event
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/event/event_handler.cc

    r7868 r7895  
    4242
    4343  /* now initialize them all to zero */
    44   this->withUNICODE(false);
     44  for (unsigned int i = 0; i < ES_NUMBER; i++)
     45    this->bUNICODE[i] = false;
    4546  this->grabEvents(false);
    4647
     
    8788  this->keyMapper.loadKeyBindings();
    8889}
     90
     91/**
     92 * @param state: to which the event handler shall change
     93 */
     94void EventHandler::setState(elState state)
     95{
     96  this->state = state;
     97  SDL_EnableUNICODE(this->bUNICODE[state]);
     98};
     99
    89100
    90101/**
     
    144155  {
    145156    for(unsigned int i = 0; i < ES_NUMBER; i++)
    146     {
    147       if( !likely(this->listeners[i][eventType].empty()))
    148       {
    149         PRINTF(2)("'%s' of class '%s' tried to subscribe to event %i @ state %i but this event has already been subscribed\n", el->getName(), el->getClassName(), eventType, state);
    150       }
    151157      this->listeners[i][eventType].push_back(el);
    152     }
    153   }
    154   else
    155   {
    156     if( likely(!this->listeners[state][eventType].empty()))
    157     {
    158       PRINTF(2)("%s of class %s tried to subscribe to event %i @ state %i but this event has already been subscribed\n", el->getName(), el->getClassName(), eventType, state);
    159     }
     158  }
     159  else
    160160    this->listeners[state][eventType].push_back(el);
    161   }
    162161}
    163162
     
    178177    {
    179178      std::vector<EventListener*>::iterator listener =
    180          std::find(this->listeners[i][eventType].begin(),
    181                    this->listeners[i][eventType].end(),
    182                    el);
     179        std::find(this->listeners[i][eventType].begin(),
     180                  this->listeners[i][eventType].end(),
     181                  el);
    183182      if (listener != this->listeners[i][eventType].end())
    184183        this->listeners[i][eventType].erase(listener);
     
    187186  {
    188187    std::vector<EventListener*>::iterator listener =
    189         std::find(this->listeners[state][eventType].begin(),
    190                   this->listeners[state][eventType].end(),
    191                   el);
     188      std::find(this->listeners[state][eventType].begin(),
     189                this->listeners[state][eventType].end(),
     190                el);
    192191    if (listener != this->listeners[state][eventType].end())
    193192      this->listeners[state][eventType].erase(listener);
     
    261260
    262261
    263 void EventHandler::withUNICODE(bool enableUNICODE)
    264 {
    265   SDL_EnableUNICODE(enableUNICODE);
    266   this->bUNICODE = enableUNICODE;
     262void EventHandler::withUNICODE(elState state, bool enableUNICODE)
     263{
     264  this->bUNICODE[state] = enableUNICODE;
     265  if (this->state == state)
     266    SDL_EnableUNICODE(enableUNICODE);
    267267}
    268268
     
    283283
    284284/**
    285  *  core function of event handler: receives all events from SDL
    286 
    287    The event from the SDL framework are collected here and distributed to all listeners.
    288 */
     285 *  @brief core function of event handler: receives all events from SDL
     286 *
     287 * The event from the SDL framework are collected here and distributed to all listeners.
     288 */
    289289void EventHandler::process()
    290290{
     
    299299        ev.bPressed = true;
    300300        ev.type = event.key.keysym.sym;
    301         if (unlikely(this->bUNICODE))
     301        if (unlikely(this->bUNICODE[this->state]))
    302302          ev.x = event.key.keysym.unicode;
    303303        break;
     
    305305        ev.bPressed = false;
    306306        ev.type = event.key.keysym.sym;
    307         if (unlikely(this->bUNICODE))
     307        if (unlikely(this->bUNICODE[this->state]))
    308308          ev.x = event.key.keysym.unicode;
    309309        break;
     
    358358    /* small debug routine: shows all events dispatched by the event handler */
    359359    PRINT(4)("\n==========================| EventHandler::process () |===\n");
    360     PRINT(4)("=  Got Event nr %i, for state %i", ev.type, this->state);
    361 
    362 
    363     for (unsigned int i = 0; i < this->listeners[this->state][ev.type].size(); i++)
     360    PRINT(4)("=  Got Event nr %i, for state %i\n", ev.type, this->state);
     361
     362    /// setting a temporary state in case of an EventListener's process changes the state.
     363    elState currentState = this->state;
     364    for (unsigned int i = 0; i < this->listeners[currentState][ev.type].size(); i++)
    364365    {
    365366      PRINT(4)("=  Event dispatcher msg: This event has been consumed\n");
     367      PRINT(4)("=  Got Event nr %i, for state %i %s::%s\n", ev.type, currentState, this->listeners[this->state][ev.type][i]->getClassName(), this->listeners[currentState][ev.type][i]->getName());
    366368      PRINT(4)("=======================================================\n");
    367       listeners[this->state][ev.type][i]->process(ev);
     369      this->listeners[currentState][ev.type][i]->process(ev);
    368370    }
    369371    /*    else
     
    375377}
    376378
    377 
     379/**
     380 * @brief An eventFilter.
     381 * @param event the Event to be filtered.
     382 * @returns 0 on filtered Event. 1 Otherwise.
     383 */
    378384int EventHandler::eventFilter(const SDL_Event *event)
    379385{
     
    400406
    401407/**
    402  * outputs some nice information about the EventHandler
     408 * @brief outputs some nice information about the EventHandler
    403409 */
    404410void EventHandler::debug() const
     
    408414  PRINT(0)("===============================\n");
    409415  for(int i = 0; i < ES_NUMBER; ++i)
     416  {
    410417    for(int j = 0; j < EV_NUMBER; ++j)
    411418      for (unsigned int evl = 0; evl < this->listeners[i][j].size(); evl++)
    412419        PRINT(0)("Event %d of State %d subscribed to %s (%p)\n", j, i, this->listeners[i][j][evl]->getName(), this->listeners[i][j][evl]);
     420  }
    413421  PRINT(0)("============================EH=\n");
    414422}
  • branches/gui/src/lib/event/event_handler.h

    r7868 r7895  
    2626  void init();
    2727
    28   /** @param state: to which the event handler shall change */
    29   inline void setState(elState state) { this->state = state; };
     28  void setState(elState state);
    3029  /** @returns the current state */
    3130  inline elState getState() const { return this->state; };
     
    4241
    4342
    44   void withUNICODE(bool enableUNICODE);
     43  void withUNICODE(elState state, bool enableUNICODE);
    4544  void grabEvents(bool grabEvents);
    4645  bool grabbedEvents() const { return this->eventsGrabbed; };
     
    6261  KeyMapper                    keyMapper;                       //!< reference to the key mapper.
    6362
    64   bool                         bUNICODE;                        //!< If unicode should be enabled.
     63  bool                         bUNICODE[ES_NUMBER];             //!< If unicode should be enabled.
    6564  bool                         eventsGrabbed;                   //!< If the events should be grabbed
    6665};
Note: See TracChangeset for help on using the changeset viewer.