Skip to content

Commit

Permalink
Add an endHover explicit method and call it (#4720)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
baconpaul authored Jul 6, 2021
1 parent bb6bf26 commit 811fae7
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/gui/SurgeGUICallbackInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<juce::Component *>(this);
Expand Down
11 changes: 7 additions & 4 deletions src/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
}

juce::Point<int> cwhere = control->asJuceComponent()->getBounds().getBottomLeft();
contextMenu.showMenuAsync(optionsForPosition(cwhere));
contextMenu.showMenuAsync(optionsForPosition(cwhere),
[control](int i) { control->endHover(); });

return 1;
}
Expand Down Expand Up @@ -245,7 +246,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
});

juce::Point<int> cwhere = control->asJuceComponent()->getBounds().getBottomLeft();
contextMenu.showMenuAsync(optionsForPosition(cwhere));
contextMenu.showMenuAsync(optionsForPosition(cwhere),
[control](int i) { control->endHover(); });

return 1;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/EffectChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ struct EffectChooser : public juce::Component, public WidgetBaseMixin<EffectChoo
mouseMove(event);
}
void mouseExit(const juce::MouseEvent &event) override { isHovered = false; }
void endHover() override
{
isHovered = false;
repaint();
}
// State for mouse events
bool isHovered{false}, hasDragged{false};
int currentHover{-1}, currentClicked{-1};
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/MenuForDiscreteParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ struct MenuForDiscreteParams : public juce::Component,
isHovered = false;
repaint();
}
void endHover() override
{
isHovered = false;
repaint();
}
juce::Point<int> mouseDownOrigin;
bool isDraggingGlyph{false};
float lastDragDistance{0};
Expand Down
5 changes: 4 additions & 1 deletion src/gui/widgets/ModulatableSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,17 @@ 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<SurgeGUIEditor>();
if (sge)
{
sge->sliderHoverEnd(getTag());
}
repaint();
}

void ModulatableSlider::mouseDrag(const juce::MouseEvent &event)
Expand Down
1 change: 1 addition & 0 deletions src/gui/widgets/ModulatableSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 3 additions & 1 deletion src/gui/widgets/ModulationSourceButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/gui/widgets/ModulationSourceButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 6 additions & 3 deletions src/gui/widgets/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ void MultiSwitch::mouseDown(const juce::MouseEvent &event)
{
if (event.mods.isPopupMenu())
{
isHovered = false;
repaint();
notifyControlModifierClicked(event.mods);
return;
}
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/widgets/MultiSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct MultiSwitch : public juce::Component, public WidgetBaseMixin<MultiSwitch>
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;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/NumberField.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ struct NumberField : public juce::Component, public WidgetBaseMixin<NumberField>
setMouseCursor(juce::MouseCursor::NormalCursor);
repaint();
}
void endHover() override
{
isHover = false;
repaint();
}

juce::Colour textColour, textHoverColour;
void setTextColour(juce::Colour c)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/Switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ struct Switch : public juce::Component, public WidgetBaseMixin<Switch>
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,
Expand Down

0 comments on commit 811fae7

Please sign in to comment.