Browse Source

Attempt to clean up label drawing for track widgets.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
4a266bc86a
6 changed files with 98 additions and 38 deletions
  1. +1
    -16
      Region.C
  2. +80
    -20
      Region.H
  3. +14
    -0
      Track.C
  4. +2
    -0
      Track.H
  5. +0
    -1
      Waveform.C
  6. +1
    -1
      main.C

+ 1
- 16
Region.C View File

@@ -324,22 +324,7 @@ Region::draw ( int X, int Y, int W, int H )
fl_font( FL_HELVETICA, 14 ); fl_font( FL_HELVETICA, 14 );
fl_color( FL_BLACK ); fl_color( FL_BLACK );


int bx = Fl::box_dx( box() );
int by = Fl::box_dy( box() );
int bw = Fl::box_dw( box() );
int bh = Fl::box_dh( box() );

int dx = min( 32767, timeline.ts_to_x( offset ) );

Fl_Align align = (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP);
fl_draw( _clip->name(), (bx + rx + 1) - dx, Y + 1 + by, rw - bw, H - bh, align );
fl_color( FL_WHITE );
fl_draw( _clip->name(), (bx + rx) - dx, Y + by , rw - bw, H - bh, align );

// fl_draw( _clip->name(), X, Y );

//(Fl_Align)FL_ALIGN_LEFT | FL_ALIGN_BOTTOM );

draw_label( _clip->name(), (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP | FL_ALIGN_INSIDE) );


/* fl_color( FL_RED ); */ /* fl_color( FL_RED ); */
/* fl_line( x(), y(), x(), y() + h() ); */ /* fl_line( x(), y(), x(), y() + h() ); */


+ 80
- 20
Region.H View File

@@ -62,7 +62,6 @@ public:
_selected = false; _selected = false;
} }



Fl_Group * parent ( void ) const { return _track; } Fl_Group * parent ( void ) const { return _track; }


int scroll_x ( void ) const { return timeline.ts_to_x( timeline.xoffset ); } int scroll_x ( void ) const { return timeline.ts_to_x( timeline.xoffset ); }
@@ -92,11 +91,81 @@ public:


virtual nframes_t length ( void ) const { return _end - _start; } virtual nframes_t length ( void ) const { return _end - _start; }


virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }

/* just draw a simple box */ /* just draw a simple box */
virtual void virtual void
draw ( int X, int Y, int W, int H ) draw ( int X, int Y, int W, int H )
{ {
fl_draw_box( FL_FLAT_BOX, x(), y(), w(), y(), _box_color );
fl_draw_box( box(), x(), y(), w(), y(), _box_color );
}


virtual void
draw_label ( const char *label, Fl_Align align )
{
int X, Y;

X = x();
Y = y();

/* FIXME: why do we have to to this here? why doesn't Fl_Lable::draw take care of this stuff? */
if ( ! (align & FL_ALIGN_INSIDE) )
{
if ( align & FL_ALIGN_RIGHT )
{
X += w();
align = (Fl_Align)((align & ~FL_ALIGN_RIGHT) | FL_ALIGN_LEFT);
}
if ( align & FL_ALIGN_BOTTOM )
{
Y += h();
align = (Fl_Align)((align & ~FL_ALIGN_BOTTOM) | FL_ALIGN_TOP);
}
}



/* fl_font( FL_HELVETICA, 14 ); */
/* fl_color( FL_BLACK ); */
/* fl_draw( label, X + 2, Y + 2, w(), h(), align ); */
/* fl_color( FL_WHITE ); */
/* fl_draw( label, X, Y, w(), h(), align ); */

/* for some reasone FL_SHADOW_LABLE doesn't always use
* black for the shadow color...so we can't rely on it. */

Fl_Label lab;

lab.color = FL_WHITE;
lab.type = FL_SHADOW_LABEL;
lab.value = label;
lab.font = FL_HELVETICA;
lab.size = 14;

int W = w();
int H = h();

if ( align & FL_ALIGN_INSIDE )
{
X += Fl::box_dx( box() );
Y += Fl::box_dy( box() );
W -= Fl::box_dw( box() );
H -= Fl::box_dh( box() );
}

if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );

int dx = 0;
int tx = timeline.ts_to_x( _offset );

if ( tx < scroll_x() )
dx = min( 32767, scroll_x() - tx );

lab.draw( X - dx, Y, W, H, align );

if ( align & FL_ALIGN_CLIP ) fl_pop_clip();

} }


