diff --git a/Source/components/ColourDropdownSelector.cpp b/Source/components/ColourDropdownSelector.cpp index 45dac58..28b697e 100644 --- a/Source/components/ColourDropdownSelector.cpp +++ b/Source/components/ColourDropdownSelector.cpp @@ -69,9 +69,33 @@ void ColourDropdownSelector::setShowPicker(bool show) colourPickerButton->setVisible(show); } +void ColourDropdownSelector::setSelectedColour(juce::Colour newColour, bool setText) +{ + if (!newColour.isOpaque()) + return; // Don't allow transparency + + if (newColour != lastSetColour) + { + lastSetColour = newColour; + selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastSetColour); + } + + if (setText) + { + colourEditorBox->setText(lastSetColour.toDisplayString(false), juce::NotificationType::dontSendNotification); + } + + callbackColourChanged(); +} + void ColourDropdownSelector::setOnValueChangeCallback(std::function callbackIn) { - callback = callbackIn; + callbackColourChanged = callbackIn; +} + +void ColourDropdownSelector::setColourPickerChangedCallback(std::function callback) +{ + callbackPickerChanged = callback; } juce::Array ColourDropdownSelector::getColourOptions() const @@ -88,6 +112,18 @@ juce::Array ColourDropdownSelector::getColourOptions() const void ColourDropdownSelector::colourChangedCallback(ColourSelectionBroadcaster* source, juce::Colour newColour) { // todo + if (pickerIsListening) + { + setSelectedColour(newColour); + + colourPickerButton->setToggleState(false, juce::NotificationType::sendNotification); + pickerIsListening = false; + + colourPickerButton->setColour(juce::TextButton::ColourIds::buttonColourId, newColour); + colourPickerButton->setColour(juce::TextButton::ColourIds::buttonOnColourId, newColour); + + // callbackPickerChanged(); + } } juce::Colour ColourDropdownSelector::getSelectedColour() @@ -145,16 +181,19 @@ void ColourDropdownSelector::valueChangedCallback() selectedColour = juce::Colour::fromString("ff" + colourEditorBox->getText()); } - if (selectedColour != lastSetColour) - { - lastSetColour = selectedColour; - selectorListeners.call(&ColourSelectionListener::colourChangedCallback, this, lastSetColour); - } - - callback(); + setSelectedColour(selectedColour, false); } void ColourDropdownSelector::togglePickerListenForColour(bool listening) { - colourPickerButton->setColour(LumatoneEditorColourIDs::OutlineColourId, juce::Colours::white); + pickerIsListening = listening; + if (pickerIsListening) + { + colourPickerButton->setColour(LumatoneEditorColourIDs::OutlineColourId, juce::Colours::white); + callbackPickerChanged(); + } + else + { + colourPickerButton->setColour(LumatoneEditorColourIDs::OutlineColourId, juce::Colour()); + } } diff --git a/Source/components/ColourDropdownSelector.h b/Source/components/ColourDropdownSelector.h index e39ce43..d2e563b 100644 --- a/Source/components/ColourDropdownSelector.h +++ b/Source/components/ColourDropdownSelector.h @@ -31,7 +31,10 @@ class ColourDropdownSelector : public juce::Component void setShowDropdown(bool show); void setShowPicker(bool show); + void setSelectedColour(juce::Colour newColour, bool setText=true); + void setOnValueChangeCallback(std::function callback); + void setColourPickerChangedCallback(std::function callback); juce::Array getColourOptions() const; @@ -55,8 +58,10 @@ class ColourDropdownSelector : public juce::Component std::unique_ptr colourPickerButton; juce::Colour lastSetColour; + bool pickerIsListening = false; - std::function callback = [](){}; + std::function callbackColourChanged = [](){}; + std::function callbackPickerChanged = [](){}; bool showDropdown = true; bool showPicker = false; diff --git a/Source/mapping_editors/MultiSelectControls.cpp b/Source/mapping_editors/MultiSelectControls.cpp index 3fa387b..e3c2d18 100644 --- a/Source/mapping_editors/MultiSelectControls.cpp +++ b/Source/mapping_editors/MultiSelectControls.cpp @@ -45,6 +45,13 @@ MultiSelectControls::MultiSelectControls(const LumatoneEditorState& stateIn) auto matchingKeyCoords = getMappingData()->getKeysWithProperties(properties); performAction(SetKeySelectionAction::NewSetKeySelectionActionByCoords(*this, matchingKeyCoords)); }); + + addColourSelectionListener(colourDropdown.get()); + colourDropdown->setColourPickerChangedCallback([&]() + { + addColourSelectionListener(colourDropdown.get()); + }); + addAndMakeVisible(colourDropdown.get()); colourDropdown->setShowPicker(true);