Skip to content

Commit

Permalink
Fix a font scaling problem (#42)
Browse files Browse the repository at this point in the history
We scaled global fonts, but they are global, so scaling multiple
times meant the fonts kept getting alrger, which FL showed on windows
with High Res displays
  • Loading branch information
baconpaul authored Sep 25, 2024
1 parent 52e3e2e commit b70a6fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/clap-saw-demo-editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ void ClapSawDemoEditor::setupUI()
{
auto scaleFont = [this](VSTGUI::CFontRef font)
{
font->setSize(font->getSize() * uiScale);
return font;
auto res = VSTGUI::makeOwned<VSTGUI::CFontDesc>(*font);
res->setSize(res->getSize() * uiScale);
res->remember();
return res;
};
scaleFont(VSTGUI::kNormalFont);
scaleFont(VSTGUI::kNormalFontVeryBig);
scaleFont(VSTGUI::kNormalFontSmall);
scaleFont(VSTGUI::kNormalFontSmaller);
knF = scaleFont(VSTGUI::kNormalFont);
knFVeryBig = scaleFont(VSTGUI::kNormalFontVeryBig);
knFSmall = scaleFont(VSTGUI::kNormalFontSmall);
knFSmaller = scaleFont(VSTGUI::kNormalFontSmaller);

// Resize as we should now have our scale
frame->setSize(applyUIScale(ClapSawDemo::GUI_DEFAULT_W),
Expand All @@ -283,7 +285,7 @@ void ClapSawDemoEditor::setupUI()
auto l = new VSTGUI::CTextLabel(VSTGUI::CRect(0, 0, getFrame()->getWidth(), applyUIScale(40)),
"Clap Saw Synth Demo");
l->setTransparency(true);
l->setFont(VSTGUI::kNormalFontVeryBig);
l->setFont(knFVeryBig);
l->setHoriAlign(VSTGUI::CHoriTxtAlign::kCenterText);
topLabel = l;
frame->addView(topLabel);
Expand All @@ -293,7 +295,7 @@ void ClapSawDemoEditor::setupUI()
VSTGUI::CPoint(getFrame()->getWidth(), applyUIScale(20))),
"poly=0");
l->setTransparency(true);
l->setFont(VSTGUI::kNormalFont);
l->setFont(knF);
l->setHoriAlign(VSTGUI::CHoriTxtAlign::kCenterText);
statusLabel = l;
frame->addView(statusLabel);
Expand All @@ -303,7 +305,7 @@ void ClapSawDemoEditor::setupUI()
VSTGUI::CPoint(getFrame()->getWidth(), applyUIScale(20))),
"https://github.com/surge-synthesizer/clap-saw-demo");
l->setTransparency(true);
l->setFont(VSTGUI::kNormalFontSmall);
l->setFont(knFSmall);
l->setHoriAlign(VSTGUI::CHoriTxtAlign::kCenterText);
repoLabel = l;
frame->addView(repoLabel);
Expand All @@ -316,7 +318,7 @@ void ClapSawDemoEditor::setupUI()
VSTGUI::CPoint(getFrame()->getWidth(), applyUIScale(20))),
sl.c_str());
l->setTransparency(true);
l->setFont(VSTGUI::kNormalFontSmaller);
l->setFont(knFSmaller);
l->setHoriAlign(VSTGUI::CHoriTxtAlign::kCenterText);
bottomLabel = l;
frame->addView(bottomLabel);
Expand All @@ -338,7 +340,7 @@ void ClapSawDemoEditor::setupUI()
VSTGUI::CPoint(applyUIScale(x) - applyUIScale(10), applyUIScale(y) + applyUIScale(155)),
VSTGUI::CPoint(applyUIScale(45), applyUIScale(15))));
l->setText(label.c_str());
l->setFont(VSTGUI::kNormalFont);
l->setFont(knF);

frame->addView(l);
return q;
Expand Down
2 changes: 2 additions & 0 deletions src/clap-saw-demo-editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct ClapSawDemoEditor : public VSTGUI::VSTGUIEditorInterface, public VSTGUI::
VSTGUI::CTextLabel *topLabel{nullptr}, *repoLabel{nullptr}, *bottomLabel{nullptr},
*statusLabel{nullptr};

VSTGUI::CFontRef knF, knFVeryBig, knFSmall, knFSmaller;

VSTGUI::CTextLabel *ampLabel{nullptr};
VSTGUI::CCheckBox *ampToggle{nullptr};
VSTGUI::CSlider *ampAttack{nullptr}, *ampRelease{nullptr};
Expand Down

0 comments on commit b70a6fe

Please sign in to comment.