From 426e301c4815b776f5b53bffb02c539842cc5636 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 19 Mar 2003 14:27:05 +0000 Subject: [PATCH] Addd a full screen toggle event handler to osgProducer & its viewer base class. --- VisualStudio/osgProducer/osgProducer.dsp | 8 ++++ include/osgProducer/FullScreenEventHandler | 42 +++++++++++++++++++++ include/osgProducer/KeyboardMouseCallback | 6 ++- include/osgProducer/Viewer | 7 +++- src/osgProducer/FullScreenEventHandler.cpp | 44 ++++++++++++++++++++++ src/osgProducer/GNUmakefile | 1 + src/osgProducer/KeyboardMouseCallback.cpp | 32 ++++++++-------- src/osgProducer/OsgCameraGroup.cpp | 4 +- src/osgProducer/Viewer.cpp | 9 ++++- 9 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 include/osgProducer/FullScreenEventHandler create mode 100644 src/osgProducer/FullScreenEventHandler.cpp diff --git a/VisualStudio/osgProducer/osgProducer.dsp b/VisualStudio/osgProducer/osgProducer.dsp index 815683b85..a3a7ea1cf 100755 --- a/VisualStudio/osgProducer/osgProducer.dsp +++ b/VisualStudio/osgProducer/osgProducer.dsp @@ -117,6 +117,10 @@ SOURCE=..\..\src\osgProducer\StatsEventHandler.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osgProducer\FullScreenEventHandler.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osgProducer\KeyboardMouseCallback.cpp # End Source File # End Group @@ -157,6 +161,10 @@ SOURCE=..\..\Include\osgProducer\StatsEventHandler # End Source File # Begin Source File +SOURCE=..\..\Include\osgProducer\FullScreenEventHandler +# End Source File +# Begin Source File + SOURCE=..\..\Include\osgProducer\EventAdapter # End Source File # End Group diff --git a/include/osgProducer/FullScreenEventHandler b/include/osgProducer/FullScreenEventHandler new file mode 100644 index 000000000..1e8595676 --- /dev/null +++ b/include/osgProducer/FullScreenEventHandler @@ -0,0 +1,42 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGPRODUCER_FULLSCREENEVENTHANDLER +#define OSGPRODUCER_FULLSCREENEVENTHANDLER 1 + +#include +#include + +namespace osgProducer { + +class FullScreenEventHandler : public osgGA::GUIEventHandler +{ + public: + + FullScreenEventHandler(osgProducer::Viewer* cg):_cg(cg) {} + + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); + + virtual void accept(osgGA::GUIEventHandlerVisitor& gehv); + + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + + protected: + + osgProducer::Viewer* _cg; +}; + +} + +#endif diff --git a/include/osgProducer/KeyboardMouseCallback b/include/osgProducer/KeyboardMouseCallback index 0d2653076..23d7f3ea4 100644 --- a/include/osgProducer/KeyboardMouseCallback +++ b/include/osgProducer/KeyboardMouseCallback @@ -30,10 +30,11 @@ namespace osgProducer { class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseCallback { public: - KeyboardMouseCallback(bool &done) : + KeyboardMouseCallback(bool &done, bool escapeKeySetsDone=true) : Producer::KeyboardMouseCallback(), _mx(0.0f),_my(0.0f),_mbutton(0), - _done(done) + _done(done), + _escapeKeySetsDone(escapeKeySetsDone) {} virtual ~KeyboardMouseCallback() {} @@ -68,6 +69,7 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC float _mx, _my; unsigned int _mbutton; bool &_done; + bool _escapeKeySetsDone; osg::Timer_t _startTick; osg::Timer _timer; diff --git a/include/osgProducer/Viewer b/include/osgProducer/Viewer index ac8266785..bd289e0cd 100644 --- a/include/osgProducer/Viewer +++ b/include/osgProducer/Viewer @@ -47,6 +47,7 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction enum ViewerOptions { + NO_EVENT_HANDLERS = 0, TRACKBALL_MANIPULATOR = 1, DRIVE_MANIPULATOR = 2, FLIGHT_MANIPULATOR = 4, @@ -54,12 +55,16 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction HEAD_LIGHT_SOURCE = 16, SKY_LIGHT_SOURCE = 32, STATS_MANIPULATOR = 64, + FULLSCREEN_MANIPULATOR = 128, + ESCAPE_SETS_DONE = 256, STANDARD_SETTINGS = TRACKBALL_MANIPULATOR| DRIVE_MANIPULATOR | FLIGHT_MANIPULATOR | STATE_MANIPULATOR | HEAD_LIGHT_SOURCE | - STATS_MANIPULATOR + STATS_MANIPULATOR | + FULLSCREEN_MANIPULATOR | + ESCAPE_SETS_DONE }; void setUpViewer(unsigned int options=STANDARD_SETTINGS); diff --git a/src/osgProducer/FullScreenEventHandler.cpp b/src/osgProducer/FullScreenEventHandler.cpp new file mode 100644 index 000000000..3c2102ca1 --- /dev/null +++ b/src/osgProducer/FullScreenEventHandler.cpp @@ -0,0 +1,44 @@ +#include + +using namespace osgProducer; + +bool FullScreenEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) +{ + if(!_cg) return false; + + if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN) + { + + switch( ea.getKey() ) + { + case 'f' : + { + Producer::CameraConfig* cfg = _cg->getCameraConfig(); + for( unsigned int i = 0; i < cfg->getNumberOfCameras(); ++i ) + { + Producer::Camera *cam = cfg->getCamera(i); + Producer::RenderSurface* rs = cam->getRenderSurface(); + rs->fullScreen(!rs->isFullScreen()); + } + + return true; + } + + default: + break; + + } + } + return false; + +} + +void FullScreenEventHandler::accept(osgGA::GUIEventHandlerVisitor& gehv) +{ + gehv.visit(*this); +} + +void FullScreenEventHandler::getUsage(osg::ApplicationUsage& usage) const +{ + usage.addKeyboardMouseBinding("f","Toggle fullscreen"); +} diff --git a/src/osgProducer/GNUmakefile b/src/osgProducer/GNUmakefile index 7b31c631a..5fdfee1df 100644 --- a/src/osgProducer/GNUmakefile +++ b/src/osgProducer/GNUmakefile @@ -7,6 +7,7 @@ CXXFILES =\ OsgCameraGroup.cpp\ OsgSceneHandler.cpp\ StatsEventHandler.cpp\ + FullScreenEventHandler.cpp\ Viewer.cpp\ LIBS += -lProducer $(GL_LIBS) -losgGA -losgUtil -losgDB -losg $(OTHER_LIBS) diff --git a/src/osgProducer/KeyboardMouseCallback.cpp b/src/osgProducer/KeyboardMouseCallback.cpp index 3ed89537e..7b8102dbd 100644 --- a/src/osgProducer/KeyboardMouseCallback.cpp +++ b/src/osgProducer/KeyboardMouseCallback.cpp @@ -12,25 +12,23 @@ using namespace osgProducer; void KeyboardMouseCallback::keyPress( Producer::KeySymbol key ) { - switch( key ) + if (_escapeKeySetsDone) { -#ifdef XK_MISCELLANY // XWindows keydefs - case XK_Escape: - _done = true; - break; -#endif -#ifdef WIN32 - case VK_ESCAPE: - _done = true; - break; -#endif + switch( key ) + { + #ifdef XK_MISCELLANY // XWindows keydefs + case XK_Escape: + _done = true; + break; + #endif + #ifdef WIN32 + case VK_ESCAPE: + _done = true; + break; + #endif + } } - - if (_done) - { - // need to contact the viewer so pass on the abort.. - } - + osg::ref_ptr event = new EventAdapter; event->adaptKeyPress(getTime(),key); diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index 51de8fb7b..b3bf2a3ef 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -30,7 +30,7 @@ public: _cameraGroup(cameraGroup), _sceneHandler(sceneHandler) {} - virtual void operator()( const RenderSurface & rs) + virtual void operator()( const Producer::RenderSurface & rs) { if (_cameraGroup) { @@ -232,7 +232,7 @@ void OsgCameraGroup::realize( ThreadingModel thread_model) sh->setDefaults(); _shvec.push_back( sh ); cam->setSceneHandler( sh ); - RenderSurface* rs = cam->getRenderSurface(); + Producer::RenderSurface* rs = cam->getRenderSurface(); rs->setRealizeCallback( new RenderSurfaceRealizeCallback(this, sh)); } diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index a1584eea0..2f8dc3ce0 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -14,6 +14,7 @@ #include #include #include +#include using namespace osgProducer; @@ -83,7 +84,7 @@ void Viewer::setUpViewer(unsigned int options) _start_tick = _timer.tick(); // set the keyboard mouse callback to catch the events from the windows. - _kbmcb = new osgProducer::KeyboardMouseCallback(_done); + _kbmcb = new osgProducer::KeyboardMouseCallback( _done, (options & ESCAPE_SETS_DONE)!=0 ); _kbmcb->setStartTick(_start_tick); // register the callback with the keyboard mouse manger. @@ -153,6 +154,12 @@ void Viewer::setUpViewer(unsigned int options) } + + if (options&FULLSCREEN_MANIPULATOR) + { + getEventHandlerList().push_back(new FullScreenEventHandler(this)); + } + } unsigned int Viewer::addCameraManipulator(osgGA::CameraManipulator* cm)