Skip to content

Commit

Permalink
Fix a couple of MultiSwitch problems (#5146)
Browse files Browse the repository at this point in the history
1. Frame wasn't observed in hover
2. Some cursor changes when dragging make it seem more natural

Closes #5114
  • Loading branch information
baconpaul authored Sep 23, 2021
1 parent 055c9fa commit 691151c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4296,6 +4296,7 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
auto drgb = currentSkin->propertyValue(skinCtrl,
Surge::Skin::Component::DRAGGABLE_HSWITCH, "1");
auto hsw = componentForSkinSession<Surge::Widgets::MultiSwitch>(skinCtrl->sessionid);
hsw->setStorage(&(synth->storage));
hsw->setRows(std::atoi(rows.c_str()));
hsw->setColumns(std::atoi(cols.c_str()));
hsw->setTag(tag);
Expand Down
28 changes: 27 additions & 1 deletion src/surge-xt/gui/widgets/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "basic_dsp.h"
#include "AccessibleHelpers.h"
#include "SurgeGUIEditor.h"
#include "SurgeGUIUtils.h"

namespace Surge
{
Expand Down Expand Up @@ -65,7 +66,7 @@ int MultiSwitch::coordinateToSelection(int x, int y)

if (columns * rows > 1)
{
return (mx + my * columns);
return limit_range(mx + my * columns, 0, columns * rows - 1);
}

return 0;
Expand All @@ -86,6 +87,7 @@ void MultiSwitch::mouseDown(const juce::MouseEvent &event)
return;
}

everDragged = false;
if (event.mods.isPopupMenu())
{
notifyControlModifierClicked(event.mods);
Expand All @@ -111,16 +113,40 @@ void MultiSwitch::mouseDrag(const juce::MouseEvent &event)
{
if (draggable)
{
if (!Surge::GUI::showCursor(storage) && !everDragged &&
event.getDistanceFromDragStart() > 0)
{
everDragged = true;
if (rows * columns > 1)
{
if (rows > columns)
setMouseCursor(juce::MouseCursor::UpDownResizeCursor);
else
setMouseCursor(juce::MouseCursor::LeftRightResizeCursor);
}
// juce::Desktop::getInstance().getMainMouseSource().enableUnboundedMouseMovement(true);
}

int sel = coordinateToSelection(event.x, event.y);
hoverSelection = sel;
setValue(limit_range((float)sel / (rows * columns - 1), 0.f, 1.f));
notifyValueChanged();
}
}

void MultiSwitch::mouseUp(const juce::MouseEvent &event)
{
if (everDragged)
{
everDragged = false;
setMouseCursor(juce::MouseCursor::NormalCursor);
// juce::Desktop::getInstance().getMainMouseSource().enableUnboundedMouseMovement(false);
}
}
void MultiSwitch::mouseEnter(const juce::MouseEvent &event)
{
hoverSelection = coordinateToSelection(event.x, event.y);

isHovered = true;
}
void MultiSwitch::mouseExit(const juce::MouseEvent &event) { endHover(); }
Expand Down
7 changes: 7 additions & 0 deletions src/surge-xt/gui/widgets/MultiSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "juce_gui_basics/juce_gui_basics.h"

class SurgeImage;
class SurgeStorage;

namespace Surge
{
Expand All @@ -36,6 +37,9 @@ struct MultiSwitch : public juce::Component, public WidgetBaseMixin<MultiSwitch>
MultiSwitch();
~MultiSwitch();

SurgeStorage *storage{nullptr};
void setStorage(SurgeStorage *s) { storage = s; }

int rows{0}, columns{0}, heightOfOneImage{0}, frameOffset{0};
int getRows() const { return rows; }
int getColumns() const { return columns; }
Expand All @@ -60,11 +64,14 @@ struct MultiSwitch : public juce::Component, public WidgetBaseMixin<MultiSwitch>
void setDraggable(bool d) { draggable = d; }

void paint(juce::Graphics &g) override;

bool everDragged{false};
void mouseDown(const juce::MouseEvent &event) override;
void mouseEnter(const juce::MouseEvent &event) override;
void mouseExit(const juce::MouseEvent &event) override;
void mouseMove(const juce::MouseEvent &event) override;
void mouseDrag(const juce::MouseEvent &event) override;
void mouseUp(const juce::MouseEvent &event) override;

void endHover() override;

Expand Down

0 comments on commit 691151c

Please sign in to comment.