| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGGA_GUIACTIONADAPTER |
|---|
| 15 | #define OSGGA_GUIACTIONADAPTER 1 |
|---|
| 16 | |
|---|
| 17 | #include <osgGA/Export> |
|---|
| 18 | #include <osg/View> |
|---|
| 19 | |
|---|
| 20 | namespace osgGA{ |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | Abstract base class defining the interface by which GUIEventHandlers may request |
|---|
| 24 | actions of the GUI system in use. These requests for actions should then be honored |
|---|
| 25 | by the GUI toolkit of the user's application. |
|---|
| 26 | |
|---|
| 27 | To provide more detail, when a GUIEventHandler (e.g. a TrackballManipulator) |
|---|
| 28 | handles an incoming event, such as a mouse event, it may wish to make |
|---|
| 29 | a request of the GUI. E.g. if a model is 'thrown', the trackball manipulator |
|---|
| 30 | may wish to start a timer, and be repeatedly called, to continuously refresh the |
|---|
| 31 | camera's position and orientation. However, it has no way of doing this, as it |
|---|
| 32 | knows nothing of the window system in which it's operating. Instead, the |
|---|
| 33 | GUIEventHandler issues it's request via a GUIActionAdapter, and the viewer |
|---|
| 34 | in use should honour the request, using the GUI system in play. |
|---|
| 35 | |
|---|
| 36 | There is more than one way of using the GUIActionAdapter. E.g. it may be inherited |
|---|
| 37 | into a Viewer class, as is done with osgGLUT::Viewer. Alternatively, a simple |
|---|
| 38 | subclass of GUIActionAdapter (e.g. osgQt::QtActionAdapter) may be passed to |
|---|
| 39 | the GUIEventHandler::handle() function; once the function has returned, the viewer |
|---|
| 40 | will then unpack the results and work out what to do to respond to the |
|---|
| 41 | requests. |
|---|
| 42 | |
|---|
| 43 | Also there are several ways to run your app and handle the updating of |
|---|
| 44 | the window. osgGLUT::Viewer always has a idle callback registered which does a |
|---|
| 45 | redraw all the time. osgGLUT::Viewer can safely ignore both requestRedraw() and |
|---|
| 46 | requestContinousUpdate() as these are happening all the time anyway. |
|---|
| 47 | |
|---|
| 48 | Other apps will probably want to respond to the requestRedraw() and |
|---|
| 49 | requestContinousUpdate(bool) and again there is more than one way to handle it. |
|---|
| 50 | You can override requestRedraw() and implement to call your own window |
|---|
| 51 | redraw straight away. Or you can implement so that a flag is set and |
|---|
| 52 | then you then respond the flag being set in your own leisure. |
|---|
| 53 | |
|---|
| 54 | */ |
|---|
| 55 | class GUIActionAdapter |
|---|
| 56 | { |
|---|
| 57 | public: |
|---|
| 58 | virtual ~GUIActionAdapter() {} |
|---|
| 59 | |
|---|
| 60 | /** Provide a mechanism for getting the osg::View associated with this GUIActionAdapter. |
|---|
| 61 | * One would use this to case view to osgViewer::View(er) if supported by the subclass.*/ |
|---|
| 62 | virtual osg::View* asView() { return 0; } |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | requestRedraw() requests a single redraw. |
|---|
| 66 | */ |
|---|
| 67 | virtual void requestRedraw() = 0; |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | requestContinousUpdate(bool) is for en/disabling a throw or idle |
|---|
| 71 | callback to be requested by a GUIEventHandler (typically a MatrixManipulator, |
|---|
| 72 | though other GUIEventHandler's may also provide functionality). |
|---|
| 73 | GUI toolkits can respond to this immediately by registering an idle/timed |
|---|
| 74 | callback, or can delay setting the callback and update at their own leisure. |
|---|
| 75 | */ |
|---|
| 76 | virtual void requestContinuousUpdate(bool needed=true) = 0; |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | requestWarpPointer(int,int) is requesting a repositioning of the mouse pointer |
|---|
| 80 | to a specified x,y location on the window. This is used by some camera manipulators |
|---|
| 81 | to initialise the mouse pointer when mouse position relative to a controls |
|---|
| 82 | neutral mouse position is required, i.e when mimicking a aircrafts joystick. |
|---|
| 83 | */ |
|---|
| 84 | virtual void requestWarpPointer(float x,float y) = 0; |
|---|
| 85 | |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | #endif |
|---|
| 91 | |
|---|