Skip to content

Commit

Permalink
- added autoscroll when dragging elements in zoomable viewport (for i…
Browse files Browse the repository at this point in the history
…nterface designer & scriptnode editor)
  • Loading branch information
christoph-hart committed Sep 30, 2024
1 parent 9551adf commit db780f4
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 2 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4d39c10811fdff150c2fd0c8552997dac2a177f2
9551adf7f1319bdfce3706472a58ff70143d7f4d
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 "4d39c10811fdff150c2fd0c8552997dac2a177f2"
#define PREVIOUS_HISE_COMMIT "9551adf7f1319bdfce3706472a58ff70143d7f4d"
7 changes: 7 additions & 0 deletions hi_scripting/scripting/components/ScriptingContentOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ void ScriptingContentOverlay::mouseUp(const MouseEvent &e)
{
lasso.setVisible(false);
lasso.endLasso();
ZoomableViewport::checkDragScroll(e, true);
lassoActive = false;
repaint();
}
Expand Down Expand Up @@ -818,6 +819,7 @@ void ScriptingContentOverlay::mouseDrag(const MouseEvent& e)

if (lasso.isVisible())
{
ZoomableViewport::checkDragScroll(e, false);
lasso.dragLasso(e);
repaint();
}
Expand Down Expand Up @@ -983,7 +985,11 @@ void ScriptingContentOverlay::Dragger::mouseDrag(const MouseEvent& e)
dragDistance = constrainer.getPosition().getTopLeft() - startBounds.getTopLeft();

if (e.eventComponent == this)
{
ZoomableViewport::checkDragScroll(e, false);
dragger.dragComponent(this, e, &constrainer);
}




Expand Down Expand Up @@ -1027,6 +1033,7 @@ void ScriptingContentOverlay::Dragger::mouseUp(const MouseEvent& e)
if (!parent->enableMouseDragging)
return;

ZoomableViewport::checkDragScroll(e, true);
findParentComponentOfClass<ScriptingContentOverlay>()->smw.endDragging();

snapShot = Image();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void ModulationSourceBaseComponent::mouseDrag(const MouseEvent& e)

container->startDragging(var(details), this, ScaledImage(createDragImage()));

ZoomableViewport::checkDragScroll(e, false);

findParentComponentOfClass<DspNetworkGraph>()->dragOverlay.setEnabled(true);
}
}
Expand All @@ -206,6 +208,8 @@ void ModulationSourceBaseComponent::mouseUp(const MouseEvent& e)
{
CHECK_MIDDLE_MOUSE_UP(e);

ZoomableViewport::checkDragScroll(e, true);

findParentComponentOfClass<DspNetworkGraph>()->dragOverlay.setEnabled(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ namespace ui
details->setProperty(PropertyIds::SwitchTarget, true);

container->startDragging(var(details), this, ScaledImage(ModulationSourceBaseComponent::createDragImageStatic(false)));
ZoomableViewport::checkDragScroll(e, false);
findParentComponentOfClass<DspNetworkGraph>()->repaint();
}
}
Expand All @@ -799,6 +800,7 @@ namespace ui
{
CHECK_MIDDLE_MOUSE_UP(event);

ZoomableViewport::checkDragScroll(event, true);
findParentComponentOfClass<DspNetworkGraph>()->repaint();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,16 @@ void dynamic::editor::mouseUp(const MouseEvent& e)
fc->repaint();
});

ZoomableViewport::checkDragScroll(e, true);
findParentComponentOfClass<DspNetworkGraph>()->repaint();
}

void dynamic::editor::mouseDrag(const MouseEvent& event)
{
CHECK_MIDDLE_MOUSE_DRAG(event);

ZoomableViewport::checkDragScroll(event, false);

findParentComponentOfClass<DspNetworkGraph>()->repaint();
}

Expand Down
9 changes: 9 additions & 0 deletions hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,15 @@ class ContainerComponent : public NodeComponent,
g.setColour(Colours::black.withAlpha(0.1f));

g.fillRoundedRectangle(b, 10.0f);

if(sliders.isEmpty())
{
auto f = GLOBAL_BOLD_FONT();
String t = "No parameters";
g.setColour(Colours::white.withAlpha(0.3f));
g.setFont(f);
g.drawText(t, getLocalBounds().toFloat(), Justification::centred);
}
}

ContainerComponent& parent;
Expand Down
7 changes: 7 additions & 0 deletions hi_scripting/scripting/scriptnode/ui/ParameterSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,11 @@ void MacroParameterSlider::mouseDrag(const MouseEvent& e)

container->startDragging(details, &slider, ScaledImage(ModulationSourceBaseComponent::createDragImageStatic(false)));

ZoomableViewport::checkDragScroll(e, false);




slider.repaintParentGraph();
}
}
Expand All @@ -1779,6 +1784,8 @@ void MacroParameterSlider::mouseUp(const MouseEvent& e)
{
CHECK_MIDDLE_MOUSE_UP(e);

ZoomableViewport::checkDragScroll(e, true);

slider.repaintParentGraph();
}

