Skip to content

Commit

Permalink
Handle font size changes in Cardinals
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Jan 30, 2025
1 parent 3742575 commit e89a93f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/core/modules/LandscapeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,8 @@ constexpr char ATMOSPHERE_MODEL_CONF_VAL_DEFAULT[]="preetham";
Cardinals::Cardinals()
: color(0.6f,0.2f,0.2f)
{
QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
screenFontSize = StelApp::getInstance().getScreenFontSize();
propMgr = StelApp::getInstance().getStelPropertyManager();
// Default font size is 24
font4WCR.setPixelSize(conf->value("viewing/cardinal_font_size", screenFontSize+11).toInt());
// Default font size is 18
font8WCR.setPixelSize(conf->value("viewing/ordinal_font_size", screenFontSize+5).toInt());
// Draw the principal wind points even smaller.
font16WCR.setPixelSize(conf->value("viewing/16wcr_font_size", screenFontSize+2).toInt());
font32WCR.setPixelSize(conf->value("viewing/32wcr_font_size", screenFontSize).toInt());
updateFontSizes();

// English names for cardinals
labels = {
Expand All @@ -94,6 +85,23 @@ Cardinals::Cardinals()
{ dSbW,"SbW" }, {dSWbS,"SWbS"}, {dSWbW,"SWbW"}, { dWbS,"WbS" },
{ dWbN,"WbN" }, {dNWbW,"NWbW"}, {dNWbN,"NWbN"}, { dNbW,"NbW" }
};
QObject::connect(&StelApp::getInstance(), &StelApp::screenFontSizeChanged,
[this]{updateFontSizes();});
}

void Cardinals::updateFontSizes()
{
QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
screenFontSize = StelApp::getInstance().getScreenFontSize();
const float scale = StelApp::getInstance().screenFontSizeRatio();
// Default font size is 24
font4WCR.setPixelSize(conf->value("viewing/cardinal_font_size", screenFontSize+11*scale).toInt());
// Default font size is 18
font8WCR.setPixelSize(conf->value("viewing/ordinal_font_size", screenFontSize+5*scale).toInt());
// Draw the principal wind points even smaller.
font16WCR.setPixelSize(conf->value("viewing/16wcr_font_size", screenFontSize+2*scale).toInt());
font32WCR.setPixelSize(conf->value("viewing/32wcr_font_size", screenFontSize).toInt());
}

Cardinals::~Cardinals()
Expand Down Expand Up @@ -159,7 +167,7 @@ void Cardinals::draw(const StelCore* core, double latitude) const
if (fader4WCR.getInterstate()>0.f)
{
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
const float ppx = static_cast<float>(core->getCurrentStelProjectorParams().devicePixelsPerPixel);
const float ppx = prj->getScreenScale();
StelPainter sPainter(prj);
sPainter.setFont(font4WCR);
float sshift=0.f, bshift=0.f, cshift=0.f, dshift=0.f, vshift=1.f;
Expand Down
3 changes: 3 additions & 0 deletions src/core/modules/LandscapeMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class Cardinals
bool getFlagShow16WCRLabels() const { return fader16WCR; }
void setFlagShow32WCRLabels(bool b) { fader32WCR = b; StelApp::immediateSave("viewing/flag_32wcr_points", b);}
bool getFlagShow32WCRLabels() const { return fader32WCR; }
private:
void updateFontSizes();

private:
class StelPropertyMgr* propMgr;
QFont font4WCR, font8WCR, font16WCR, font32WCR;
Expand Down

0 comments on commit e89a93f

Please sign in to comment.