Skip to content

Commit

Permalink
Fix segmented connection bug when moving objects
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Jan 7, 2025
1 parent 137886f commit 017699e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Source/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void Connection::renderConnectionOrder(NVGcontext* nvg)
}
}

void Connection::pushPathState()
void Connection::pushPathState(bool force)
{
if (!inlet || !outlet)
return;
Expand All @@ -332,6 +332,7 @@ void Connection::pushPathState()
}

cnv->pathUpdater->pushPathState(this, newPathState);
if(force) cnv->pathUpdater->timerCallback();
}

void Connection::popPathState()
Expand Down Expand Up @@ -836,7 +837,7 @@ void Connection::componentMovedOrResized(Component& component, bool wasMoved, bo
auto offsetPath = getPath();
offsetPath.applyTransform(translation);
setPath(offsetPath);

updateReconnectHandle();

clipRegion.transformAll(translation);
Expand Down
9 changes: 5 additions & 4 deletions Source/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Connection final : public DrawablePath
t_outconnect* getPointer() const;

t_symbol* getPathState() const;
void pushPathState();
void pushPathState(bool force = false);
void popPathState();

void componentMovedOrResized(Component& component, bool wasMoved, bool wasResized) override;
Expand Down Expand Up @@ -328,10 +328,9 @@ class ConnectionPathUpdater final : public Timer {
Canvas* canvas;

moodycamel::ReaderWriterQueue<std::pair<Component::SafePointer<Connection>, t_symbol*>> connectionUpdateQueue = moodycamel::ReaderWriterQueue<std::pair<Component::SafePointer<Connection>, t_symbol*>>(4096);

void timerCallback() override;


public:

explicit ConnectionPathUpdater(Canvas* cnv)
: canvas(cnv)
{
Expand All @@ -342,4 +341,6 @@ class ConnectionPathUpdater final : public Timer {
connectionUpdateQueue.enqueue({ connection, newPathState });
startTimer(50);
}

void timerCallback() override;
};
5 changes: 4 additions & 1 deletion Source/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,12 @@ void Object::mouseUp(MouseEvent const& e)
}

if (ds.didStartDragging) {
for(auto* connection : getConnections())
connection->pushPathState(true);

applyBounds();
cnv->patch.endUndoSequence("Drag");
cnv->objectGrid.clearIndicators(false);
applyBounds();
ds.didStartDragging = false;
}

Expand Down
1 change: 1 addition & 0 deletions Source/Pd/Patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ t_outconnect* Patch::setConnctionPath(t_object* src, int const nout, t_object* s
{
if (auto patch = ptr.get<t_glist>()) {
setCurrent();
std::cout << "Path updated" << std::endl;
return pd::Interface::setConnectionPath(patch.get(), src, nout, sink, nin, oldConnectionPath, newConnectionPath);
}

Expand Down

0 comments on commit 017699e

Please sign in to comment.