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 02628e10623400d11a5edf59d96a357a72967461
parent 540253c5fdd0866172c1dcdaf6da54fb6b6047cb
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Mon, 14 Mar 2022 20:41:50 +0100

add support for text buttons & labels

Diffstat:
Msource/jucePlugin/CMakeLists.txt | 2++
Msource/jucePlugin/genericUI/comboboxStyle.cpp | 21---------------------
Msource/jucePlugin/genericUI/comboboxStyle.h | 3---
Asource/jucePlugin/genericUI/labelStyle.cpp | 11+++++++++++
Asource/jucePlugin/genericUI/labelStyle.h | 12++++++++++++
Asource/jucePlugin/genericUI/textbuttonStyle.cpp | 15+++++++++++++++
Asource/jucePlugin/genericUI/textbuttonStyle.h | 13+++++++++++++
Msource/jucePlugin/genericUI/uiObject.cpp | 36++++++++++++++++++++++++++++++++++++
Msource/jucePlugin/genericUI/uiObject.h | 4++++
Msource/jucePlugin/genericUI/uiObjectStyle.cpp | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msource/jucePlugin/genericUI/uiObjectStyle.h | 10++++++++++
11 files changed, 168 insertions(+), 24 deletions(-)

diff --git a/source/jucePlugin/CMakeLists.txt b/source/jucePlugin/CMakeLists.txt @@ -79,6 +79,8 @@ set(SOURCES_GENERICUI genericUI/rotaryStyle.cpp genericUI/rotaryStyle.h genericUI/comboboxStyle.cpp genericUI/comboboxStyle.h genericUI/buttonStyle.cpp genericUI/buttonStyle.h + genericUI/labelStyle.cpp genericUI/labelStyle.h + genericUI/textbuttonStyle.cpp genericUI/textbuttonStyle.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,27 +2,6 @@ namespace genericUI { - juce::Font ComboboxStyle::getComboBoxFont(juce::ComboBox& _comboBox) - { - auto font = UiObjectStyle::getComboBoxFont(_comboBox); - applyFontProperties(font); - return font; - } - - juce::Font ComboboxStyle::getLabelFont(juce::Label& _label) - { - auto font = UiObjectStyle::getLabelFont(_label); - applyFontProperties(font); - return font; - } - - juce::Font ComboboxStyle::getPopupMenuFont() - { - auto font = UiObjectStyle::getPopupMenuFont(); - applyFontProperties(font); - return font; - } - 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,9 +6,6 @@ namespace genericUI { class ComboboxStyle : public UiObjectStyle { - juce::Font getComboBoxFont(juce::ComboBox&) override; - juce::Font getLabelFont(juce::Label&) override; - juce::Font getPopupMenuFont() override; 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/labelStyle.cpp b/source/jucePlugin/genericUI/labelStyle.cpp @@ -0,0 +1,11 @@ +#include "labelStyle.h" + +namespace genericUI +{ + void LabelStyle::apply(juce::Label& _target) const + { + _target.setColour(juce::Label::ColourIds::textColourId, m_color); + _target.setText(m_text, juce::dontSendNotification); + _target.setJustificationType(m_align); + } +} diff --git a/source/jucePlugin/genericUI/labelStyle.h b/source/jucePlugin/genericUI/labelStyle.h @@ -0,0 +1,12 @@ +#pragma once + +#include "uiObjectStyle.h" + +namespace genericUI +{ + class LabelStyle : public UiObjectStyle + { + public: + void apply(juce::Label& _target) const; + }; +} diff --git a/source/jucePlugin/genericUI/textbuttonStyle.cpp b/source/jucePlugin/genericUI/textbuttonStyle.cpp @@ -0,0 +1,15 @@ +#include "textbuttonStyle.h" + +namespace genericUI +{ + void TextButtonStyle::drawButtonBackground(juce::Graphics& _graphics, juce::Button& _button, const juce::Colour& backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) + { + } + + void TextButtonStyle::apply(juce::TextButton& _target) const + { + _target.setColour(juce::TextButton::ColourIds::textColourOffId, m_color); + _target.setColour(juce::TextButton::ColourIds::textColourOnId, m_color); + _target.setButtonText(m_text); + } +} diff --git a/source/jucePlugin/genericUI/textbuttonStyle.h b/source/jucePlugin/genericUI/textbuttonStyle.h @@ -0,0 +1,13 @@ +#pragma once + +#include "uiObjectStyle.h" + +namespace genericUI +{ + class TextButtonStyle : public UiObjectStyle + { + void drawButtonBackground(juce::Graphics&, juce::Button&, const juce::Colour& backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override; + public: + void apply(juce::TextButton& _target) const; + }; +} diff --git a/source/jucePlugin/genericUI/uiObject.cpp b/source/jucePlugin/genericUI/uiObject.cpp @@ -10,6 +10,8 @@ #include "rotaryStyle.h" #include "comboboxStyle.h" #include "buttonStyle.h" +#include "textbuttonStyle.h" +#include "labelStyle.h" #include "../VirusController.h" #include "../VirusParameterBinding.h" @@ -92,6 +94,22 @@ namespace genericUI bindParameter(_editor, _target); } + void UiObject::apply(Editor& _editor, juce::Label& _target) + { + apply(_editor, static_cast<juce::Component&>(_target)); + auto* s = new LabelStyle(); + createStyle(_editor, _target, s); + s->apply(_target); + } + + void UiObject::apply(Editor& _editor, juce::TextButton& _target) + { + apply(_editor, static_cast<juce::Component&>(_target)); + auto* s = new TextButtonStyle(); + 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); @@ -140,6 +158,24 @@ namespace genericUI apply(_editor, *c); m_juceObjects.emplace_back(std::move(c)); } + else if(hasComponent("textbutton")) + { + auto c = std::make_unique<juce::TextButton>(m_name); + apply(_editor, *c); + m_juceObjects.emplace_back(std::move(c)); + } + else if(hasComponent("label")) + { + auto c = std::make_unique<juce::Label>(m_name); + apply(_editor, *c); + m_juceObjects.emplace_back(std::move(c)); + } + else if(hasComponent("component")) + { + auto c = std::make_unique<juce::Component>(); + apply(_editor, *c); + m_juceObjects.emplace_back(std::move(c)); + } else assert(false && "unknown object type"); diff --git a/source/jucePlugin/genericUI/uiObject.h b/source/jucePlugin/genericUI/uiObject.h @@ -8,6 +8,8 @@ namespace juce { + class TextButton; + class Label; class DrawableButton; class ComboBox; class LookAndFeel_V4; @@ -36,6 +38,8 @@ namespace genericUI void apply(Editor& _editor, juce::Slider& _target); void apply(Editor& _editor, juce::ComboBox& _target); void apply(Editor& _editor, juce::DrawableButton& _target); + void apply(Editor& _editor, juce::Label& _target); + void apply(Editor& _editor, juce::TextButton& _target); void collectVariants(std::set<std::string>& _dst, const std::string& _property) const; diff --git a/source/jucePlugin/genericUI/uiObjectStyle.cpp b/source/jucePlugin/genericUI/uiObjectStyle.cpp @@ -5,6 +5,8 @@ namespace genericUI { + UiObjectStyle::UiObjectStyle() = default; + void UiObjectStyle::setTileSize(int _w, int _h) { m_tileSizeX = _w; @@ -33,6 +35,69 @@ namespace genericUI setDrawable(_editor.getImageDrawable(tex)); setTextHeight(_object.getPropertyInt("textHeight")); + + m_text = _object.getProperty("text"); + const auto color = _object.getProperty("color"); + + if(color.size() == 8) + { + uint32_t r,g,b,a; + sscanf(color.c_str(), "%02x%02x%02x%02x", &r, &g, &b, &a); + m_color = juce::Colour(static_cast<uint8_t>(r), static_cast<uint8_t>(g), static_cast<uint8_t>(b), static_cast<uint8_t>(a)); + } + + const auto alignH = _object.getProperty("alignH"); + if(!alignH.empty()) + { + juce::Justification a = 0; + switch (alignH[0]) + { + case 'L': a = juce::Justification::left; break; + case 'C': a = juce::Justification::horizontallyCentred; break; + case 'R': a = juce::Justification::right; break; + } + m_align = a; + } + const auto alignV = _object.getProperty("alignH"); + if(!alignV.empty()) + { + juce::Justification a = 0; + switch (alignV[0]) + { + case 'T': a = juce::Justification::top; break; + case 'C': a = juce::Justification::verticallyCentred; break; + case 'B': a = juce::Justification::bottom; break; + } + m_align = m_align.getFlags() | a.getFlags(); + } + } + + juce::Font UiObjectStyle::getComboBoxFont(juce::ComboBox& _comboBox) + { + auto font = LookAndFeel_V4::getComboBoxFont(_comboBox); + applyFontProperties(font); + return font; + } + + juce::Font UiObjectStyle::getLabelFont(juce::Label& _label) + { + auto font = LookAndFeel_V4::getLabelFont(_label); + applyFontProperties(font); + return font; + } + + juce::Font UiObjectStyle::getPopupMenuFont() + { + auto font = LookAndFeel_V4::getPopupMenuFont(); + applyFontProperties(font); + return font; + } + + juce::Font UiObjectStyle::getTextButtonFont(juce::TextButton& _textButton, int buttonHeight) + { + auto font = LookAndFeel_V4::getTextButtonFont(_textButton, buttonHeight); + applyFontProperties(font); + return font; } void UiObjectStyle::applyFontProperties(juce::Font& _font) const diff --git a/source/jucePlugin/genericUI/uiObjectStyle.h b/source/jucePlugin/genericUI/uiObjectStyle.h @@ -10,6 +10,8 @@ namespace genericUI class UiObjectStyle : public juce::LookAndFeel_V4 { public: + UiObjectStyle(); + void setTileSize(int _w, int _h); void setDrawable(juce::Drawable* _drawable); void setTextHeight(int _height); @@ -17,11 +19,19 @@ namespace genericUI virtual void apply(Editor& _editor, const UiObject& _object); protected: + juce::Font getComboBoxFont(juce::ComboBox&) override; + juce::Font getLabelFont(juce::Label&) override; + juce::Font getPopupMenuFont() override; + juce::Font getTextButtonFont(juce::TextButton&, int buttonHeight) override; + void applyFontProperties(juce::Font& _font) const; int m_tileSizeX = 0; int m_tileSizeY = 0; juce::Drawable* m_drawable = nullptr; int m_textHeight = 0; + std::string m_text; + juce::Colour m_color = juce::Colour(0xffffffff); + juce::Justification m_align = 0; }; }