Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7897 in orxonox.OLD for branches/gui/src/lib


Ignore:
Timestamp:
May 27, 2006, 6:02:19 AM (19 years ago)
Author:
bensch
Message:

/ When Changing the State, all the keys will be released.

/ This is done by sending each eventListener, that still
/ has an Event subscribed, a Release Event.

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

Legend:

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

    r7895 r7897  
    9494void EventHandler::setState(elState state)
    9595{
     96  /// When Changing the State, all the keys will be released.
     97  /// This is done by sending each eventListener, that still
     98  /// has an Event subscribed, a Release Event.
     99  int keyCount;
     100  Uint8 * pressedKeys = SDL_GetKeyState(&keyCount);
     101  for (unsigned int i = 0; i < SDLK_LAST; i++)
     102  {
     103    if (pressedKeys[i])
     104    {
     105      Event ev;
     106      ev.bPressed = false;
     107      ev.type = i;
     108      if (unlikely(this->bUNICODE[this->state]))
     109        ev.x = i;
     110      this->dispachEvent( ev );
     111    }
     112  }
     113
    96114  this->state = state;
    97115  SDL_EnableUNICODE(this->bUNICODE[state]);
     
    227245}
    228246
     247/**
     248 * @brief returns true if at state and eventType there is something subscribed.
     249 * @param state the state to check in.
     250 * @param eventType the eventtype to check.
     251 * @returns true if a event is subscibed.
     252 */
    229253bool EventHandler::isSubscribed(elState state, int eventType)
    230254{
     
    260284
    261285
     286/**
     287 * @brief if the unicode characters should be recorded.
     288 * @param state the State in whitch to set the new Value.
     289 * @param enableUNICODE: enabled, or disabled.
     290 */
    262291void EventHandler::withUNICODE(elState state, bool enableUNICODE)
    263292{
     
    267296}
    268297
     298/**
     299 * @brief grabs InputEvents.
     300 * @param grabEvents if the Events should be grabbed(true) or released(false)
     301 */
    269302void EventHandler::grabEvents(bool grabEvents)
    270303{
     
    281314  }
    282315}
     316
    283317
    284318/**
     
    287321 * The event from the SDL framework are collected here and distributed to all listeners.
    288322 */
    289 void EventHandler::process()
     323void EventHandler::process() const
    290324{
    291325  SDL_Event event;
     
    355389        break;
    356390    }
    357 
    358     /* small debug routine: shows all events dispatched by the event handler */
    359     PRINT(4)("\n==========================| EventHandler::process () |===\n");
    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++)
    365     {
    366       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());
    368       PRINT(4)("=======================================================\n");
    369       this->listeners[currentState][ev.type][i]->process(ev);
    370     }
    371     /*    else
    372         {
    373           PRINT(4)("=  Event dispatcher msg: This event has NOT been consumed\n");
    374           PRINT(4)("=======================================================\n");
    375         }*/
    376   }
    377 }
     391    this->dispachEvent(ev);
     392  }
     393}
     394
     395
     396/**
     397 * @brief dispaches an Event.
     398 * @param event the Event to dispach.
     399 */
     400void EventHandler::dispachEvent(const Event& event) const
     401{
     402  /* small debug routine: shows all events dispatched by the event handler */
     403  PRINT(4)("\n==========================| EventHandler::process () |===\n");
     404  PRINT(4)("=  Got Event nr %i, for state %i\n", event.type, this->state);
     405
     406  /// setting a temporary state in case of an EventListener's process changes the state.
     407  elState currentState = this->state;
     408  for (unsigned int i = 0; i < this->listeners[currentState][event.type].size(); i++)
     409  {
     410    PRINT(4)("=  Event dispatcher msg: This event has been consumed\n");
     411    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());
     412    PRINT(4)("=======================================================\n");
     413    this->listeners[currentState][event.type][i]->process(event);
     414  }
     415  /*    else
     416  {
     417        PRINT(4)("=  Event dispatcher msg: This event has NOT been consumed\n");
     418        PRINT(4)("=======================================================\n");
     419  }*/
     420}
     421
     422
    378423
    379424/**
  • branches/gui/src/lib/event/event_handler.h

    r7895 r7897  
    1111#include "key_mapper.h"
    1212#include "event_def.h"
     13#include "event.h"
    1314#include <stack>
    1415#include <vector>
     
    4546  bool grabbedEvents() const { return this->eventsGrabbed; };
    4647
    47   void process();
     48  void process() const;
     49  void dispachEvent(const Event& event) const;
    4850
    4951  static int eventFilter(const SDL_Event *event);
Note: See TracChangeset for help on using the changeset viewer.