Skip to content

Commit

Permalink
Start plumbing for changing modbutton font (#5942)
Browse files Browse the repository at this point in the history
Addresses #5843

Also minor formatting tweaks, and slight renaming of waveshaper analysis font connectors (I bet nobody used them so far anyways).
  • Loading branch information
mkruselj authored Mar 5, 2022
1 parent ad1b11b commit 32db2d8
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
13 changes: 8 additions & 5 deletions src/common/SkinFonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Widgets
const FontDesc NumberField("fonts.widgets.numberfield", System::Display),
EffectLabel("fonts.widgets.effectlabel", System::Display);
const FontDesc TabButtonFont("fonts.widgets.tabbutton", System::Display);
const FontDesc ModButtonFont("fonts.widgets.modbutton", 8, FontDesc::FontStyleFlags::bold);

} // namespace Widgets
namespace PatchStore
Expand All @@ -40,13 +41,15 @@ namespace LuaEditor
const FontDesc Code("fonts.luaeditor.code", FontDesc::MONO, 9);
}

namespace WaveshaperAnalysis
namespace Waveshaper
{
const FontDesc Title("fonts.waveshaper.analysis.title", 9, FontDesc::FontStyleFlags::bold),
DriveAmount("fonts.waveshaper.analysis.drive_amount", 9),
DriveLabel("fonts.waveshaper.analysis.drive_label", 7);
namespace Preview
{
const FontDesc Title("fonts.waveshaper.preview.title", 9, FontDesc::FontStyleFlags::bold),
DriveAmount("fonts.waveshaper.preview.driveamount", 9),
DriveLabel("fonts.waveshaper.preview.drivelabel", 7);
}

} // namespace Waveshaper
} // namespace Fonts

