2008-04-20 23:46:47 +02:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#include "Control_Sequence.H"
|
|
|
|
#include "Track.H"
|
|
|
|
|
2008-04-22 02:45:17 +02:00
|
|
|
bool Control_Sequence::draw_with_gradient = true;
|
|
|
|
bool Control_Sequence::draw_with_polygon = true;
|
|
|
|
bool Control_Sequence::draw_with_grid = true;
|
2008-04-21 05:05:25 +02:00
|
|
|
|
|
|
|
Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 )
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
|
|
|
_track = track;
|
|
|
|
|
|
|
|
if ( track )
|
|
|
|
track->add( this );
|
|
|
|
|
|
|
|
log_create();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Control_Sequence::~Control_Sequence ( )
|
|
|
|
{
|
|
|
|
log_destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Control_Sequence::init ( void )
|
|
|
|
{
|
|
|
|
_track = NULL;
|
|
|
|
|
|
|
|
color( fl_darker( FL_GREEN ) );
|
|
|
|
}
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
void
|
|
|
|
Control_Sequence::get ( Log_Entry &e )
|
|
|
|
{
|
|
|
|
Sequence::get( e );
|
|
|
|
|
|
|
|
e.add( ":t", _track );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Control_Sequence::set ( Log_Entry &e )
|
|
|
|
{
|
|
|
|
Sequence::set( e );
|
|
|
|
|
|
|
|
for ( int i = 0; i < e.size(); ++i )
|
|
|
|
{
|
|
|
|
const char *s, *v;
|
|
|
|
|
|
|
|
e.get( i, &s, &v );
|
|
|
|
|
|
|
|
if ( ! strcmp( ":t", s ) )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
sscanf( v, "%X", &i );
|
|
|
|
Track *t = (Track*)Loggable::find( i );
|
|
|
|
|
|
|
|
assert( t );
|
|
|
|
|
|
|
|
t->add( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Control_Sequence::draw ( void )
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( ! fl_not_clipped( x(), y(), w(), h() ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
fl_push_clip( x(), y(), w(), h() );
|
|
|
|
|
2008-04-23 05:40:31 +02:00
|
|
|
/* draw the box with the ends cut off. */
|
|
|
|
draw_box( box(), x() - Fl::box_dx( box() ), y(), w() + Fl::box_dw( box() ), h(), color() );
|
|
|
|
|
|
|
|
|
|
|
|
const int bx = x();
|
|
|
|
const int by = y() + Fl::box_dy( box() );
|
|
|
|
const int bw = w();
|
|
|
|
const int bh = h() - Fl::box_dh( box() );
|
2008-04-20 23:46:47 +02:00
|
|
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
2008-04-23 05:40:31 +02:00
|
|
|
fl_clip_box( bx, by, bw, bh, X, Y, W, H );
|
2008-04-20 23:46:47 +02:00
|
|
|
|
2008-04-22 02:45:17 +02:00
|
|
|
if ( draw_with_gradient )
|
2008-04-22 01:45:54 +02:00
|
|
|
{
|
|
|
|
Fl_Color target = fl_color_average( color(), FL_WHITE, 0.50f );
|
|
|
|
|
2008-04-23 05:40:31 +02:00
|
|
|
for ( int gy = 0; gy < bh; gy++ )
|
2008-04-22 01:45:54 +02:00
|
|
|
{
|
2008-04-23 05:40:31 +02:00
|
|
|
fl_color( fl_color_average( target, selection_color(), gy / (float)bh) );
|
|
|
|
fl_line( X, by + gy, X + W, by + gy );
|
2008-04-22 01:45:54 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-20 23:46:47 +02:00
|
|
|
|
2008-04-22 02:45:17 +02:00
|
|
|
if ( draw_with_grid )
|
|
|
|
{
|
|
|
|
fl_color( fl_darker( color() ) );
|
|
|
|
|
2008-04-23 05:40:31 +02:00
|
|
|
const int inc = bh / 10;
|
2008-04-22 02:45:17 +02:00
|
|
|
if ( inc )
|
2008-04-23 05:40:31 +02:00
|
|
|
for ( int gy = 0; gy < bh; gy += inc )
|
|
|
|
fl_line( X, by + gy, X + W, by + gy );
|
2008-04-22 02:45:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
fl_color( fl_color_average( selection_color(), color(), 0.90f ) );
|
2008-04-22 01:45:54 +02:00
|
|
|
fl_line_style( FL_SOLID, 4 );
|
|
|
|
|
2008-04-22 02:45:17 +02:00
|
|
|
if ( draw_with_polygon )
|
2008-04-22 01:45:54 +02:00
|
|
|
fl_begin_complex_polygon();
|
|
|
|
else
|
|
|
|
fl_begin_line();
|
2008-04-20 23:46:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
list <Sequence_Widget *>::const_iterator e = _widgets.end();
|
|
|
|
e--;
|
|
|
|
|
|
|
|
if ( _widgets.size() )
|
|
|
|
for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); ; r++ )
|
|
|
|
{
|
2008-04-22 01:45:54 +02:00
|
|
|
const int ry = (*r)->y();
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
if ( r == _widgets.begin() )
|
|
|
|
{
|
2008-04-22 02:45:17 +02:00
|
|
|
if ( draw_with_gradient )
|
2008-04-22 01:45:54 +02:00
|
|
|
{
|
2008-04-23 05:40:31 +02:00
|
|
|
fl_vertex( bx, by );
|
|
|
|
fl_vertex( bx, ry );
|
2008-04-22 01:45:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-23 05:40:31 +02:00
|
|
|
fl_vertex( bx, bh + by );
|
|
|
|
fl_vertex( bx, ry );
|
2008-04-22 01:45:54 +02:00
|
|
|
}
|
2008-04-20 23:46:47 +02:00
|
|
|
}
|
|
|
|
|
2008-04-22 01:45:54 +02:00
|
|
|
fl_vertex( (*r)->x(), ry );
|
2008-04-20 23:46:47 +02:00
|
|
|
|
|
|
|
if ( r == e )
|
|
|
|
{
|
2008-04-22 02:45:17 +02:00
|
|
|
if ( draw_with_gradient )
|
2008-04-22 01:45:54 +02:00
|
|
|
{
|
2008-04-23 05:40:31 +02:00
|
|
|
fl_vertex( bx + bw, ry );
|
|
|
|
fl_vertex( bx + bw, by );
|
2008-04-22 01:45:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-23 05:40:31 +02:00
|
|
|
fl_vertex( bx + bw, ry );
|
|
|
|
fl_vertex( bx + bw, bh + by );
|
2008-04-22 01:45:54 +02:00
|
|
|
}
|
2008-04-20 23:46:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-04-22 02:45:17 +02:00
|
|
|
if ( draw_with_polygon )
|
2008-04-22 01:45:54 +02:00
|
|
|
fl_end_complex_polygon();
|
|
|
|
else
|
|
|
|
fl_end_line();
|
2008-04-20 23:46:47 +02:00
|
|
|
|
|
|
|
fl_line_style( FL_SOLID, 0 );
|
|
|
|
|
|
|
|
timeline->draw_measure_lines( x(), y(), w(), h(), color() );
|
|
|
|
|
|
|
|
for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
|
|
|
|
(*r)->draw_box();
|
|
|
|
|
|
|
|
fl_pop_clip();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Control_Sequence::handle ( int m )
|
|
|
|
{
|
|
|
|
int r = Sequence::handle( m );
|
|
|
|
|
|
|
|
if ( r )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
case FL_PUSH:
|
|
|
|
{
|
|
|
|
if ( Fl::event_button1() )
|
|
|
|
{
|
|
|
|
Control_Point *r = new Control_Point( this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ), (float)(Fl::event_y() - y()) / h() );
|
|
|
|
|
|
|
|
add( r );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|