Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7895 in orxonox.OLD for branches/gui


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

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

Location:
branches/gui/src
Files:
6 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};
  • branches/gui/src/lib/gui/gl_gui/glgui_handler.cc

    r7893 r7895  
    3737
    3838
     39    EventHandler::getInstance()->withUNICODE(ES_MENU, true );
     40
    3941    this->cursor = NULL;
    4042    for (unsigned int i = 0; i < EV_NUMBER; i++)
     
    4244      this->subscribeEvent(ES_MENU, i);
    4345    }
    44 
    4546  }
    4647
     
    7980    EventHandler::getInstance()->pushState(ES_MENU);
    8081
     82
     83
    8184  }
    8285
     
    8487  {
    8588    EventHandler::getInstance()->popState();
     89
    8690
    8791  }
  • branches/gui/src/lib/gui/gl_gui/glgui_inputline.cc

    r7894 r7895  
    3636  {}
    3737
    38   float GLGuiInputLine::repeatDelay = 1.0;
    39   float GLGuiInputLine::repeatRate = .1;
     38  float GLGuiInputLine::repeatDelay = 0.3f;
     39  float GLGuiInputLine::repeatRate  = 0.01f;
    4040
    4141
     
    9797      else if (likely(event.type < 127))
    9898      {
     99        this->delayNext = GLGuiInputLine::repeatDelay;
     100
    99101        this->appendCharacter(event.x);
    100102        this->pressedKey = event.type;
     
    102104        return true;
    103105      }
    104       this->delayNext = this->repeatDelay;
    105106    }
    106107    else // if(!event.bPressed)
     
    113114        return true;
    114115      }
    115     }
    116 
    117     if (likely(event.type < 127))
    118     {
    119       this->appendCharacter(event.type);
    120       return true;
    121116    }
    122117
     
    135130    if (this->delayNext > 0.0)
    136131      this->delayNext -= dt;
     132        else if (this->pressedKey != SDLK_FIRST )
     133    {
     134      this->delayNext = GLGuiInputLine::repeatRate;
     135      switch (this->pressedKey)
     136      {
     137        case SDLK_BACKSPACE:
     138          this->removeCharacters(1);
     139          break;
     140        default:
     141        {
     142          if (likely(this->pressedKey < 127))
     143            this->appendCharacter(this->pressedKeyName);
     144        }
     145      }
     146    }
     147
     148
    137149  }
    138150
  • branches/gui/src/lib/shell/shell.cc

    r7868 r7895  
    7070    this->subscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
    7171    this->subscribeEvent(ES_SHELL, EV_VIDEO_RESIZE);
     72    EventHandler::getInstance()->withUNICODE(ES_SHELL, true);
    7273
    7374    // BUFFER
     
    8384    this->textSize = 15;
    8485    this->lineSpacing = 0;
    85     this->bActive = true;
     86    this->bActive = false;
    8687    this->fontFile = SHELL_DEFAULT_FONT;
    8788
     
    121122
    122123    EventHandler::getInstance()->pushState(ES_SHELL);
    123     EventHandler::getInstance()->withUNICODE(true);
    124124
    125125    this->setRelCoorSoft2D(0, 0, 5);
     
    152152    this->deactivate2D();
    153153
    154     EventHandler::getInstance()->withUNICODE(false);
    155154    EventHandler::getInstance()->popState();
    156155
  • branches/gui/src/story_entities/simple_game_menu.cc

    r7893 r7895  
    8484
    8585  OrxGui::GLGuiHandler::getInstance()->activateCursor();
     86  OrxGui::GLGuiHandler::getInstance()->activate();
    8687  /////
    8788  if (root != NULL)
Note: See TracChangeset for help on using the changeset viewer.