From ea071d3f1e456cab3d289a60114d241d3587f219 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 13 Apr 2007 14:54:41 +0000 Subject: [PATCH] Added fullscreen toggle event handler --- applications/osgviewer/osgviewer.cpp | 103 +++++++++++++++++++++------ 1 file changed, 83 insertions(+), 20 deletions(-) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 0d737f8ca..bcd2dd750 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -47,25 +47,6 @@ public: { if (ea.getKey()=='m') { -#if 0 - switch(viewer->getThreadingModel()) - { - case(osgViewer::Viewer::SingleThreaded): - viewer->setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); - osg::notify(osg::NOTICE)<<"Threading model 'CullDrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); - osg::notify(osg::NOTICE)<<"Threading model 'DrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::SingleThreaded); - osg::notify(osg::NOTICE)<<"Threading model 'SingleThreaded' selected."<getThreadingModel()) { case(osgViewer::Viewer::SingleThreaded): @@ -89,7 +70,6 @@ public: osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<(&aa); + if (!viewer) return false; + + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::KEYUP): + { + if (ea.getKey()=='f') + { + osgViewer::Viewer::Windows windows; + viewer->getWindows(windows); + + for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); + itr != windows.end(); + ++itr) + { + toggleFullscreen(*itr); + } + } + } + default: break; + } + + return false; + } + + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const + { + usage.addKeyboardMouseBinding("f","Toggle full screen."); + } + + + void toggleFullscreen(osgViewer::GraphicsWindow* window) + { + + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) + { + osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot toggle window fullscreen."<getScreenResolution(*(window->getTraits()), screen_width, screen_height); + + int x, y, width, height; + window->getWindowRectangle(x, y, width, height); + + bool isFullScreen = x==0 && y==0 && width==screen_width && height==screen_height; + if (isFullScreen) + { + window->setWindowRectangle(screen_width/4, screen_height/4, screen_width/2, screen_height/2); + window->setWindowDecoration(true); + } + else + { + window->setWindowDecoration(false); + window->setWindowRectangle(0, 0, screen_width, screen_height); + } + + window->grabFocusIfPointerInWindow(); + + return; + + } + + + + bool _done; +}; + int main(int argc, char** argv) { // use an ArgumentParser object to manage the program arguments. @@ -204,6 +264,9 @@ int main(int argc, char** argv) // add the thread model handler viewer.addEventHandler(new ThreadingHandler); + // add the full screen toggle handler + viewer.addEventHandler(new FullScreenToggleHandler); + // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler);