Allow interactive trimming of regions.

This commit is contained in:
Jonathan Moore Liles 2008-02-15 22:23:58 -06:00
parent 62781a70ed
commit 41ac62e2cd
3 changed files with 56 additions and 19 deletions

View File

@ -37,6 +37,35 @@ Region::Region ( int X, int Y, int W, int H, const char *L=0 ) : Waveform( X, Y,
_track = NULL;
}
void
Region::trim ( enum trim_e t, int X )
{
switch ( t )
{
case LEFT:
{
int d = X - x();
_start += d;
resize( x() + d, y(), w() - d, h() );
break;
}
case RIGHT:
{
int d = (x() + w()) - X;
_end -= d;
resize( x(), y(), w() - d, h() );
break;
}
default:
return;
}
redraw();
parent()->redraw();
}
int
Region::handle ( int m )
{
@ -45,7 +74,7 @@ Region::handle ( int m )
return 1;
static int ox, oy;
static enum trim_e trimming;
switch ( m )
{
@ -59,27 +88,15 @@ Region::handle ( int m )
switch ( Fl::event_button() )
{
case 1:
{
/* trim */
int d = X - x();
_start += d;
resize( x() + d, y(), w() - d, h() );
redraw();
parent()->redraw();
trim( trimming = LEFT, X );
break;
}
case 3:
{
int d = (x() + w()) - X;
_end -= d;
resize( x(), y(), w() - d, h() );
redraw();
parent()->redraw();
trim( trimming = RIGHT, X );
break;
}
default:
return 0;
}
fl_cursor( FL_CURSOR_WE );
return 1;
}
else
@ -102,6 +119,15 @@ Region::handle ( int m )
return 1;
case FL_DRAG:
if ( Fl::event_state() & FL_CTRL )
if ( trimming )
{
trim( trimming, Fl::event_x() );
return 1;
}
else
return 0;
if ( ox + Fl::event_x() >= _track->x() )
position( ox + Fl::event_x(), y() );
@ -135,7 +161,11 @@ Region::draw ( void )
{
draw_box();
// fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
Waveform::draw();
// fl_pop_clip();
draw_label();
}

View File

@ -28,6 +28,10 @@ class Region : public Waveform
Track *_track;
enum trim_e { NO, LEFT, RIGHT };
void trim ( enum trim_e t, int X );
public:
Region ( int X, int Y, int W, int H, const char *L );

9
main.C
View File

@ -20,6 +20,7 @@
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Pack.H>
#include <FL/Fl_Group.H>
@ -50,13 +51,15 @@ main ( int argc, char **argv )
init_colors();
Fl_Window *main_window = new Fl_Window( 0, 0, 800, 600 );
Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 );
Fl_Scroll *scroll = new Fl_Scroll( 0, 0, 800, 600 );
Fl_Pack *tracks = new Fl_Pack( 0, 0, 5000, 5000 );
tracks->type( Fl_Pack::VERTICAL );
Fl::get_system_colors();
Fl::scheme( "plastic" );
// Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 );
@ -103,8 +106,8 @@ main ( int argc, char **argv )
Region *wave2 = new Region( 0, 0, 350, 100, "bar" );
wave2->peaks( peaks );
wave2->start( 0 );
wave2->end( len / 2 );
wave2->start( 300 );
wave2->end( len );
track2->add( wave2 );