From 952217b6b0f6c07c79c16cc84590520ca13a8a1f Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 28 Sep 2024 09:56:45 -0400 Subject: [PATCH] (int)getStringWidth -> getStringWidthInt (#7804) Sigh. --- .../code_utils/fix_string_width.pl | 3 ++- src/surge-xt/gui/SurgeJUCELookAndFeel.cpp | 6 +++--- src/surge-xt/gui/overlays/AboutScreen.cpp | 4 ++-- src/surge-xt/gui/overlays/FilterAnalysis.cpp | 4 ++-- src/surge-xt/gui/overlays/MSEGEditor.cpp | 4 ++-- src/surge-xt/gui/overlays/Oscilloscope.cpp | 6 +++--- src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp | 2 +- .../gui/widgets/MenuCustomComponents.cpp | 2 +- .../gui/widgets/ParameterInfowindow.cpp | 18 +++++++++--------- 9 files changed, 25 insertions(+), 24 deletions(-) rename fix_string_width.pl => scripts/code_utils/fix_string_width.pl (75%) diff --git a/fix_string_width.pl b/scripts/code_utils/fix_string_width.pl similarity index 75% rename from fix_string_width.pl rename to scripts/code_utils/fix_string_width.pl index 088ffd456b2..27bfffee3a6 100644 --- a/fix_string_width.pl +++ b/scripts/code_utils/fix_string_width.pl @@ -26,7 +26,8 @@ sub findfiles if (m/getStringWidth/) { print; - s/([^\s\{]+).getStringWidthFloat\(/juce::GlyphArrangement::getStringWidth\($1, /; + # s/([^\s\{]+).getStringWidthFloat\(/juce::GlyphArrangement::getStringWidth\($1, /; + s/\(int\)juce::GlyphArrangement::getStringWidth/juce::GlyphArrangement::getStringWidthInt/; print; #die; } diff --git a/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp b/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp index f532f683bfe..19d3ba18beb 100644 --- a/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp +++ b/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp @@ -146,7 +146,7 @@ void SurgeJUCELookAndFeel::drawLabel(Graphics &graphics, Label &label) int SurgeJUCELookAndFeel::getTabButtonBestWidth(TabBarButton &b, int d) { auto f = skin->getFont(Fonts::Widgets::TabButtonFont); - auto r = (int)juce::GlyphArrangement::getStringWidth(f, b.getButtonText()) + 20; + auto r = juce::GlyphArrangement::getStringWidthInt(f, b.getButtonText()) + 20; return r; } @@ -238,8 +238,8 @@ void SurgeJUCELookAndFeel::drawDocumentWindowTitleBar(DocumentWindow &window, Gr fontVersion = fontSurge; } - auto sw = (int)juce::GlyphArrangement::getStringWidth(fontSurge, surgeLabel); - auto vw = (int)juce::GlyphArrangement::getStringWidth(fontVersion, surgeVersion); + auto sw = juce::GlyphArrangement::getStringWidthInt(fontSurge, surgeLabel); + auto vw = juce::GlyphArrangement::getStringWidthInt(fontVersion, surgeVersion); auto icon = associatedBitmapStore->getImage(IDB_SURGE_ICON); diff --git a/src/surge-xt/gui/overlays/AboutScreen.cpp b/src/surge-xt/gui/overlays/AboutScreen.cpp index f973e19f4db..d54128e75d3 100644 --- a/src/surge-xt/gui/overlays/AboutScreen.cpp +++ b/src/surge-xt/gui/overlays/AboutScreen.cpp @@ -302,7 +302,7 @@ void AboutScreen::resized() lb->setColour(juce::Label::textColourId, skin->getColor(Colors::AboutPage::Link)); lb->setText(std::get<1>(l), juce::NotificationType::dontSendNotification); - auto strw = (int)juce::GlyphArrangement::getStringWidth(font, std::get<1>(l)) + 8; + auto strw = juce::GlyphArrangement::getStringWidthInt(font, std::get<1>(l)) + 8; lb->setBounds(margin + colW, h0, strw, lHeight); addAndMakeVisible(*lb); @@ -344,7 +344,7 @@ void AboutScreen::resized() lb->setColour(juce::Label::textColourId, skin->getColor(Colors::AboutPage::Link)); lb->setText(std::get<1>(l), juce::NotificationType::dontSendNotification); - auto strw = (int)juce::GlyphArrangement::getStringWidth(font, std::get<1>(l)) + 8; + auto strw = juce::GlyphArrangement::getStringWidthInt(font, std::get<1>(l)) + 8; lb->setBounds(rightSide + colW, h1, strw, lHeight); addAndMakeVisible(*lb); diff --git a/src/surge-xt/gui/overlays/FilterAnalysis.cpp b/src/surge-xt/gui/overlays/FilterAnalysis.cpp index f825d68acbb..0ab8f6671f7 100644 --- a/src/surge-xt/gui/overlays/FilterAnalysis.cpp +++ b/src/surge-xt/gui/overlays/FilterAnalysis.cpp @@ -220,7 +220,7 @@ void FilterAnalysis::paint(juce::Graphics &g) const auto freqString = juce::String(over1000 ? freq / 1000.f : freq) + (over1000 ? "k" : ""); const auto labelRect = - juce::Rectangle{(int)juce::GlyphArrangement::getStringWidth(font, freqString), + juce::Rectangle{juce::GlyphArrangement::getStringWidthInt(font, freqString), labelHeight} .withBottomY(height - 2) .withRightX((int)xPos); @@ -248,7 +248,7 @@ void FilterAnalysis::paint(juce::Graphics &g) const auto dbString = juce::String(dB) + " dB"; const auto labelRect = - juce::Rectangle{(int)juce::GlyphArrangement::getStringWidth(font, dbString), + juce::Rectangle{juce::GlyphArrangement::getStringWidthInt(font, dbString), labelHeight} .withBottomY((int)yPos) .withRightX(width - 2); diff --git a/src/surge-xt/gui/overlays/MSEGEditor.cpp b/src/surge-xt/gui/overlays/MSEGEditor.cpp index fc2f989bf3b..ad9d5e10ff5 100644 --- a/src/surge-xt/gui/overlays/MSEGEditor.cpp +++ b/src/surge-xt/gui/overlays/MSEGEditor.cpp @@ -1553,8 +1553,8 @@ struct MSEGCanvas : public juce::Component, public Surge::GUI::SkinConsumingComp std::string txt = fmt::format("X: {:.{}f}", pxt(cx), prec), txt2 = fmt::format("Y: {:.{}f}", val, prec); - int sw1 = (int)juce::GlyphArrangement::getStringWidth(g.getCurrentFont(), txt), - sw2 = (int)juce::GlyphArrangement::getStringWidth(g.getCurrentFont(), txt2); + int sw1 = juce::GlyphArrangement::getStringWidthInt(g.getCurrentFont(), txt), + sw2 = juce::GlyphArrangement::getStringWidthInt(g.getCurrentFont(), txt2); float dragX = r.getRight(), dragY = r.getBottom(); float dragW = 6 + std::max(sw1, sw2), dragH = 22; diff --git a/src/surge-xt/gui/overlays/Oscilloscope.cpp b/src/surge-xt/gui/overlays/Oscilloscope.cpp index b9938024775..b0392c31847 100644 --- a/src/surge-xt/gui/overlays/Oscilloscope.cpp +++ b/src/surge-xt/gui/overlays/Oscilloscope.cpp @@ -1499,7 +1499,7 @@ void Oscilloscope::Background::paintSpectrumBackground(juce::Graphics &g) juce::String(over1000 ? freq / 1000.f : freq) + (over1000 ? "k" : ""); // Label will go past the end of the scopeRect. const auto labelRect = - juce::Rectangle{(int)juce::GlyphArrangement::getStringWidth(font, freqString), + juce::Rectangle{juce::GlyphArrangement::getStringWidthInt(font, freqString), labelHeight} .withCentre(juce::Point(xPos, height + 10)); @@ -1543,7 +1543,7 @@ void Oscilloscope::Background::paintSpectrumBackground(juce::Graphics &g) // Label will go past the end of the scopeRect. const auto labelRect = - juce::Rectangle{(int)juce::GlyphArrangement::getStringWidth(font, dbString), + juce::Rectangle{juce::GlyphArrangement::getStringWidthInt(font, dbString), labelHeight} .withBottomY((int)(yPos + (labelHeight / 2)) + 1) .withRightX(width + 32); @@ -1657,7 +1657,7 @@ void Oscilloscope::Background::paintWaveformBackground(juce::Graphics &g) } // Label will go past the end of the scopeRect. - auto labelWidth = (int)juce::GlyphArrangement::getStringWidth(font, timeString); + auto labelWidth = juce::GlyphArrangement::getStringWidthInt(font, timeString); auto labelRect = juce::Rectangle{labelWidth, labelHeight}.withCentre( juce::Point(xPos, height + 10)); auto justify = juce::Justification::bottom; diff --git a/src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp b/src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp index bd1657537a8..3d5c16358e0 100644 --- a/src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp +++ b/src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp @@ -1390,7 +1390,7 @@ void LFOAndStepDisplay::paintStepSeq(juce::Graphics &g) std::string txt = fmt::format("{:.{}f} %", ss->steps[draggedStep] * 100.f, prec); - int sw = (int)juce::GlyphArrangement::getStringWidth(g.getCurrentFont(), txt); + int sw = juce::GlyphArrangement::getStringWidthInt(g.getCurrentFont(), txt); auto sr = steprect[draggedStep]; diff --git a/src/surge-xt/gui/widgets/MenuCustomComponents.cpp b/src/surge-xt/gui/widgets/MenuCustomComponents.cpp index dbddff9a462..58c9fa26b92 100644 --- a/src/surge-xt/gui/widgets/MenuCustomComponents.cpp +++ b/src/surge-xt/gui/widgets/MenuCustomComponents.cpp @@ -96,7 +96,7 @@ void MenuTitleHelpComponent::getIdealSize(int &idealWidth, int &idealHeight) idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : std::round(font.getHeight() * 1.3f); - idealWidth = (int)juce::GlyphArrangement::getStringWidth(font, label) + idealHeight * 2; + idealWidth = juce::GlyphArrangement::getStringWidthInt(font, label) + idealHeight * 2; idealWidth += 20; } diff --git a/src/surge-xt/gui/widgets/ParameterInfowindow.cpp b/src/surge-xt/gui/widgets/ParameterInfowindow.cpp index c626aec7282..7cda0d1a462 100644 --- a/src/surge-xt/gui/widgets/ParameterInfowindow.cpp +++ b/src/surge-xt/gui/widgets/ParameterInfowindow.cpp @@ -131,9 +131,9 @@ void ParameterInfowindow::setBoundsToAccompany(const juce::Rectangle &contr if (name.empty()) { - auto sl1 = (int)juce::GlyphArrangement::getStringWidth(font, display); - auto sl2 = (int)juce::GlyphArrangement::getStringWidth(font, displayAlt); - auto pad = (int)juce::GlyphArrangement::getStringWidth(font, " "); + auto sl1 = juce::GlyphArrangement::getStringWidthInt(font, display); + auto sl2 = juce::GlyphArrangement::getStringWidthInt(font, displayAlt); + auto pad = juce::GlyphArrangement::getStringWidthInt(font, " "); desiredWidth = std::max(sl1 + sl2 + pad, desiredWidth); } else @@ -144,17 +144,17 @@ void ParameterInfowindow::setBoundsToAccompany(const juce::Rectangle &contr { lheight = font.getHeight() * 3 + 11; // row 2 - auto r1l = (int)juce::GlyphArrangement::getStringWidth(font, name); - auto r2l = (int)juce::GlyphArrangement::getStringWidth( + auto r1l = juce::GlyphArrangement::getStringWidthInt(font, name); + auto r2l = juce::GlyphArrangement::getStringWidthInt( font, mdiws.dvalminus + " " + mdiws.val + " " + mdiws.dvalplus); - auto r3l = (int)juce::GlyphArrangement::getStringWidth(font, mdiws.valminus + " " + - mdiws.valplus); + auto r3l = juce::GlyphArrangement::getStringWidthInt(font, mdiws.valminus + " " + + mdiws.valplus); desiredWidth = std::max(std::max(std::max(r1l, r2l), r3l) + 8, desiredWidth); } else { - auto sln = (int)juce::GlyphArrangement::getStringWidth(font, name); - auto sl1 = (int)juce::GlyphArrangement::getStringWidth(font, display); + auto sln = juce::GlyphArrangement::getStringWidthInt(font, name); + auto sl1 = juce::GlyphArrangement::getStringWidthInt(font, display); desiredWidth = std::max(std::max(sln, sl1) + 8, desiredWidth); lheight = font.getHeight() * 2 + 9; }