From Daneil Sjölie - modifications to the support of custom GUIEventHandlers in osgGLUT
This commit is contained in:
parent
70861ef70e
commit
65934ef824
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <osgGLUT/Window>
|
#include <osgGLUT/Window>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace osgGLUT
|
namespace osgGLUT
|
||||||
@ -82,13 +83,17 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
|
|||||||
void selectCameraManipulator(unsigned int pos,
|
void selectCameraManipulator(unsigned int pos,
|
||||||
unsigned int viewport = 0);
|
unsigned int viewport = 0);
|
||||||
|
|
||||||
void addEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0);
|
void prependEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0);
|
||||||
|
void appendEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0);
|
||||||
|
|
||||||
// derived from osgGA::GUIActionAdapter
|
// derived from osgGA::GUIActionAdapter
|
||||||
virtual void requestRedraw() {} // redraw always by idle callback done.
|
virtual void requestRedraw() {} // redraw always by idle callback done.
|
||||||
virtual void requestContinuousUpdate(bool /*needed*/) {} // continuous update always
|
virtual void requestContinuousUpdate(bool /*needed*/) {} // continuous update always
|
||||||
virtual void requestWarpPointer(int x,int y);
|
virtual void requestWarpPointer(int x,int y);
|
||||||
|
virtual void requestShutdown() { exit(1); };
|
||||||
|
|
||||||
|
/// Toggle fullscreen
|
||||||
|
virtual void toggleFullScreen();
|
||||||
/** read the command line string list, removing any matched control sequences.*/
|
/** read the command line string list, removing any matched control sequences.*/
|
||||||
void readCommandLine(std::vector<std::string>& commandLine);
|
void readCommandLine(std::vector<std::string>& commandLine);
|
||||||
|
|
||||||
@ -97,7 +102,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
|
|||||||
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
|
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
|
||||||
|
|
||||||
typedef std::vector<osg::ref_ptr<osgGA::CameraManipulator> > CameraManipList;
|
typedef std::vector<osg::ref_ptr<osgGA::CameraManipulator> > CameraManipList;
|
||||||
typedef std::vector<osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;
|
typedef std::list<osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -111,7 +116,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
|
|||||||
virtual void keyboard(unsigned char key, int x, int y);
|
virtual void keyboard(unsigned char key, int x, int y);
|
||||||
|
|
||||||
void setFocusedViewport(unsigned int pos);
|
void setFocusedViewport(unsigned int pos);
|
||||||
int mapWindowXYToSceneView(int x, int y);
|
int mapWindowXYToViewport(int x, int y);
|
||||||
|
|
||||||
void showStats(unsigned int i); // gwm 24.09.01 pass the viewport to collect sta for each viewport
|
void showStats(unsigned int i); // gwm 24.09.01 pass the viewport to collect sta for each viewport
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ int main( int argc, char **argv )
|
|||||||
|
|
||||||
if (manuallyCreateImpostors)
|
if (manuallyCreateImpostors)
|
||||||
{
|
{
|
||||||
viewer.addEventHandler(new OccluderEventHandler(viewer.getViewportSceneView(0),rootnode));
|
viewer.prependEventHandler(new OccluderEventHandler(viewer.getViewportSceneView(0),rootnode));
|
||||||
}
|
}
|
||||||
|
|
||||||
// open the viewer window.
|
// open the viewer window.
|
||||||
|
@ -187,7 +187,7 @@ int main( int argc, char **argv )
|
|||||||
viewer.addViewport(rootNode);
|
viewer.addViewport(rootNode);
|
||||||
|
|
||||||
// register additional event handler
|
// register additional event handler
|
||||||
viewer.addEventHandler(osgNew MyEventHandler(&seq), 0);
|
viewer.prependEventHandler(osgNew MyEventHandler(&seq), 0);
|
||||||
|
|
||||||
// register trackball, flight and drive.
|
// register trackball, flight and drive.
|
||||||
viewer.registerCameraManipulator(new osgGA::TrackballManipulator);
|
viewer.registerCameraManipulator(new osgGA::TrackballManipulator);
|
||||||
|
@ -173,6 +173,22 @@ void Viewer::readCommandLine(std::vector<std::string>& commandLine)
|
|||||||
_displaySettings->readCommandLine(commandLine);
|
_displaySettings->readCommandLine(commandLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Viewer::toggleFullScreen()
|
||||||
|
{
|
||||||
|
_fullscreen = !_fullscreen;
|
||||||
|
if (_fullscreen)
|
||||||
|
{
|
||||||
|
_saved_ww = _ww;
|
||||||
|
_saved_wh = _wh;
|
||||||
|
glutFullScreen();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
//glutPositionWindow(wx,wy);
|
||||||
|
glutReshapeWindow(_saved_ww,_saved_wh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure and open the GLUT window for this Viewer
|
* Configure and open the GLUT window for this Viewer
|
||||||
*
|
*
|
||||||
@ -317,7 +333,13 @@ unsigned int Viewer::registerCameraManipulator(osgGA::CameraManipulator* cm,
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::addEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport)
|
void Viewer::prependEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport)
|
||||||
|
{
|
||||||
|
ViewportDef &viewp = _viewportList[viewport];
|
||||||
|
viewp._eventHandlerList.push_front( handler );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Viewer::appendEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport)
|
||||||
{
|
{
|
||||||
ViewportDef &viewp = _viewportList[viewport];
|
ViewportDef &viewp = _viewportList[viewport];
|
||||||
viewp._eventHandlerList.push_back( handler );
|
viewp._eventHandlerList.push_back( handler );
|
||||||
@ -376,6 +398,7 @@ float Viewer::app(unsigned int viewport)
|
|||||||
if ( eh->valid() ) {
|
if ( eh->valid() ) {
|
||||||
if ( (*eh)->handle(*ea,*this) ) {
|
if ( (*eh)->handle(*ea,*this) ) {
|
||||||
handled = true;
|
handled = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -421,7 +444,7 @@ float Viewer::draw(unsigned int viewport)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Viewer::mapWindowXYToSceneView(int x, int y)
|
int Viewer::mapWindowXYToViewport(int x, int y)
|
||||||
{
|
{
|
||||||
int ogl_y = _wh-y;
|
int ogl_y = _wh-y;
|
||||||
|
|
||||||
@ -775,6 +798,7 @@ void Viewer::mouseMotion(int x, int y)
|
|||||||
if ( eh->valid() ) {
|
if ( eh->valid() ) {
|
||||||
if ( (*eh)->handle(*ea,*this) ) {
|
if ( (*eh)->handle(*ea,*this) ) {
|
||||||
handled = true;
|
handled = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -799,7 +823,7 @@ void Viewer::mousePassiveMotion(int x, int y)
|
|||||||
// Switch viewport focus if no buttons are pressed
|
// Switch viewport focus if no buttons are pressed
|
||||||
if (ea->getButtonMask() == 0)
|
if (ea->getButtonMask() == 0)
|
||||||
{
|
{
|
||||||
int focus = mapWindowXYToSceneView(x,y);
|
int focus = mapWindowXYToViewport(x,y);
|
||||||
if (focus >= 0 && focus != int(_focusedViewport))
|
if (focus >= 0 && focus != int(_focusedViewport))
|
||||||
setFocusedViewport(focus);
|
setFocusedViewport(focus);
|
||||||
}
|
}
|
||||||
@ -812,6 +836,7 @@ void Viewer::mousePassiveMotion(int x, int y)
|
|||||||
if ( eh->valid() ) {
|
if ( eh->valid() ) {
|
||||||
if ( (*eh)->handle(*ea,*this) ) {
|
if ( (*eh)->handle(*ea,*this) ) {
|
||||||
handled = true;
|
handled = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -836,7 +861,7 @@ void Viewer::mouse(int button, int state, int x, int y)
|
|||||||
mask == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
|
mask == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
|
||||||
mask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON))
|
mask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON))
|
||||||
{
|
{
|
||||||
int focus = mapWindowXYToSceneView(x,y);
|
int focus = mapWindowXYToViewport(x,y);
|
||||||
if (focus >= 0 && focus != int(_focusedViewport))
|
if (focus >= 0 && focus != int(_focusedViewport))
|
||||||
setFocusedViewport(focus);
|
setFocusedViewport(focus);
|
||||||
}
|
}
|
||||||
@ -849,6 +874,7 @@ void Viewer::mouse(int button, int state, int x, int y)
|
|||||||
if ( eh->valid() ) {
|
if ( eh->valid() ) {
|
||||||
if ( (*eh)->handle(*ea,*this) ) {
|
if ( (*eh)->handle(*ea,*this) ) {
|
||||||
handled = true;
|
handled = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -868,7 +894,6 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
|||||||
osg::ref_ptr<GLUTEventAdapter> ea = osgNew GLUTEventAdapter;
|
osg::ref_ptr<GLUTEventAdapter> ea = osgNew GLUTEventAdapter;
|
||||||
ea->adaptKeyboard(clockSeconds(),key,x,y);
|
ea->adaptKeyboard(clockSeconds(),key,x,y);
|
||||||
|
|
||||||
bool handled = false;
|
|
||||||
for ( EventHandlerList::iterator eh =
|
for ( EventHandlerList::iterator eh =
|
||||||
_viewportList[_focusedViewport]._eventHandlerList.begin();
|
_viewportList[_focusedViewport]._eventHandlerList.begin();
|
||||||
eh != _viewportList[_focusedViewport]._eventHandlerList.end();
|
eh != _viewportList[_focusedViewport]._eventHandlerList.end();
|
||||||
@ -879,11 +904,9 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !handled ) {
|
if ( _viewportList[_focusedViewport]._cameraManipulator->handle(
|
||||||
if ( _viewportList[_focusedViewport]._cameraManipulator->handle(
|
*ea,*this) ) {
|
||||||
*ea,*this) ) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key>='1' && key<='3')
|
if (key>='1' && key<='3')
|
||||||
@ -1104,17 +1127,7 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f' :
|
case 'f' :
|
||||||
_fullscreen = !_fullscreen;
|
toggleFullScreen();
|
||||||
if (_fullscreen)
|
|
||||||
{
|
|
||||||
_saved_ww = _ww;
|
|
||||||
_saved_wh = _wh;
|
|
||||||
glutFullScreen();
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
//glutPositionWindow(wx,wy);
|
|
||||||
glutReshapeWindow(_saved_ww,_saved_wh);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o' :
|
case 'o' :
|
||||||
|
Loading…
Reference in New Issue
Block a user