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 010c3fb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
30 changes: 22 additions & 8 deletions src/core/modules/ConstellationMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
#include <QStringList>
#include <QDir>

namespace
{

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

}

// constructor which loads all data from appropriate files
ConstellationMgr::ConstellationMgr(StarMgr *_hip_stars)
: hipStarMgr(_hip_stars),
Expand Down Expand Up @@ -711,18 +723,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 = screenScale(*sPainter.getProjector());

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 +1455,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 = screenScale(*sPainter.getProjector());

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
35 changes: 26 additions & 9 deletions src/core/modules/Nebula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
#include <QDebug>
#include <QBuffer>

namespace
{

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

}

const QString Nebula::NEBULA_TYPE = QStringLiteral("Nebula");

StelTextureSP Nebula::texRegion;
Expand Down Expand Up @@ -754,7 +766,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 = screenScale(*sPainter.getProjector());
size *= scale;

const float roundRadius = 0.35 * size;
Expand Down Expand Up @@ -841,7 +853,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 = screenScale(*sPainter.getProjector());
size *= scale;

const float roundRadius = 0.35 * size;
Expand Down Expand Up @@ -897,7 +909,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 = screenScale(*sPainter.getProjector());
size *= scale;

sPainter.setBlending(true);
Expand All @@ -923,7 +935,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 = screenScale(*sPainter.getProjector());
size *= scale;

const float radiusY = 0.35 * size;
Expand Down Expand Up @@ -957,21 +969,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 = screenScale(*sPainter.getProjector());
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 +993,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 = screenScale(*sPainter.getProjector());
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 010c3fb

Please sign in to comment.