From 41ac62e2cdeedfb020d3bf59b9dd096fd8278740 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Fri, 15 Feb 2008 22:23:58 -0600 Subject: [PATCH] Allow interactive trimming of regions. --- Region.C | 62 +++++++++++++++++++++++++++++++++++++++++--------------- Region.H | 4 ++++ main.C | 9 +++++--- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/Region.C b/Region.C index 578d7cf..d325a10 100644 --- a/Region.C +++ b/Region.C @@ -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(); } diff --git a/Region.H b/Region.H index d4ead91..60eb907 100644 --- a/Region.H +++ b/Region.H @@ -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 ); diff --git a/main.C b/main.C index 57eb14f..b9b2cfc 100644 --- a/main.C +++ b/main.C @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -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 );