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

# OgreEventProcessor.cpp

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://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 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 #include "OgreStableHeaders.h"
    00026
    00027 #include "OgreEventProcessor.h"
    00028 #include "OgreOverlayManager.h"
    00029 #include "OgreEventQueue.h"
    00030 #include "OgreRoot.h"
    00031 #include "OgreMouseEvent.h"
    00032 #include "OgreKeyEvent.h"
    00033 #include "OgreActionEvent.h"
    00034 #include "OgreInput.h"
    00035 #include "OgreCursor.h"
    00036
    00037
    00038 namespace Ogre {
    00039     //-----------------------------------------------------------------------
    00040     template<> EventProcessor* Singleton<EventProcessor>::ms_Singleton = 0;
    00041     EventProcessor* EventProcessor::getSingletonPtr(void)
    00042     {
    00043         return ms_Singleton;
    00044     }
    00045     EventProcessor& EventProcessor::getSingleton(void)
    00046     {
    00047         assert( ms_Singleton );  return ( *ms_Singleton );
    00048     }
    00049     //-----------------------------------------------------------------------
    00050 //-----------------------------------------------------------------------------
    00051     EventProcessor::EventProcessor() :
    00052         MouseTarget(),
    00053         MouseMotionTarget()
    00054     {
    00055         mEventQueue = 0;
    00056         mInputDevice = 0;
    00057         mRegisteredAsFrameListener = false;
    00058     }
    00059
    00060 //-----------------------------------------------------------------------------
    00061     EventProcessor::~EventProcessor()
    00062     {
    00063
    00064         cleanup();
    00065     }
    00066
    00067 //-----------------------------------------------------------------------------
    00068     void EventProcessor::cleanup()
    00069     {
    00070         if (mEventQueue)
    00071             delete mEventQueue;
    00072
    00073         for(DispatcherList::iterator i = mDispatcherList.begin(); i != mDispatcherList.end(); ++i )
    00074         {
    00075             delete *i;
    00076         }
    00077         mDispatcherList.clear();
    00078
    00079         PlatformManager::getSingleton().destroyInputReader(mInputDevice);
    00080
    00081     }
    00082
    00083 //-----------------------------------------------------------------------------
    00084     void EventProcessor::stopProcessingEvents()
    00085     {
    00086
    00087         mEventQueue->activateEventQueue(false);
    00088
    00089         if(mRegisteredAsFrameListener)
    00090         {
    00091             Root::getSingleton().removeFrameListener(this);
    00092             mRegisteredAsFrameListener = false;
    00093         }
    00094
    00095     }
    00096
    00097 //-----------------------------------------------------------------------------
    00098     void EventProcessor::initialise(RenderWindow* ren)
    00099     {
    00100         cleanup();
    00101
    00102
    00103         mEventQueue = new EventQueue();
    00104
    00105         mInputDevice = PlatformManager::getSingleton().createInputReader();
    00106         mInputDevice->useBufferedInput(mEventQueue);
    00107         mInputDevice->initialise(ren,true, true, false);
    00108
    00109     }
    00110 //-----------------------------------------------------------------------------
    00111
    00112     void EventProcessor::addTargetManager(TargetManager* targetManager)
    00113     {
    00114         EventDispatcher* pDispatcher = new EventDispatcher(targetManager);
    00115         mDispatcherList.push_back(pDispatcher);
    00116     }
    00117
    00118     //-----------------------------------------------------------------------------
    00119     void EventProcessor::addEventTarget(EventTarget* eventTarget)
    00120     {
    00121         mEventTargetList.push_back(eventTarget);
    00122     }
    00123
    00124
    00125 //-----------------------------------------------------------------------------
    00126     void EventProcessor::startProcessingEvents(bool registerListener)
    00127     {
    00128         if(registerListener)
    00129         {
    00130             Root::getSingleton().addFrameListener(this);
    00131             mRegisteredAsFrameListener = true;
    00132         }
    00133
    00134         mEventQueue->activateEventQueue(true);
    00135     }
    00136
    00137
    00138 //-----------------------------------------------------------------------------
    00139     bool EventProcessor::frameStarted(const FrameEvent& evt)
    00140     {
    00141         mInputDevice->capture();
    00142
    00143         while (mEventQueue->getSize() > 0)
    00144         {
    00145             InputEvent* e = mEventQueue->pop();
    00146             processEvent(e);
    00147             delete e;
    00148         }
    00149
    00150         return true;
    00151     }
    00152
    00153 //-----------------------------------------------------------------------------
    00154     void EventProcessor::processEvent(InputEvent* e)
    00155     {
    00156             // try the event dispatcher list
    00157         for (DispatcherList::iterator i = mDispatcherList.begin(); i != mDispatcherList.end(); ++i )
    00158         {
    00159             (*i)->dispatchEvent(e);
    00160         }
    00161
    00162             // try the event target list
    00163         if (!e->isConsumed())
    00164         {
    00165             EventTargetList::iterator i, iEnd;
    00166
    00167             iEnd = mEventTargetList.end();
    00168             for (i = mEventTargetList.begin(); i != iEnd; ++i )
    00169             {
    00170                 (*i)->processEvent(e);
    00171             }
    00172         }
    00173
    00174         if (!e->isConsumed())
    00175         {
    00176             switch(e->getID())
    00177             {
    00178             case MouseEvent::ME_MOUSE_PRESSED:
    00179             case MouseEvent::ME_MOUSE_RELEASED:
    00180             case MouseEvent::ME_MOUSE_CLICKED:
    00181             case MouseEvent::ME_MOUSE_ENTERED:
    00182             case MouseEvent::ME_MOUSE_EXITED:
    00183             case MouseEvent::ME_MOUSE_DRAGENTERED:
    00184             case MouseEvent::ME_MOUSE_DRAGEXITED:
    00185             case MouseEvent::ME_MOUSE_DRAGDROPPED:
    00186                 processMouseEvent(static_cast<MouseEvent*>(e));
    00187                 break;
    00188             case MouseEvent::ME_MOUSE_MOVED:
    00189             case MouseEvent::ME_MOUSE_DRAGGED:
    00190             case MouseEvent::ME_MOUSE_DRAGMOVED:
    00191                 processMouseMotionEvent(static_cast<MouseEvent*>(e));
    00192                 break;
    00193             case KeyEvent::KE_KEY_PRESSED:
    00194             case KeyEvent::KE_KEY_RELEASED:
    00195             case KeyEvent::KE_KEY_CLICKED:
    00196                 processKeyEvent(static_cast<KeyEvent*>(e));
    00197                 break;
    00198             }
    00199         }
    00200     }
    00201
    00202 //-----------------------------------------------------------------------------
    00203     void EventProcessor::addCursorMoveListener(MouseMotionListener* c)
    00204     {
    00205         mInputDevice->addCursorMoveListener(c);
    00206     }
    00207 //-----------------------------------------------------------------------------
    00208     void EventProcessor::removeCursorMoveListener(MouseMotionListener* c)
    00209     {
    00210         mInputDevice->removeCursorMoveListener(c);
    00211     }
    00212
    00213 //-----------------------------------------------------------------------------
    00214     Real EventProcessor::getLeft() const
    00215     {
    00216         return 0;
    00217     }
    00218
    00219 //-----------------------------------------------------------------------------
    00220     Real EventProcessor::getTop() const
    00221     {
    00222         return 0;
    00223     }
    00224
    00225 //-----------------------------------------------------------------------------
    00226     PositionTarget* EventProcessor::getPositionTargetParent() const
    00227     {
    00228         return NULL;
    00229     }
    00230 //-----------------------------------------------------------------------------
    00231
    00232 }
    00233

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:23 2004