From 00845b17b970a9bb27460bc53f31566f904586cb Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 11 May 2017 08:39:48 +0100 Subject: [PATCH] Prevent PUI menubar obscuring startup tips Add an additional visibility flag to the menubar implementations, conditional on whether or not the menubar overlaps the window content. (I.e for PUI but not Cocoa). This flag is linked to a new property /sim/menubar/overlap-hide, which the renderer drives off the splash- screen visibility. --- src/GUI/FGCocoaMenuBar.hxx | 8 ++++++++ src/GUI/FGCocoaMenuBar.mm | 12 ++++++++++++ src/GUI/FGPUIMenuBar.cxx | 32 ++++++++++++++++++++++++++++---- src/GUI/FGPUIMenuBar.hxx | 8 +++++++- src/GUI/menubar.hxx | 13 +++++++++++++ src/GUI/new_gui.cxx | 15 +++++++++++++++ src/GUI/new_gui.hxx | 2 ++ src/Viewer/renderer.cxx | 6 ++++++ 8 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/GUI/FGCocoaMenuBar.hxx b/src/GUI/FGCocoaMenuBar.hxx index f18baf496..daf45e5a4 100644 --- a/src/GUI/FGCocoaMenuBar.hxx +++ b/src/GUI/FGCocoaMenuBar.hxx @@ -55,6 +55,14 @@ public: * Test whether the menu bar is visible. */ virtual bool isVisible () const; + + /** + * This is a no-op on Cocoa - the menubar doesn't overlap the window + * when its drawn. + */ + void setHideIfOverlapsWindow(bool hide) override; + + bool getHideIfOverlapsWindow() const override; class CocoaMenuBarPrivate; private: diff --git a/src/GUI/FGCocoaMenuBar.mm b/src/GUI/FGCocoaMenuBar.mm index c82546f32..288017ab7 100644 --- a/src/GUI/FGCocoaMenuBar.mm +++ b/src/GUI/FGCocoaMenuBar.mm @@ -9,6 +9,7 @@ #include #include #include +#include #include
#include @@ -325,3 +326,14 @@ void FGCocoaMenuBar::hide() // no-op } +void FGCocoaMenuBar::setHideIfOverlapsWindow(bool hide) +{ + SG_UNUSED(hide); + // no-op +} + +bool FGCocoaMenuBar::getHideIfOverlapsWindow() const +{ + return false; +} + diff --git a/src/GUI/FGPUIMenuBar.cxx b/src/GUI/FGPUIMenuBar.cxx index 9f5283685..4833058b7 100644 --- a/src/GUI/FGPUIMenuBar.cxx +++ b/src/GUI/FGPUIMenuBar.cxx @@ -111,17 +111,15 @@ FGPUIMenuBar::init () void FGPUIMenuBar::show () { - if (_menuBar != 0) - _menuBar->reveal(); _visible = true; + recomputeVisibility(); } void FGPUIMenuBar::hide () { - if (_menuBar != 0) - _menuBar->hide(); _visible = false; + recomputeVisibility(); } bool @@ -130,6 +128,32 @@ FGPUIMenuBar::isVisible () const return _visible; } +void +FGPUIMenuBar::setHideIfOverlapsWindow(bool hide) +{ + _hideOverlapping = hide; + recomputeVisibility(); +} + +bool +FGPUIMenuBar::getHideIfOverlapsWindow() const +{ + return _hideOverlapping; +} + +void +FGPUIMenuBar::recomputeVisibility() +{ + if (_menuBar) { + const bool actualVis = _visible && (!_hideOverlapping); + if (actualVis) { + _menuBar->reveal(); + } else { + _menuBar->hide(); + } + } +} + void FGPUIMenuBar::fireItem (puObject * item) { diff --git a/src/GUI/FGPUIMenuBar.hxx b/src/GUI/FGPUIMenuBar.hxx index fa21c05b3..3a196ef5b 100644 --- a/src/GUI/FGPUIMenuBar.hxx +++ b/src/GUI/FGPUIMenuBar.hxx @@ -69,7 +69,10 @@ public: */ virtual bool isVisible () const; + void setHideIfOverlapsWindow(bool hide) override; + bool getHideIfOverlapsWindow() const override; + /** * IGNORE THIS METHOD!!! * @@ -113,9 +116,12 @@ private: // Add listener that enables/disables menu entries. void add_enabled_listener(SGPropertyNode * node); + void recomputeVisibility(); + // Is the menu visible? bool _visible; - + bool _hideOverlapping = false; + // The top-level menubar itself. puMenuBar * _menuBar; diff --git a/src/GUI/menubar.hxx b/src/GUI/menubar.hxx index 2c6f0f33d..e46b28983 100644 --- a/src/GUI/menubar.hxx +++ b/src/GUI/menubar.hxx @@ -48,6 +48,19 @@ public: */ virtual bool isVisible () const = 0; + /** + * Request the menubar to be hidden if its display overlays the main window content. + * (Which essentially means the PUI menubar at the moment). This is used to prevent + * the menubar overlapping the splash-screen during startup. + * + * The state of this flag is independant of the normal menubar visibility, i.e this + * flag and the normal visibility and AND-ed together inside the code. + */ + virtual void setHideIfOverlapsWindow(bool hide) = 0; + + // corresponding getter to valye able. + virtual bool getHideIfOverlapsWindow() const = 0; + /** * Read a menu label from the menu's property tree. * Take care of mapping it to the appropriate translation, if available. diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index 4f0721c93..05917c980 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -71,6 +71,9 @@ NewGUI::init () fgTie("/sim/menubar/visibility", this, &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible); + fgTie("/sim/menubar/overlap-hide", this, + &NewGUI::getMenuBarOverlapHide, &NewGUI::setMenuBarOverlapHide); + setStyle(); SGPath p(globals->get_fg_root(), "gui/dialogs"); readDir(p); @@ -305,6 +308,18 @@ NewGUI::setMenuBarVisible (bool visible) _menubar->hide(); } +bool +NewGUI::getMenuBarOverlapHide() const +{ + return _menubar->getHideIfOverlapsWindow(); +} + +void +NewGUI::setMenuBarOverlapHide(bool hide) +{ + _menubar->setHideIfOverlapsWindow(hide); +} + void NewGUI::newDialog (SGPropertyNode* props) { diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index 4df077d48..f89acb1f2 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -201,6 +201,8 @@ protected: */ virtual void reset (bool reload); + bool getMenuBarOverlapHide() const; + void setMenuBarOverlapHide(bool hide); private: void createMenuBarImplementation(); diff --git a/src/Viewer/renderer.cxx b/src/Viewer/renderer.cxx index 6689d426d..99cd780b7 100644 --- a/src/Viewer/renderer.cxx +++ b/src/Viewer/renderer.cxx @@ -468,6 +468,11 @@ FGRenderer::preinit( void ) _updateVisitor->setFrameStamp(_frameStamp.get()); viewer->setUpdateVisitor(_updateVisitor.get()); fgSetDouble("/sim/startup/splash-alpha", 1.0); + + // hide the menubar if it overlaps the window, so the splash screen + // is completely visible. We reset this value when the splash screen + // is fading out. + fgSetBool("/sim/menubar/overlap-hide", true); } class ShadowMapSizeListener : public SGPropertyChangeListener { @@ -1594,6 +1599,7 @@ FGRenderer::update( ) { _splash_alpha->setDoubleValue((sAlpha < 0) ? 0.0 : sAlpha); syncPausePopupState(); + fgSetBool("/sim/menubar/overlap-hide", false); } FGLight *l = static_cast(globals->get_subsystem("lighting"));