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 (c) 2000-2005 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 Public 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 Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 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 OgreEventProcessor.h - 00027 The EventProcessor controls getting events, storing them in a queue, and 00028 dispatching events. 00029 It contains an InputDevice which creates InputEvents. The events are then 00030 stored FIFO in the EventQueue. 00031 00032 The EventProcessor is a frame listener, so each frame, it empties the entire 00033 queue to the list of dispatchers. 00034 00035 Each dispatcher corresponds to a registered TargetManager. 00036 00037 The TargetManagers need to be registered with the Processor before initialise is called. 00038 00039 After intialise is called, the Processor will start processing events once startProcessingEvents is called. 00040 00041 The Processor acts like a default EventTarget, so it can process events that no dispatcher consumes. 00042 You can listen default actions to the processor by e.g. 00043 mProcessor->addMouseListener(defaultMouseMovement); 00044 00045 WARNING: The event objects are created in InputReader when they are submitted to the queue 00046 , yet destroyed in the Event Processor when they are taken off the queue. 00047 Deleting objects in different locations to where they are created is usually undesirable, however, 00048 since the Processor, queue and InputReader are tightly coupled (only the Processor is visible to the outside) 00049 this can be an exception. 00050 The reason for this is for performance... The alternative, is to do 2 more event copies when sending events to the queue, 00051 so the queue manages creating (copying the event from the inputReader) and deleting objects once popped - however 00052 this would require the events to be copied twice.. So I have avoided this by having the same event object passed around 00053 and not copied. 00054 ------------------- 00055 begin : Nov 19 2002 00056 copyright : (C) 2002 by Kenny Sabir 00057 email : kenny@sparksuit.com 00058 ***************************************************************************/ 00059 00060 #ifndef __EventProcessor_H__ 00061 #define __EventProcessor_H__ 00062 00063 #include <list> 00064 #include "OgrePrerequisites.h" 00065 #include "OgreSingleton.h" 00066 #include "OgreFrameListener.h" 00067 #include "OgreMouseTarget.h" 00068 #include "OgreKeyTarget.h" 00069 #include "OgreMouseMotionTarget.h" 00070 00071 namespace Ogre { 00090 class _OgreExport EventProcessor : public FrameListener, public MouseTarget, public MouseMotionTarget, public Singleton<EventProcessor>, public KeyTarget 00091 { 00092 protected: 00093 EventQueue* mEventQueue; 00098 void cleanup(); 00099 InputReader* mInputDevice; 00100 typedef std::list<EventDispatcher*> DispatcherList; 00101 typedef std::list<EventTarget*> EventTargetList; 00102 DispatcherList mDispatcherList; 00103 EventTargetList mEventTargetList; 00104 bool mRegisteredAsFrameListener; 00105 00106 public: 00107 EventProcessor(); 00108 virtual ~EventProcessor(); 00109 00113 void startProcessingEvents(bool registerListener=true); 00114 00119 void stopProcessingEvents(); 00120 00126 void initialise(RenderWindow* ren); 00127 00132 void processEvent(InputEvent* e); 00133 00138 void addCursorMoveListener(MouseMotionListener* c); 00139 00144 void removeCursorMoveListener(MouseMotionListener* c); 00145 00151 void addTargetManager(TargetManager* targetManager); 00152 00158 void addEventTarget(EventTarget* eventTarget); 00159 00165 bool frameStarted(const FrameEvent& evt); 00166 00167 // PositionTarget methods 00171 Real getTop() const; 00172 00176 Real getLeft() const; 00177 00181 PositionTarget* getPositionTargetParent() const; 00182 00183 00184 00185 bool isKeyEnabled() const 00186 { return true; } 00187 00188 inline InputReader* getInputReader() 00189 { return mInputDevice; } 00205 static EventProcessor& getSingleton(void); 00221 static EventProcessor* getSingletonPtr(void); 00222 }; 00223 00224 00225 00226 } 00227 00228 00229 #endif //__EventProcessor_H__
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:40 2006