Skip to content

Commit

Permalink
ZoomContainer Translate is porporational to size (#128)
Browse files Browse the repository at this point in the history
Also flip sign on wheel zoom gestures
  • Loading branch information
baconpaul authored Sep 4, 2024
1 parent 456caf3 commit e321b9b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions include/sst/jucegui/components/ZoomContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct ZoomContainer : juce::Component, juce::ScrollBar::Listener
// HZOM by -Delta Y
if (contents->supportsHorizontalZoom())
{
adjustHorizontalZoom(event.position, 1.0 - wheel.deltaY);
adjustHorizontalZoom(event.position, 1.0 + wheel.deltaY);
}
return;
}
Expand All @@ -118,7 +118,7 @@ struct ZoomContainer : juce::Component, juce::ScrollBar::Listener
// VZoom by delta Y
if (contents->supportsVerticalZoom())
{
adjustVerticalZoom(event.position, 1.0 - wheel.deltaY);
adjustVerticalZoom(event.position, 1.0 + wheel.deltaY);
}
return;
}
Expand All @@ -131,7 +131,11 @@ struct ZoomContainer : juce::Component, juce::ScrollBar::Listener
{
auto dy = wheel.deltaX;
auto rs = hScroll->getCurrentRangeStart();
rs = std::clamp(rs - dy, 0., 1.);
auto rw = hScroll->getCurrentRangeSize();

// You want translation to be relative to the size to make
// it sort of "uniform speed"
rs = std::clamp(rs - dy * rw * 2, 0., 1.);
hScroll->setCurrentRangeStart(rs);
}
}
Expand All @@ -141,7 +145,9 @@ struct ZoomContainer : juce::Component, juce::ScrollBar::Listener
{
auto dy = wheel.deltaY;
auto rs = vScroll->getCurrentRangeStart();
rs = std::clamp(rs - dy, 0., 1.);
auto rw = vScroll->getCurrentRangeSize();

rs = std::clamp(rs - dy * rw * 2, 0., 1.);
vScroll->setCurrentRangeStart(rs);
}
}
Expand Down

0 comments on commit e321b9b

Please sign in to comment.