Browse Source

Implement snap-to for regions.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
a055856c56
2 changed files with 43 additions and 4 deletions
  1. +9
    -1
      Region.C
  2. +34
    -3
      Track.H

+ 9
- 1
Region.C View File

@@ -216,7 +216,15 @@ Region::handle ( int m )
}

if ( ox + X >= _track->x() )
position( ox + X, y() );
{
int nx = ox + X;

// nx = _track->snap( this, nx );

position( nx, y() );

_track->snap( this );
}

if ( Y > y() + h() )
{


+ 34
- 3
Track.H View File

@@ -60,9 +60,6 @@ public:

void add ( Region *r )
{

printf( "add" );

if ( r->track() )
{
r->track()->remove_region( r );
@@ -80,6 +77,40 @@ public:
r->redraw();
}

/** snap /r/ to nearest edge */
void
snap ( Region *r )
{
const int snap_pixels = 10;

int rx1 = r->x();
int rx2 = r->x() + r->w();

for ( int i = children(); i-- ; )
{
const Fl_Widget *w = child( i );

if ( w == r )
continue;

int wx1 = w->x();
int wx2 = w->x() + w->w();

if ( abs( rx1 - wx2 ) < snap_pixels )
{
rx1 = wx2 - 1;
break;
}

if ( abs( rx2 - wx1 ) < snap_pixels )
{
rx1 = (wx1 - r->w()) + 1;
break;
}
}
r->position( rx1, y() );
}

int handle ( int m )
{
switch ( m )


Loading…
Cancel
Save