2008-03-03 22:00:38 +01: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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
2008-03-31 12:00:47 +02:00
|
|
|
/* TODO:
|
|
|
|
|
|
|
|
What if we solve the continuous-modification/sync issue by making a
|
|
|
|
copy of the 'pushed' widget, and operating on that instead (hiding
|
|
|
|
the original), then when the widget is released, copy its data into
|
|
|
|
the original?
|
|
|
|
|
|
|
|
*/
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Sequence_Widget.H"
|
2008-03-03 22:00:38 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
list <Sequence_Widget *> Sequence_Widget::_selection;
|
|
|
|
Sequence_Widget * Sequence_Widget::_current = NULL;
|
|
|
|
Sequence_Widget * Sequence_Widget::_pushed = NULL;
|
|
|
|
Sequence_Widget * Sequence_Widget::_belowmouse = NULL;
|
2008-03-03 22:00:38 +01:00
|
|
|
|
|
|
|
void
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence_Widget::draw_label ( const char *label, Fl_Align align, Fl_Color color )
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2008-04-27 07:59:07 +02:00
|
|
|
X += abs_w();
|
2008-03-03 22:00:38 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-06 05:08:06 +01:00
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
Fl_Label lab;
|
|
|
|
|
2008-03-06 04:24:31 +01:00
|
|
|
lab.color = color;
|
2008-03-06 05:08:06 +01:00
|
|
|
// lab.type = FL_SHADOW_LABEL;
|
|
|
|
lab.type = FL_ENGRAVED_LABEL;
|
2008-03-03 22:00:38 +01:00
|
|
|
lab.value = label;
|
|
|
|
lab.font = FL_HELVETICA;
|
|
|
|
lab.size = 14;
|
|
|
|
|
2008-03-06 05:08:06 +01:00
|
|
|
int lw, lh;
|
|
|
|
|
|
|
|
fl_font( lab.font, lab.size );
|
|
|
|
fl_measure( lab.value, lw, lh );
|
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
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;
|
|
|
|
|
2008-04-27 07:59:07 +02:00
|
|
|
/* adjust for scrolling */
|
2008-03-03 22:00:38 +01:00
|
|
|
if ( abs_x() < scroll_x() )
|
|
|
|
dx = min( 32767, scroll_x() - abs_x() );
|
|
|
|
|
2008-03-06 05:08:06 +01:00
|
|
|
{
|
|
|
|
const Fl_Boxtype b = FL_ROUND_UP_BOX;
|
|
|
|
const int bx = Fl::box_dx( b );
|
|
|
|
const int bw = Fl::box_dw( b );
|
|
|
|
|
|
|
|
if ( align & FL_ALIGN_BOTTOM )
|
|
|
|
fl_draw_box( b, X - dx - bx, Y + H - lh, lw + bw, lh, FL_GRAY );
|
2008-04-26 14:37:25 +02:00
|
|
|
else if ( align == FL_ALIGN_LEFT )
|
|
|
|
fl_draw_box( b, X - dx, Y + ((H / 2) - (lh / 2)), lw + bw, lh, FL_GRAY );
|
|
|
|
else if ( align & FL_ALIGN_TOP )
|
|
|
|
fl_draw_box( b, X - dx - bx + ((W / 2) - (lw / 2)), Y + ((H / 2) - (lh / 2)), lw + bw, lh, FL_GRAY );
|
2008-03-06 05:08:06 +01:00
|
|
|
}
|
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
lab.draw( X - dx, Y, W, H, align );
|
|
|
|
|
|
|
|
if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-03-04 01:25:05 +01:00
|
|
|
int
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence_Widget::dispatch ( int m )
|
2008-03-04 01:25:05 +01:00
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence_Widget::_current = this;
|
2008-03-04 01:25:05 +01:00
|
|
|
|
|
|
|
if ( selected() )
|
|
|
|
{
|
|
|
|
Loggable::block_start();
|
|
|
|
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
for ( list <Sequence_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
|
2008-03-04 01:25:05 +01:00
|
|
|
if ( *i != this )
|
|
|
|
r |= (*i)->handle( m );
|
|
|
|
|
|
|
|
r |= handle( m );
|
|
|
|
|
|
|
|
Loggable::block_end();
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return handle( m );
|
|
|
|
}
|
2008-03-03 22:00:38 +01:00
|
|
|
|
|
|
|
/* base hanlde just does basic dragging */
|
|
|
|
int
|
2008-04-19 06:16:21 +02:00
|
|
|
Sequence_Widget::handle ( int m )
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
|
|
|
int X = Fl::event_x();
|
|
|
|
int Y = Fl::event_y();
|
|
|
|
|
|
|
|
Logger _log( this );
|
|
|
|
|
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
case FL_ENTER:
|
|
|
|
fl_cursor( FL_CURSOR_HAND );
|
|
|
|
return 1;
|
|
|
|
case FL_LEAVE:
|
|
|
|
fl_cursor( FL_CURSOR_DEFAULT );
|
|
|
|
return 1;
|
|
|
|
case FL_PUSH:
|
|
|
|
{
|
2008-03-06 20:30:08 +01:00
|
|
|
/* deletion */
|
2008-03-03 22:00:38 +01:00
|
|
|
if ( Fl::event_state() & FL_CTRL &&
|
2008-03-05 23:51:04 +01:00
|
|
|
Fl::event_button3() )
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
|
|
|
redraw();
|
|
|
|
_track->queue_delete( this );
|
2008-04-22 00:39:11 +02:00
|
|
|
return 1;
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
2008-03-05 23:51:04 +01:00
|
|
|
else
|
|
|
|
if ( Fl::event_button1() )
|
|
|
|
return 1;
|
2008-03-03 22:00:38 +01:00
|
|
|
|
2008-03-05 23:51:04 +01:00
|
|
|
return 0;
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
|
|
|
case FL_RELEASE:
|
2008-03-04 01:25:05 +01:00
|
|
|
if ( _drag )
|
|
|
|
{
|
2008-04-02 09:19:48 +02:00
|
|
|
end_drag();
|
2008-03-03 22:00:38 +01:00
|
|
|
_log.release();
|
2008-03-04 01:25:05 +01:00
|
|
|
}
|
|
|
|
|
2008-03-06 01:14:46 +01:00
|
|
|
fl_cursor( FL_CURSOR_HAND );
|
2008-03-06 20:30:08 +01:00
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
return 1;
|
|
|
|
case FL_DRAG:
|
2008-03-09 01:38:34 +01:00
|
|
|
case FL_DND_DRAG:
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
2008-03-04 01:25:05 +01:00
|
|
|
if ( ! _drag )
|
2008-03-03 22:00:38 +01:00
|
|
|
{
|
2008-04-02 09:19:48 +02:00
|
|
|
begin_drag ( Drag( x() - X, y() - Y ) );
|
2008-03-03 22:00:38 +01:00
|
|
|
_log.hold();
|
|
|
|
}
|
|
|
|
|
2008-03-06 20:30:08 +01:00
|
|
|
fl_cursor( FL_CURSOR_MOVE );
|
2008-03-04 01:25:05 +01:00
|
|
|
|
2008-03-06 20:30:08 +01:00
|
|
|
const int ox = _drag->x;
|
2008-03-04 01:25:05 +01:00
|
|
|
|
2008-03-03 22:00:38 +01:00
|
|
|
redraw();
|
|
|
|
|
|
|
|
if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() )
|
|
|
|
{
|
|
|
|
int nx = (ox + X) - _track->x();
|
|
|
|
|
2008-04-02 09:19:48 +02:00
|
|
|
// _r->offset = timeline->x_to_ts( nx ) + timeline->xoffset;
|
2008-03-03 22:36:33 +01:00
|
|
|
offset( timeline->x_to_ts( nx ) + timeline->xoffset );
|
2008-03-03 22:00:38 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
if ( Sequence_Widget::_current == this )
|
2008-03-04 01:25:05 +01:00
|
|
|
_track->snap( this );
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( X >= _track->x() + _track->w() ||
|
|
|
|
X <= _track->x() )
|
|
|
|
{
|
|
|
|
/* this drag needs to scroll */
|
|
|
|
|
|
|
|
nframes_t pos = timeline->xoffset;
|
|
|
|
|
|
|
|
nframes_t d = timeline->x_to_ts( 100 );
|
|
|
|
|
|
|
|
if ( X <= _track->x() )
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( pos > d )
|
|
|
|
pos -= d;
|
|
|
|
else
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pos += d;
|
|
|
|
|
2008-03-07 00:29:28 +01:00
|
|
|
timeline->xposition( timeline->ts_to_x( pos ) );
|
2008-04-27 20:44:20 +02:00
|
|
|
|
|
|
|
/* FIXME: why isn't this enough? */
|
|
|
|
// _track->redraw();
|
|
|
|
timeline->redraw();
|
2008-03-03 22:00:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|