Update NTK.
[nondaw.git] / timeline / src / Annotation_Sequence.H
blobae3fed6c35c09d3082147abe0cf2dbe3b549ac94
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 #pragma once
22 #include "Sequence.H"
23 #include "Annotation_Point.H"
24 #include "Annotation_Region.H"
25 #include "Timeline.H"
27 #include "Track.H"
29 class Annotation_Sequence : public Sequence
32 protected:
34     virtual void get ( Log_Entry &e ) const
35         {
36             e.add( ":track", _track );
37         }
39     void
40     set ( Log_Entry &e )
41         {
42             for ( int i = 0; i < e.size(); ++i )
43             {
44                 const char *s, *v;
46                 e.get( i, &s, &v );
48                 if ( ! strcmp( ":track", s ) )
49                 {
50                     int i;
51                     sscanf( v, "%X", &i );
52                     Track *t = (Track*)Loggable::find( i );
54                     assert( t );
56                     t->add( this );
57                 }
58             }
59         }
61     Annotation_Sequence ( ) : Sequence ( 0 )
62         {
63             color( fl_darker( FL_GREEN ) );
64         }
66 public:
69     LOG_CREATE_FUNC( Annotation_Sequence );
71     Fl_Cursor cursor ( void ) const { return FL_CURSOR_INSERT; }
73     Annotation_Sequence ( Track *track ) : Sequence( track )
74         {
75             color( fl_darker(  FL_GREEN ) );
77             log_create();
78         }
80 /*     Annotation_Sequence ( int X, int Y, int W, int H ) : Sequence ( 0 ) */
81 /*         { */
82 /*         } */
84     ~Annotation_Sequence ( )
85         {
86             Loggable::block_start();
88             clear();
90             log_destroy();
92             track()->remove( this );
94             Loggable::block_end();
95         }
97     int handle ( int m )
98         {
100             if ( Sequence::handle( m ) )
101                 return 1;
103             switch ( m )
104             {
105                 case FL_PUSH:
106                 {
107                     Logger log( this );
109                     if ( Fl::event_button1() )
110                     {
111                         add( new Annotation_Point( this, x_to_offset( Fl::event_x() ), "mark" ) );
112                         redraw();
113                     }
114                     if ( Fl::event_button3() && Fl::event_shift() )
115                     {
116                         Annotation_Region *r = new Annotation_Region( this, x_to_offset( Fl::event_x() ), "mark" );
118                         add( r );
120                         Sequence_Widget::pushed( r );
122                         r->handle( m );
124                         redraw();
126                         return 1;
128                     }
129                     else if ( Fl::event_button3() && ! ( Fl::event_state() & ( FL_ALT | FL_SHIFT | FL_CTRL ) ) )
130                     {
132                         Fl_Menu_Item menu[] =
133                             {
134                                 { "Remove" },
135                                 { 0 }
136                             };
138                         const Fl_Menu_Item *r = menu->popup( Fl::event_x(), Fl::event_y(), "Annotation Sequence" );
140                         if ( r )
141                         {
142                             if ( r == &menu[ 0 ] )
143                             {
144                                 Fl::delete_widget( this );
145                             }
147                         }
149                         return 1;
150                     }
151                     break;
152                 }
153                 default:
154                     break;
155             }
157             return 0;
158         }