Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

gui: EventDispacher much better

Location:
branches/gui/src/lib/event
Files:
3 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);
Note: See TracChangeset for help on using the changeset viewer.