00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
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
00118 void scrollPerformed(ScrollEvent* e);
00119
00126 static KeyListener* add(KeyListener* a, KeyListener* b);
00127 static MouseListener* add(MouseListener* a, MouseListener* b);
00128 static ActionListener* add(ActionListener* a, ActionListener* b);
00129 static MouseMotionListener* add(MouseMotionListener* a, MouseMotionListener* b) ;
00130 static ListSelectionListener* add(ListSelectionListener* a, ListSelectionListener* b) ;
00131 static ScrollListener* add(ScrollListener* a, ScrollListener* b) ;
00132
00133
00141 // static TextListener* add(TextListener* a, TextListener* b);
00142
00143
00144
00150 void keyPressed(KeyEvent* e);
00151
00157 void keyReleased(KeyEvent* e);
00158
00164 void keyClicked(KeyEvent* e);
00165
00171 void mouseClicked(MouseEvent* e);
00172
00178 void mouseDragged(MouseEvent* e);
00179
00185 void mouseEntered(MouseEvent* e);
00186
00192 void mouseExited(MouseEvent* e);
00193
00199 void mouseMoved(MouseEvent* e);
00200
00206 void mousePressed(MouseEvent* e);
00207
00213 void mouseReleased(MouseEvent* e);
00214
00221 static ActionListener* remove(ActionListener* l, ActionListener* oldl);
00222
00229 static ScrollListener* remove(ScrollListener* l, ScrollListener* oldl);
00230
00237 static ListSelectionListener* remove(ListSelectionListener* l, ListSelectionListener* oldl);
00238
00245 static KeyListener* remove(KeyListener* l, KeyListener* oldl);
00246
00253 static MouseMotionListener* remove(MouseMotionListener* l, MouseMotionListener* oldl);
00254
00261 static MouseListener* remove(MouseListener* l, MouseListener* oldl);
00262
00263 // static TextListener* remove(TextListener* l, TextListener* oldl);
00264
00270 EventListener* remove(EventListener* oldl, bool& deleteSelf) ;
00271
00272 virtual bool isMulticaster() const;
00273
00274
00275 protected:
00276 EventListener* mA;
00277 EventListener* mB;
00278
00290 static EventListener* removeInternal(EventListener* l, EventListener* oldl);
00291
00303 static EventListener* addInternal(EventListener* a, EventListener* b) ;
00304
00310 static EventListener* convertMultiToListener(EventMulticaster* m);
00311
00318 static EventMulticaster* convertListenerToMulti(EventListener* l);
00319
00320 };
00321
00322
00323
00324 }
00325
00326
00327 #endif //__EVENT_MULTICASTER_H__
00328
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:10 2004