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 | #include "OgreStableHeaders.h"
|
---|
26 |
|
---|
27 | #include "OgreEventProcessor.h"
|
---|
28 | #include "OgreEventDispatcher.h"
|
---|
29 | #include "OgreEventQueue.h"
|
---|
30 | #include "OgreRoot.h"
|
---|
31 | #include "OgreMouseEvent.h"
|
---|
32 | #include "OgreKeyEvent.h"
|
---|
33 | #include "OgreInput.h"
|
---|
34 | #include "OgreCursor.h"
|
---|
35 | #include "OgrePlatformManager.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | namespace Ogre {
|
---|
39 | //-----------------------------------------------------------------------
|
---|
40 | template<> EventProcessor* Singleton<EventProcessor>::ms_Singleton = 0;
|
---|
41 | EventProcessor* EventProcessor::getSingletonPtr(void)
|
---|
42 | {
|
---|
43 | return ms_Singleton;
|
---|
44 | }
|
---|
45 | EventProcessor& EventProcessor::getSingleton(void)
|
---|
46 | {
|
---|
47 | assert( ms_Singleton ); return ( *ms_Singleton );
|
---|
48 | }
|
---|
49 | //-----------------------------------------------------------------------
|
---|
50 | //-----------------------------------------------------------------------------
|
---|
51 | EventProcessor::EventProcessor() :
|
---|
52 | MouseTarget(),
|
---|
53 | MouseMotionTarget()
|
---|
54 | {
|
---|
55 | mEventQueue = 0;
|
---|
56 | mInputDevice = 0;
|
---|
57 | mRegisteredAsFrameListener = false;
|
---|
58 | }
|
---|
59 |
|
---|
60 | //-----------------------------------------------------------------------------
|
---|
61 | EventProcessor::~EventProcessor()
|
---|
62 | {
|
---|
63 | // just in case more frames are still being rendered
|
---|
64 | // and was registered as a FrameListener.
|
---|
65 | stopProcessingEvents();
|
---|
66 | cleanup();
|
---|
67 | }
|
---|
68 |
|
---|
69 | //-----------------------------------------------------------------------------
|
---|
70 | void EventProcessor::cleanup()
|
---|
71 | {
|
---|
72 | if (mEventQueue)
|
---|
73 | delete mEventQueue;
|
---|
74 |
|
---|
75 | for(DispatcherList::iterator i = mDispatcherList.begin(); i != mDispatcherList.end(); ++i )
|
---|
76 | {
|
---|
77 | delete *i;
|
---|
78 | }
|
---|
79 | mDispatcherList.clear();
|
---|
80 |
|
---|
81 | PlatformManager::getSingleton().destroyInputReader(mInputDevice);
|
---|
82 |
|
---|
83 | }
|
---|
84 |
|
---|
85 | //-----------------------------------------------------------------------------
|
---|
86 | void EventProcessor::stopProcessingEvents()
|
---|
87 | {
|
---|
88 |
|
---|
89 | mEventQueue->activateEventQueue(false);
|
---|
90 |
|
---|
91 | if(mRegisteredAsFrameListener)
|
---|
92 | {
|
---|
93 | Root::getSingleton().removeFrameListener(this);
|
---|
94 | mRegisteredAsFrameListener = false;
|
---|
95 | }
|
---|
96 |
|
---|
97 | }
|
---|
98 |
|
---|
99 | //-----------------------------------------------------------------------------
|
---|
100 | void EventProcessor::initialise(RenderWindow* ren)
|
---|
101 | {
|
---|
102 | cleanup();
|
---|
103 |
|
---|
104 |
|
---|
105 | mEventQueue = new EventQueue();
|
---|
106 |
|
---|
107 | mInputDevice = PlatformManager::getSingleton().createInputReader();
|
---|
108 | mInputDevice->useBufferedInput(mEventQueue);
|
---|
109 | mInputDevice->initialise(ren,true, true, false);
|
---|
110 |
|
---|
111 | }
|
---|
112 | //-----------------------------------------------------------------------------
|
---|
113 |
|
---|
114 | void EventProcessor::addTargetManager(TargetManager* targetManager)
|
---|
115 | {
|
---|
116 | EventDispatcher* pDispatcher = new EventDispatcher(targetManager);
|
---|
117 | mDispatcherList.push_back(pDispatcher);
|
---|
118 | }
|
---|
119 |
|
---|
120 | //-----------------------------------------------------------------------------
|
---|
121 | void EventProcessor::addEventTarget(EventTarget* eventTarget)
|
---|
122 | {
|
---|
123 | mEventTargetList.push_back(eventTarget);
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | //-----------------------------------------------------------------------------
|
---|
128 | void EventProcessor::startProcessingEvents(bool registerListener)
|
---|
129 | {
|
---|
130 | if(registerListener)
|
---|
131 | {
|
---|
132 | Root::getSingleton().addFrameListener(this);
|
---|
133 | mRegisteredAsFrameListener = true;
|
---|
134 | }
|
---|
135 |
|
---|
136 | mEventQueue->activateEventQueue(true);
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | //-----------------------------------------------------------------------------
|
---|
141 | bool EventProcessor::frameStarted(const FrameEvent& evt)
|
---|
142 | {
|
---|
143 | mInputDevice->capture();
|
---|
144 |
|
---|
145 | while (mEventQueue->getSize() > 0)
|
---|
146 | {
|
---|
147 | InputEvent* e = mEventQueue->pop();
|
---|
148 | processEvent(e);
|
---|
149 | delete e;
|
---|
150 | }
|
---|
151 |
|
---|
152 | return true;
|
---|
153 | }
|
---|
154 |
|
---|
155 | //-----------------------------------------------------------------------------
|
---|
156 | void EventProcessor::processEvent(InputEvent* e)
|
---|
157 | {
|
---|
158 | // try the event dispatcher list
|
---|
159 | for (DispatcherList::iterator i = mDispatcherList.begin(); i != mDispatcherList.end(); ++i )
|
---|
160 | {
|
---|
161 | (*i)->dispatchEvent(e);
|
---|
162 | }
|
---|
163 |
|
---|
164 | // try the event target list
|
---|
165 | if (!e->isConsumed())
|
---|
166 | {
|
---|
167 | EventTargetList::iterator i, iEnd;
|
---|
168 |
|
---|
169 | iEnd = mEventTargetList.end();
|
---|
170 | for (i = mEventTargetList.begin(); i != iEnd; ++i )
|
---|
171 | {
|
---|
172 | (*i)->processEvent(e);
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | if (!e->isConsumed())
|
---|
177 | {
|
---|
178 | switch(e->getID())
|
---|
179 | {
|
---|
180 | case MouseEvent::ME_MOUSE_PRESSED:
|
---|
181 | case MouseEvent::ME_MOUSE_RELEASED:
|
---|
182 | case MouseEvent::ME_MOUSE_CLICKED:
|
---|
183 | case MouseEvent::ME_MOUSE_ENTERED:
|
---|
184 | case MouseEvent::ME_MOUSE_EXITED:
|
---|
185 | case MouseEvent::ME_MOUSE_DRAGENTERED:
|
---|
186 | case MouseEvent::ME_MOUSE_DRAGEXITED:
|
---|
187 | case MouseEvent::ME_MOUSE_DRAGDROPPED:
|
---|
188 | processMouseEvent(static_cast<MouseEvent*>(e));
|
---|
189 | break;
|
---|
190 | case MouseEvent::ME_MOUSE_MOVED:
|
---|
191 | case MouseEvent::ME_MOUSE_DRAGGED:
|
---|
192 | case MouseEvent::ME_MOUSE_DRAGMOVED:
|
---|
193 | processMouseMotionEvent(static_cast<MouseEvent*>(e));
|
---|
194 | break;
|
---|
195 | case KeyEvent::KE_KEY_PRESSED:
|
---|
196 | case KeyEvent::KE_KEY_RELEASED:
|
---|
197 | case KeyEvent::KE_KEY_CLICKED:
|
---|
198 | processKeyEvent(static_cast<KeyEvent*>(e));
|
---|
199 | break;
|
---|
200 | }
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | //-----------------------------------------------------------------------------
|
---|
205 | void EventProcessor::addCursorMoveListener(MouseMotionListener* c)
|
---|
206 | {
|
---|
207 | mInputDevice->addCursorMoveListener(c);
|
---|
208 | }
|
---|
209 | //-----------------------------------------------------------------------------
|
---|
210 | void EventProcessor::removeCursorMoveListener(MouseMotionListener* c)
|
---|
211 | {
|
---|
212 | mInputDevice->removeCursorMoveListener(c);
|
---|
213 | }
|
---|
214 |
|
---|
215 | //-----------------------------------------------------------------------------
|
---|
216 | Real EventProcessor::getLeft() const
|
---|
217 | {
|
---|
218 | return 0;
|
---|
219 | }
|
---|
220 |
|
---|
221 | //-----------------------------------------------------------------------------
|
---|
222 | Real EventProcessor::getTop() const
|
---|
223 | {
|
---|
224 | return 0;
|
---|
225 | }
|
---|
226 |
|
---|
227 | //-----------------------------------------------------------------------------
|
---|
228 | PositionTarget* EventProcessor::getPositionTargetParent() const
|
---|
229 | {
|
---|
230 | return NULL;
|
---|
231 | }
|
---|
232 | //-----------------------------------------------------------------------------
|
---|
233 |
|
---|
234 | }
|
---|
235 |
|
---|