Expose device-pixel-ratio to properties.
This allows scaling of the UI accordingly, to keep things usable on HiDPi screens. (Note this is not fixed yet, but this is a step)
This commit is contained in:
parent
4d900a5c26
commit
09972be25a
3 changed files with 22 additions and 9 deletions
|
@ -141,6 +141,12 @@ void GLWindow::onScreenChanged()
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
||||||
_devicePixelRatio = screen()->devicePixelRatio();
|
_devicePixelRatio = screen()->devicePixelRatio();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (_isPrimaryWindow) {
|
||||||
|
// allow PUI and Canvas to be scaled
|
||||||
|
fgSetDouble("/sim/rendering/gui-pixel-ratio", _devicePixelRatio);
|
||||||
|
}
|
||||||
|
|
||||||
syncGeometryWithOSG();
|
syncGeometryWithOSG();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,8 +361,6 @@ void GLWindow::wheelEvent( QWheelEvent* event )
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsWindowQt5::GraphicsWindowQt5(osg::GraphicsContext::Traits* traits)
|
GraphicsWindowQt5::GraphicsWindowQt5(osg::GraphicsContext::Traits* traits)
|
||||||
: _realized(false)
|
|
||||||
, _updateContextNeeded(false)
|
|
||||||
{
|
{
|
||||||
_traits = traits;
|
_traits = traits;
|
||||||
init(0);
|
init(0);
|
||||||
|
@ -385,14 +389,12 @@ bool GraphicsWindowQt5::init( Qt::WindowFlags f )
|
||||||
//flags |= Qt::MaximizeUsingFullscreenGeometryHint;
|
//flags |= Qt::MaximizeUsingFullscreenGeometryHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create widget
|
// create window
|
||||||
_window.reset(new GLWindow);
|
_window.reset(new GLWindow);
|
||||||
_window->setFlags(flags);
|
_window->setFlags(flags);
|
||||||
_window->setSurfaceType(QSurface::OpenGLSurface);
|
_window->setSurfaceType(QSurface::OpenGLSurface);
|
||||||
_window->setFormat(traits2qSurfaceFormat(_traits.get()));
|
_window->setFormat(traits2qSurfaceFormat(_traits.get()));
|
||||||
_window->create();
|
_window->create();
|
||||||
|
|
||||||
|
|
||||||
_window->setTitle( _traits->windowName.c_str() );
|
_window->setTitle( _traits->windowName.c_str() );
|
||||||
|
|
||||||
// to get OS-dependant default positioning of the window (which is desirable),
|
// to get OS-dependant default positioning of the window (which is desirable),
|
||||||
|
@ -418,6 +420,10 @@ bool GraphicsWindowQt5::init( Qt::WindowFlags f )
|
||||||
}
|
}
|
||||||
|
|
||||||
_window->_isPrimaryWindow = windowData->isPrimaryWindow;
|
_window->_isPrimaryWindow = windowData->isPrimaryWindow;
|
||||||
|
if (_window->_isPrimaryWindow) {
|
||||||
|
fgSetDouble("/sim/rendering/gui-pixel-ratio", _window->_devicePixelRatio);
|
||||||
|
}
|
||||||
|
|
||||||
_window->setGraphicsWindow( this );
|
_window->setGraphicsWindow( this );
|
||||||
useCursor( _traits->useCursor );
|
useCursor( _traits->useCursor );
|
||||||
|
|
||||||
|
@ -760,7 +766,11 @@ void GraphicsWindowQt5::requestRedraw()
|
||||||
|
|
||||||
void GraphicsWindowQt5::requestContinuousUpdate(bool needed)
|
void GraphicsWindowQt5::requestContinuousUpdate(bool needed)
|
||||||
{
|
{
|
||||||
GraphicsWindow::requestContinuousUpdate(needed);
|
_continousUpdate = needed;
|
||||||
|
GraphicsWindow::requestContinuousUpdate(needed);
|
||||||
|
if (_continousUpdate) {
|
||||||
|
_window->requestUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsWindowQt5::setFullscreen(bool isFullscreen)
|
void GraphicsWindowQt5::setFullscreen(bool isFullscreen)
|
||||||
|
|
|
@ -112,7 +112,7 @@ protected:
|
||||||
QSet<QEvent::Type> _eventCompressor;
|
QSet<QEvent::Type> _eventCompressor;
|
||||||
|
|
||||||
bool _forwardKeyEvents = false;
|
bool _forwardKeyEvents = false;
|
||||||
qreal _devicePixelRatio;
|
qreal _devicePixelRatio = 1.0;
|
||||||
|
|
||||||
// is this the primary (GUI) window
|
// is this the primary (GUI) window
|
||||||
bool _isPrimaryWindow = false;
|
bool _isPrimaryWindow = false;
|
||||||
|
@ -198,8 +198,9 @@ protected:
|
||||||
QOpenGLContext* _shareContext = nullptr;
|
QOpenGLContext* _shareContext = nullptr;
|
||||||
bool _ownsWidget;
|
bool _ownsWidget;
|
||||||
QCursor _currentCursor;
|
QCursor _currentCursor;
|
||||||
bool _realized;
|
bool _realized = false;
|
||||||
bool _updateContextNeeded;
|
bool _updateContextNeeded = false;
|
||||||
|
bool _continousUpdate = false;
|
||||||
osg::observer_ptr< osgViewer::ViewerBase > _viewer;
|
osg::observer_ptr< osgViewer::ViewerBase > _viewer;
|
||||||
|
|
||||||
// if true, we will generate a resize event on the next
|
// if true, we will generate a resize event on the next
|
||||||
|
|
|
@ -372,6 +372,8 @@ void fgOSInit(int* argc, char** argv)
|
||||||
SG_LOG(SG_GL, SG_INFO, "Using Qt implementation of GraphicsWindow");
|
SG_LOG(SG_GL, SG_INFO, "Using Qt implementation of GraphicsWindow");
|
||||||
flightgear::initQtWindowingSystem();
|
flightgear::initQtWindowingSystem();
|
||||||
} else {
|
} else {
|
||||||
|
// stock OSG windows are not Hi-DPI aware
|
||||||
|
fgSetDouble("/sim/rendering/gui-pixel-ratio", 1.0);
|
||||||
SG_LOG(SG_GL, SG_INFO, "Using stock OSG implementation of GraphicsWindow");
|
SG_LOG(SG_GL, SG_INFO, "Using stock OSG implementation of GraphicsWindow");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue