[692] | 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 | /***************************************************************************
|
---|
| 27 | OgreEventDispatcher.h -
|
---|
| 28 | Handles the Dispatching of events to a EventTarget (mainly a PositionTarget for
|
---|
| 29 | mouse moving). The EventTargets are managed by a target manager.
|
---|
| 30 |
|
---|
| 31 | A EventDispatcher is needed for each TargetManager. ie 1 dispatcher for the OverlayManager,
|
---|
| 32 | for managing the 2D GUI components, and another EventDispatcher for a SceneManager
|
---|
| 33 | managing the 3D objects.(NOTE currently the SceneManager isn't a TargetManager.. this is a TODO).
|
---|
| 34 |
|
---|
| 35 | -------------------
|
---|
| 36 | begin : Nov 19 2002
|
---|
| 37 | copyright : (C) 2002 by Kenny Sabir
|
---|
| 38 | email : kenny@sparksuit.com
|
---|
| 39 | ***************************************************************************/
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | #ifndef __EventDispatcher_H__
|
---|
| 44 | #define __EventDispatcher_H__
|
---|
| 45 |
|
---|
| 46 | #include "OgrePrerequisites.h"
|
---|
| 47 |
|
---|
| 48 | namespace Ogre {
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | Handles the Dispatching of events to a EventTarget (mainly a PositionTarget for
|
---|
| 52 | mouse moving).
|
---|
| 53 | @remarks
|
---|
| 54 | A EventDispatcher is needed for each TargetManager. ie 1 dispatcher for the OverlayManager,
|
---|
| 55 | for managing the 2D GUI components, and another EventDispatcher for a SceneManager
|
---|
| 56 | managing the 3D objects.(NOTE currently the SceneManager isn't a TargetManager.. this is a TODO).
|
---|
| 57 | */
|
---|
| 58 | class _OgreExport EventDispatcher
|
---|
| 59 | {
|
---|
| 60 | protected:
|
---|
| 61 | TargetManager* mTargetManager;
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * The current PositionTarget that has focus that is being
|
---|
| 65 | * hosted by this GuiContainer. If this is a null reference then
|
---|
| 66 | * there is currently no focus on a PositionTarget being
|
---|
| 67 | * hosted by this GuiContainer
|
---|
| 68 | */
|
---|
| 69 | PositionTarget* mFocus; // isn't implemented yet
|
---|
| 70 |
|
---|
| 71 | /**
|
---|
| 72 | * The current PositionTarget, over which, the current drag operation originated.
|
---|
| 73 | * Only valid when mDragging is true. May be null.
|
---|
| 74 | */
|
---|
| 75 | PositionTarget* mMouseDragSource;
|
---|
| 76 |
|
---|
| 77 | /**
|
---|
| 78 | * PositionTarget the Keycursor is on
|
---|
| 79 | */
|
---|
| 80 | PositionTarget* mKeyCursorOn;
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * The last PositionTarget entered
|
---|
| 84 | */
|
---|
| 85 | PositionTarget* mTargetLastEntered;
|
---|
| 86 |
|
---|
| 87 | /**
|
---|
| 88 | * Screen coordinates of the last (or current) mouse event. Will eventually be
|
---|
| 89 | * useful for managing mouse cursors.
|
---|
| 90 | */
|
---|
| 91 | Real mMouseX;
|
---|
| 92 | Real mMouseY;
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * Indicates if the mouse pointer is currently being dragged...
|
---|
| 96 | * this is needed because we may receive exit events while dragging
|
---|
| 97 | * and need to keep the current mouse target in this case.
|
---|
| 98 | */
|
---|
| 99 | bool mDragging; // i.e. mouse grab
|
---|
| 100 |
|
---|
| 101 | /**
|
---|
| 102 | * Indicates whether or not Drag/Drop event will be generated during the
|
---|
| 103 | * next drag sequence.
|
---|
| 104 | *
|
---|
| 105 | * @see setDragDrop
|
---|
| 106 | */
|
---|
| 107 | bool mDragDropOn;
|
---|
| 108 |
|
---|
| 109 | /**
|
---|
| 110 | * Indicates whether or not Drag/Drop events are currently being generated.
|
---|
| 111 | */
|
---|
| 112 | bool mDragDropActive;
|
---|
| 113 |
|
---|
| 114 | int mEventMask;
|
---|
| 115 |
|
---|
| 116 | //-------------------
|
---|
| 117 | // protected methods
|
---|
| 118 |
|
---|
| 119 | bool processKeyEvent(KeyEvent* e) ;
|
---|
| 120 |
|
---|
| 121 | /**
|
---|
| 122 | * This method attempts to distribute a mouse event to a lightweight
|
---|
| 123 | * PositionTarget. It tries to avoid doing any unnecessary probes down
|
---|
| 124 | * into the PositionTarget tree to minimize the overhead of determining
|
---|
| 125 | * where to route the event, since mouse movement events tend to
|
---|
| 126 | * come in large and frequent amounts.
|
---|
| 127 | */
|
---|
| 128 |
|
---|
| 129 | bool processMouseEvent(MouseEvent* e) ;
|
---|
| 130 |
|
---|
| 131 | /**
|
---|
| 132 | * Sends a mouse event to the current mouse event recipient using
|
---|
| 133 | * the given event (sent to the windowed host) as a srcEvent. If
|
---|
| 134 | * the mouse event target is still in the PositionTarget tree, the
|
---|
| 135 | * coordinates of the event are translated to those of the target.
|
---|
| 136 | * If the target has been removed, we don't bother to send the
|
---|
| 137 | * message.
|
---|
| 138 | */
|
---|
| 139 |
|
---|
| 140 | void retargetMouseEvent(PositionTarget* target, MouseEvent* e) ;
|
---|
| 141 |
|
---|
| 142 | /**
|
---|
| 143 | * Sends a mouse event to the current mouse event recipient using
|
---|
| 144 | * the given event (sent to the windowed host) as a srcEvent. If
|
---|
| 145 | * the mouse event target is still in the PositionTarget tree, the
|
---|
| 146 | * coordinates of the event are translated to those of the target.
|
---|
| 147 | * If the target has been removed, we don't bother to send the
|
---|
| 148 | * message.
|
---|
| 149 | */
|
---|
| 150 |
|
---|
| 151 | void retargetMouseEvent(PositionTarget* target, int id, MouseEvent* e, bool consume = false) ;
|
---|
| 152 |
|
---|
| 153 | /**
|
---|
| 154 | * Sends a key event to the current mouse event recipient using
|
---|
| 155 | * the given event (sent to the windowed host) as a srcEvent.
|
---|
| 156 | */
|
---|
| 157 |
|
---|
| 158 | void retargetKeyEvent(PositionTarget* target, int id, MouseEvent* e) ;
|
---|
| 159 |
|
---|
| 160 | /*
|
---|
| 161 | * Generates enter/exit events as mouse moves over lw PositionTargets
|
---|
| 162 | * @param targetOver Target mouse is over (including native container)
|
---|
| 163 | * @param e Mouse event in native container
|
---|
| 164 | */
|
---|
| 165 |
|
---|
| 166 | void trackMouseEnterExit(PositionTarget* targetOver, MouseEvent* e) ;
|
---|
| 167 |
|
---|
| 168 | /*
|
---|
| 169 | * Generates FocusIn/FocusOut events as the keyboard focus changes.
|
---|
| 170 | * @param targetOver Target mouse is over (including native container)
|
---|
| 171 | * @param e Mouse event in native container
|
---|
| 172 | */
|
---|
| 173 | void trackKeyEnterExit(PositionTarget* targetOver, MouseEvent* e);
|
---|
| 174 |
|
---|
| 175 | public:
|
---|
| 176 | EventDispatcher(TargetManager* pTargetManager);
|
---|
| 177 | virtual ~EventDispatcher();
|
---|
| 178 |
|
---|
| 179 | /**
|
---|
| 180 | * Dispatches an event to a PositionTarget if necessary, and
|
---|
| 181 | * returns whether or not the event was forwarded to a
|
---|
| 182 | * sub-PositionTarget.
|
---|
| 183 | *
|
---|
| 184 | * @param e the event
|
---|
| 185 | */
|
---|
| 186 | bool dispatchEvent(InputEvent* e);
|
---|
| 187 |
|
---|
| 188 | /**
|
---|
| 189 | * Enables or disables the mouse drag/drop events on the next mouse
|
---|
| 190 | * drag sequence. It has no effect on the current drag sequence, if any.
|
---|
| 191 | * Drag/drop events are typically enabled when the mouse enters the area
|
---|
| 192 | * of a particular PositionTarget.
|
---|
| 193 | *
|
---|
| 194 | * @param dragDropOn Indicates whether or not the drag/drop events should
|
---|
| 195 | * be enabled.
|
---|
| 196 | */
|
---|
| 197 | void setDragDrop(bool dragDropOn);
|
---|
| 198 |
|
---|
| 199 | /**
|
---|
| 200 | * Returns the X screen coordinate of the current mouse position.
|
---|
| 201 | */
|
---|
| 202 | inline Real getMouseX() const { return mMouseX; }
|
---|
| 203 | /**
|
---|
| 204 | * Returns the Y screen coordinate of the current mouse position.
|
---|
| 205 | */
|
---|
| 206 | inline Real getMouseY() const { return mMouseY; }
|
---|
| 207 | };
|
---|
| 208 |
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | #endif
|
---|