gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit f512241114a63627ebe15ecf877692b7fc7879eb
parent 83a3fcea5faf4ba895957d26dcf145bb5a429aaa
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Tue, 15 Mar 2022 21:04:14 +0100

support tooltips / hyperlink buttons / cleanup

Diffstat:
Msource/jucePlugin/CMakeLists.txt | 1+
Msource/jucePlugin/genericUI/comboboxStyle.cpp | 8++++++--
Msource/jucePlugin/genericUI/comboboxStyle.h | 4++++
Asource/jucePlugin/genericUI/hyperlinkbuttonStyle.cpp | 12++++++++++++
Asource/jucePlugin/genericUI/hyperlinkbuttonStyle.h | 17+++++++++++++++++
Msource/jucePlugin/genericUI/textbuttonStyle.cpp | 2+-
Msource/jucePlugin/genericUI/textbuttonStyle.h | 2+-
Msource/jucePlugin/genericUI/uiObject.cpp | 41++++++++++++++++++++++++++++++++++-------
Msource/jucePlugin/genericUI/uiObject.h | 3+++
Msource/jucePlugin/genericUI/uiObjectStyle.cpp | 1+
Msource/jucePlugin/genericUI/uiObjectStyle.h | 1+
11 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/source/jucePlugin/CMakeLists.txt b/source/jucePlugin/CMakeLists.txt @@ -90,6 +90,7 @@ set(SOURCES_GENERICUI genericUI/buttonStyle.cpp genericUI/buttonStyle.h genericUI/labelStyle.cpp genericUI/labelStyle.h genericUI/textbuttonStyle.cpp genericUI/textbuttonStyle.h + genericUI/hyperlinkbuttonStyle.cpp genericUI/hyperlinkbuttonStyle.h genericUI/uiObject.cpp genericUI/uiObject.h genericUI/uiObjectStyle.cpp genericUI/uiObjectStyle.h diff --git a/source/jucePlugin/genericUI/comboboxStyle.cpp b/source/jucePlugin/genericUI/comboboxStyle.cpp @@ -2,8 +2,12 @@ namespace genericUI { - void ComboboxStyle::drawComboBox(juce::Graphics& _graphics, int width, int height, bool isButtonDown, int buttonX, - int buttonY, int buttonW, int buttonH, juce::ComboBox& _comboBox) + void ComboboxStyle::apply(juce::ComboBox& _target) const + { + _target.setColour(juce::ComboBox::ColourIds::textColourId, m_color); + } + + void ComboboxStyle::drawComboBox(juce::Graphics& _graphics, int width, int height, bool isButtonDown, int buttonX, int buttonY, int buttonW, int buttonH, juce::ComboBox& _comboBox) { } } diff --git a/source/jucePlugin/genericUI/comboboxStyle.h b/source/jucePlugin/genericUI/comboboxStyle.h @@ -6,6 +6,10 @@ namespace genericUI { class ComboboxStyle : public UiObjectStyle { + public: + void apply(juce::ComboBox& _target) const; + + private: void drawComboBox(juce::Graphics&, int width, int height, bool isButtonDown, int buttonX, int buttonY, int buttonW, int buttonH, juce::ComboBox&) override; }; } \ No newline at end of file diff --git a/source/jucePlugin/genericUI/hyperlinkbuttonStyle.cpp b/source/jucePlugin/genericUI/hyperlinkbuttonStyle.cpp @@ -0,0 +1,12 @@ +#include "hyperlinkbuttonStyle.h" + +namespace genericUI +{ + void HyperlinkButtonStyle::apply(juce::HyperlinkButton& _target) const + { + _target.setColour(juce::HyperlinkButton::ColourIds::textColourId, m_color); + _target.setURL(juce::URL(juce::String(m_url))); + + TextButtonStyle::apply(_target); + } +} diff --git a/source/jucePlugin/genericUI/hyperlinkbuttonStyle.h b/source/jucePlugin/genericUI/hyperlinkbuttonStyle.h @@ -0,0 +1,17 @@ +#pragma once + +#include "textbuttonStyle.h" + +namespace juce +{ + class HyperlinkButton; +} + +namespace genericUI +{ + class HyperlinkButtonStyle : public TextButtonStyle + { + public: + void apply(juce::HyperlinkButton& _target) const; + }; +} diff --git a/source/jucePlugin/genericUI/textbuttonStyle.cpp b/source/jucePlugin/genericUI/textbuttonStyle.cpp @@ -6,7 +6,7 @@ namespace genericUI { } - void TextButtonStyle::apply(juce::TextButton& _target) const + void TextButtonStyle::apply(juce::Button& _target) const { _target.setColour(juce::TextButton::ColourIds::textColourOffId, m_color); _target.setColour(juce::TextButton::ColourIds::textColourOnId, m_color); diff --git a/source/jucePlugin/genericUI/textbuttonStyle.h b/source/jucePlugin/genericUI/textbuttonStyle.h @@ -8,6 +8,6 @@ namespace genericUI { void drawButtonBackground(juce::Graphics&, juce::Button&, const juce::Colour& backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override; public: - void apply(juce::TextButton& _target) const; + void apply(juce::Button& _target) const; }; } diff --git a/source/jucePlugin/genericUI/uiObject.cpp b/source/jucePlugin/genericUI/uiObject.cpp @@ -10,6 +10,7 @@ #include "comboboxStyle.h" #include "buttonStyle.h" #include "textbuttonStyle.h" +#include "hyperlinkbuttonStyle.h" #include "labelStyle.h" #include "../VirusController.h" @@ -85,8 +86,10 @@ namespace genericUI void UiObject::apply(Editor& _editor, juce::ComboBox& _target) { apply(_editor, static_cast<juce::Component&>(_target)); - createStyle(_editor, _target, new ComboboxStyle()); + auto* s = new ComboboxStyle(); + createStyle(_editor, _target, s); bindParameter(_editor, _target); + s->apply(_target); } void UiObject::apply(Editor& _editor, juce::DrawableButton& _target) @@ -114,6 +117,14 @@ namespace genericUI s->apply(_target); } + void UiObject::apply(Editor& _editor, juce::HyperlinkButton& _target) + { + apply(_editor, static_cast<juce::Component&>(_target)); + auto* s = new HyperlinkButtonStyle(); + createStyle(_editor, _target, s); + s->apply(_target); + } + void UiObject::collectVariants(std::set<std::string>& _dst, const std::string& _property) const { const std::string res = getProperty(_property); @@ -135,6 +146,7 @@ namespace genericUI } else if(hasComponent("image")) { + // @Juce: Juce does not respect translations on drawables by using setPositionAndSize, even though a Drawable is a component?! Doesn't make sense to me auto* c = createJuceObject<juce::Component>(_editor); auto img = _editor.createImageDrawable(getProperty("texture")); c->addAndMakeVisible(img.get()); @@ -146,11 +158,11 @@ namespace genericUI } else if(hasComponent("button")) { - auto c = std::make_unique<juce::DrawableButton>(m_name, juce::DrawableButton::ImageRaw); - apply(_editor, *c); - if(!m_name.empty()) - _editor.registerComponent(m_name, c.get()); - m_juceObjects.emplace_back(std::move(c)); + createJuceObject(_editor, new juce::DrawableButton(m_name, juce::DrawableButton::ImageRaw)); + } + else if(hasComponent("hyperlinkbutton")) + { + createJuceObject<juce::HyperlinkButton>(_editor); } else if(hasComponent("textbutton")) { @@ -248,7 +260,12 @@ namespace genericUI template <typename T> T* UiObject::createJuceObject(Editor& _editor) { - auto c = std::make_unique<T>(); + return createJuceObject(_editor, new T()); + } + + template <typename T> T* UiObject::createJuceObject(Editor& _editor, T* _object) + { + std::unique_ptr<T> c(_object); apply(_editor, *c); auto* comp = c.get(); m_juceObjects.emplace_back(std::move(c)); @@ -256,6 +273,16 @@ namespace genericUI if(!m_name.empty()) _editor.registerComponent(m_name, comp); + auto* tooltipClient = dynamic_cast<juce::SettableTooltipClient*>(_object); + + if(tooltipClient) + { + const auto tooltip = getProperty("tooltip"); + + if(!tooltip.empty()) + tooltipClient->setTooltip(tooltip); + } + return comp; } diff --git a/source/jucePlugin/genericUI/uiObject.h b/source/jucePlugin/genericUI/uiObject.h @@ -8,6 +8,7 @@ namespace juce { + class HyperlinkButton; class TextButton; class Label; class DrawableButton; @@ -40,6 +41,7 @@ namespace genericUI void apply(Editor& _editor, juce::DrawableButton& _target); void apply(Editor& _editor, juce::Label& _target); void apply(Editor& _editor, juce::TextButton& _target); + void apply(Editor& _editor, juce::HyperlinkButton& _target); void collectVariants(std::set<std::string>& _dst, const std::string& _property) const; @@ -51,6 +53,7 @@ namespace genericUI private: bool hasComponent(const std::string& _component) const; template<typename T> T* createJuceObject(Editor& _editor); + template<typename T> T* createJuceObject(Editor& _editor, T* _object); bool parse(juce::DynamicObject* _obj); diff --git a/source/jucePlugin/genericUI/uiObjectStyle.cpp b/source/jucePlugin/genericUI/uiObjectStyle.cpp @@ -74,6 +74,7 @@ namespace genericUI m_bold = _object.getPropertyInt("bold") != 0; m_italic = _object.getPropertyInt("italic") != 0; + m_url = _object.getProperty("url"); } juce::Font UiObjectStyle::getComboBoxFont(juce::ComboBox& _comboBox) diff --git a/source/jucePlugin/genericUI/uiObjectStyle.h b/source/jucePlugin/genericUI/uiObjectStyle.h @@ -35,5 +35,6 @@ namespace genericUI juce::Justification m_align = 0; bool m_bold = false; bool m_italic = false; + std::string m_url; }; }