Skip to content

Commit

Permalink
A different approach to stuck hover (#6016)
Browse files Browse the repository at this point in the history
Stuck hover is way easier with a bool which is just set in the
menu handler. This accomplishes that and also fixes slider,
multiswitch, switch, and mod button

Addresses #5318
  • Loading branch information
baconpaul authored Apr 5, 2022
1 parent 9523d32 commit 7074d54
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
23 changes: 5 additions & 18 deletions src/surge-xt/gui/SurgeGUICallbackInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,12 @@ struct IComponentTagValue
virtual float getValue() const = 0;
virtual void setValue(float) = 0;

int hoverCount{0};
virtual int incrementHover()
{
hoverCount++;
return hoverCount;
}
virtual int decrementHover()
{
hoverCount--;
return hoverCount;
}
virtual void forceEndHover()
{
hoverCount = 1;
endHover();
}
bool stuckHover{false};
virtual void stuckHoverOn() { stuckHover = true; }
virtual void stuckHoverOff() { stuckHover = false; }

virtual void startHover(const juce::Point<float> &) { incrementHover(); }
virtual void endHover() { decrementHover(); }
virtual void startHover(const juce::Point<float> &) {}
virtual void endHover() {}

juce::Component *asJuceComponent()
{
Expand Down
7 changes: 5 additions & 2 deletions src/surge-xt/gui/SurgeJUCEHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ inline std::function<void(int)> makeEndHoverCallback(Surge::GUI::IComponentTagVa
if (!that)
return [](int) {};

that->incrementHover();
that->stuckHoverOn();

return
[safethat = juce::Component::SafePointer<juce::Component>(that->asJuceComponent())](int x) {
if (safethat)
{
auto igtv = dynamic_cast<Surge::GUI::IComponentTagValue *>(safethat.getComponent());
if (igtv)
igtv->forceEndHover();
{
igtv->stuckHoverOff();
igtv->endHover();
}
}
};
}
Expand Down
5 changes: 1 addition & 4 deletions src/surge-xt/gui/widgets/ModulatableSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,6 @@ void ModulatableSlider::onSkinChanged()
void ModulatableSlider::mouseEnter(const juce::MouseEvent &event) { startHover(event.position); }
void ModulatableSlider::startHover(const juce::Point<float> &p)
{
if (incrementHover() > 1)
return;

enqueueFutureInfowindow(SurgeGUIEditor::InfoQAction::START, p);
isHovered = true;
auto sge = firstListenerOfType<SurgeGUIEditor>();
Expand All @@ -394,7 +391,7 @@ void ModulatableSlider::mouseExit(const juce::MouseEvent &event) { endHover(); }

void ModulatableSlider::endHover()
{
if (decrementHover() != 0)
if (stuckHover)
return;

enqueueFutureInfowindow(SurgeGUIEditor::InfoQAction::LEAVE);
Expand Down
3 changes: 3 additions & 0 deletions src/surge-xt/gui/widgets/ModulationSourceButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ void ModulationSourceButton::startHover(const juce::Point<float> &f)

void ModulationSourceButton::endHover()
{
if (stuckHover)
return;

bool oh = isHovered;
isHovered = false;

Expand Down
5 changes: 1 addition & 4 deletions src/surge-xt/gui/widgets/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ void MultiSwitch::mouseEnter(const juce::MouseEvent &event) { startHover(event.p

void MultiSwitch::startHover(const juce::Point<float> &p)
{
if (incrementHover() > 1)
return;

if (everDragged && isMouseDown) // don't change hover state during a drag
{
hoverSelection = getIntegerValue();
Expand All @@ -264,7 +261,7 @@ void MultiSwitch::mouseExit(const juce::MouseEvent &event) { endHover(); }

void MultiSwitch::endHover()
{
if (decrementHover() != 0)
if (stuckHover)
return;

isHovered = false;
Expand Down
3 changes: 3 additions & 0 deletions src/surge-xt/gui/widgets/Switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ struct Switch : public juce::Component, public WidgetBaseMixin<Switch>, public L
void mouseExit(const juce::MouseEvent &event) override;
void endHover() override
{
if (stuckHover)
return;

isHovered = false;
repaint();
}
Expand Down

0 comments on commit 7074d54

Please sign in to comment.