From 010c3fb69450d5e98b4db6b30b99225d5c82f7ff Mon Sep 17 00:00:00 2001 From: Ruslan Kabatsayev Date: Sat, 11 Jan 2025 12:53:59 +0800 Subject: [PATCH] Scale lines according to screen font size --- src/core/modules/ConstellationMgr.cpp | 30 +++++++++++++++++------ src/core/modules/Nebula.cpp | 35 ++++++++++++++++++++------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/core/modules/ConstellationMgr.cpp b/src/core/modules/ConstellationMgr.cpp index ecf6fd33024b1..c3de67071df27 100644 --- a/src/core/modules/ConstellationMgr.cpp +++ b/src/core/modules/ConstellationMgr.cpp @@ -46,6 +46,18 @@ #include #include +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), @@ -711,10 +723,11 @@ 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(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(); @@ -722,7 +735,7 @@ void ConstellationMgr::drawLines(StelPainter& sPainter, const StelCore* core) co { 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); } @@ -1442,16 +1455,17 @@ bool ConstellationMgr::loadBoundaries(const QString& boundaryFile) void ConstellationMgr::drawBoundaries(StelPainter& sPainter, const Vec3d &obsVelocity) const { - const float ppx = static_cast(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); } diff --git a/src/core/modules/Nebula.cpp b/src/core/modules/Nebula.cpp index 1700ce6a6d982..af39ecb7c8471 100644 --- a/src/core/modules/Nebula.cpp +++ b/src/core/modules/Nebula.cpp @@ -39,6 +39,18 @@ #include #include +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; @@ -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; @@ -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; @@ -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); @@ -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; @@ -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); } } @@ -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(getAngularRadius(Q_NULLPTR)) *(M_PI_180f)*static_cast(sPainter.getProjector()->getPixelPerRadAtCenter()) / static_cast(sPainter.getProjector()->getDevicePixelsPerPixel()); + { + const float scale = screenScale(*sPainter.getProjector()); + const float angularRadiusAtCenter = static_cast(getAngularRadius(nullptr)) * M_PI_180f; + const float pixPerRadAtCenter = static_cast(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;