/* base hanlde just does basic dragging */ /* base hanlde just does basic dragging */
@@ -153,24 +222,17 @@ public:
{ {
float _tempo; float _tempo;


static Fl_Boxtype box ( void ) { return FL_UP_BOX; }

public: public:


Tempo_Point ( )
{
_tempo = 120;
_offset = 0;
_start = 0;
_end = 300;
}
/* Tempo_Point ( ) */
/* { */
/* _tempo = 120; */
/* } */


Tempo_Point ( nframes_t when, float bpm ) Tempo_Point ( nframes_t when, float bpm )
{ {
_tempo = bpm; _tempo = bpm;
_offset = when; _offset = when;
_start = 0;
_end = 300;
} }


int w ( void ) const { return 10; } int w ( void ) const { return 10; }
@@ -182,17 +244,14 @@ public:
if ( x() < 0 ) if ( x() < 0 )
return; return;


fl_draw_box( box(), x(), Y, w(), H, _box_color );
Track_Widget::draw( x(), Y, w(), H );



char pat[40]; char pat[40];


snprintf( pat, 40, "%.1f", _tempo ); snprintf( pat, 40, "%.1f", _tempo );


fl_font( FL_HELVETICA, 14 );
fl_color( FL_BLACK );
fl_draw( pat, x() + w() + 1, Y + 1, w(), h(), FL_ALIGN_LEFT );
fl_color( FL_WHITE );
fl_draw( pat, x() + w(), Y, w(), h(), FL_ALIGN_LEFT );
draw_label( pat, FL_ALIGN_RIGHT );


} }


@@ -209,7 +268,6 @@ public:
static Fl_Color _selection_color; static Fl_Color _selection_color;
static Fl_Color selection_color ( void ) { return _selection_color; } static Fl_Color selection_color ( void ) { return _selection_color; }
static void selection_color ( Fl_Color v ) { _selection_color = v; } static void selection_color ( Fl_Color v ) { _selection_color = v; }
static Fl_Boxtype box ( void ) { return _box; }


enum trim_e { NO, LEFT, RIGHT }; enum trim_e { NO, LEFT, RIGHT };
void trim ( enum trim_e t, int X ); void trim ( enum trim_e t, int X );
@@ -217,6 +275,8 @@ public:


public: public:


Fl_Boxtype box ( void ) const { return Region::_box; }

Region ( const Region & rhs ); Region ( const Region & rhs );
Region ( Clip *c ); Region ( Clip *c );




+ 14
- 0
Track.C View File

@@ -24,6 +24,20 @@


#include <FL/fl_draw.H> #include <FL/fl_draw.H>



static bool
sort_func ( Track_Widget *lhs, Track_Widget *rhs )
{
return *lhs < *rhs;
}


void
Track::sort ( void )
{
_regions.sort( sort_func );
}

void void
Track::draw ( void ) Track::draw ( void )
{ {


+ 2
- 0
Track.H View File

@@ -68,4 +68,6 @@ public:
void snap ( Track_Widget *r ); void snap ( Track_Widget *r );
int handle ( int m ); int handle ( int m );


void sort ( void );

}; };

+ 0
- 1
Waveform.C View File

@@ -79,7 +79,6 @@ draw_waveform ( int X, int Y, int W, int H, Clip *_clip, nframes_t _start, nfram


fl_color( fl_darker( fl_darker( color ) ) ); fl_color( fl_darker( fl_darker( color ) ) );



fl_line_style( FL_SOLID, 2 ); fl_line_style( FL_SOLID, 2 );


fl_begin_line(); fl_begin_line();


+ 1
- 1
main.C View File

@@ -136,7 +136,7 @@ main ( int argc, char **argv )
Track *tempo_track = new Track( 0, 0, 800, 24 ); Track *tempo_track = new Track( 0, 0, 800, 24 );


tempo_track->label( "tempo map" ); tempo_track->label( "tempo map" );
tempo_track->add( new Tempo_Point );
tempo_track->add( new Tempo_Point( 0, 120 ) );


tempo_track->add( new Tempo_Point( 56000, 250 ) ); tempo_track->add( new Tempo_Point( 56000, 250 ) );




Loading…
Cancel
Save