Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreEventMulticaster.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://ogre.sourceforge.net/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General  License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General  License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General  License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 
00026 /***************************************************************************
00027 OgreEventMulticaster.h  -  
00028       This class implements efficient and thread-safe multi-cast event 
00029       dispatching.  
00030       It will manage an immutable structure consisting of a binary chain of 
00031       event listeners and will dispatch events to those listeners.  Because
00032       the structure is immutable, it is safe to use this API to add/remove
00033       listeners during the process of an event dispatch operation.
00034      
00035       An example of how this class could be used to implement a new
00036       component which fires "action" events:
00037      
00038        // member variable
00039       ActionListener* mActionListener;
00040      
00041       void addActionListener(ActionListener* l) 
00042       {
00043          mActionListener = EventMulticaster::add(mActionListener, l);
00044       }
00045       void removeActionListener(ActionListener* l) 
00046       {
00047          mActionListener = EventMulticaster::remove(mActionListener, l);
00048       }
00049       void processEvent(InputEvent* e) 
00050       {
00051           // when event occurs which is an action
00052           if (mActionListener != NULL) 
00053           {
00054               mActionListener->actionPerformed(static_cast<ActionEvent*>(e));
00055           }         
00056       }
00057 
00058 -------------------
00059 begin                : Nov 19 2002
00060 copyright            : (C) 2002 by Kenny Sabir
00061 email                : kenny@sparksuit.com
00062 ***************************************************************************/
00063 
00064 #ifndef __EVENT_MULTICASTER_H__
00065 #define __EVENT_MULTICASTER_H__
00066 
00067 #include "OgrePrerequisites.h"
00068 #include "OgreEventListeners.h"
00069 
00070 
00071 namespace Ogre {
00072 
00081     class _OgreExport EventMulticaster :  public MouseListener, public ActionListener
00082     {
00083     public:
00084 
00085 
00086 
00096         EventMulticaster(EventListener* a, EventListener* b);
00097 
00103          void listSelected(ListSelectionEvent* e);
00104 
00105 
00111          void actionPerformed(ActionEvent* e);
00112 
00119          static MouseListener* add(MouseListener* a, MouseListener* b);
00120          static ActionListener* add(ActionListener* a, ActionListener* b);
00121          static MouseMotionListener* add(MouseMotionListener* a, MouseMotionListener* b) ;
00122          static ListSelectionListener* add(ListSelectionListener* a, ListSelectionListener* b) ;
00123 
00130 //       static KeyListener* add(KeyListener* a, KeyListener* b);
00131 
00139 //       static TextListener* add(TextListener* a, TextListener* b);
00140 
00141 
00142 
00148 //       void keyPressed(KeyEvent* e);
00149 
00155 //       void keyReleased(KeyEvent* e);
00156 
00162 //       void keyTyped(KeyEvent* e);
00163 
00169          void mouseClicked(MouseEvent* e);
00170 
00176          void mouseDragged(MouseEvent* e);
00177 
00183          void mouseEntered(MouseEvent* e);
00184 
00190          void mouseExited(MouseEvent* e);
00191 
00197          void mouseMoved(MouseEvent* e);
00198 
00204          void mousePressed(MouseEvent* e);
00205 
00211          void mouseReleased(MouseEvent* e);
00212 
00219          static ActionListener* remove(ActionListener* l, ActionListener* oldl);
00220 
00227          static ListSelectionListener* remove(ListSelectionListener* l, ListSelectionListener* oldl);
00228 
00235 //       static KeyListener* remove(KeyListener* l, KeyListener* oldl);
00236 
00243          static MouseMotionListener* remove(MouseMotionListener* l, MouseMotionListener* oldl);
00244 
00251          static MouseListener* remove(MouseListener* l, MouseListener* oldl);
00252 
00253 //       static TextListener* remove(TextListener* l, TextListener* oldl);
00254 
00260          EventListener* remove(EventListener* oldl, bool& deleteSelf) ;
00261 
00262         virtual bool isMulticaster();
00263 
00264 
00265     protected:
00266         EventListener* mA;
00267         EventListener* mB;
00268 
00280          static EventListener* removeInternal(EventListener* l, EventListener* oldl);
00281 
00293          static EventListener* addInternal(EventListener* a, EventListener* b) ;
00294 
00300          static EventListener* convertMultiToListener(EventMulticaster* m);
00301 
00308          static EventMulticaster* convertListenerToMulti(EventListener* l);
00309 
00310     };
00311 
00312 
00313 
00314 }
00315 
00316 
00317 #endif //__EVENT_MULTICASTER_H__
00318 

Copyright © 2002 by The OGRE Team