diff --git a/Makefile b/Makefile index aaa0a30..b71ae2e 100644 --- a/Makefile +++ b/Makefile @@ -11,3 +11,6 @@ OBJS=Waveform.o Region.o main.o test: $(OBJS) $(CXX) $(CXXFLAGS) $(LIBS) $(OBJS) -o $@ + +clean: + rm -f $(OBJS) test diff --git a/Region.C b/Region.C index 24d6d12..578d7cf 100644 --- a/Region.C +++ b/Region.C @@ -17,18 +17,24 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ +#include "Track.H" #include "Region.H" #include #include #include +#include + +#include Region::Region ( int X, int Y, int W, int H, const char *L=0 ) : Waveform( X, Y, W, H, L ) { - align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM ); + align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP ); labeltype( FL_SHADOW_LABEL ); labelcolor( FL_WHITE ); box( FL_PLASTIC_UP_BOX ); + + _track = NULL; } int @@ -38,6 +44,9 @@ Region::handle ( int m ) if ( Fl_Widget::handle( m ) ) return 1; + static int ox, oy; + + switch ( m ) { case FL_PUSH: @@ -73,9 +82,46 @@ Region::handle ( int m ) } return 1; } + else + { + ox = x() - Fl::event_x(); + oy = y() - Fl::event_y(); + + if ( Fl::event_button() == 2 ) + { +// _track->add( new Region( *this ) ); + } + + return 1; + } return 0; break; } + case FL_RELEASE: + fl_cursor( FL_CURSOR_DEFAULT ); + return 1; + case FL_DRAG: + + if ( ox + Fl::event_x() >= _track->x() ) + position( ox + Fl::event_x(), y() ); + + if ( Fl::event_y() > y() + h() ) + { + if ( _track->next() ) + _track->next()->add( this ); + } + else + if ( Fl::event_y() < y() ) + { + if ( _track->prev() ) + _track->prev()->add( this ); + } +// if ( Fl::event_y() - oy >= h() ) + + parent()->redraw(); + + fl_cursor( FL_CURSOR_MOVE ); + return 1; default: return 0; break; diff --git a/Region.H b/Region.H index 402237c..d4ead91 100644 --- a/Region.H +++ b/Region.H @@ -17,16 +17,24 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ +#pragma once + +class Track; #include "Waveform.H" class Region : public Waveform { + Track *_track; + public: Region ( int X, int Y, int W, int H, const char *L ); int handle ( int m ); void draw ( void ); + + Track * track ( void ) { return _track; } + void track ( Track *t ) { _track = t; } }; diff --git a/Track.H b/Track.H new file mode 100644 index 0000000..8693ec0 --- /dev/null +++ b/Track.H @@ -0,0 +1,83 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +#pragma once + +#include + +#include "Region.H" + + +#include + +#include +using std::list; + +class Track : public Fl_Group +{ + Track *_next; + Track *_prev; + + list _regions; + + char *_name; + +public: + + Track ( int X, int Y, int W, int H ) : Fl_Group( X, Y, W, H ) + { + _next = _prev = NULL; + _name = NULL; + + box( FL_DOWN_BOX ); + color( fl_darker( FL_GRAY ) ); + } + + Track *next ( void ) { return _next; } + Track *prev ( void ) { return _prev; } + void prev ( Track *t ) { _prev = t; } + void next ( Track *t ) { _next = t; } + + void remove_region ( Region *r ) + { + _regions.remove( r ); + } + + void add ( Region *r ) + { + + printf( "add" ); + + if ( r->track() ) + { + r->track()->remove_region( r ); + r->track()->redraw(); + } + + _regions.push_back( r ); + + r->track( this ); + + Fl_Group::add( r ); +// add( r ); + + r->position( r->x(), y() ); + r->redraw(); + } +}; diff --git a/Waveform.C b/Waveform.C index 3f7786a..ed47f58 100644 --- a/Waveform.C +++ b/Waveform.C @@ -143,6 +143,8 @@ Waveform::draw ( int X, int Y, int W, int H ) fl_color( fl_darker( fl_darker( selection_color() ) ) ); + fl_line_style( FL_SOLID, 2 ); + fl_begin_line(); j = 0; @@ -167,6 +169,8 @@ Waveform::draw ( int X, int Y, int W, int H ) fl_end_line(); + fl_line_style( FL_SOLID, 0 ); + fl_pop_matrix(); // fl_pop_clip(); diff --git a/main.C b/main.C index 96af6e5..57eb14f 100644 --- a/main.C +++ b/main.C @@ -35,6 +35,8 @@ Fl_Color velocity_colors[128]; +#include "Track.H" + void init_colors ( void ) { @@ -52,10 +54,16 @@ main ( int argc, char **argv ) Fl_Scroll *scroll = new Fl_Scroll( 0, 0, 800, 600 ); - Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 ); + Fl_Pack *tracks = new Fl_Pack( 0, 0, 5000, 5000 ); + tracks->type( Fl_Pack::VERTICAL ); + + +// Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 ); + + Track *track1 = new Track( 40, 0, 5000, 100 ); // pack->type( Fl_Pack::VERTICAL ); - pack->box( FL_DOWN_BOX ); +// pack->box( FL_DOWN_BOX ); Region *wave = new Region( 0, 0, 5000, 100, "foo" ); @@ -78,19 +86,34 @@ main ( int argc, char **argv ) fread( peaks, len, 1, fp ); - wave->peaks( peaks ); wave->start( 0 ); wave->end( len ); wave->color( FL_CYAN ); wave->selection_color( fl_darker( FL_GRAY ) ); - wave->selection_color( FL_GREEN ); - pack->add( wave ); + track1->add( wave ); + + track1->end(); + + Track *track2 = new Track( 40, 0, 5000, 100 ); + + Region *wave2 = new Region( 0, 0, 350, 100, "bar" ); + + wave2->peaks( peaks ); + wave2->start( 0 ); + wave2->end( len / 2 ); + + track2->add( wave2 ); + + track2->end(); + + track1->next( track2 ); + track2->prev( track1 ); - pack->end(); + tracks->end(); scroll->end(); main_window->end();