/*
Expand Down
6 changes: 5 additions & 1 deletion src/common/SkinFonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace Widgets
{
extern const Surge::Skin::FontDesc NumberField, EffectLabel;
extern const Surge::Skin::FontDesc TabButtonFont;
extern const Surge::Skin::FontDesc ModButtonFont;
} // namespace Widgets
namespace PatchStore
{
Expand All @@ -95,10 +96,13 @@ namespace LuaEditor
{
extern const Surge::Skin::FontDesc Code;
}
namespace WaveshaperAnalysis
namespace Waveshaper
{
namespace Preview
{
extern const Surge::Skin::FontDesc Title, DriveAmount, DriveLabel;
}
} // namespace Waveshaper

} // namespace Fonts
#endif // SURGE_XT_SKINFONTS_H
56 changes: 38 additions & 18 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,25 +1288,33 @@ void SurgeGUIEditor::openOrRecreateEditor()

if (e.isPrimary)
{
auto r = positionForModulationGrid(ms);

int state = 0;
auto r = positionForModulationGrid(ms);

if (ms == modsource)
{
state = mod_editor ? 2 : 1;
}

if (ms == modsource_editor[current_scene])
{
state |= 4;
}

if (!gui_modsrc[ms])
{
gui_modsrc[ms] = std::make_unique<Surge::Widgets::ModulationSourceButton>();
}

// would be nice if this had worked, alas...
// auto ff = currentSkin->getFont(Fonts::Widgets::ModButtonFont);
// gui_modsrc[ms]->setFont(ff);

gui_modsrc[ms]->setBounds(r);
gui_modsrc[ms]->setTag(tag_mod_source0 + ms);
gui_modsrc[ms]->addListener(this);
gui_modsrc[ms]->setSkin(currentSkin, bitmapStore);
gui_modsrc[ms]->setStorage(&(synth->storage));

gui_modsrc[ms]->update_rt_vals(false, 0, synth->isModsourceUsed(ms));

setupAlternates(ms);
Expand All @@ -1326,16 +1334,22 @@ void SurgeGUIEditor::openOrRecreateEditor()
}

addAndMakeVisibleWithTracking(frame->getModButtonLayer(), *gui_modsrc[ms]);

if (ms >= ms_ctrl1 && ms <= ms_ctrl8 && synth->learn_custom == ms - ms_ctrl1)
{
showMidiLearnOverlay(r);
}
}
}

auto moRect = positionForModOverview();

if (!modOverviewLauncher)
{
modOverviewLauncher =
std::make_unique<Surge::Widgets::ModulationOverviewLaunchButton>(this);
}

modOverviewLauncher->setBounds(moRect);
modOverviewLauncher->setSkin(currentSkin);
addAndMakeVisibleWithTracking(frame->getModButtonLayer(), *modOverviewLauncher);
Expand Down Expand Up @@ -4910,33 +4924,39 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
// TODO: Pull the default font size from some central location at a later date
hs->setFont(Surge::GUI::getFontManager()->displayFont);

hs->setFontSize(std::atoi(
currentSkin->propertyValue(skinCtrl, Surge::Skin::Component::FONT_SIZE, "9").c_str()));

hs->setTextHOffset(std::atoi(
currentSkin->propertyValue(skinCtrl, Surge::Skin::Component::TEXT_HOFFSET, "0")
.c_str()));

hs->setTextVOffset(std::atoi(
currentSkin->propertyValue(skinCtrl, Surge::Skin::Component::TEXT_VOFFSET, "0")
.c_str()));

hs->setDeactivated(false);
hs->setDeactivatedFn([p]() { return p->appears_deactivated(); });

auto ff = currentSkin->propertyValue(skinCtrl, Surge::Skin::Component::FONT_FAMILY, "");
auto fs = std::atoi(
currentSkin->propertyValue(skinCtrl, Surge::Skin::Component::FONT_SIZE, "9").c_str());

if (fs < 1)
{
fs = 9;
}

if (ff.size() > 0)
{
if (currentSkin->typeFaces.find(ff) != currentSkin->typeFaces.end())
{
hs->setFont(juce::Font(currentSkin->typeFaces[ff]).withPointHeight(fs));
hs->setFontSize(fs);
}
}
else if (fs > 0)
else
{
hs->setFont(Surge::GUI::getFontManager()->getLatoAtSize(fs));
}

hs->setTextHOffset(std::atoi(
currentSkin->propertyValue(skinCtrl, Surge::Skin::Component::TEXT_HOFFSET, "0")
.c_str()));

hs->setTextVOffset(std::atoi(
currentSkin->propertyValue(skinCtrl, Surge::Skin::Component::TEXT_VOFFSET, "0")
.c_str()));

hs->setDeactivated(false);
hs->setDeactivatedFn([p]() { return p->appears_deactivated(); });

if (p->valtype == vt_int || p->valtype == vt_bool)
{
hs->setIsStepped(true);
Expand Down
6 changes: 3 additions & 3 deletions src/surge-xt/gui/overlays/WaveShaperAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ void WaveShaperAnalysis::paint(juce::Graphics &g)
std::ostringstream oss;
oss << std::fixed << std::setprecision(2) << sliderDb;

g.setFont(skin->getFont(Fonts::WaveshaperAnalysis::DriveAmount));
g.setFont(skin->getFont(Fonts::Waveshaper::Preview::DriveAmount));
g.setColour(skin->getColor(Colors::Waveshaper::Preview::Text));
g.drawText(oss.str(), tx, juce::Justification::centred);

tx = tx.translated(0, 12);

g.setFont(skin->getFont(Fonts::WaveshaperAnalysis::DriveLabel));
g.setFont(skin->getFont(Fonts::Waveshaper::Preview::DriveLabel));
g.setColour(skin->getColor(Colors::Waveshaper::Preview::Text));
g.drawText("Drive (dB)", tx, juce::Justification::centred);
}
Expand All @@ -132,7 +132,7 @@ void WaveShaperAnalysis::paint(juce::Graphics &g)
title << "Current: " << wst_names[wstype];

g.setColour(skin->getColor(Colors::Waveshaper::Preview::Text));
g.setFont(skin->getFont(Fonts::WaveshaperAnalysis::Title));
g.setFont(skin->getFont(Fonts::Waveshaper::Preview::Title));
g.drawText(title.str(), txtr, juce::Justification::centred);
}

Expand Down
6 changes: 2 additions & 4 deletions src/surge-xt/gui/widgets/ModulationSourceButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,11 @@ void ModulationSourceButton::paint(juce::Graphics &g)
g.setColour(FillCol);
g.fillRect(fillRect);

auto btnFont = Surge::GUI::getFontManager()->getLatoAtSize(8, juce::Font::bold);

if (!isMeta)
{
// modbutton name settings
g.setColour(FontCol);
g.setFont(btnFont);
g.setFont(font);

// modbutton name
g.drawText(getCurrentModLabel(), getLocalBounds(), juce::Justification::centred);
Expand All @@ -187,7 +185,7 @@ void ModulationSourceButton::paint(juce::Graphics &g)
auto topRect = getLocalBounds().withHeight(splitHeight);

g.setColour(FontCol);
g.setFont(btnFont);
g.setFont(font);
g.drawText(getCurrentModLabel(), topRect, juce::Justification::centred);

// macro slider area
Expand Down
8 changes: 8 additions & 0 deletions src/surge-xt/gui/widgets/ModulationSourceButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ struct ModulationSourceButton : public juce::Component,
repaint();
}

juce::Font font;

void setFont(const juce::Font &f)
{
font = f;
repaint();
}

bool isHovered{false};

void mouseEnter(const juce::MouseEvent &event) override;
Expand Down

0 comments on commit 32db2d8

Please sign in to comment.