OpenGL DPI scaling support (#11883)

Scale opengl width/height based on primary screen DPI scaling.
This commit is contained in:
jonjenssen
2024-11-15 12:12:59 +01:00
committed by GitHub
parent f6109cab2b
commit dbea0e2593
6 changed files with 57 additions and 39 deletions

View File

@@ -61,8 +61,11 @@ bool RiuComparisonViewMover::eventFilter( QObject* watched, QEvent* event )
if ( m_dragState == LEFT_EDGE )
{
const int viewWidth = m_viewer->width();
const int viewHeight = m_viewer->height();
QPointF mousePos = mEv->localPos();
QPointF normMousePos = { mousePos.x() / m_viewer->width(), mousePos.y() / m_viewer->height() };
QPointF normMousePos = { mousePos.x() / viewWidth, mousePos.y() / viewHeight };
cvf::Rectf orgCompViewWindow = m_viewer->comparisonViewVisibleNormalizedRect();
float minx = normMousePos.x();
@@ -97,8 +100,9 @@ void RiuComparisonViewMover::paintMoverHandles( QPainter* painter )
const int handleThickness = 7;
cvf::Rectf normalizedComparisonRect = m_viewer->comparisonViewVisibleNormalizedRect();
int viewerWidth = m_viewer->width();
int viewerHeight = m_viewer->height();
const auto ratio = m_viewer->displayScalingRatio();
int viewerWidth = (int)( ratio * m_viewer->width() );
int viewerHeight = (int)( ratio * m_viewer->height() );
int leftEdgePos = viewerWidth * normalizedComparisonRect.min().x();
int width = viewerWidth * normalizedComparisonRect.width();

View File

@@ -401,6 +401,11 @@ void RiuViewer::paintOverlayItems( QPainter* painter )
// and when they are shared between views the positions are overwritten.
updateLegendLayout();
// adjust for possible DPI scaling
auto ratio = displayScalingRatio();
const auto trueWidth = (int)( ratio * this->width() );
const auto trueHeight = (int)( ratio * this->height() );
int columnWidth = 200;
int edgeAxisFrameBorderWidth = m_showWindowEdgeAxes ? m_windowEdgeAxisOverlay->frameBorderWidth() : 0;
@@ -415,7 +420,7 @@ void RiuViewer::paintOverlayItems( QPainter* painter )
if ( m_showInfoText ) columnWidth = std::max( columnWidth, m_infoLabel->sizeHint().width() );
int columnPos = width() - columnWidth - margin - edgeAxisFrameBorderWidth;
int columnPos = trueWidth - columnWidth - margin - edgeAxisFrameBorderWidth;
if ( isComparisonViewActive() )
{
@@ -424,9 +429,8 @@ void RiuViewer::paintOverlayItems( QPainter* painter )
{
columnWidth = 200;
// int sliderPos = width() * comparisonViewVisibleNormalizedRect().min().x();
int sliderPos = 0.5 * width();
int compViewItemsXPos = sliderPos + 0.5 * ( width() - sliderPos ) - 0.5 * columnWidth;
int sliderPos = 0.5 * trueWidth;
int compViewItemsXPos = sliderPos + 0.5 * ( trueWidth - sliderPos ) - 0.5 * columnWidth;
columnPos = 0.5 * sliderPos - 0.5 * columnWidth;
if ( m_showInfoText )
@@ -520,13 +524,13 @@ void RiuViewer::paintOverlayItems( QPainter* painter )
{
m_histogramWidget->resize( columnWidth, 40 );
m_histogramWidget->render( painter, QPoint( columnPos, yPos ) );
// yPos += m_histogramWidget->height() + margin;
}
if ( m_showVersionInfo ) // Version Label
{
QSize size( m_versionInfoLabel->sizeHint().width(), m_versionInfoLabel->sizeHint().height() );
QPoint pos( width() - size.width() - margin - edgeAxisFrameBorderWidth, height() - size.height() - margin - edgeAxisFrameBorderHeight );
QSize size( m_versionInfoLabel->sizeHint().width(), m_versionInfoLabel->sizeHint().height() );
QPoint pos( trueWidth - size.width() - margin - edgeAxisFrameBorderWidth,
trueHeight - size.height() - margin - edgeAxisFrameBorderHeight );
m_versionInfoLabel->resize( size.width(), size.height() );
m_versionInfoLabel->render( painter, pos );
}
@@ -550,8 +554,9 @@ void RiuViewer::paintOverlayItems( QPainter* painter )
cvf::Vec3d screenCoords;
if ( mainCamera()->project( displayCoord, &screenCoords ) )
{
int translatedMousePosY = height() - screenCoords.y();
QPoint centerPos( screenCoords.x(), translatedMousePosY );
int translatedMousePosX = (int)( ratio * screenCoords.x() );
int translatedMousePosY = (int)( ratio * ( height() - screenCoords.y() ) );
QPoint centerPos( translatedMousePosX, translatedMousePosY );
// Draw a cross hair marker
int markerHalfLength = 6;
@@ -926,8 +931,9 @@ void RiuViewer::updateLegendLayout()
auto scaleLegendSize = m_scaleLegend->renderSize();
auto otherItemsHeight = m_versionInfoLabel->sizeHint().height();
const int xPos = width() - (int)scaleLegendSize.x() - margin - edgeAxisBorderWidth;
const int yPos = margin + edgeAxisBorderHeight + margin + otherItemsHeight;
const auto ratio = displayScalingRatio();
const int xPos = (int)( ratio * width() ) - (int)scaleLegendSize.x() - margin - edgeAxisBorderWidth;
const int yPos = margin + edgeAxisBorderHeight + margin + otherItemsHeight;
m_scaleLegend->setLayoutFixedPosition( { xPos, yPos } );
}
@@ -1058,14 +1064,6 @@ void RiuViewer::optimizeClippingPlanes()
caf::Viewer::optimizeClippingPlanes();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::resizeGL( int width, int height )
{
caf::Viewer::resizeGL( width, height );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -141,7 +141,6 @@ public slots:
protected:
void optimizeClippingPlanes() override;
void resizeGL( int width, int height ) override;
void mouseMoveEvent( QMouseEvent* e ) override;
void enterEvent( QEnterEvent* e ) override;
void leaveEvent( QEvent* ) override;