Skip to content

Commit

Permalink
Add LongPressMixin to other widgets (#5979)
Browse files Browse the repository at this point in the history
Closes #5802 after tweaking it a little more - for some reason long press doesn't activate context menu for EffectChooser.

Also long press context menu is not implemented in OscillatorWaveformDisplay (Alias additive editor has a context menu which would be nice to open via touch too).
  • Loading branch information
mkruselj authored Mar 20, 2022
1 parent d425feb commit e26d69f
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 26 deletions.
13 changes: 9 additions & 4 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,16 +2206,21 @@ juce::PopupMenu::Options SurgeGUIEditor::popupMenuOptions(const juce::Point<int>
juce::PopupMenu::Options SurgeGUIEditor::popupMenuOptions(const juce::Component *c,
bool useComponentBounds)
{
juce::Point<int> where;

if (!c || !useComponentBounds)
{
auto where = frame->getLocalPoint(nullptr, juce::Desktop::getMousePosition());
return popupMenuOptions(where);
where = frame->getLocalPoint(nullptr, juce::Desktop::getMousePosition());
}
else
{
auto where = c->getBounds().getBottomLeft();
return popupMenuOptions(where);
where = c->getBounds().getBottomLeft();
}

if (Surge::GUI::isTouchMode(&(synth->storage)))
where = c->getBounds().getBottomLeft();

return popupMenuOptions(where);
}

void SurgeGUIEditor::showZoomMenu(const juce::Point<int> &where,
Expand Down
9 changes: 9 additions & 0 deletions src/surge-xt/gui/widgets/EffectChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ void EffectChooser::mouseDown(const juce::MouseEvent &event)
return;
}

mouseDownLongHold(event);

hasDragged = false;
currentClicked = -1;

Expand Down Expand Up @@ -302,6 +304,7 @@ void EffectChooser::mouseUp(const juce::MouseEvent &event)
if (hasDragged)
{
setMouseCursor(juce::MouseCursor::NormalCursor);

for (int i = 0; i < n_fx_slots; ++i)
{
auto r = getEffectRectangle(i);
Expand Down Expand Up @@ -334,6 +337,8 @@ void EffectChooser::mouseUp(const juce::MouseEvent &event)
hasDragged = false;
repaint();
}

mouseUpLongHold(event);
}

void EffectChooser::mouseDrag(const juce::MouseEvent &event)
Expand All @@ -343,6 +348,8 @@ void EffectChooser::mouseDrag(const juce::MouseEvent &event)
return;
}

mouseDragLongHold(event);

if (event.getDistanceFromDragStart() > 3 && event.mods.isLeftButtonDown())
{
if (!hasDragged)
Expand All @@ -361,6 +368,8 @@ void EffectChooser::mouseDrag(const juce::MouseEvent &event)

void EffectChooser::mouseMove(const juce::MouseEvent &event)
{
mouseMoveLongHold(event);

int nextHover = -1;
int nextSceneHover = -1;

Expand Down
4 changes: 3 additions & 1 deletion src/surge-xt/gui/widgets/EffectChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ namespace Surge
{
namespace Widgets
{
struct EffectChooser : public juce::Component, public WidgetBaseMixin<EffectChooser>
struct EffectChooser : public juce::Component,
public WidgetBaseMixin<EffectChooser>,
public LongHoldMixin<EffectChooser>
{
EffectChooser();
~EffectChooser();
Expand Down
8 changes: 8 additions & 0 deletions src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,8 @@ void LFOAndStepDisplay::mouseDown(const juce::MouseEvent &event)
}
}

mouseDownLongHold(event);

if (waveform_display.contains(event.position.toInt()) && sge)
{
if (isMSEG() || isFormula())
Expand Down Expand Up @@ -1778,6 +1780,8 @@ void LFOAndStepDisplay::enterExitWaveform(bool isInWF)

void LFOAndStepDisplay::mouseMove(const juce::MouseEvent &event)
{
mouseMoveLongHold(event);

int nextHover = -1;

for (int i = 0; i < n_lfo_types; ++i)
Expand Down Expand Up @@ -1886,6 +1890,8 @@ void LFOAndStepDisplay::mouseDrag(const juce::MouseEvent &event)
return;
}

mouseDragLongHold(event);

if (dragMode != NONE && event.getDistanceFromDragStart() > 0)
{
if (!Surge::GUI::showCursor(storage))
Expand Down Expand Up @@ -1997,6 +2003,8 @@ void LFOAndStepDisplay::mouseDrag(const juce::MouseEvent &event)

void LFOAndStepDisplay::mouseUp(const juce::MouseEvent &event)
{
mouseUpLongHold(event);

if (event.mouseWasDraggedSinceMouseDown())
{
if (!Surge::GUI::showCursor(storage))
Expand Down
4 changes: 3 additions & 1 deletion src/surge-xt/gui/widgets/LFOAndStepDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace Surge
{
namespace Widgets
{
struct LFOAndStepDisplay : public juce::Component, public WidgetBaseMixin<LFOAndStepDisplay>
struct LFOAndStepDisplay : public juce::Component,
public WidgetBaseMixin<LFOAndStepDisplay>,
public LongHoldMixin<LFOAndStepDisplay>
{
LFOAndStepDisplay(SurgeGUIEditor *e);
void paint(juce::Graphics &g) override;
Expand Down
24 changes: 16 additions & 8 deletions src/surge-xt/gui/widgets/MenuForDiscreteParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ void MenuForDiscreteParams::mouseDown(const juce::MouseEvent &event)
return;
}

mouseDownLongHold(event);

if (glyphMode && glyphPosition.contains(event.position))
{
mouseDownOrigin = event.position.toInt();
Expand All @@ -203,17 +205,21 @@ void MenuForDiscreteParams::mouseDown(const juce::MouseEvent &event)
notifyControlModifierClicked(event.mods, true);
}

void MenuForDiscreteParams::mouseDrag(const juce::MouseEvent &e)
void MenuForDiscreteParams::mouseDrag(const juce::MouseEvent &event)
{
if (supressMainFrameMouseEvent(e))
if (supressMainFrameMouseEvent(event))
{
return;
}

auto d = e.getDistanceFromDragStartX() - e.getDistanceFromDragStartY();
mouseDragLongHold(event);

auto d = event.getDistanceFromDragStartX() - event.getDistanceFromDragStartY();

if (fabs(d - lastDragDistance) > 10)
{
int inc = 1;

if (d - lastDragDistance < 0)
{
inc = -1;
Expand All @@ -226,16 +232,18 @@ void MenuForDiscreteParams::mouseDrag(const juce::MouseEvent &e)
}
}

void MenuForDiscreteParams::mouseDoubleClick(const juce::MouseEvent &e)
void MenuForDiscreteParams::mouseDoubleClick(const juce::MouseEvent &event)
{
if (glyphMode && glyphPosition.contains(e.position))
if (glyphMode && glyphPosition.contains(event.position))
{
notifyControlModifierDoubleClicked(e.mods.allKeyboardModifiers);
notifyControlModifierDoubleClicked(event.mods.allKeyboardModifiers);
}
}

void MenuForDiscreteParams::mouseUp(const juce::MouseEvent &e)
void MenuForDiscreteParams::mouseUp(const juce::MouseEvent &event)
{
mouseUpLongHold(event);

if (isDraggingGlyph && !Surge::GUI::showCursor(storage))
{
juce::Desktop::getInstance().getMainMouseSource().enableUnboundedMouseMovement(false);
Expand All @@ -246,7 +254,7 @@ void MenuForDiscreteParams::mouseUp(const juce::MouseEvent &e)
isDraggingGlyph = false;
}

void MenuForDiscreteParams::mouseWheelMove(const juce::MouseEvent &e,
void MenuForDiscreteParams::mouseWheelMove(const juce::MouseEvent &event,
const juce::MouseWheelDetails &w)
{
int dir = wheelAccumulationHelper.accumulate(w, false, true);
Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/widgets/MenuForDiscreteParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Widgets
*/
struct MenuForDiscreteParams : public juce::Component,
public WidgetBaseMixin<MenuForDiscreteParams>,
public LongHoldMixin<MenuForDiscreteParams>,
public ModulatableControlInterface

{
Expand Down
8 changes: 8 additions & 0 deletions src/surge-xt/gui/widgets/ModulationSourceButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ void ModulationSourceButton::mouseDown(const juce::MouseEvent &event)
everDragged = false;
mouseDownLocation = event.position;

mouseDownLongHold(event);

if (needsHamburger() && hamburgerHome.contains(event.position.toInt()))
{
auto menu = juce::PopupMenu();
Expand Down Expand Up @@ -523,6 +525,8 @@ void ModulationSourceButton::onSkinChanged()

void ModulationSourceButton::mouseUp(const juce::MouseEvent &event)
{
mouseUpLongHold(event);

setMouseCursor(juce::MouseCursor::NormalCursor);

transientArmed = false;
Expand Down Expand Up @@ -581,7 +585,11 @@ void ModulationSourceButton::mouseDrag(const juce::MouseEvent &event)
auto distance = event.position.getX() - mouseDownLocation.getX();

if (mouseMode == PREDRAG_VALUE && distance == 0)
{
return;
}

mouseDragLongHold(event);

if (mouseMode == PREDRAG_VALUE)
{
Expand Down
3 changes: 2 additions & 1 deletion src/surge-xt/gui/widgets/ModulationSourceButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace Surge
namespace Widgets
{
struct ModulationSourceButton : public juce::Component,
public WidgetBaseMixin<ModulationSourceButton>
public WidgetBaseMixin<ModulationSourceButton>,
public LongHoldMixin<ModulationSourceButton>
{
ModulationSourceButton();

Expand Down
6 changes: 6 additions & 0 deletions src/surge-xt/gui/widgets/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void MultiSwitch::mouseDown(const juce::MouseEvent &event)
juce::Timer::callAfterDelay(250, [this]() { this->setCursorToArrow(); });
}

mouseDownLongHold(event);
setValue(coordinateToValue(event.x, event.y));
notifyValueChanged();

Expand All @@ -162,6 +163,8 @@ void MultiSwitch::mouseMove(const juce::MouseEvent &event)
{
int ohs = hoverSelection;

mouseMoveLongHold(event);

hoverSelection = coordinateToSelection(event.x, event.y);

if (ohs != hoverSelection || !isHovered)
Expand Down Expand Up @@ -199,6 +202,8 @@ void MultiSwitch::mouseDrag(const juce::MouseEvent &event)
return;
}

mouseDragLongHold(event);

if (draggable)
{
if (!everDragged)
Expand Down Expand Up @@ -227,6 +232,7 @@ void MultiSwitch::mouseDrag(const juce::MouseEvent &event)

void MultiSwitch::mouseUp(const juce::MouseEvent &event)
{
mouseUpLongHold(event);
isMouseDown = false;
setMouseCursor(juce::MouseCursor::NormalCursor);

Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/widgets/MultiSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Widgets
*/
struct MultiSwitch : public juce::Component,
public WidgetBaseMixin<MultiSwitch>,
public LongHoldMixin<MultiSwitch>,
public Surge::Widgets::HasAccessibleSubComponentForFocus
{
MultiSwitch();
Expand Down
8 changes: 8 additions & 0 deletions src/surge-xt/gui/widgets/NumberField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ void NumberField::mouseDown(const juce::MouseEvent &event)
return;
}

mouseDownLongHold(event);

mouseMode = DRAG;

if (!Surge::GUI::showCursor(storage))
Expand All @@ -153,6 +155,8 @@ void NumberField::mouseDrag(const juce::MouseEvent &event)
return;
}

mouseDragLongHold(event);

float d = -event.getDistanceFromDragStartY();
float dD = d - lastDistanceChecked;
float thresh = 10;
Expand All @@ -169,6 +173,8 @@ void NumberField::mouseDrag(const juce::MouseEvent &event)
}
void NumberField::mouseUp(const juce::MouseEvent &event)
{
mouseUpLongHold(event);

if (mouseMode == DRAG)
{
if (!Surge::GUI::showCursor(storage))
Expand All @@ -180,6 +186,7 @@ void NumberField::mouseUp(const juce::MouseEvent &event)
}
mouseMode = NONE;
}

void NumberField::mouseDoubleClick(const juce::MouseEvent &event)
{
if (supressMainFrameMouseEvent(event))
Expand All @@ -190,6 +197,7 @@ void NumberField::mouseDoubleClick(const juce::MouseEvent &event)
notifyControlModifierDoubleClicked(event.mods);
repaint();
}

void NumberField::mouseWheelMove(const juce::MouseEvent &event,
const juce::MouseWheelDetails &wheel)
{
Expand Down
4 changes: 3 additions & 1 deletion src/surge-xt/gui/widgets/NumberField.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace Surge
{
namespace Widgets
{
struct NumberField : public juce::Component, public WidgetBaseMixin<NumberField>
struct NumberField : public juce::Component,
public WidgetBaseMixin<NumberField>,
public LongHoldMixin<NumberField>
{
NumberField() : juce::Component(), WidgetBaseMixin<NumberField>() {}

Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/gui/widgets/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void Switch::mouseDown(const juce::MouseEvent &event)
return;
}

mouseDownLongHold(event);

if (isMultiIntegerValued())
{
storage->getPatch().isDirty = true;
Expand Down
2 changes: 1 addition & 1 deletion src/surge-xt/gui/widgets/Switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Widgets
*
* The rough contract is:
*/
struct Switch : public juce::Component, public WidgetBaseMixin<Switch>
struct Switch : public juce::Component, public WidgetBaseMixin<Switch>, public LongHoldMixin<Switch>
{
Switch();
~Switch();
Expand Down
Loading

0 comments on commit e26d69f

Please sign in to comment.