Added sendPointerEvent and sendKeyEvent virtual methods to osg::Image to

facilitate the subclassing of Image providing interactive behaviours so as
used in the vnc interactive VncImage class.

osgViewer::InteractiveImageHandler provides an event handler that convertes osgGA 
mouse and keyboard events into the coordinate frame of an image based on ray intersection with geometry in
the associated subgraph.

Changed the ordering of events processing in Viewer and CompositeViewer to allow
scene graph event handlers to take precidence over viewer event handlers and camera manipulators
This commit is contained in:
Robert Osfield
2008-11-03 15:08:04 +00:00
parent 545a5d02c7
commit 70e1c60819
5 changed files with 199 additions and 47 deletions

View File

@@ -309,6 +309,14 @@ class OSG_EXPORT Image : public Object
virtual void update(NodeVisitor* nv) {}
/** method for sending pointer events to images that are acting as front ends to interactive surfaces such as a vnc or browser window.*/
virtual void sendPointerEvent(int x, int y, int buttonMask) {};
/** method for sending key events to images that are acting as front ends to interactive surfaces such as a vnc or browser window.*/
virtual void sendKeyEvent(int key, bool keyDown) {};
protected :
virtual ~Image();

View File

@@ -362,6 +362,28 @@ class OSGVIEWER_EXPORT ScreenCaptureHandler : public osgGA::GUIEventHandler
void addCallbackToViewer(osgViewer::ViewerBase& viewer);
};
/** InteractiveImage is an event handler that computes the mouse coordinates in an images coordinate frame
* and then passes keyboard and mouse events to it. This event handler is useful for vnc or browser
* surfaces in the 3D scene.*/
class OSGVIEWER_EXPORT InteractiveImageHandler : public osgGA::GUIEventHandler
{
public:
InteractiveImageHandler(osg::Image* image):
_image(image) {}
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv);
protected:
virtual ~InteractiveImageHandler() {}
bool mousePosition(osgViewer::View* view, osg::NodeVisitor* nv, const osgGA::GUIEventAdapter& ea, int& x, int &y) const;
osg::observer_ptr<osg::Image> _image;
};
}
#endif