initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / trackcanvas.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2014 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifndef TRACKCANVAS_H
23 #define TRACKCANVAS_H
24
25 #include "asset.inc"
26 #include "auto.inc"
27 #include "autos.inc"
28 #include "bctimer.inc"
29 #include "edit.inc"
30 #include "edithandles.inc"
31 #include "edl.inc"
32 #include "floatauto.inc"
33 #include "floatautos.inc"
34 #include "guicast.h"
35 #include "indexable.h"
36 #include "keyframe.inc"
37 #include "mwindow.inc"
38 #include "mwindowgui.inc"
39 #include "plugin.inc"
40 #include "pluginset.inc"
41 #include "plugintoggles.inc"
42 #include "resourcepixmap.inc"
43 #include "timelinepane.inc"
44 #include "track.inc"
45 #include "tracks.inc"
46 #include "transitionhandles.inc"
47
48 // draw mode:
49 // NORMAL_DRAW causes incremental drawing of pixmaps.  Used for navigation and index refresh.
50 // FORCE_REDRAW causes all resource pixmaps to be redrawn from scratch.  Used by editing.
51 // IGNORE_THREAD causes resource pixmaps to ignore picon thread.  Used by Piconthread.
52 #define NORMAL_DRAW 1
53 #define FORCE_REDRAW 2
54 #define IGNORE_THREAD 3
55
56 class TrackCanvas : public BC_SubWindow
57 {
58 public:
59         TrackCanvas(MWindow *mwindow, MWindowGUI *gui);
60         TrackCanvas(MWindow *mwindow, TimelinePane *pane, int x, int y, int w, int h);
61         ~TrackCanvas();
62
63         void create_objects();
64         void resize_event();
65         int drag_start_event();
66         int cursor_leave_event();
67         int keypress_event();
68         void draw_resources(int mode = 0,
69                 int indexes_only = 0,     // Redraw only certain audio resources with indexes
70                 Indexable *indexable = 0);
71         void draw_highlight_rectangle(int x, int y, int w, int h);
72         void draw_playback_cursor();
73         void draw_highlighting();
74 // User can either call draw or draw_overlays to copy a fresh 
75 // canvas and just draw the overlays over it
76         void draw_overlays();
77         void update_handles();
78 // Convert edit coords to transition coords
79         void get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h);
80         void get_handle_coords(Edit *edit, 
81                 int64_t &x, 
82                 int64_t &y, 
83                 int64_t &w, 
84                 int64_t &h, 
85                 int side);
86         int get_drag_values(float *percentage, 
87                 int64_t *position,
88                 int do_clamp,
89                 int cursor_x,
90                 int cursor_y,
91                 Auto *current);
92         void draw_title(Edit *edit, 
93                 int64_t edit_x, 
94                 int64_t edit_y, 
95                 int64_t edit_w, 
96                 int64_t edit_h);
97         void draw_automation();
98         void draw_inout_points();
99         void draw_auto(Auto *current, 
100                 int x, 
101                 int y, 
102                 int center_pixel, 
103                 int zoom_track);
104         void draw_floatauto(Auto *current, 
105                 int x, 
106                 int y, 
107                 int in_x,
108                 int in_y,
109                 int out_x,
110                 int out_y,
111                 int center_pixel, 
112                 int zoom_track);
113         int test_auto(Auto *current, 
114                 int x, 
115                 int y, 
116                 int center_pixel, 
117                 int zoom_track, 
118                 int cursor_x, 
119                 int cursor_y, 
120                 int buttonpress);
121         int test_floatauto(Auto *current, 
122                 int x, 
123                 int y, 
124                 int in_x,
125                 int in_y,
126                 int out_x,
127                 int out_y,
128                 int center_pixel, 
129                 int zoom_track, 
130                 int cursor_x, 
131                 int cursor_y, 
132                 int buttonpress);
133         void draw_floatline(int center_pixel, 
134                 FloatAuto *previous,
135                 FloatAuto *current,
136                 FloatAutos *autos,
137                 double unit_start,
138                 double zoom_units,
139                 double yscale,
140                 int ax,
141                 int ay,
142                 int ax2,
143                 int ay2);
144         int test_floatline(int center_pixel, 
145                 FloatAutos *autos,
146                 double unit_start,
147                 double zoom_units,
148                 double yscale,
149                 int x1,
150                 int x2,
151                 int cursor_x, 
152                 int cursor_y, 
153                 int buttonpress);
154         void draw_toggleline(int center_pixel, 
155                 int ax,
156                 int ay,
157                 int ax2,
158                 int ay2);
159         int test_toggleline(Autos *autos,
160                 int center_pixel, 
161                 int x1,
162                 int y1,
163                 int x2,
164                 int y2,
165                 int cursor_x, 
166                 int cursor_y, 
167                 int buttonpress);
168         int do_keyframes(int cursor_x, 
169                 int cursor_y, 
170                 int draw, 
171                 int buttonpress, 
172                 int &new_cursor,
173                 int &update_cursor,
174                 int &rerender);
175
176         int do_float_autos(Track *track, 
177                 Autos *autos, 
178                 int cursor_x, 
179                 int cursor_y, 
180                 int draw, 
181                 int buttonpress,
182                 int x_offset,
183                 int y_offset,
184                 int color,
185         Auto* &auto_instance);
186         int do_int_autos(Track *track, 
187                 Autos *autos, 
188                 int cursor_x, 
189                 int cursor_y, 
190                 int draw, 
191                 int buttonpress,
192                 int x_offset,
193                 int y_offset,
194                 int color,
195         Auto* &auto_instance);
196         int do_autos(Track *track, 
197                 Autos *autos, 
198                 int cursor_x, 
199                 int cursor_y, 
200                 int draw, 
201                 int buttonpress,
202                 BC_Pixmap *pixmap,
203         Auto* &auto_instance,
204                 int &rerender);
205         int do_plugin_autos(Track *track,
206                 int cursor_x, 
207                 int cursor_y, 
208                 int draw, 
209                 int buttonpress,
210                 Plugin* &keyframe_plugin,
211                 KeyFrame* &keyframe_instance);
212
213
214         void calculate_viewport(Track *track, 
215                 double &view_start,
216                 double &unit_start,
217                 double &view_end,
218                 double &unit_end,
219                 double &yscale,
220                 int &center_pixel,
221                 double &zoom_sample,
222                 double &zoom_units);
223
224 // Convert percentage position inside track to value.
225 // if is_toggle is 1, the result is either 0 or 1.
226 // if reference is nonzero and a FloatAuto, 
227 //     the result is made relative to the value in reference.
228         float percentage_to_value(float percentage, 
229                 int is_toggle,
230                 Auto *reference);
231
232 // Get x and y of a FloatAuto relative to center_pixel
233         void calculate_auto_position(double *x, 
234                 double *y,
235                 double *in_x,
236                 double *in_y,
237                 double *out_x,
238                 double *out_y,
239                 Auto *current,
240                 double unit_start,
241                 double zoom_units,
242                 double yscale);
243         void synchronize_autos(float change, Track *skip, FloatAuto *fauto, int fill_gangs);
244
245
246         void draw_brender_start();
247         void draw_loop_points();
248         void draw_transitions();
249         void draw_drag_handle();
250         void draw_plugins();
251         void refresh_plugintoggles();
252         void update_edit_handles(Edit *edit, int64_t edit_x, int64_t edit_y, int64_t edit_w, int64_t edit_h);
253         void update_transitions();
254         void update_keyframe_handles(Track *track);
255 // Draw everything to synchronize with the view.
256         void draw(int mode = 0, int hide_cursor = 1);
257 // Draw resources during index building
258         void draw_indexes(Indexable *indexable);
259 // Get location of edit on screen without boundary checking
260         void edit_dimensions(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
261         void track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
262         void plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
263         void get_pixmap_size(Edit *edit, int64_t edit_x, int64_t edit_w, int64_t &pixmap_x, int64_t &pixmap_w, int64_t &pixmap_h);
264         ResourcePixmap* create_pixmap(Edit *edit, int64_t edit_x, int64_t pixmap_x, int64_t pixmap_w, int64_t pixmap_h);
265         void update_cursor(int flush);
266 // Get edit and handle the cursor is over
267         int do_edit_handles(int cursor_x, 
268                 int cursor_y, 
269                 int button_press,
270                 int &redraw,
271                 int &rerender);
272 // Get plugin and handle the cursor if over
273         int do_plugin_handles(int cursor_x, 
274                 int cursor_y, 
275                 int button_press,
276                 int &redraw,
277                 int &rerender);
278 // Get edit the cursor is over
279         int do_edits(int cursor_x, 
280                 int cursor_y, 
281                 int button_press,
282                 int drag_start,
283                 int &redraw,
284                 int &rerender,
285                 int &new_cursor,
286                 int &update_cursor);
287         int do_tracks(int cursor_x, 
288                 int cursor_y,
289                 int button_press);
290         int test_resources(int cursor_x, int cursor_y);
291         int do_plugins(int cursor_x, 
292                 int cursor_y, 
293                 int drag_start,
294                 int button_press,
295                 int &redraw,
296                 int &rerender);
297         int do_transitions(int cursor_x, 
298                 int cursor_y, 
299                 int button_press,
300                 int &new_cursor,
301                 int &update_cursor);
302         void draw_cropped_line(int x1, 
303                 int y1, 
304                 int x2, 
305                 int y2, 
306                 int min_y,
307                 int max_y);
308         int button_press_event();
309         int button_release_event();
310         int cursor_motion_event();
311         int activate();
312         int deactivate();
313         int repeat_event(int64_t duration);
314         void start_dragscroll();
315         void stop_dragscroll();
316         int start_selection(double position);
317         int drag_motion_event();
318         int drag_stop_event();
319         int drag_motion(Track **over_track,
320                 Edit **over_edit,
321                 PluginSet **over_pluginset,
322                 Plugin **over_plugin);
323         int drag_stop(int *redraw);
324         void end_edithandle_selection();
325         void end_pluginhandle_selection();
326 // Number of seconds spanned by the trackcanvas
327         double time_visible();
328         void update_drag_handle();
329         int update_drag_edit();
330         int update_drag_floatauto(int cursor_x, int cursor_y);
331         int update_drag_toggleauto(int cursor_x, int cursor_y);
332         int update_drag_auto(int cursor_x, int cursor_y);
333         int update_drag_pluginauto(int cursor_x, int cursor_y);
334
335 // Update status bar to reflect drag operation
336         void update_drag_caption();
337
338         int get_title_h();
339         int resource_h();
340
341 // Display hourglass if timer expired
342         void test_timer();
343 // get the relevant patchbay by traversing the panes
344 //      Patchbay* get_patchbay();
345
346         MWindow *mwindow;
347         MWindowGUI *gui;
348         TimelinePane *pane;
349 // Allows overlays to get redrawn without redrawing the resources
350         BC_Pixmap *background_pixmap;
351         BC_Pixmap *transition_pixmap;
352         EditHandles *edit_handles;
353 //      TransitionHandles *transition_handles;
354         BC_Pixmap *keyframe_pixmap;
355         BC_Pixmap *camerakeyframe_pixmap;
356         BC_Pixmap *modekeyframe_pixmap;
357         BC_Pixmap *pankeyframe_pixmap;
358         BC_Pixmap *projectorkeyframe_pixmap;
359         BC_Pixmap *maskkeyframe_pixmap;
360         
361         int active;
362 // Currently in a drag scroll operation
363         int drag_scroll;
364 // Don't stop hourglass if it was never started before the operation.
365         int hourglass_enabled;
366 // position used by timebar, when the timebar needs to draw a highlight
367         double timebar_position;
368
369 // Temporary for picon drawing
370         VFrame *temp_picon;
371 // Timer for hourglass
372         Timer *resource_timer;
373
374 // Plugin toggle interfaces
375         ArrayList<PluginOn*> plugin_on_toggles;
376         ArrayList<PluginShow*> plugin_show_toggles;
377
378
379
380 // event handlers
381         void draw_paste_destination();
382
383 // ====================================== cursor selection type
384
385
386         double selection_midpoint;        // division between current ends
387
388 };
389
390 #endif