Update NTK.
[nondaw.git] / timeline / src / Control_Point.C
blob2d385d5d5b2a9738d41aa40a187702d221d3d8ed
2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 #include <FL/fl_draw.H>
22 #include "Control_Point.H"
26 Control_Point::Control_Point ( Sequence *t, nframes_t when, float y )
28     _sequence = t;
29     _y = y;
30     _r->start = when;
31     _box_color = FL_WHITE;
33     log_create();
36 Control_Point::Control_Point ( const Control_Point &rhs ) : Sequence_Point( rhs )
38     _y = rhs._y;
40     log_create();
43 void
44 Control_Point::get ( Log_Entry &e ) const
46     Sequence_Point::get( e );
48     e.add( ":y", _y );
51 void
52 Control_Point::set ( Log_Entry &e )
54     for ( int i = 0; i < e.size(); ++i )
55     {
56         const char *s, *v;
58         e.get( i, &s, &v );
60         if ( ! strcmp( s, ":y" ) )
61             _y = atof( v );
63         redraw();
65         //          _make_label();
66     }
68     Sequence_Point::set( e );
71 void
72 Control_Point::draw_box ( void )
74     if ( selected() )
75     {
76         fl_color( selection_color() );
77         fl_pie( x(), y(), w(), h(), 0, 360 );
78     }
80     fl_color( box_color() );
82     fl_arc( x(), y(), w(), h(), 0, 360 );
84     if ( this == Sequence_Widget::belowmouse() ||
85          this == Sequence_Widget::pushed() )
86     {
87         char val[10];
88         snprintf( val, sizeof( val ), "%+.2f", 1.0 - _y * 2 );
90         Fl_Align a = 0;
92         if ( x() < _sequence->x() + ( _sequence->w() / 2 ) )
93             a |= FL_ALIGN_RIGHT;
94         else
95             a |= FL_ALIGN_LEFT;
97         if ( y() < _sequence->y() + ( _sequence->h() / 2 ) )
98             a |= FL_ALIGN_BOTTOM;
99         else
100             a |= FL_ALIGN_TOP;
101             
102         draw_label( val, a, FL_FOREGROUND_COLOR );
103     }
108 Control_Point::handle ( int m )
110     int r = Sequence_Widget::handle( m );
112     switch ( m )
113     {
115         case FL_RELEASE:
116             sequence()->sort();
117             redraw();
118             break;
119         case FL_ENTER:
120         case FL_LEAVE:
121             redraw();
122             break;
123         case FL_DRAG:
124         {
125             sequence()->sort();
127             if ( nselected() > 1 )
128                 // only allow horizontal movement when part of a selection...
129                 break;
131             int Y = Fl::event_y() - parent()->y();
133             if ( Y >= 0 && Y < parent()->h() )
134             {
135                 _y = (float)Y / parent()->h();
136                 redraw();
137             }
139             break;
140         }
141     }
143     return r;