1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | /***************************************************************************
|
---|
26 | OgreEventProcessor.h -
|
---|
27 | The EventProcessor controls getting events, storing them in a queue, and
|
---|
28 | dispatching events.
|
---|
29 | It contains an InputDevice which creates InputEvents. The events are then
|
---|
30 | stored FIFO in the EventQueue.
|
---|
31 |
|
---|
32 | The EventProcessor is a frame listener, so each frame, it empties the entire
|
---|
33 | queue to the list of dispatchers.
|
---|
34 |
|
---|
35 | Each dispatcher corresponds to a registered TargetManager.
|
---|
36 |
|
---|
37 | The TargetManagers need to be registered with the Processor before initialise is called.
|
---|
38 |
|
---|
39 | After intialise is called, the Processor will start processing events once startProcessingEvents is called.
|
---|
40 |
|
---|
41 | The Processor acts like a default EventTarget, so it can process events that no dispatcher consumes.
|
---|
42 | You can listen default actions to the processor by e.g.
|
---|
43 | mProcessor->addMouseListener(defaultMouseMovement);
|
---|
44 |
|
---|
45 | WARNING: The event objects are created in InputReader when they are submitted to the queue
|
---|
46 | , yet destroyed in the Event Processor when they are taken off the queue.
|
---|
47 | Deleting objects in different locations to where they are created is usually undesirable, however,
|
---|
48 | since the Processor, queue and InputReader are tightly coupled (only the Processor is visible to the outside)
|
---|
49 | this can be an exception.
|
---|
50 | The reason for this is for performance... The alternative, is to do 2 more event copies when sending events to the queue,
|
---|
51 | so the queue manages creating (copying the event from the inputReader) and deleting objects once popped - however
|
---|
52 | this would require the events to be copied twice.. So I have avoided this by having the same event object passed around
|
---|
53 | and not copied.
|
---|
54 | -------------------
|
---|
55 | begin : Nov 19 2002
|
---|
56 | copyright : (C) 2002 by Kenny Sabir
|
---|
57 | email : kenny@sparksuit.com
|
---|
58 | ***************************************************************************/
|
---|
59 |
|
---|
60 | #ifndef __EventProcessor_H__
|
---|
61 | #define __EventProcessor_H__
|
---|
62 |
|
---|
63 | #include <list>
|
---|
64 | #include "OgrePrerequisites.h"
|
---|
65 | #include "OgreSingleton.h"
|
---|
66 | #include "OgreFrameListener.h"
|
---|
67 | #include "OgreMouseTarget.h"
|
---|
68 | #include "OgreKeyTarget.h"
|
---|
69 | #include "OgreMouseMotionTarget.h"
|
---|
70 |
|
---|
71 | namespace Ogre {
|
---|
72 | /** The EventProcessor controls getting events, storing them in a queue, and
|
---|
73 | dispatching events.
|
---|
74 | @remarks
|
---|
75 | An application can create an instance of this class to receive buffered input, as opposed
|
---|
76 | to creating an InputReader directly and retrieving snapshot state only. This class
|
---|
77 | contains an InputReader which it uses to create InputEvents which are then
|
---|
78 | stored FIFO in the EventQueue.
|
---|
79 | @par
|
---|
80 | The EventProcessor is a frame listener, so each frame, it empties the entire
|
---|
81 | queue to the list of dispatchers. Each dispatcher corresponds to a registered TargetManager.
|
---|
82 | The TargetManagers need to be registered with the Processor before initialise is called.
|
---|
83 | After intialise is called, the Processor will start processing events once
|
---|
84 | startProcessingEvents is called.
|
---|
85 | @par
|
---|
86 | The Processor acts like a default EventTarget, so it can process events that no dispatcher consumes.
|
---|
87 | You can listen default actions to the processor by e.g.
|
---|
88 | mProcessor->addMouseListener(defaultMouseMovement);
|
---|
89 | */
|
---|
90 | class _OgreExport EventProcessor : public FrameListener, public MouseTarget, public MouseMotionTarget, public Singleton<EventProcessor>, public KeyTarget
|
---|
91 | {
|
---|
92 | protected:
|
---|
93 | EventQueue* mEventQueue;
|
---|
94 | /**
|
---|
95 | * empty queue and cleanup objects
|
---|
96 | *
|
---|
97 | */
|
---|
98 | void cleanup();
|
---|
99 | InputReader* mInputDevice;
|
---|
100 | typedef std::list<EventDispatcher*> DispatcherList;
|
---|
101 | typedef std::list<EventTarget*> EventTargetList;
|
---|
102 | DispatcherList mDispatcherList;
|
---|
103 | EventTargetList mEventTargetList;
|
---|
104 | bool mRegisteredAsFrameListener;
|
---|
105 |
|
---|
106 | public:
|
---|
107 | EventProcessor();
|
---|
108 | virtual ~EventProcessor();
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Registers FrameListener, and activates the queue
|
---|
112 | */
|
---|
113 | void startProcessingEvents(bool registerListener=true);
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Removes this from being a FrameListener,
|
---|
117 | * and deactivates the queue
|
---|
118 | */
|
---|
119 | void stopProcessingEvents();
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Creates the Queue object,
|
---|
123 | * Creates the InputReader object
|
---|
124 | * initialises the InputReader to use buffered input
|
---|
125 | */
|
---|
126 | void initialise(RenderWindow* ren);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Processes default events,
|
---|
130 | * these are events are aren't handled by any dispatcher
|
---|
131 | */
|
---|
132 | void processEvent(InputEvent* e);
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Adds a mouse motion listener to the cursor object.
|
---|
136 | * This keeps the Cursor object hidden.
|
---|
137 | */
|
---|
138 | void addCursorMoveListener(MouseMotionListener* c);
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Removes a mouse motion listener to the cursor object.
|
---|
142 | * This keeps the Cursor object hidden.
|
---|
143 | */
|
---|
144 | void removeCursorMoveListener(MouseMotionListener* c);
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Creates a dispatcher object that dispatches to the targetManager.
|
---|
148 | * Adds the new dispatcher object to the dispatcher list.
|
---|
149 | */
|
---|
150 |
|
---|
151 | void addTargetManager(TargetManager* targetManager);
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Creates a dispatcher object that dispatches to the targetManager.
|
---|
155 | * Adds the new dispatcher object to the dispatcher list.
|
---|
156 | */
|
---|
157 |
|
---|
158 | void addEventTarget(EventTarget* eventTarget);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Processes all events on the queue.
|
---|
162 | * sends each event to each dispatcher.
|
---|
163 | * deletes the event objects
|
---|
164 | */
|
---|
165 | bool frameStarted(const FrameEvent& evt);
|
---|
166 |
|
---|
167 | // PositionTarget methods
|
---|
168 | /**
|
---|
169 | * returns 0, since this is a default event target, default events have a top of 0
|
---|
170 | */
|
---|
171 | Real getTop() const;
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * returns 0, since this is a default event target, default events have a left of 0
|
---|
175 | */
|
---|
176 | Real getLeft() const;
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * returns NULL, There is no parent of the default event target.
|
---|
180 | */
|
---|
181 | PositionTarget* getPositionTargetParent() const;
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 | bool isKeyEnabled() const
|
---|
186 | { return true; }
|
---|
187 |
|
---|
188 | inline InputReader* getInputReader()
|
---|
189 | { return mInputDevice; }
|
---|
190 | /** Override standard Singleton retrieval.
|
---|
191 | @remarks
|
---|
192 | Why do we do this? Well, it's because the Singleton
|
---|
193 | implementation is in a .h file, which means it gets compiled
|
---|
194 | into anybody who includes it. This is needed for the
|
---|
195 | Singleton template to work, but we actually only want it
|
---|
196 | compiled into the implementation of the class based on the
|
---|
197 | Singleton, not all of them. If we don't change this, we get
|
---|
198 | link errors when trying to use the Singleton-based class from
|
---|
199 | an outside dll.
|
---|
200 | @par
|
---|
201 | This method just delegates to the template version anyway,
|
---|
202 | but the implementation stays in this single compilation unit,
|
---|
203 | preventing link errors.
|
---|
204 | */
|
---|
205 | static EventProcessor& getSingleton(void);
|
---|
206 | /** Override standard Singleton retrieval.
|
---|
207 | @remarks
|
---|
208 | Why do we do this? Well, it's because the Singleton
|
---|
209 | implementation is in a .h file, which means it gets compiled
|
---|
210 | into anybody who includes it. This is needed for the
|
---|
211 | Singleton template to work, but we actually only want it
|
---|
212 | compiled into the implementation of the class based on the
|
---|
213 | Singleton, not all of them. If we don't change this, we get
|
---|
214 | link errors when trying to use the Singleton-based class from
|
---|
215 | an outside dll.
|
---|
216 | @par
|
---|
217 | This method just delegates to the template version anyway,
|
---|
218 | but the implementation stays in this single compilation unit,
|
---|
219 | preventing link errors.
|
---|
220 | */
|
---|
221 | static EventProcessor* getSingletonPtr(void);
|
---|
222 | };
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | #endif //__EventProcessor_H__
|
---|