From 811fae7925e07dcd34f76259bac42cf3b8c7ad22 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 5 Jul 2021 20:42:17 -0400 Subject: [PATCH] Add an endHover explicit method and call it (#4720) This results in popup menus calling endHover at selection and thus making the menu-at-hover go away if we implement endHover on all our components prolerly which I think I have Closes #4487 --- src/gui/SurgeGUICallbackInterfaces.h | 2 ++ src/gui/SurgeGUIEditorValueCallbacks.cpp | 11 +++++++---- src/gui/widgets/EffectChooser.h | 5 +++++ src/gui/widgets/MenuForDiscreteParams.h | 5 +++++ src/gui/widgets/ModulatableSlider.cpp | 5 ++++- src/gui/widgets/ModulatableSlider.h | 1 + src/gui/widgets/ModulationSourceButton.cpp | 4 +++- src/gui/widgets/ModulationSourceButton.h | 1 + src/gui/widgets/MultiSwitch.cpp | 9 ++++++--- src/gui/widgets/MultiSwitch.h | 2 ++ src/gui/widgets/NumberField.h | 5 +++++ src/gui/widgets/Switch.h | 5 +++++ 12 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/gui/SurgeGUICallbackInterfaces.h b/src/gui/SurgeGUICallbackInterfaces.h index 13eff74af69..5548c6cdee0 100644 --- a/src/gui/SurgeGUICallbackInterfaces.h +++ b/src/gui/SurgeGUICallbackInterfaces.h @@ -26,6 +26,8 @@ struct IComponentTagValue virtual float getValue() const = 0; virtual void setValue(float) = 0; + virtual void endHover() {} + juce::Component *asJuceComponent() { auto r = dynamic_cast(this); diff --git a/src/gui/SurgeGUIEditorValueCallbacks.cpp b/src/gui/SurgeGUIEditorValueCallbacks.cpp index 1fdbf759c47..1e8c2bdfc78 100644 --- a/src/gui/SurgeGUIEditorValueCallbacks.cpp +++ b/src/gui/SurgeGUIEditorValueCallbacks.cpp @@ -195,7 +195,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c } juce::Point cwhere = control->asJuceComponent()->getBounds().getBottomLeft(); - contextMenu.showMenuAsync(optionsForPosition(cwhere)); + contextMenu.showMenuAsync(optionsForPosition(cwhere), + [control](int i) { control->endHover(); }); return 1; } @@ -245,7 +246,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c }); juce::Point cwhere = control->asJuceComponent()->getBounds().getBottomLeft(); - contextMenu.showMenuAsync(optionsForPosition(cwhere)); + contextMenu.showMenuAsync(optionsForPosition(cwhere), + [control](int i) { control->endHover(); }); return 1; } @@ -775,7 +777,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c // FIXME: This one shouldn't be async yet since the macro can get swept underneath us contextMenu.showMenu(juce::PopupMenu::Options()); - + control->endHover(); return 1; } @@ -1952,7 +1954,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c } } - contextMenu.showMenuAsync(juce::PopupMenu::Options()); + contextMenu.showMenuAsync(juce::PopupMenu::Options(), + [control](int i) { control->endHover(); }); return 1; } diff --git a/src/gui/widgets/EffectChooser.h b/src/gui/widgets/EffectChooser.h index 5e7ffc194fd..761a71ccd51 100644 --- a/src/gui/widgets/EffectChooser.h +++ b/src/gui/widgets/EffectChooser.h @@ -68,6 +68,11 @@ struct EffectChooser : public juce::Component, public WidgetBaseMixin mouseDownOrigin; bool isDraggingGlyph{false}; float lastDragDistance{0}; diff --git a/src/gui/widgets/ModulatableSlider.cpp b/src/gui/widgets/ModulatableSlider.cpp index 6cc1943f7d1..0942ebbf0ea 100644 --- a/src/gui/widgets/ModulatableSlider.cpp +++ b/src/gui/widgets/ModulatableSlider.cpp @@ -297,7 +297,9 @@ void ModulatableSlider::mouseEnter(const juce::MouseEvent &event) } } -void ModulatableSlider::mouseExit(const juce::MouseEvent &event) +void ModulatableSlider::mouseExit(const juce::MouseEvent &event) { endHover(); } + +void ModulatableSlider::endHover() { isHovered = false; auto sge = firstListenerOfType(); @@ -305,6 +307,7 @@ void ModulatableSlider::mouseExit(const juce::MouseEvent &event) { sge->sliderHoverEnd(getTag()); } + repaint(); } void ModulatableSlider::mouseDrag(const juce::MouseEvent &event) diff --git a/src/gui/widgets/ModulatableSlider.h b/src/gui/widgets/ModulatableSlider.h index 365be2694d0..c8c617b9aa7 100644 --- a/src/gui/widgets/ModulatableSlider.h +++ b/src/gui/widgets/ModulatableSlider.h @@ -77,6 +77,7 @@ struct ModulatableSlider : public juce::Component, void mouseDoubleClick(const juce::MouseEvent &event) override; void mouseWheelMove(const juce::MouseEvent &event, const juce::MouseWheelDetails &wheel) override; + void endHover() override; SurgeStorage *storage{nullptr}; void setStorage(SurgeStorage *s) { storage = s; } diff --git a/src/gui/widgets/ModulationSourceButton.cpp b/src/gui/widgets/ModulationSourceButton.cpp index e66ae7b0e55..1e5e7c82873 100644 --- a/src/gui/widgets/ModulationSourceButton.cpp +++ b/src/gui/widgets/ModulationSourceButton.cpp @@ -305,7 +305,9 @@ void ModulationSourceButton::mouseEnter(const juce::MouseEvent &event) repaint(); } -void ModulationSourceButton::mouseExit(const juce::MouseEvent &event) +void ModulationSourceButton::mouseExit(const juce::MouseEvent &event) { endHover(); } + +void ModulationSourceButton::endHover() { isHovered = false; repaint(); diff --git a/src/gui/widgets/ModulationSourceButton.h b/src/gui/widgets/ModulationSourceButton.h index 365c40b9e28..9eec7296878 100644 --- a/src/gui/widgets/ModulationSourceButton.h +++ b/src/gui/widgets/ModulationSourceButton.h @@ -93,6 +93,7 @@ struct ModulationSourceButton : public juce::Component, void mouseEnter(const juce::MouseEvent &event) override; void mouseExit(const juce::MouseEvent &event) override; + void endHover() override; void onSkinChanged() override; diff --git a/src/gui/widgets/MultiSwitch.cpp b/src/gui/widgets/MultiSwitch.cpp index d1caec26cf0..9316619b661 100644 --- a/src/gui/widgets/MultiSwitch.cpp +++ b/src/gui/widgets/MultiSwitch.cpp @@ -77,8 +77,6 @@ void MultiSwitch::mouseDown(const juce::MouseEvent &event) { if (event.mods.isPopupMenu()) { - isHovered = false; - repaint(); notifyControlModifierClicked(event.mods); return; } @@ -114,7 +112,12 @@ void MultiSwitch::mouseEnter(const juce::MouseEvent &event) hoverSelection = coordinateToSelection(event.x, event.y); isHovered = true; } -void MultiSwitch::mouseExit(const juce::MouseEvent &event) { isHovered = false; } +void MultiSwitch::mouseExit(const juce::MouseEvent &event) { endHover(); } +void MultiSwitch::endHover() +{ + isHovered = false; + repaint(); +} void MultiSwitch::mouseWheelMove(const juce::MouseEvent &event, const juce::MouseWheelDetails &wheel) { diff --git a/src/gui/widgets/MultiSwitch.h b/src/gui/widgets/MultiSwitch.h index 341f9e5322c..3da2ce6086d 100644 --- a/src/gui/widgets/MultiSwitch.h +++ b/src/gui/widgets/MultiSwitch.h @@ -66,6 +66,8 @@ struct MultiSwitch : public juce::Component, public WidgetBaseMixin void mouseMove(const juce::MouseEvent &event) override; void mouseDrag(const juce::MouseEvent &event) override; + void endHover() override; + Surge::GUI::WheelAccumulationHelper wheelHelper; void mouseWheelMove(const juce::MouseEvent &event, const juce::MouseWheelDetails &wheel) override; diff --git a/src/gui/widgets/NumberField.h b/src/gui/widgets/NumberField.h index 784f91ec1f9..8285d7e36dc 100644 --- a/src/gui/widgets/NumberField.h +++ b/src/gui/widgets/NumberField.h @@ -102,6 +102,11 @@ struct NumberField : public juce::Component, public WidgetBaseMixin setMouseCursor(juce::MouseCursor::NormalCursor); repaint(); } + void endHover() override + { + isHover = false; + repaint(); + } juce::Colour textColour, textHoverColour; void setTextColour(juce::Colour c) diff --git a/src/gui/widgets/Switch.h b/src/gui/widgets/Switch.h index 92246e6df76..b58989e7d14 100644 --- a/src/gui/widgets/Switch.h +++ b/src/gui/widgets/Switch.h @@ -68,6 +68,11 @@ struct Switch : public juce::Component, public WidgetBaseMixin void mouseDown(const juce::MouseEvent &event) override; void mouseEnter(const juce::MouseEvent &event) override; void mouseExit(const juce::MouseEvent &event) override; + void endHover() override + { + isHovered = false; + repaint(); + } Surge::GUI::WheelAccumulationHelper wheelHelper; void mouseWheelMove(const juce::MouseEvent &event,