Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7903 in orxonox.OLD


Ignore:
Timestamp:
May 27, 2006, 2:18:55 PM (18 years ago)
Author:
bensch
Message:

gui: EventDispacher much better

Location:
branches/gui/src/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/event/event_def.h

    r7868 r7903  
    3030  EV_VIDEO_RESIZE,
    3131
     32  EV_LEAVE_STATE,
    3233  EV_MAIN_QUIT,
    3334
  • branches/gui/src/lib/event/event_handler.cc

    r7898 r7903  
    9393void EventHandler::setState(elState state)
    9494{
     95  if (state == this->state)
     96    return;
     97
    9598  /// When Changing the State, all the keys will be released.
    9699  /// This is done by sending each eventListener, that still
     
    107110      if (unlikely(this->bUNICODE[this->state]))
    108111        ev.x = i;
    109       this->dispachEvent( ev );
    110     }
    111   }
    112 
     112      this->dispachEvent(this->state, ev );
     113    }
     114  }
     115
     116  // switching to the new State.
     117  elState oldState = this->state;
    113118  this->state = state;
     119
     120  // in the End the Corresponding handler will be notified.
     121  Event stateSwitchEvent;
     122  stateSwitchEvent.type = EV_LEAVE_STATE;
     123  this->dispachEvent(oldState, stateSwitchEvent);
     124
    114125  SDL_EnableUNICODE(this->bUNICODE[state]);
    115126};
     
    388399        break;
    389400    }
    390     this->dispachEvent(ev);
     401    this->dispachEvent(this->state, ev);
    391402  }
    392403}
     
    397408 * @param event the Event to dispach.
    398409 */
    399 void EventHandler::dispachEvent(const Event& event) const
     410void EventHandler::dispachEvent(elState state, const Event& event) const
    400411{
    401412  /* small debug routine: shows all events dispatched by the event handler */
    402413  PRINT(4)("\n==========================| EventHandler::process () |===\n");
    403   PRINT(4)("=  Got Event nr %i, for state %i\n", event.type, this->state);
     414  PRINT(4)("=  Got Event nr %i, for state %i\n", event.type, state);
    404415
    405416  /// setting a temporary state in case of an EventListener's process changes the state.
    406   elState currentState = this->state;
    407   for (unsigned int i = 0; i < this->listeners[currentState][event.type].size(); i++)
     417  for (unsigned int i = 0; i < this->listeners[state][event.type].size(); i++)
    408418  {
    409419    PRINT(4)("=  Event dispatcher msg: This event has been consumed\n");
    410     PRINT(4)("=  Got Event nr %i, for state %i %s::%s\n", event.type, currentState, this->listeners[this->state][event.type][i]->getClassName(), this->listeners[currentState][event.type][i]->getName());
     420    PRINT(4)("=  Got Event nr %i, for state %i %s::%s\n", event.type, state, this->listeners[state][event.type][i]->getClassName(), this->listeners[state][event.type][i]->getName());
    411421    PRINT(4)("=======================================================\n");
    412     this->listeners[currentState][event.type][i]->process(event);
     422    this->listeners[state][event.type][i]->process(event);
    413423  }
    414424  /*    else
  • branches/gui/src/lib/event/event_handler.h

    r7897 r7903  
    4747
    4848  void process() const;
    49   void dispachEvent(const Event& event) const;
     49  void dispachEvent(elState state, const Event& event) const;
    5050
    5151  static int eventFilter(const SDL_Event *event);
  • branches/gui/src/lib/gui/gl_gui/glgui_handler.cc

    r7899 r7903  
    9595  void GLGuiHandler::process(const Event &event)
    9696  {
    97     if (event.type == EV_MOUSE_BUTTON_LEFT)
     97    switch (event.type)
    9898    {
     99      case  EV_MOUSE_BUTTON_LEFT:
     100        if (GLGuiWidget::focused() != NULL)
     101        {
     102          if (event.bPressed)
     103          {
     104            if (GLGuiWidget::focused()->clickable())
     105              GLGuiWidget::focused()->click();
     106          }
     107          else
     108          {
     109            if (GLGuiWidget::focused()->clickable())
     110              GLGuiWidget::focused()->release();
     111          }
     112        }
     113        break;
     114      case EV_LEAVE_STATE:
     115        if (GLGuiWidget::focused() != NULL)
     116          GLGuiWidget::focused()->breakFocus();
     117    }
    99118
    100       if (GLGuiWidget::focused() != NULL)
    101       {
    102         if (event.bPressed)
    103         {
    104           if (GLGuiWidget::focused()->clickable())
    105           GLGuiWidget::focused()->click();
    106         }
    107         else
    108         {
    109           if (GLGuiWidget::focused()->clickable())
    110             GLGuiWidget::focused()->release();
    111         }
    112       }
    113     }
     119
    114120
    115121    if (GLGuiWidget::focused())
     
    118124    }
    119125
     126
     127
    120128  }
    121129
    122130  void GLGuiHandler::draw()
    123131  {
    124 //    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
     132    //    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
    125133  }
    126134
  • branches/gui/src/lib/gui/gl_gui/glgui_widget.cc

    r7896 r7903  
    7777  void GLGuiWidget::giveFocus()
    7878  {
     79    if (GLGuiWidget::focused() != NULL)
     80      GLGuiWidget::focused()->breakFocus();
    7981    GLGuiWidget::_focused = this;
    8082    this->receivedFocus();
     
    8385  void GLGuiWidget::breakFocus()
    8486  {
    85     GLGuiWidget::_focused = NULL;
    86     this->_pushed = false;
    87     this->removedFocus();
     87    if (GLGuiWidget::_focused == this)
     88    {
     89      GLGuiWidget::_focused = NULL;
     90      this->_pushed = false;
     91      this->removedFocus();
     92    }
    8893  };
    8994
Note: See TracChangeset for help on using the changeset viewer.