From 3df7337cc3807693fb4d81cac9c0e7150f6b3b3a Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 23 May 2021 12:17:48 -0400 Subject: [PATCH] Remove CEffectLabel; Introduce Surge::Widgets::EffectLabel (#4589) Addresses #4587 --- CMakeLists.txt | 1 - .../include/efvg/escape_from_vstgui.h | 2 + src/gui/CEffectLabel.h | 47 ---------------- src/gui/SurgeGUIEditor.cpp | 18 +++++-- src/gui/SurgeGUIEditor.h | 3 ++ src/gui/widgets/EffectLabel.h | 54 +++++++++++++++++++ 6 files changed, 72 insertions(+), 53 deletions(-) delete mode 100644 src/gui/CEffectLabel.h create mode 100644 src/gui/widgets/EffectLabel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b1092ad226e..72f25867600 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,7 +336,6 @@ set(SURGE_GENERATED_SOURCES set(SURGE_GUI_SOURCES src/gui/CAboutBox.cpp - src/gui/CEffectLabel.h src/gui/CEffectSettings.cpp src/gui/CHSwitch2.cpp src/gui/CLFOGui.cpp diff --git a/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h b/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h index 4525bd1457b..ec637ed8cd7 100644 --- a/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h +++ b/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h @@ -393,6 +393,8 @@ struct CColor return red == that.red && green == that.green && blue == that.blue && alpha == that.alpha; } juce::Colour asJuceColour() const { return juce::Colour(red, green, blue, alpha); } + + operator juce::Colour() const { return asJuceColour(); } uint8_t red, green, blue, alpha; }; diff --git a/src/gui/CEffectLabel.h b/src/gui/CEffectLabel.h deleted file mode 100644 index a9914363cd6..00000000000 --- a/src/gui/CEffectLabel.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -** Surge Synthesizer is Free and Open Source Software -** -** Surge is made available under the Gnu General Public License, v3.0 -** https://www.gnu.org/licenses/gpl-3.0.en.html -** -** Copyright 2004-2020 by various individuals as described by the Git transaction log -** -** All source at: https://github.com/surge-synthesizer/surge.git -** -** Surge was a commercial product from 2004-2018, with Copyright and ownership -** in that period held by Claes Johanson at Vember Audio. Claes made Surge -** open source in September 2018. -*/ - -#pragma once -#include "SkinSupport.h" -#include "SkinColors.h" -#include "RuntimeFont.h" - -class CEffectLabel : public VSTGUI::CControl, public Surge::GUI::SkinConsumingComponent -{ - public: - CEffectLabel(const VSTGUI::CRect &size) : VSTGUI::CControl(size, 0, 0, 0) {} - - virtual void draw(VSTGUI::CDrawContext *dc) override - { - VSTGUI::CRect size = getViewSize(); - VSTGUI::CRect bl(size); - bl.top = bl.bottom - 2; - - dc->setFillColor(skin->getColor(Colors::Effect::Label::Separator)); - dc->drawRect(bl, VSTGUI::kDrawFilled); - - dc->setFontColor(skin->getColor(Colors::Effect::Label::Text)); - dc->setFont(Surge::GUI::getFontManager()->displayFont); - dc->drawString(label.c_str(), size, VSTGUI::kLeftText, true); - - setDirty(false); - } - void setLabel(std::string s) { label = s; } - - private: - std::string label; - - CLASS_METHODS(CEffectLabel, VSTGUI::CControl) -}; diff --git a/src/gui/SurgeGUIEditor.cpp b/src/gui/SurgeGUIEditor.cpp index b8d7c087a40..664341a4daa 100644 --- a/src/gui/SurgeGUIEditor.cpp +++ b/src/gui/SurgeGUIEditor.cpp @@ -26,7 +26,6 @@ #include "CEffectSettings.h" #include "CSurgeVuMeter.h" #include "CMenuAsSlider.h" -#include "CEffectLabel.h" #include "CTextButtonWithHover.h" #include "CAboutBox.h" #include "SurgeBitmaps.h" @@ -43,6 +42,7 @@ #include "ModulationEditor.h" #include "LuaEditors.h" +#include "widgets/EffectLabel.h" #include "widgets/Switch.h" #include "widgets/VerticalLabel.h" @@ -1246,10 +1246,18 @@ void SurgeGUIEditor::openOrRecreateEditor() vr.right += 5; vr.offset(5, -12); vr.offset(0, yofs * synth->fx[current_fx]->group_label_ypos(i)); - CEffectLabel *lb = new CEffectLabel(vr); - lb->setLabel(label); - lb->setSkin(currentSkin, bitmapStore); - frame->addView(lb); + if (!effectLabels[i]) + { + effectLabels[i] = std::make_unique(); + } + effectLabels[i]->setBounds(vr.asJuceIntRect()); + effectLabels[i]->setLabel(label); + effectLabels[i]->setSkin(currentSkin, bitmapStore); + frame->juceComponent()->addAndMakeVisible(*effectLabels[i]); + } + else + { + effectLabels[i].reset(nullptr); } } } diff --git a/src/gui/SurgeGUIEditor.h b/src/gui/SurgeGUIEditor.h index 01689248ba1..8b04858ccce 100644 --- a/src/gui/SurgeGUIEditor.h +++ b/src/gui/SurgeGUIEditor.h @@ -48,6 +48,7 @@ namespace Widgets { struct Switch; struct VerticalLabel; +struct EffectLabel; } // namespace Widgets } // namespace Surge @@ -478,6 +479,8 @@ class SurgeGUIEditor : public EditorType, /* * This is the JUCE component management */ + std::array, 15> effectLabels; + std::unordered_map> juceSkinComponents; template diff --git a/src/gui/widgets/EffectLabel.h b/src/gui/widgets/EffectLabel.h new file mode 100644 index 00000000000..23714c5f07b --- /dev/null +++ b/src/gui/widgets/EffectLabel.h @@ -0,0 +1,54 @@ +/* +** Surge Synthesizer is Free and Open Source Software +** +** Surge is made available under the Gnu General Public License, v3.0 +** https://www.gnu.org/licenses/gpl-3.0.en.html +** +** Copyright 2004-2021 by various individuals as described by the Git transaction log +** +** All source at: https://github.com/surge-synthesizer/surge.git +** +** Surge was a commercial product from 2004-2018, with Copyright and ownership +** in that period held by Claes Johanson at Vember Audio. Claes made Surge +** open source in September 2018. +*/ + +#ifndef SURGE_XT_EFFECTLABEL_H +#define SURGE_XT_EFFECTLABEL_H + +#include +#include "SkinSupport.h" +#include "RuntimeFont.h" +#include + +namespace Surge +{ +namespace Widgets +{ +struct EffectLabel : public juce::Component, public Surge::GUI::SkinConsumingComponent +{ + EffectLabel() = default; + ~EffectLabel() = default; + + std::string label; + void setLabel(const std::string &l) + { + label = l; + repaint(); + } + + void paint(juce::Graphics &g) override + { + auto lb = getLocalBounds().withTrimmedTop(getHeight() - 2); + g.setColour(skin->getColor(Colors::Effect::Label::Separator)); + g.fillRect(lb); + + g.setColour(skin->getColor(Colors::Effect::Label::Text)); + g.setFont(Surge::GUI::getFontManager()->displayFont); + g.drawText(label, getLocalBounds(), juce::Justification::centredLeft); + } +}; +} // namespace Widgets +} // namespace Surge + +#endif // SURGE_XT_EFFECTLABEL_H