From be23a4a79c51c51310df762c0ac573de2b29f8d1 Mon Sep 17 00:00:00 2001 From: zsliu98 Date: Thu, 26 Dec 2024 16:00:58 -0500 Subject: [PATCH] feat(ui setting panel): add colour & control import --- source/gui/interface_definitions.hpp | 2 +- .../two_value_rotary_slider.hpp | 9 +- .../panel/ui_panel/internal_setting_panel.cpp | 176 ++++++++++++------ .../panel/ui_panel/internal_setting_panel.hpp | 38 +++- source/panel/ui_panel/ui_setting_panel.cpp | 6 +- 5 files changed, 154 insertions(+), 77 deletions(-) diff --git a/source/gui/interface_definitions.hpp b/source/gui/interface_definitions.hpp index 354f239..ccbfbb6 100644 --- a/source/gui/interface_definitions.hpp +++ b/source/gui/interface_definitions.hpp @@ -227,7 +227,7 @@ namespace zlInterface { float cornerSize, const fillShadowEllipseArgs &margs) const; - juce::Colour getColourByIdx(colourIdx idx) const { + juce::Colour getColourByIdx(const colourIdx idx) const { return customColours[static_cast(idx)]; } diff --git a/source/gui/slider/two_value_rotary_slider/two_value_rotary_slider.hpp b/source/gui/slider/two_value_rotary_slider/two_value_rotary_slider.hpp index b9b9489..82e8c46 100644 --- a/source/gui/slider/two_value_rotary_slider/two_value_rotary_slider.hpp +++ b/source/gui/slider/two_value_rotary_slider/two_value_rotary_slider.hpp @@ -67,11 +67,6 @@ namespace zlInterface { inline bool getEditable() const { return editable.load(); } - void setMouseDragSensitivity(const int x) { - dragDistance = x; - updateDragDistance(); - } - inline void setFontScale(const float x1, const float x2) { labelLookAndFeel.setFontScale(x1); labelLookAndFeel1.setFontScale(x2); @@ -79,6 +74,10 @@ namespace zlInterface { editorFontScale = x2; } + void lookAndFeelChanged() override { + updateDragDistance(); + } + private: UIBase &uiBase; diff --git a/source/panel/ui_panel/internal_setting_panel.cpp b/source/panel/ui_panel/internal_setting_panel.cpp index 06ee721..04457f6 100644 --- a/source/panel/ui_panel/internal_setting_panel.cpp +++ b/source/panel/ui_panel/internal_setting_panel.cpp @@ -10,17 +10,22 @@ #include "internal_setting_panel.hpp" namespace zlPanel { + static juce::Colour getIntColour(const int r, const int g, const int b, float alpha) { + return { + static_cast(r), + static_cast(g), + static_cast(b), + alpha + }; + } + InternalSettingPanel::InternalSettingPanel(PluginProcessor &p, zlInterface::UIBase &base) : pRef(p), uiBase(base), nameLAF(base), textSelector(base, *this, false, 9.6f, 8.f, .5f, .4f), backgroundSelector(base, *this, false, 9.6f, 8.f, .5f, .4f), shadowSelector(base, *this, false, 9.6f, 8.f, .5f, .4f), - glowSelector(base, *this, false, 9.6f, 8.f, .5f, .4f), - roughWheelSlider("Rough", base), - fineWheelSlider("Fine", base), - rotaryStyleBox("", zlState::rotaryStyle::choices, base), - rotaryDragSensitivitySlider("Distance", base) { + glowSelector(base, *this, false, 9.6f, 8.f, .5f, .4f) { juce::ignoreUnused(pRef); nameLAF.setJustification(juce::Justification::centred); nameLAF.setFontScale(1.f); @@ -30,33 +35,14 @@ namespace zlPanel { addAndMakeVisible(selectorLabels[i]); addAndMakeVisible(selectors[i]); } - wheelLabel.setText("Mouse-Wheel Sensitivity", juce::dontSendNotification); - wheelLabel.setLookAndFeel(&nameLAF); - addAndMakeVisible(wheelLabel); - roughWheelSlider.getSlider().setDoubleClickReturnValue(true, 1.0); - fineWheelSlider.getSlider().setDoubleClickReturnValue(true, 0.1); - for (auto &s: {&roughWheelSlider, &fineWheelSlider}) { - s->getSlider().setRange(0.0, 1.0, 0.01); - s->setFontScale(1.125f, 1.125f); - addAndMakeVisible(s); - } - rotaryStyleLabel.setText("Rotary Slider Style", juce::dontSendNotification); - rotaryStyleLabel.setLookAndFeel(&nameLAF); - addAndMakeVisible(rotaryStyleLabel); - rotaryStyleBox.getLAF().setFontScale(1.125f); - addAndMakeVisible(rotaryStyleBox); - rotaryDragSensitivitySlider.setFontScale(1.125f, 1.125f); - rotaryDragSensitivitySlider.getSlider().setRange(2.0, 32.0, 0.01); - rotaryDragSensitivitySlider.getSlider().setDoubleClickReturnValue(true, 10.0); - addAndMakeVisible(rotaryDragSensitivitySlider); - } - - InternalSettingPanel::~InternalSettingPanel() { - for (size_t i = 0; i < numSelectors; ++i) { - selectorLabels[i].setLookAndFeel(nullptr); - } - wheelLabel.setLookAndFeel(nullptr); - rotaryStyleLabel.setLookAndFeel(nullptr); + colourImportLabel.setText("Import Colours", juce::dontSendNotification); + colourImportLabel.setLookAndFeel(&nameLAF); + colourImportLabel.addMouseListener(this, false); + addAndMakeVisible(colourImportLabel); + controlImportLabel.setText("Import Controls", juce::dontSendNotification); + controlImportLabel.setLookAndFeel(&nameLAF); + controlImportLabel.addMouseListener(this, false); + addAndMakeVisible(controlImportLabel); } void InternalSettingPanel::resized() { @@ -66,51 +52,119 @@ namespace zlPanel { auto localBound = bound.removeFromTop(uiBase.getFontSize() * iHeight); selectorLabels[i].setBounds(localBound.removeFromTop(localBound.getHeight() * .5f).toNearestInt()); selectors[i]->setBounds(localBound.toNearestInt()); - } { + } + { bound.removeFromTop(uiBase.getFontSize() * .5f); - auto localBound = bound.removeFromTop(uiBase.getFontSize() * iHeight); - wheelLabel.setBounds(localBound.removeFromTop(localBound.getHeight() * .5f).toNearestInt()); - const auto sWidth = (bound.getWidth() - uiBase.getFontSize() * 1.f) * 0.45f; - roughWheelSlider.setBounds(localBound.removeFromLeft(sWidth).toNearestInt()); - localBound.removeFromLeft(uiBase.getFontSize() * 1.f); - fineWheelSlider.setBounds(localBound.removeFromLeft(sWidth).toNearestInt()); - } { + const auto localBound = bound.removeFromTop(uiBase.getFontSize() * iHeight * .5f); + colourImportLabel.setBounds(localBound.toNearestInt()); + } + { bound.removeFromTop(uiBase.getFontSize() * .5f); - auto localBound = bound.removeFromTop(uiBase.getFontSize() * iHeight); - rotaryStyleLabel.setBounds(localBound.removeFromTop(localBound.getHeight() * .5f).toNearestInt()); - const auto sWidth = (bound.getWidth() - uiBase.getFontSize() * 1.f) * 0.45f; - rotaryStyleBox.setBounds(localBound.removeFromLeft(sWidth).toNearestInt()); - localBound.removeFromLeft(uiBase.getFontSize() * 1.f); - rotaryDragSensitivitySlider.setBounds(localBound.removeFromLeft(sWidth).toNearestInt()); + const auto localBound = bound.removeFromTop(uiBase.getFontSize() * iHeight * .5f); + controlImportLabel.setBounds(localBound.toNearestInt()); } } void InternalSettingPanel::loadSetting() { for (size_t i = 0; i < numSelectors; ++i) { - selectors[i]->setColour(uiBase.getColourByIdx(static_cast(i))); + selectors[i]->setColour(uiBase.getColourByIdx(colourIdx[i])); } - roughWheelSlider.getSlider().setValue( - static_cast(uiBase.getSensitivity(zlInterface::sensitivityIdx::mouseWheel))); - fineWheelSlider.getSlider().setValue( - static_cast(uiBase.getSensitivity(zlInterface::sensitivityIdx::mouseWheelFine))); - rotaryStyleBox.getBox().setSelectedId(static_cast(uiBase.getRotaryStyleID()) + 1); - rotaryDragSensitivitySlider.getSlider().setValue(static_cast(uiBase.getRotaryDragSensitivity())); } void InternalSettingPanel::saveSetting() { for (size_t i = 0; i < numSelectors; ++i) { - uiBase.setColourByIdx(static_cast(i), selectors[i]->getColour()); + uiBase.setColourByIdx(colourIdx[i], selectors[i]->getColour()); } - uiBase.setSensitivity(static_cast(roughWheelSlider.getSlider().getValue()), - zlInterface::sensitivityIdx::mouseWheel); - uiBase.setSensitivity(static_cast(fineWheelSlider.getSlider().getValue()), - zlInterface::sensitivityIdx::mouseWheelFine); - uiBase.setRotaryStyleID(static_cast(rotaryStyleBox.getBox().getSelectedId() - 1)); - uiBase.setRotaryDragSensitivity(static_cast(rotaryDragSensitivitySlider.getSlider().getValue())); uiBase.saveToAPVTS(); } void InternalSettingPanel::resetSetting() { - loadSetting(); + textSelector.setColour(getIntColour(247, 246, 244, 1.f)); + backgroundSelector.setColour(getIntColour((255 - 214) / 2, (255 - 223) / 2, (255 - 236) / 2, 1.f)); + shadowSelector.setColour(getIntColour(0, 0, 0, 1.f)); + glowSelector.setColour(getIntColour(70, 66, 62, 1.f)); + saveSetting(); + } + + void InternalSettingPanel::mouseDown(const juce::MouseEvent &event) { + if (event.originalComponent == &colourImportLabel) { + importColours(); + } else if (event.originalComponent == &controlImportLabel) { + importControls(); + } + } + + void InternalSettingPanel::importColours() { + myChooser = std::make_unique( + "Load the colour settings...", settingDirectory, "*.xml", + true, false, nullptr); + constexpr auto settingOpenFlags = juce::FileBrowserComponent::openMode | + juce::FileBrowserComponent::canSelectFiles; + myChooser->launchAsync(settingOpenFlags, [this](const juce::FileChooser &chooser) { + if (chooser.getResults().size() <= 0) { return; } + const juce::File settingFile(chooser.getResult()); + if (const auto xmlInput = juce::XmlDocument::parse(settingFile)) { + for (size_t i = 0; i < numSelectors; ++i) { + if (const auto *xmlColour = xmlInput->getChildByName(colourTagNames[i])) { + const juce::Colour colour = getIntColour( + xmlColour->getIntAttribute("r"), + xmlColour->getIntAttribute("g"), + xmlColour->getIntAttribute("b"), + static_cast(xmlColour->getDoubleAttribute("o"))); + uiBase.setColourByIdx(colourIdx[i], colour); + } + } + uiBase.saveToAPVTS(); + loadSetting(); + } + }); + } + + void InternalSettingPanel::importControls() { + myChooser = std::make_unique( + "Load the control settings...", settingDirectory, "*.xml", + true, false, nullptr); + constexpr auto settingOpenFlags = juce::FileBrowserComponent::openMode | + juce::FileBrowserComponent::canSelectFiles; + myChooser->launchAsync(settingOpenFlags, [this](const juce::FileChooser &chooser) { + if (chooser.getResults().size() <= 0) { return; } + const juce::File settingFile(chooser.getResult()); + if (const auto xmlInput = juce::XmlDocument::parse(settingFile)) { + if (const auto *xmlElement = xmlInput->getChildByName("drag_fine_sensitivity")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setSensitivity(static_cast(x), zlInterface::sensitivityIdx::mouseDragFine); + } + if (const auto *xmlElement = xmlInput->getChildByName("drag_sensitivity")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setSensitivity(static_cast(x), zlInterface::sensitivityIdx::mouseDrag); + } + if (const auto *xmlElement = xmlInput->getChildByName("wheel_fine_sensitivity")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setSensitivity(static_cast(x), zlInterface::sensitivityIdx::mouseWheelFine); + } + if (const auto *xmlElement = xmlInput->getChildByName("wheel_sensitivity")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setSensitivity(static_cast(x), zlInterface::sensitivityIdx::mouseWheel); + } + if (const auto *xmlElement = xmlInput->getChildByName("rotary_drag_sensitivity")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setRotaryDragSensitivity(static_cast(x)); + } + if (const auto *xmlElement = xmlInput->getChildByName("rotary_style")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setRotaryStyleID(static_cast(x)); + } + if (const auto *xmlElement = xmlInput->getChildByName("slider_double_click_func")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setIsSliderDoubleClickOpenEditor(x > 0.5); + } + if (const auto *xmlElement = xmlInput->getChildByName("wheel_shift_reverse")) { + const auto x = xmlElement->getDoubleAttribute("value"); + uiBase.setIsMouseWheelShiftReverse(x > 0.5); + } + uiBase.saveToAPVTS(); + loadSetting(); + } + }); } } // zlPanel diff --git a/source/panel/ui_panel/internal_setting_panel.hpp b/source/panel/ui_panel/internal_setting_panel.hpp index 1158f0d..44522c5 100644 --- a/source/panel/ui_panel/internal_setting_panel.hpp +++ b/source/panel/ui_panel/internal_setting_panel.hpp @@ -16,9 +16,9 @@ namespace zlPanel { class InternalSettingPanel final : public juce::Component { public: - explicit InternalSettingPanel(PluginProcessor &p, zlInterface::UIBase &base); + static constexpr float heightP = 28.f; - ~InternalSettingPanel() override; + explicit InternalSettingPanel(PluginProcessor &p, zlInterface::UIBase &base); void loadSetting(); @@ -26,6 +26,8 @@ namespace zlPanel { void resetSetting(); + void mouseDown(const juce::MouseEvent &event) override; + void resized() override; private: @@ -34,11 +36,7 @@ namespace zlPanel { zlInterface::UIBase &uiBase; zlInterface::NameLookAndFeel nameLAF; zlInterface::ColourOpacitySelector textSelector, backgroundSelector, shadowSelector, glowSelector; - juce::Label wheelLabel; - zlInterface::CompactLinearSlider roughWheelSlider, fineWheelSlider; - juce::Label rotaryStyleLabel; - zlInterface::CompactCombobox rotaryStyleBox; - zlInterface::CompactLinearSlider rotaryDragSensitivitySlider; + juce::Label colourImportLabel, controlImportLabel; static constexpr size_t numSelectors = 4; std::array selectorLabels; @@ -54,6 +52,32 @@ namespace zlPanel { "Shadow Colour", "Glow Colour" }; + + std::array colourIdx { + zlInterface::colourIdx::textColour, + zlInterface::colourIdx::backgroundColour, + zlInterface::colourIdx::shadowColour, + zlInterface::colourIdx::glowColour + }; + + std::array colourTagNames{ + "text_colour", + "background_colour", + "shadow_colour", + "glow_colour", + }; + + std::unique_ptr myChooser; + inline auto static const settingDirectory = + juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory) + .getChildFile("Audio") + .getChildFile("Presets") + .getChildFile(JucePlugin_Manufacturer) + .getChildFile("Shared Settings"); + + void importColours(); + + void importControls(); }; } // zlPanel diff --git a/source/panel/ui_panel/ui_setting_panel.cpp b/source/panel/ui_panel/ui_setting_panel.cpp index d060a8f..d6052a3 100644 --- a/source/panel/ui_panel/ui_setting_panel.cpp +++ b/source/panel/ui_panel/ui_setting_panel.cpp @@ -71,9 +71,9 @@ namespace zlPanel { internelPanel.setBounds(0, 0, juce::roundToInt(bound.getWidth()), - juce::roundToInt(bound.getHeight() * 2.55f)); - viewPort.setBounds(bound.removeFromTop(bound.getHeight() * .9125f).toNearestInt()); - const auto iconWidth = std::min(uiBase.getFontSize() * 1.25f, bound.getHeight() * .8f); + juce::roundToInt((InternalSettingPanel::heightP + 1.f) * uiBase.getFontSize())); + viewPort.setBounds(bound.removeFromTop(bound.getHeight() * .9f).toNearestInt()); + const auto iconWidth = bound.getHeight() * .95f; const auto leftBound = bound.removeFromLeft( bound.getWidth() * .3333333f).withSizeKeepingCentre(iconWidth, iconWidth); const auto centerBound = bound.removeFromLeft(