Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7866 in orxonox.OLD


Ignore:
Timestamp:
May 26, 2006, 1:11:10 PM (18 years ago)
Author:
bensch
Message:

Events are subscribed at the EventListener, and not the EventHandler

Location:
branches/gui/src
Files:
15 edited

Legend:

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

    r5553 r7866  
    1212#include "SDL/SDL_keysym.h"
    1313#endif
    14 #include "stdincl.h"
    1514
    1615
  • branches/gui/src/lib/event/event_handler.cc

    r7756 r7866  
    171171   unsubscribe(EventListener* el, elState state) function
    172172*/
    173 void EventHandler::unsubscribe(elState state, int eventType)
     173void EventHandler::unsubscribe(EventListener* el, elState state, int eventType)
    174174{
    175175  PRINTF(4)("Unsubscribing event type nr: %i\n", eventType);
    176176  if (state == ES_ALL)
    177177    for (unsigned int i = 0; i < ES_NUMBER; i++)
    178       this->listeners[i][eventType].clear();
    179   else
    180     this->listeners[state][eventType].clear();
    181 }
    182 
    183 
    184 /**
    185  * unsubscribe all events from a specific listener
     178    {
     179      std::vector<EventListener*>::iterator listener =
     180         std::find(this->listeners[i][eventType].begin(),
     181                   this->listeners[i][eventType].end(),
     182                   el);
     183      if (listener != this->listeners[i][eventType].end())
     184        this->listeners[i][eventType].erase(listener);
     185    }
     186  else
     187  {
     188    std::vector<EventListener*>::iterator listener =
     189        std::find(this->listeners[state][eventType].begin(),
     190                  this->listeners[state][eventType].end(),
     191                  el);
     192    if (listener != this->listeners[state][eventType].end())
     193      this->listeners[state][eventType].erase(listener);
     194  }
     195}
     196
     197
     198/**
     199 * @brief unsubscribe all events from a specific listener
    186200 * @param el: the listener that wants to unsubscribe itself
    187201 * @param state: the state in which the events shall be unsubscribed
    188 
    189 */
     202 */
    190203void EventHandler::unsubscribe(EventListener* el, elState state)
    191204{
  • branches/gui/src/lib/event/event_handler.h

    r7756 r7866  
    3535
    3636  void subscribe(EventListener* el, elState state, int eventType);
    37   void unsubscribe(elState state, int eventType);
     37  void unsubscribe(EventListener* el, elState state, int eventType);
    3838  void unsubscribe(EventListener* el, elState state = ES_ALL);
    3939  void flush(elState state);
  • branches/gui/src/lib/event/event_listener.cc

    r4866 r7866  
    2323
    2424/**
    25  * standard constructor
    26 */
     25 * @brief standard constructor
     26 */
    2727EventListener::EventListener ()
    2828{
     
    3232
    3333/**
    34  *  standard deconstructor
    35 */
     34 * @brief standard deconstructor
     35 *
     36 * Unsubscribes all Subscribed Events, of this EventListener.
     37 */
    3638EventListener::~EventListener ()
    3739{
     
    3941  EventHandler::getInstance()->unsubscribe(this, ES_ALL);
    4042}
     43
     44bool EventListener::isEventSubscribed(elState state, int eventType) const
     45{
     46  return EventHandler::getInstance()->isSubscribed(state, eventType);
     47}
     48
     49
     50/**
     51 * @brief Subscribes an Events to this EventListener.
     52 * @param state the state to subscribe to.
     53 * @param eventType the Type of Event to subscribe.
     54 */
     55void EventListener::subscribeEvent(elState state, int eventType)
     56{
     57  EventHandler::getInstance()->subscribe(this, state, eventType);
     58}
     59
     60
     61/**
     62 * @brief Unubscribes an Event from this EventListener.
     63 * @param state the state to unsubscribe from.
     64 * @param eventType the Type of Event to unsubscribe.
     65 */
     66void EventListener::unsubscribeEvent(elState state, int eventType)
     67{
     68  EventHandler::getInstance()->unsubscribe(this, state, eventType);
     69}
     70
     71void EventListener::unsubscribeEvents(elState state)
     72{
     73  EventHandler::getInstance()->unsubscribe(this, state);
     74}
     75
  • branches/gui/src/lib/event/event_listener.h

    r5291 r7866  
    99#include "base_object.h"
    1010#include "event.h"
     11#include "event_def.h"
    1112
    1213//! A class for event listener
     
    1718  virtual ~EventListener();
    1819
     20  bool isEventSubscribed(elState state, int eventType) const;
     21
     22  void subscribeEvent(elState state, int eventType);
     23  void unsubscribeEvent(elState state, int eventType);
     24  void unsubscribeEvents(elState state = ES_ALL);
     25
    1926  /**
    20    * abstract function that processes events from the handler
     27   * @brief abstract function that processes events from the handler
    2128   * @param event: the event
    2229   */
    2330  virtual void process(const Event &event) = 0;
     31
    2432};
    2533
  • branches/gui/src/lib/gui/gl_gui/glgui_handler.cc

    r7840 r7866  
    3131    this->setClassID(CL_GLGUI_HANDLER, "GLGuiHandler");
    3232    this->setName("GLGuiHandler");
     33
     34    //this->subscribeEvent()
    3335
    3436  }
  • branches/gui/src/lib/gui/gl_gui/glgui_widget.h

    r7855 r7866  
    5656    bool focusOverWidget(float x, float y);
    5757
    58     // if something was clickt on the GUI-widget.
     58
     59    virtual void update() {};
     60    virtual void draw() const;
     61
     62    Material& backMaterial() { return this->backMat; };
     63    const Material& backMaterial() const { return this->backMat; };
     64
     65    Material& frontMaterial() { return this->frontMat; };
     66    const Material& frontMaterial() const { return this->frontMat; };
     67
     68  protected:
     69        // if something was clickt on the GUI-widget.
    5970    virtual void clicked(const Event& event) {};
    6071    virtual void released(const Event& event) {};
     
    6576    virtual void destroyed() {};
    6677
    67     virtual void update() {};
    68     virtual void draw() const;
    6978
    70     Material& backMaterial() { return this->backMat; };
    71     Material& frontMaterial() { return this->frontMat; };
    72 
    73   protected:
    7479    inline void startDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
    7580    inline void endDraw() const { glPopMatrix(); };
  • branches/gui/src/lib/shell/shell.cc

    r7764 r7866  
    6565
    6666    // EVENT-Handler subscription of '`' to all States.
    67     EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
    68     EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_F12);
    69     EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEUP);
    70     EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEDOWN);
    71     EventHandler::getInstance()->subscribe(this, ES_SHELL, EV_VIDEO_RESIZE);
     67    this->subscribeEvent(ES_ALL, SDLK_BACKQUOTE);
     68    this->subscribeEvent(ES_ALL, SDLK_F12);
     69    this->subscribeEvent(ES_SHELL, SDLK_PAGEUP);
     70    this->subscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
     71    this->subscribeEvent(ES_SHELL, EV_VIDEO_RESIZE);
    7272
    7373    // BUFFER
  • branches/gui/src/lib/shell/shell_input.cc

    r7858 r7866  
    2020#include "shell_command.h"
    2121#include "shell_command_class.h"
    22 #include "event_handler.h"
    2322
    2423#include "debug.h"
     
    5049    this->setRepeatDelay(.3, .05);
    5150
    52     // subscribe all keyboard commands to ES_SEHLL
    53     EventHandler* evh = EventHandler::getInstance();
     51    // subscribe all keyboard commands to ES_SHELL
    5452    for (int i = 1; i < SDLK_LAST; i++)
    5553    {
    56       if (!evh->isSubscribed(ES_SHELL, i))
    57         evh->subscribe(this, ES_SHELL, i);
     54      if (!this->isEventSubscribed(ES_SHELL, i))
     55        this->subscribeEvent(ES_SHELL, i);
    5856    }
    5957    // unsubscribe unused TODO improve.
    60     evh->unsubscribe(ES_SHELL, SDLK_BACKQUOTE);
    61     evh->unsubscribe(ES_SHELL, SDLK_F12);
    62     evh->unsubscribe(ES_SHELL, SDLK_PAGEUP);
    63     evh->unsubscribe(ES_SHELL, SDLK_PAGEDOWN);
     58    this->unsubscribeEvent(ES_SHELL, SDLK_BACKQUOTE);
     59    this->unsubscribeEvent(ES_SHELL, SDLK_F12);
     60    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP);
     61    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
    6462
    6563  }
  • branches/gui/src/story_entities/movie_loader.cc

    r7283 r7866  
    7070ErrorMessage MovieLoader::unloadData()
    7171{
    72   EventHandler::getInstance()->unsubscribe(this, ES_GAME);
     72  this->unsubscribeEvents(ES_GAME);
    7373}
    7474
  • branches/gui/src/story_entities/simple_game_menu.cc

    r7765 r7866  
    1818
    1919#include "simple_game_menu.h"
     20
     21#include "event_handler.h"
    2022
    2123#include "state.h"
     
    3234#include "camera.h"
    3335
    34 #include "event_handler.h"
    3536#include "graphics_engine.h"
    3637#include "object_manager.h"
     
    112113  GameWorld::init();
    113114
    114   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP);
    115   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN);
    116   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN);
    117   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE);
    118   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_ESCAPE);
     115  this->subscribeEvent(ES_MENU, SDLK_UP);
     116  this->subscribeEvent(ES_MENU, SDLK_DOWN);
     117  this->subscribeEvent(ES_MENU, SDLK_RETURN);
     118  this->subscribeEvent(ES_MENU, SDLK_SPACE);
     119  this->subscribeEvent(ES_MENU, SDLK_ESCAPE);
    119120
    120121  this->dataTank->localCamera->setRelCoor(this->cameraVector);
     
    253254ErrorMessage SimpleGameMenu::unloadData()
    254255{
    255   EventHandler::getInstance()->unsubscribe(this, ES_MENU);
     256  this->unsubscribeEvents(ES_MENU);
    256257
    257258  std::vector<MenuLayer>::iterator mit;
  • branches/gui/src/world_entities/camera.cc

    r7347 r7866  
    3131  this->target = new CameraTarget();
    3232
    33   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW0);
    34   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW1);
    35   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW2);
    36   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW3);
    37   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW4);
    38   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW5);
     33  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW0);
     34  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW1);
     35  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW2);
     36  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW3);
     37  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW4);
     38  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW5);
    3939
    4040  this->setFovy(90);
  • branches/gui/src/world_entities/playable.cc

    r7713 r7866  
    1616
    1717#include "playable.h"
    18 #include "event_handler.h"
     18
     19#include "key_mapper.h"
    1920
    2021#include "player.h"
     
    225226
    226227    // unsubscibe all events.
    227     EventHandler* evh = EventHandler::getInstance();
    228228    std::vector<int>::iterator ev;
    229229    for (ev = this->events.begin(); ev != events.end(); ev++)
    230       evh->unsubscribe( ES_GAME, (*ev));
     230      player->unsubscribeEvent(ES_GAME, (*ev));
    231231
    232232    // leave the entity
     
    251251
    252252    /*EventHandler*/
    253     EventHandler* evh = EventHandler::getInstance();
    254253    std::vector<int>::iterator ev;
    255254    for (ev = this->events.begin(); ev != events.end(); ev++)
    256       evh->subscribe(player, ES_GAME, (*ev));
     255      player->subscribeEvent(ES_GAME, (*ev));
    257256
    258257    this->enter();
     
    440439
    441440  if (this->currentPlayer != NULL)
    442     EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
     441    this->currentPlayer->subscribeEvent(ES_GAME, eventType);
    443442}
    444443
     
    453452
    454453  if (this->currentPlayer != NULL)
    455     EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
     454    this->currentPlayer->unsubscribeEvent(ES_GAME, eventType);
    456455}
    457456
  • branches/gui/src/world_entities/player.cc

    r7337 r7866  
    4040  this->hud.show();
    4141
    42   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_CHANGE_SHIP);
     42  this->subscribeEvent(ES_GAME, KeyMapper::PEV_CHANGE_SHIP);
    4343}
    4444
  • branches/gui/src/world_entities/weapons/crosshair.cc

    r7221 r7866  
    6565  this->material = new Material;
    6666
    67   //EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
     67  //this->subscribeEvent(ES_GAME, EV_MOUSE_MOTION);
    6868
    6969  // center the mouse on the screen, and also hide the cursors
Note: See TracChangeset for help on using the changeset viewer.