Skip to content

Commit

Permalink
Scale lines according to screen font size
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Jan 11, 2025
1 parent 581c924 commit be151fa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/core/StelProjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "StelTranslator.hpp"

#include "StelProjector.hpp"
#include "StelApp.hpp"

#include <QDebug>
#include <QString>
Expand Down Expand Up @@ -309,6 +310,13 @@ float StelProjector::getPixelPerRadAtCenter() const
return pixelPerRad;
}

float StelProjector::getScreenScale() const
{
const float dppRatio = getDevicePixelsPerPixel();
const float fontRatio = StelApp::getInstance().screenFontSizeRatio();
return dppRatio * fontRatio;
}

//! Get the current FOV diameter in degrees
float StelProjector::getFov() const {
return 360.f/static_cast<float>(M_PI)*viewScalingFactorToFov(0.5f*static_cast<float>(viewportFovDiameter)/pixelPerRad);
Expand Down
4 changes: 4 additions & 0 deletions src/core/StelProjector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ class StelProjector
//! Get size of a radian in pixels at the center of the viewport disk
float getPixelPerRadAtCenter() const;

//! Get the scale factor for objects drawn on screen. This takes into account
//! font size and the OS-given high-DPI scaling setting (see #getDevicePixelsPerPixel).
float getScreenScale() const;

//! Get the current FOV diameter in degrees
float getFov() const;

Expand Down
18 changes: 10 additions & 8 deletions src/core/modules/ConstellationMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,18 +711,19 @@ void ConstellationMgr::drawArt(StelPainter& sPainter, const Vec3d &obsVelocity)
// Draw constellations lines
void ConstellationMgr::drawLines(StelPainter& sPainter, const StelCore* core) const
{
const float ppx = static_cast<float>(sPainter.getProjector()->getDevicePixelsPerPixel());
const float scale = sPainter.getProjector()->getScreenScale();

sPainter.setBlending(true);
if (constellationLineThickness>1 || ppx>1.f)
sPainter.setLineWidth(constellationLineThickness*ppx); // set line thickness
if (constellationLineThickness>1 || scale>1.f)
sPainter.setLineWidth(constellationLineThickness*scale); // set line thickness
sPainter.setLineSmooth(true);

const SphericalCap& viewportHalfspace = sPainter.getProjector()->getBoundingCap();
for (auto* constellation : constellations)
{
constellation->drawOptim(sPainter, core, viewportHalfspace);
}
if (constellationLineThickness>1 || ppx>1.f)
if (constellationLineThickness>1 || scale>1.f)
sPainter.setLineWidth(1); // restore line thickness
sPainter.setLineSmooth(false);
}
Expand Down Expand Up @@ -1442,16 +1443,17 @@ bool ConstellationMgr::loadBoundaries(const QString& boundaryFile)

void ConstellationMgr::drawBoundaries(StelPainter& sPainter, const Vec3d &obsVelocity) const
{
const float ppx = static_cast<float>(sPainter.getProjector()->getDevicePixelsPerPixel());
const float scale = sPainter.getProjector()->getScreenScale();

sPainter.setBlending(false);
if (constellationBoundariesThickness>1 || ppx>1.f)
sPainter.setLineWidth(constellationBoundariesThickness*ppx); // set line thickness
if (constellationBoundariesThickness>1 || scale>1.f)
sPainter.setLineWidth(constellationBoundariesThickness*scale); // set line thickness
sPainter.setLineSmooth(true);
for (auto* constellation : constellations)
{
constellation->drawBoundaryOptim(sPainter, obsVelocity);
}
if (constellationBoundariesThickness>1 || ppx>1.f)
if (constellationBoundariesThickness>1 || scale>1.f)
sPainter.setLineWidth(1); // restore line thickness
sPainter.setLineSmooth(false);
}
Expand Down
23 changes: 14 additions & 9 deletions src/core/modules/Nebula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ void Nebula::renderDarkNebulaMarker(StelPainter& sPainter, const float x, const
float size, const Vec3f color) const
{
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
const auto scale = sPainter.getProjector()->getDevicePixelsPerPixel();
const float scale = sPainter.getProjector()->getScreenScale();
size *= scale;

const float roundRadius = 0.35 * size;
Expand Down Expand Up @@ -841,7 +841,7 @@ void Nebula::renderMarkerRoundedRect(StelPainter& sPainter, const float x, const
float size, const Vec3f color) const
{
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
const auto scale = sPainter.getProjector()->getDevicePixelsPerPixel();
const float scale = sPainter.getProjector()->getScreenScale();
size *= scale;

const float roundRadius = 0.35 * size;
Expand Down Expand Up @@ -897,7 +897,7 @@ void Nebula::renderRoundMarker(StelPainter& sPainter, const float x, const float
float size, const Vec3f color, const bool crossed) const
{
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
const auto scale = sPainter.getProjector()->getDevicePixelsPerPixel();
const float scale = sPainter.getProjector()->getScreenScale();
size *= scale;

sPainter.setBlending(true);
Expand All @@ -923,7 +923,7 @@ void Nebula::renderEllipticMarker(StelPainter& sPainter, const float x, const fl
const float aspectRatio, const float angle, const Vec3f color) const
{
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
const auto scale = sPainter.getProjector()->getDevicePixelsPerPixel();
const float scale = sPainter.getProjector()->getScreenScale();
size *= scale;

const float radiusY = 0.35 * size;
Expand Down Expand Up @@ -957,21 +957,21 @@ void Nebula::renderMarkerPointedCircle(StelPainter& sPainter, const float x, con
float size, const Vec3f color, const bool insideRect) const
{
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
const auto scale = sPainter.getProjector()->getDevicePixelsPerPixel();
const float scale = sPainter.getProjector()->getScreenScale();
size *= scale;

texPointElement->bind();
sPainter.setColor(color, hintsBrightness);
sPainter.setBlending(true, GL_SRC_ALPHA, GL_ONE);
const auto numPoints = StelUtils::getSmallerPowerOfTwo(std::clamp(int(0.4f*size), 8, 4096));
const auto spriteSize = std::min(0.25f * 2*M_PIf*size / numPoints, 5.f);
const auto numPoints = StelUtils::getSmallerPowerOfTwo(std::clamp(int(0.4f*size/scale), 8, 4096));
const auto spriteSize = std::min(0.25f * 2*M_PIf*size / numPoints, 5.f * scale);
if(insideRect)
size -= spriteSize*2;
const float*const cossin = StelUtils::ComputeCosSinRhoZone((2*M_PIf)/numPoints, numPoints, 0);
for(int n = 0; n < numPoints; ++n)
{
const auto cosa = cossin[2*n], sina = cossin[2*n+1];
sPainter.drawSprite2dMode(x - size*sina, y - size*cosa, spriteSize);
sPainter.drawSprite2dModeNoDeviceScale(x - size*sina, y - size*cosa, spriteSize);
}
}

Expand All @@ -981,7 +981,12 @@ float Nebula::getHintSize(StelPainter& sPainter) const
float scaledSize = 0.0f;
// Should getPixelPerRadAtCenter() not adjust for HiDPI? Apparently it does not!
if (drawHintProportional)
scaledSize = static_cast<float>(getAngularRadius(Q_NULLPTR)) *(M_PI_180f)*static_cast<float>(sPainter.getProjector()->getPixelPerRadAtCenter()) / static_cast<float>(sPainter.getProjector()->getDevicePixelsPerPixel());
{
const float scale = sPainter.getProjector()->getScreenScale();
const float angularRadiusAtCenter = static_cast<float>(getAngularRadius(nullptr)) * M_PI_180f;
const float pixPerRadAtCenter = static_cast<float>(sPainter.getProjector()->getPixelPerRadAtCenter());
scaledSize = angularRadiusAtCenter * pixPerRadAtCenter / scale;
}
// TODO: Is it correct that for NebRegions any catalog data for getAngularRadius() is ignored? And that NebRegions are ALWAYS drawn with larger symbol?
if (nType==NebRegion)
scaledSize = 12.f;
Expand Down

0 comments on commit be151fa

Please sign in to comment.