Skip to content

Commit

Permalink
Use the correct screen when making a screenshot
Browse files Browse the repository at this point in the history
Current code picks a screen based only on the size of the scene,
ignoring the position of the window. Asking the widget for its screen
is the proper way of doing this.
  • Loading branch information
10110111 committed Dec 5, 2023
1 parent 30fde21 commit fc45042
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/StelMainView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,8 @@ void StelMainView::doScreenshot(void)
// HiDPI screens interfere, and the viewing angle has to be maintained.
// First, image size:
glWidget->makeCurrent();
const auto pixelRatio = QOpenGLContext::currentContext()->screen()->devicePixelRatio();
const auto screen = QOpenGLContext::currentContext()->screen();
const auto pixelRatio = screen->devicePixelRatio();
int physImgWidth = std::lround(stelScene->width() * pixelRatio);
int physImgHeight = std::lround(stelScene->height() * pixelRatio);
bool nightModeWasEnabled=nightModeEffect->isEnabled();
Expand Down Expand Up @@ -1739,7 +1740,7 @@ void StelMainView::doScreenshot(void)
sParams.viewportXywh[3] = virtImgHeight;

// Configure a helper value to allow some modules to tweak their output sizes. Currently used by StarMgr, maybe solve font issues?
customScreenshotMagnification=static_cast<float>(virtImgHeight)/static_cast<float>(qApp->screenAt(QPoint(stelScene->width()*0.5, stelScene->height()*0.5))->geometry().height());
customScreenshotMagnification=static_cast<float>(virtImgHeight)/static_cast<float>(screen->geometry().height());
sParams.viewportCenter.set(0.0+(0.5+pParams.viewportCenterOffset.v[0])*virtImgWidth,
0.0+(0.5+pParams.viewportCenterOffset.v[1])*virtImgHeight);
sParams.viewportFovDiameter = qMin(virtImgWidth,virtImgHeight);
Expand Down

0 comments on commit fc45042

Please sign in to comment.