1
0
Fork 0

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.
This commit is contained in:
James Turner 2017-05-11 08:39:48 +01:00
parent 4dc2e4fc09
commit 00845b17b9
8 changed files with 91 additions and 5 deletions

View file

@ -56,6 +56,14 @@ public:
*/
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:
std::unique_ptr<CocoaMenuBarPrivate> p;

View file

@ -9,6 +9,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/SGBinding.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/sg_inlines.h>
#include <Main/fg_props.hxx>
#include <GUI/CocoaHelpers_private.h>
@ -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;
}

View file

@ -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)
{

View file

@ -69,6 +69,9 @@ public:
*/
virtual bool isVisible () const;
void setHideIfOverlapsWindow(bool hide) override;
bool getHideIfOverlapsWindow() const override;
/**
* IGNORE THIS METHOD!!!
@ -113,8 +116,11 @@ private:
// Add <enabled> 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;

View file

@ -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.

View file

@ -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)
{

View file

@ -201,6 +201,8 @@ protected:
*/
virtual void reset (bool reload);
bool getMenuBarOverlapHide() const;
void setMenuBarOverlapHide(bool hide);
private:
void createMenuBarImplementation();

View file

@ -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<FGLight*>(globals->get_subsystem("lighting"));