Skip to content

Commit

Permalink
- added ZoomableViewport::scrollToRectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Oct 28, 2024
1 parent 22fc800 commit bfbfe2e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 5 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45b2c9c1d2ce367335e9c9258ff66111f25f3ae4
22fc80083350aa3daa41e39ef6fc5090db505056
2 changes: 1 addition & 1 deletion hi_backend/backend/currentGit.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PREVIOUS_HISE_COMMIT "45b2c9c1d2ce367335e9c9258ff66111f25f3ae4"
#define PREVIOUS_HISE_COMMIT "22fc80083350aa3daa41e39ef6fc5090db505056"
6 changes: 4 additions & 2 deletions hi_dsp_library/snex_basics/snex_DynamicType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ VariableStorage::VariableStorage(Types::ID type_, const var& value)
else if (type_ == Types::ID::Double)
data.d.value = static_cast<double>(value);
else if (type_ == Types::ID::Pointer)
{
data.p.data = reinterpret_cast<void*>((int64)value);
}
else if (type_ == Types::ID::Event)
data.e = HiseEvent();
else if (type_ == Types::ID::Block)
data.b = {};
else
jassertfalse;
}
Expand Down
63 changes: 62 additions & 1 deletion hi_tools/hi_standalone_components/ZoomableViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,41 @@ void ZoomableViewport::timerCallback()
repaint();
}

void ZoomableViewport::scrollToRectangle(Rectangle<int> areaToShow, bool skipIfVisible, bool animate)
{
auto tBounds = getLocalBounds().toDouble();
auto aBounds = areaToShow.toDouble();

auto areaInViewport = getLocalArea(content, areaToShow).toDouble();

auto centerPositionInGraph = areaToShow.getCentre().toDouble();
auto cBounds = getLocalArea(content, content->getLocalBounds()).toDouble();

auto visibleArea = cBounds.getIntersection(tBounds);

if(!skipIfVisible || !visibleArea.contains(areaInViewport))
{
auto centerX = centerPositionInGraph.getX() * zoomFactor;
auto centerY = centerPositionInGraph.getY() * zoomFactor;

auto offsetX = getLocalBounds().getWidth() / 2 - centerX;
auto offsetY = getLocalBounds().getHeight() / 2 - centerY;

auto normX = Helpers::pixelToNorm(offsetX, cBounds.getWidth(), tBounds.getWidth());
auto normY = Helpers::pixelToNorm(offsetY, cBounds.getHeight(), tBounds.getHeight());

if(animate)
{
dragScrollTimer.scrollToPosition({normX, normY});
}
else
{
hBar.setCurrentRangeStart(normX, sendNotificationSync);
vBar.setCurrentRangeStart(normY, sendNotificationSync);
}
}
}

void ZoomableViewport::zoomToRectangle(Rectangle<int> areaToShow)
{
auto tBounds = getLocalBounds().toFloat();
Expand Down Expand Up @@ -641,6 +676,27 @@ void SubmenuComboBox::rebuildPopupMenu()

void ZoomableViewport::DragScrollTimer::timerCallback()
{
if(scrollAnimationCounter != -1)
{
auto numFrames = JUCE_LIVE_CONSTANT_OFF(30);
auto alpha = (double)scrollAnimationCounter++ / (double)(numFrames);
alpha = hmath::pow(alpha, 6.0);

auto newX = Interpolator::interpolateLinear(scrollAnimationStart.getX(), scrollAnimationTarget.getX(), alpha);
auto newY = Interpolator::interpolateLinear(scrollAnimationStart.getY(), scrollAnimationTarget.getY(), alpha);

parent.hBar.setCurrentRangeStart(newX, sendNotificationSync);
parent.vBar.setCurrentRangeStart(newY, sendNotificationSync);

if(scrollAnimationCounter > numFrames)
{
scrollAnimationCounter = -1;
stopTimer();
scrollAnimationStart = {};
scrollAnimationTarget = {};
}
}

auto factor = JUCE_LIVE_CONSTANT_OFF(0.03);
auto expo = JUCE_LIVE_CONSTANT_OFF(1.2);

Expand Down Expand Up @@ -672,10 +728,15 @@ void ZoomableViewport::DragScrollTimer::setPosition(const MouseEvent& e, bool is
wasInCentre = false;
lx = 0.0;
ly = 0.0;
stopTimer();

if(scrollAnimationCounter == -1)
stopTimer();
return;
}

if(scrollAnimationCounter != -1)
return;

auto vpos = parent.getLocalPoint(e.eventComponent, e.getPosition());
auto vb = parent.getLocalBounds();
auto padding = jmin(vb.getWidth(), vb.getHeight()) / 6;
Expand Down
20 changes: 20 additions & 0 deletions hi_tools/hi_standalone_components/ZoomableViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ struct ZoomableViewport : public Component,
double lx = 0.0;
double ly = 0.0;

void scrollToPosition(Point<double> normalisedTargetPosition)
{
wasInCentre = false;
lx = 0.0;
ly = 0.0;
scrollAnimationStart = { parent.hBar.getCurrentRangeStart(), parent.vBar.getCurrentRangeStart() };
scrollAnimationTarget = normalisedTargetPosition;
scrollAnimationCounter = 0;
startTimer(15);
}

Point<double> scrollAnimationStart;
Point<double> scrollAnimationTarget;
int scrollAnimationCounter = -1;


ZoomableViewport& parent;

} dragScrollTimer;
Expand Down Expand Up @@ -221,6 +237,8 @@ struct ZoomableViewport : public Component,

virtual ~ZoomableViewport();



static bool checkDragScroll(const MouseEvent& e, bool isMouseUp);

static bool checkViewportScroll(const MouseEvent& e, const MouseWheelDetails& details);
Expand Down Expand Up @@ -251,6 +269,8 @@ struct ZoomableViewport : public Component,

void zoomToRectangle(Rectangle<int> areaToShow);

void scrollToRectangle(Rectangle<int> areaToShow, bool skipIfVisible, bool animate=true);

void setZoomFactor(float newZoomFactor, Point<float> centerPositionInGraph);

void setMaxZoomFactor(float newMaxZoomFactor);
Expand Down

0 comments on commit bfbfe2e

Please sign in to comment.