Skip to content

Commit

Permalink
Make filter XY pad work with out-of-bounds mouse movement (#6912)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkruselj authored Apr 7, 2023
1 parent 8059472 commit 8604817
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/surge-xt/gui/overlays/FilterAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,28 @@ void FilterAnalysis::mouseDrag(const juce::MouseEvent &event)
auto lb = getLocalBounds().transformedBy(getTransform().inverted());
auto dRect = lb.withTrimmedTop(15).reduced(4);

if (event.mods.isLeftButtonDown() && dRect.contains(event.position.toInt()))
float rx0 = dRect.getX();
float rx1 = dRect.getX() + dRect.getWidth() - 1;
float ry0 = dRect.getY();
float ry1 = dRect.getY() + dRect.getHeight() - 1;

juce::Point<float> mousePoint =
event.getPosition()
.transformedBy(
juce::AffineTransform().translated(dRect.getX(), dRect.getY()).inverted())
.toFloat();

mousePoint.setX(std::clamp(mousePoint.getX(), rx0, rx1));
mousePoint.setY(std::clamp(mousePoint.getY(), ry0, ry1));

if (event.mods.isLeftButtonDown() && dRect.contains(mousePoint.toInt()))
{
auto &ss = editor->getPatch().scene[editor->current_scene];
auto &fs = ss.filterunit[whichFilter];

auto width = dRect.getWidth();
auto height = dRect.getHeight();

juce::Point<int> mousePoint = event.getPosition().transformedBy(
juce::AffineTransform().translated(dRect.getX(), dRect.getY()).inverted());

auto xNorm = mousePoint.x / (float)width;
auto freq = std::pow(GRAPH_MAX_FREQ / GRAPH_MIN_FREQ, xNorm) * GRAPH_MIN_FREQ;

Expand Down

0 comments on commit 8604817

Please sign in to comment.