[692] | 1 |
|
---|
| 2 | /*
|
---|
| 3 | -----------------------------------------------------------------------------
|
---|
| 4 | This source file is part of OGRE
|
---|
| 5 | (Object-oriented Graphics Rendering Engine)
|
---|
| 6 | For the latest info, see http://www.ogre3d.org/
|
---|
| 7 |
|
---|
| 8 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 9 | Also see acknowledgements in Readme.html
|
---|
| 10 |
|
---|
| 11 | This program is free software you can redistribute it and/or modify it under
|
---|
| 12 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 13 | Foundation either version 2 of the License, or (at your option) any later
|
---|
| 14 | version.
|
---|
| 15 |
|
---|
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 17 | ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 19 |
|
---|
| 20 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 21 | this program if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 23 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 24 | -----------------------------------------------------------------------------
|
---|
| 25 | */
|
---|
| 26 | #include "OgreStableHeaders.h"
|
---|
| 27 |
|
---|
| 28 | #include "OgreMouseTarget.h"
|
---|
| 29 | #include "OgreMouseEvent.h"
|
---|
| 30 | #include "OgreEventListeners.h"
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | namespace Ogre {
|
---|
| 34 | MouseTarget::MouseTarget()
|
---|
| 35 | : mMouseWithin(false)
|
---|
| 36 | {
|
---|
| 37 | }
|
---|
| 38 | //-----------------------------------------------------------------------
|
---|
| 39 |
|
---|
| 40 | void MouseTarget::processMouseEvent(MouseEvent* e)
|
---|
| 41 | {
|
---|
| 42 | // Remove all marked listeners
|
---|
| 43 | std::set<MouseListener*>::iterator i;
|
---|
| 44 | for (i = mRemovedListeners.begin(); i != mRemovedListeners.end(); i++)
|
---|
| 45 | {
|
---|
| 46 | mMouseListeners.erase(*i);
|
---|
| 47 | }
|
---|
| 48 | mRemovedListeners.clear();
|
---|
| 49 |
|
---|
| 50 | // Tell all listeners
|
---|
| 51 | for (i= mMouseListeners.begin(); i != mMouseListeners.end(); i++)
|
---|
| 52 | {
|
---|
| 53 | MouseListener* listener = *i;
|
---|
| 54 |
|
---|
| 55 | if (listener != 0)
|
---|
| 56 | {
|
---|
| 57 | int id = e->getID();
|
---|
| 58 | switch(id)
|
---|
| 59 | {
|
---|
| 60 | case MouseEvent::ME_MOUSE_PRESSED:
|
---|
| 61 | listener->mousePressed(e);
|
---|
| 62 | break;
|
---|
| 63 | case MouseEvent::ME_MOUSE_RELEASED:
|
---|
| 64 | listener->mouseReleased(e);
|
---|
| 65 | break;
|
---|
| 66 | case MouseEvent::ME_MOUSE_CLICKED:
|
---|
| 67 | listener->mouseClicked(e);
|
---|
| 68 | break;
|
---|
| 69 | case MouseEvent::ME_MOUSE_EXITED:
|
---|
| 70 | mMouseWithin = false;
|
---|
| 71 | listener->mouseExited(e);
|
---|
| 72 | break;
|
---|
| 73 | case MouseEvent::ME_MOUSE_ENTERED:
|
---|
| 74 | mMouseWithin = true;
|
---|
| 75 | listener->mouseEntered(e);
|
---|
| 76 | break;
|
---|
| 77 | case MouseEvent::ME_MOUSE_DRAGENTERED:
|
---|
| 78 | mMouseWithin = true;
|
---|
| 79 | listener->mouseDragEntered(e);
|
---|
| 80 | break;
|
---|
| 81 | case MouseEvent::ME_MOUSE_DRAGEXITED:
|
---|
| 82 | mMouseWithin = false;
|
---|
| 83 | listener->mouseDragExited(e);
|
---|
| 84 | break;
|
---|
| 85 | case MouseEvent::ME_MOUSE_DRAGDROPPED:
|
---|
| 86 | listener->mouseDragDropped(e);
|
---|
| 87 | break;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | void MouseTarget::addMouseListener(MouseListener* l)
|
---|
| 94 | {
|
---|
| 95 | mMouseListeners.insert(l);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | void MouseTarget::removeMouseListener(MouseListener* l)
|
---|
| 99 | {
|
---|
| 100 | mRemovedListeners.insert(l);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | //-----------------------------------------------------------------------
|
---|
| 104 | bool MouseTarget::isMouseWithin() const
|
---|
| 105 | {
|
---|
| 106 | return mMouseWithin;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|