From c45f3aa4fb8728474a407c50e6a5c9c9a64d0625 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 22 Oct 2013 19:12:34 +0000 Subject: [PATCH] Merged changes to DisplaySettings from Stephan Huber in prep for controlling the menu hiding behaviour under OSX. Added new WindowSystemInterface::setDisplaySettings() method to provide a mechanism for passing settings onto the WindowSystemInterface so it can then set up the system appropriately. Added assignment of the DisplaySettings to the WindowSystemInterface in Viewer/ComppsiteViewer::realize(). --- include/osg/DisplaySettings | 24 ++++++++++++++------- include/osg/GraphicsContext | 5 +++++ src/osg/DisplaySettings.cpp | 35 +++++++++++++++++++++++++++++++ src/osgViewer/CompositeViewer.cpp | 11 ++++++++-- src/osgViewer/Viewer.cpp | 14 +++++++------ 5 files changed, 74 insertions(+), 15 deletions(-) diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index d7688d2f3..c0746cb62 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -283,21 +283,29 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced /** Get the hint of the profile mask to use in when creating graphic contexts.*/ unsigned int getGLContextProfileMask() const { return _glContextProfileMask; } - - + + void setKeystoneHint(bool enabled) { _keystoneHint = enabled; } bool getKeystoneHint() const { return _keystoneHint; } - + typedef std::vector FileNames; void setKeystoneFileNames(const FileNames& filenames) { _keystoneFileNames = filenames; } FileNames& getKeystoneFileNames() { return _keystoneFileNames; } const FileNames& getKeystoneFileNames() const { return _keystoneFileNames; } - + typedef std::vector< osg::ref_ptr > Objects; void setKeystones(const Objects& objects) { _keystones = objects; } Objects& getKeystones() { return _keystones; } const Objects& getKeystones() const { return _keystones; } + enum OSXMenubarBehavior { + MENUBAR_AUTO_HIDE, + MENUBAR_FORCE_HIDE, + MENUBAR_FORCE_SHOW + }; + + OSXMenubarBehavior getOSXMenubarBehavior() const { return _OSXMenubarBehavior; } + void setOSXMenubarBehavior(OSXMenubarBehavior hint) { _OSXMenubarBehavior = hint; } /** helper function for computing the left eye projection matrix.*/ virtual osg::Matrixd computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const; @@ -365,11 +373,13 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced SwapMethod _swapMethod; - + bool _keystoneHint; FileNames _keystoneFileNames; - Objects _keystones; - + Objects _keystones; + + OSXMenubarBehavior _OSXMenubarBehavior; + }; } diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index cd30b2f40..625165f42 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -176,6 +176,10 @@ class OSG_EXPORT GraphicsContext : public Object virtual void enumerateScreenSettings(const ScreenIdentifier& screenIdentifier, ScreenSettingsList & resolutionList) = 0; + virtual void setDisplaySettings(DisplaySettings*) {} + + virtual osg::DisplaySettings* getDisplaySettings() const { return 0; } + virtual GraphicsContext* createGraphicsContext(Traits* traits) = 0; virtual ~WindowingSystemInterface() {} @@ -206,6 +210,7 @@ class OSG_EXPORT GraphicsContext : public Object settings.refreshRate = refreshRate; return setScreenSettings(screenIdentifier, settings); } + }; diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 81050e4f8..d4a227d06 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -100,6 +100,8 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs) _keystoneHint = vs._keystoneHint; _keystoneFileNames = vs._keystoneFileNames; _keystones = vs._keystones; + + _OSXMenubarBehavior = vs._OSXMenubarBehavior; } void DisplaySettings::merge(const DisplaySettings& vs) @@ -157,6 +159,9 @@ void DisplaySettings::merge(const DisplaySettings& vs) Objects::iterator found_itr = std::find(_keystones.begin(), _keystones.end(), object); if (found_itr == _keystones.end()) _keystones.push_back(const_cast(object)); } + + if (vs._OSXMenubarBehavior > _OSXMenubarBehavior) + _OSXMenubarBehavior = vs._OSXMenubarBehavior; } void DisplaySettings::setDefaults() @@ -215,6 +220,8 @@ void DisplaySettings::setDefaults() _swapMethod = SWAP_DEFAULT; _keystoneHint = false; + + _OSXMenubarBehavior = MENUBAR_AUTO_HIDE; } void DisplaySettings::setMaxNumberOfGraphicsContexts(unsigned int num) @@ -327,6 +334,9 @@ static ApplicationUsageProxy DisplaySetting_e29(ApplicationUsage::ENVIRONMENTAL_ "OSG_KEYSTONE_FILES [:filename]..", "Specify filenames of keystone parameter files. Under Windows use ; to deliminate files, otherwise use :"); +static ApplicationUsageProxy DisplaySetting_e30(ApplicationUsage::ENVIRONMENTAL_VARIABLE, + "OSG_MENUBAR_BEHAVIOR ", + "OSX Only : Specify the behavior of the menubar (AUTO_HIDE, FORCE_HIDE, FORCE_SHOW)"); void DisplaySettings::readEnvironmentalVariables() { @@ -658,6 +668,24 @@ void DisplaySettings::readEnvironmentalVariables() _keystoneFileNames.push_back(lastPath); } } + + if( (ptr = getenv("OSG_MENUBAR_BEHAVIOR")) != 0) + { + if (strcmp(ptr,"AUTO_HIDE")==0) + { + _OSXMenubarBehavior = MENUBAR_AUTO_HIDE; + } + else + if (strcmp(ptr,"FORCE_HIDE")==0) + { + _OSXMenubarBehavior = MENUBAR_FORCE_HIDE; + } + else + if (strcmp(ptr,"FORCE_SHOW")==0) + { + _OSXMenubarBehavior = MENUBAR_FORCE_SHOW; + } + } } void DisplaySettings::readCommandLine(ArgumentParser& arguments) @@ -686,6 +714,7 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments) arguments.getApplicationUsage()->addCommandLineOption("--keystone ","Specify a keystone file to be used by the viewer for keystone correction."); arguments.getApplicationUsage()->addCommandLineOption("--keystone-on","Set the keystone hint to true to tell the viewer to do keystone correction."); arguments.getApplicationUsage()->addCommandLineOption("--keystone-off","Set the keystone hint to false."); + arguments.getApplicationUsage()->addCommandLineOption("--menubar-behavior ","Set the menubar behavior (AUTO_HIDE | FORCE_HIDE | FORCE_SHOW)"); } std::string str; @@ -824,6 +853,12 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments) else if (str=="UNDEFINED") _swapMethod = SWAP_UNDEFINED; } + while(arguments.read("--menubar-behavior",str)) + { + if (str=="AUTO_HIDE") _OSXMenubarBehavior = MENUBAR_AUTO_HIDE; + else if (str=="FORCE_HIDE") _OSXMenubarBehavior = MENUBAR_FORCE_HIDE; + else if (str=="FORCE_SHOW") _OSXMenubarBehavior = MENUBAR_FORCE_SHOW; + } } diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index 10645ed24..b43b625a6 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -585,8 +585,15 @@ void CompositeViewer::realize() return; } - unsigned int maxTexturePoolSize = osg::DisplaySettings::instance()->getMaxTexturePoolSize(); - unsigned int maxBufferObjectPoolSize = osg::DisplaySettings::instance()->getMaxBufferObjectPoolSize(); + // get the display settings that will be active for this viewer + osg::DisplaySettings* ds = osg::DisplaySettings::instance().get(); + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + + // pass on the display settings to the WindowSystemInterface. + if (wsi && wsi->getDisplaySettings()==0) wsi->setDisplaySettings(ds); + + unsigned int maxTexturePoolSize = ds->getMaxTexturePoolSize(); + unsigned int maxBufferObjectPoolSize = ds->getMaxBufferObjectPoolSize(); for(Contexts::iterator citr = contexts.begin(); citr != contexts.end(); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 9ed6e1342..948993bec 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -520,13 +520,15 @@ void Viewer::realize() return; } - unsigned int maxTexturePoolSize = osg::DisplaySettings::instance()->getMaxTexturePoolSize(); - if (_camera->getDisplaySettings()) maxTexturePoolSize = std::max(maxTexturePoolSize, _camera->getDisplaySettings()->getMaxTexturePoolSize()); - if (_displaySettings.valid()) maxTexturePoolSize = std::max(maxTexturePoolSize, _displaySettings->getMaxTexturePoolSize()); + // get the display settings that will be active for this viewer + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - unsigned int maxBufferObjectPoolSize = osg::DisplaySettings::instance()->getMaxBufferObjectPoolSize(); - if (_displaySettings.valid()) maxBufferObjectPoolSize = std::max(maxBufferObjectPoolSize, _displaySettings->getMaxBufferObjectPoolSize()); - if (_camera->getDisplaySettings()) maxBufferObjectPoolSize = std::max(maxBufferObjectPoolSize, _camera->getDisplaySettings()->getMaxBufferObjectPoolSize()); + // pass on the display settings to the WindowSystemInterface. + if (wsi && wsi->getDisplaySettings()==0) wsi->setDisplaySettings(ds); + + unsigned int maxTexturePoolSize = ds->getMaxTexturePoolSize(); + unsigned int maxBufferObjectPoolSize = ds->getMaxBufferObjectPoolSize(); for(Contexts::iterator citr = contexts.begin(); citr != contexts.end();