Addd a full screen toggle event handler to osgProducer & its viewer base
class.
This commit is contained in:
@@ -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
|
||||
|
||||
42
include/osgProducer/FullScreenEventHandler
Normal file
42
include/osgProducer/FullScreenEventHandler
Normal file
@@ -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 <osgGA/GUIEventHandler>
|
||||
#include <osgProducer/Viewer>
|
||||
|
||||
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
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
44
src/osgProducer/FullScreenEventHandler.cpp
Normal file
44
src/osgProducer/FullScreenEventHandler.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <osgProducer/FullScreenEventHandler>
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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<EventAdapter> event = new EventAdapter;
|
||||
event->adaptKeyPress(getTime(),key);
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <osgProducer/Viewer>
|
||||
#include <osgProducer/FrameStatsHandler>
|
||||
#include <osgProducer/StatsEventHandler>
|
||||
#include <osgProducer/FullScreenEventHandler>
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user