Skip to content

Commit

Permalink
The newly created spot can be moved around by holding the key.
Browse files Browse the repository at this point in the history
Let's benefit from the fact that we do everything from a
behaviour.
  • Loading branch information
tinevez committed Nov 11, 2024
1 parent 848cc24 commit 48883de
Showing 1 changed file with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,11 @@ public void init( final int x, final int y )

final int timepoint = renderer.getCurrentTimepoint();
renderer.getGlobalPosition( x, y, pos );
final V ref = overlayGraph.vertexRef();
lock.writeLock().lock();
try
{
// Add new spot.
final V vertex = overlayGraph.addVertex( ref ).init( timepoint, pos, EditBehaviours.lastRadius );
overlayGraph.addVertex( source ).init( timepoint, pos, EditBehaviours.lastRadius );

// Link to it if autolink mode is on.
if ( EditBehaviours.autoLink )
Expand All @@ -657,12 +656,12 @@ public void init( final int x, final int y )
* Careful with directed graphs. We always check and
* create links forward in time.
*/
final int t1 = vertex.getTimepoint();
final int t1 = source.getTimepoint();
final int t2 = previous.getTimepoint();
if ( t1 != t2 )
{
final V from = t1 > t2 ? previous : vertex;
final V to = t1 > t2 ? vertex : previous;
final V from = t1 > t2 ? previous : source;
final V to = t1 > t2 ? source : previous;
final E eref = overlayGraph.edgeRef();
overlayGraph.addEdge( from, to, eref ).init();
overlayGraph.releaseRef( eref );
Expand All @@ -673,19 +672,18 @@ public void init( final int x, final int y )
undo.setUndoPoint();

if ( FOCUS_EDITED_SPOT )
focus.focusVertex( vertex );
focus.focusVertex( source );

if ( SELECT_ADDED_SPOT )
{
selection.pauseListeners();
selection.clearSelection();
selection.setSelected( vertex, true );
selection.setSelected( source, true );
selection.resumeListeners();
}
}
finally
{
overlayGraph.releaseRef( ref );
lock.writeLock().unlock();
}
}
Expand Down Expand Up @@ -731,32 +729,43 @@ public void init( final int x, final int y )
@Override
public void drag( final int x, final int y )
{
if ( moving && !creatingNewSpot )
if ( moving )
{
lock.readLock().lock();
try
if ( creatingNewSpot )
{
// Move the new spot around.
renderer.getGlobalPosition( x, y, pos );
LinAlgHelpers.add( pos, start, pos );
source.setPosition( pos );
}
else
{
if ( renderer.getVertexAt( x, y, POINT_SELECT_DISTANCE_TOLERANCE, target ) == null )
// Show a future link to a new or existing spot.
lock.readLock().lock();
try
{
// No target in the vicinity - paint the future one.
overlay.paintGhostTarget = true;
System.out.println( "[AddOrLinkSpot] No near target" ); // DEBUG
renderer.getGlobalPosition( x, y, pos );
LinAlgHelpers.add( pos, start, pos );
System.arraycopy( pos, 0, overlay.to, 0, pos.length );
if ( renderer.getVertexAt( x, y, POINT_SELECT_DISTANCE_TOLERANCE, target ) == null )
{
// No target in the vicinity - paint the future one.
overlay.paintGhostTarget = true;
System.out.println( "[AddOrLinkSpot] No near target" ); // DEBUG
renderer.getGlobalPosition( x, y, pos );
LinAlgHelpers.add( pos, start, pos );
System.arraycopy( pos, 0, overlay.to, 0, pos.length );
}
else
{
// Snap ghost link to found target.
overlay.paintGhostTarget = false;
System.out.println( "[AddOrLinkSpot] Found a close target: " + target ); // DEBUG
target.localize( overlay.to );
}
}
else
finally
{
// Snap ghost link to found target.
overlay.paintGhostTarget = false;
System.out.println( "[AddOrLinkSpot] Found a close target: " + target ); // DEBUG
target.localize( overlay.to );
lock.readLock().unlock();
}
}
finally
{
lock.readLock().unlock();
}
}
}

Expand Down

0 comments on commit 48883de

Please sign in to comment.