Expand Down
85 changes: 85 additions & 0 deletions hi_tools/hi_standalone_components/ZoomableViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ZoomableViewport::ZoomableViewport(Component* n) :
hBar(false),
vBar(true),
content(n),
dragScrollTimer(*this),
mouseWatcher(new MouseWatcher(*this))
{
sf.addScrollBarToAnimate(hBar);
Expand Down Expand Up @@ -108,6 +109,16 @@ ZoomableViewport::~ZoomableViewport()
content = nullptr;
}

bool ZoomableViewport::checkDragScroll(const MouseEvent& e, bool isMouseUp)
{
if(auto vp = e.eventComponent->findParentComponentOfClass<ZoomableViewport>())
{
vp->dragScrollTimer.setPosition(e, isMouseUp);
}

return false;
}

bool ZoomableViewport::checkViewportScroll(const MouseEvent& e, const MouseWheelDetails& wheel)
{
if (wheel.deltaX > 0.0 || wheel.deltaY > 0.0)
Expand Down Expand Up @@ -622,6 +633,80 @@ void SubmenuComboBox::rebuildPopupMenu()
refreshTickState();
}

void ZoomableViewport::DragScrollTimer::timerCallback()
{
auto factor = JUCE_LIVE_CONSTANT_OFF(0.03);
auto expo = JUCE_LIVE_CONSTANT_OFF(1.2);

auto dx = jlimit(-1.0, 1.0, (double)xDelta / (double)(parent.getWidth() / 5));
auto dy = jlimit(-1.0, 1.0, (double)yDelta / (double)(parent.getHeight() / 5));

dx = hmath::sign(dx) * std::pow(hmath::abs(dx), expo);
dy = hmath::sign(dy) * std::pow(hmath::abs(dy), expo);

auto a = JUCE_LIVE_CONSTANT_OFF(0.74);

dx = lx * a + dx * (1.0 - a);
dy = ly * a + dy * (1.0 - a);

lx = dx;
ly = dy;

dx *= factor;
dy *= factor;

parent.hBar.setCurrentRangeStart(jlimit(0.0, 1.0, parent.hBar.getCurrentRangeStart() + dx));
parent.vBar.setCurrentRangeStart(jlimit(0.0, 1.0, parent.vBar.getCurrentRangeStart() + dy));
}

void ZoomableViewport::DragScrollTimer::setPosition(const MouseEvent& e, bool isMouseUp)
{
if(isMouseUp)
{
wasInCentre = false;
lx = 0.0;
ly = 0.0;
stopTimer();
return;
}

auto vpos = parent.getLocalPoint(e.eventComponent, e.getPosition());
auto vb = parent.getLocalBounds();
auto padding = jmin(vb.getWidth(), vb.getHeight()) / 6;

vb = vb.reduced(padding);

if(vpos.getX() > vb.getRight())
xDelta = vpos.getX() - vb.getRight();
else if (vpos.getX() < vb.getX())
xDelta = vpos.getX() - vb.getX();
else
xDelta = 0;

if(vpos.getY() > vb.getBottom())
yDelta = vpos.getY() - vb.getBottom();
else if (vpos.getY() < vb.getY())
yDelta = vpos.getY() - vb.getY();
else
yDelta = 0;

if(xDelta == 0 && yDelta == 0)
wasInCentre = true;

auto shouldScroll = wasInCentre && (xDelta != 0 || yDelta != 0);

if(shouldScroll != isTimerRunning())
{
if(shouldScroll)
startTimer(30);
else
{
if(hmath::abs(lx) < 0.005 && hmath::abs(ly) < 0.005)
stopTimer();
}
}
}

ZoomableViewport::MouseWatcher::MouseWatcher(ZoomableViewport& p):
parent(p)
{
Expand Down
25 changes: 25 additions & 0 deletions hi_tools/hi_standalone_components/ZoomableViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,29 @@ struct ZoomableViewport : public Component,
public Timer,
public DragAnimator::Listener
{
struct DragScrollTimer: public Timer
{
DragScrollTimer(ZoomableViewport& parent_):
parent(parent_)
{};

void timerCallback() override;

void setPosition(const MouseEvent& e, bool isMouseUp);

bool wasInCentre = false;
int xDelta = 0;
int yDelta = 0;

double lx = 0.0;
double ly = 0.0;

ZoomableViewport& parent;

} dragScrollTimer;



enum ColourIds
{
backgroundColourId = 9000
Expand Down Expand Up @@ -198,6 +221,8 @@ struct ZoomableViewport : public Component,

virtual ~ZoomableViewport();

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

static bool checkViewportScroll(const MouseEvent& e, const MouseWheelDetails& details);

static bool checkMiddleMouseDrag(const MouseEvent& e, MouseEventFlags type);
Expand Down

0 comments on commit db780f4

Please sign in to comment.