color coded keyframe curves, keyframe popups, cwin scrollbar fixes
[goodguy/history.git] / cinelerra-5.1 / 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 "intauto.inc"
35 #include "guicast.h"
36 #include "indexable.h"
37 #include "keyframe.inc"
38 #include "mwindow.inc"
39 #include "mwindowgui.inc"
40 #include "plugin.inc"
41 #include "pluginset.inc"
42 #include "plugintoggles.inc"
43 #include "resourcepixmap.inc"
44 #include "timelinepane.inc"
45 #include "track.inc"
46 #include "tracks.inc"
47 #include "transitionhandles.inc"
48 #include "keyframe.inc"
49
50 #include <stdarg.h>
51
52 // draw mode:
53 // NORMAL_DRAW causes incremental drawing of pixmaps.  Used for navigation and index refresh.
54 // FORCE_REDRAW causes all resource pixmaps to be redrawn from scratch.  Used by editing.
55 // IGNORE_THREAD causes resource pixmaps to ignore picon thread.  Used by Piconthread.
56 #define NORMAL_DRAW 1
57 #define FORCE_REDRAW 2
58 #define IGNORE_THREAD 3
59
60 class TrackCanvas : public BC_SubWindow
61 {
62 public:
63         TrackCanvas(MWindow *mwindow, MWindowGUI *gui);
64         TrackCanvas(MWindow *mwindow, TimelinePane *pane, int x, int y, int w, int h);
65         ~TrackCanvas();
66
67         void create_objects();
68         void resize_event();
69         int drag_start_event();
70         int cursor_leave_event();
71         int keypress_event();
72         void draw_resources(int mode = 0,
73                 int indexes_only = 0,     // Redraw only certain audio resources with indexes
74                 Indexable *indexable = 0);
75         void draw_highlight_rectangle(int x, int y, int w, int h);
76         void draw_highlight_insertion(int x, int y, int w, int h);
77         void draw_playback_cursor();
78         void draw_highlighting();
79         void draw_keyframe_reticle();
80         int draw_hairline(Auto *auto_keyframe, int color);
81
82 // User can either call draw or draw_overlays to copy a fresh
83 // canvas and just draw the overlays over it
84         void draw_overlays();
85         void update_handles();
86 // Convert edit coords to transition coords
87         void get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h);
88         void get_handle_coords(Edit *edit,
89                 int64_t &x,
90                 int64_t &y,
91                 int64_t &w,
92                 int64_t &h,
93                 int side);
94         int get_drag_values(float *percentage,
95                 int64_t *position,
96                 int do_clamp,
97                 int cursor_x,
98                 int cursor_y,
99                 Auto *current);
100         void draw_title(Edit *edit,
101                 int64_t edit_x,
102                 int64_t edit_y,
103                 int64_t edit_w,
104                 int64_t edit_h);
105         void draw_automation();
106         void draw_inout_points();
107         void draw_auto(Auto *current,
108                 int x,
109                 int y,
110                 int center_pixel,
111                 int zoom_track);
112         void draw_floatauto(FloatAuto *current, 
113                 int x, 
114                 int y, 
115                 int in_x, 
116                 int in_y, 
117                 int out_x, 
118                 int out_y, 
119                 int center_pixel, 
120                 int zoom_track,
121                 int color);
122         int test_auto(Auto *current,
123                 int x,
124                 int y,
125                 int center_pixel,
126                 int zoom_track,
127                 int cursor_x,
128                 int cursor_y,
129                 int buttonpress);
130         int test_floatauto(FloatAuto *current,
131                 int x,
132                 int y,
133                 int in_x,
134                 int in_y,
135                 int out_x,
136                 int out_y,
137                 int center_pixel,
138                 int zoom_track,
139                 int cursor_x,
140                 int cursor_y,
141                 int buttonpress,
142                 int autogrouptype);
143         void draw_floatline(int center_pixel,
144                 FloatAuto *previous,
145                 FloatAuto *current,
146                 FloatAutos *autos,
147                 double unit_start,
148                 double zoom_units,
149                 double yscale,
150                 int ax,
151                 int ay,
152                 int ax2,
153                 int ay2,
154                 int color,
155                 int autogrouptype);
156         int test_floatline(int center_pixel,
157                 FloatAutos *autos,
158                 double unit_start,
159                 double zoom_units,
160                 double yscale,
161                 int x1,
162                 int x2,
163                 int cursor_x,
164                 int cursor_y,
165                 int buttonpress,
166                 int autogrouptype);
167         void draw_toggleline(int center_pixel,
168                 int ax,
169                 int ay,
170                 int ax2,
171                 int ay2);
172         int test_toggleline(Autos *autos,
173                 int center_pixel,
174                 int x1,
175                 int y1,
176                 int x2,
177                 int y2,
178                 int cursor_x,
179                 int cursor_y,
180                 int buttonpress);
181         int do_keyframes(int cursor_x,
182                 int cursor_y,
183                 int draw,
184                 int buttonpress,
185                 int &new_cursor,
186                 int &update_cursor,
187                 int &rerender);
188
189         int do_float_autos(Track *track,
190                 Autos *autos,
191                 int cursor_x,
192                 int cursor_y,
193                 int draw,
194                 int buttonpress,
195                 int x_offset,
196                 int y_offset,
197                 int color,
198                 Auto* &auto_instance,
199                 int autogrouptype);
200         int do_int_autos(Track *track,
201                 Autos *autos,
202                 int cursor_x,
203                 int cursor_y,
204                 int draw,
205                 int buttonpress,
206                 int x_offset,
207                 int y_offset,
208                 int color,
209                 Auto * &auto_instance);
210         int do_autos(Track *track,
211                 Autos *autos,
212                 int cursor_x,
213                 int cursor_y,
214                 int draw,
215                 int buttonpress,
216                 BC_Pixmap *pixmap,
217                 Auto* &auto_instance,
218                 int &rerender);
219         int do_plugin_autos(Track *track,
220                 int cursor_x,
221                 int cursor_y,
222                 int draw,
223                 int buttonpress,
224                 Plugin* &keyframe_plugin,
225                 KeyFrame* &keyframe_instance);
226
227
228         void calculate_viewport(Track *track,
229                 double &view_start,
230                 double &unit_start,
231                 double &view_end,
232                 double &unit_end,
233                 double &yscale,
234                 int &center_pixel,
235                 double &zoom_sample,
236                 double &zoom_units);
237
238 // Convert percentage position inside track to value.
239 // if is_toggle is 1, the result is either 0 or 1.
240 // if reference is nonzero and a FloatAuto,
241 //     the result is made relative to the value in reference.
242         float percentage_to_value(float percentage,
243                 int is_toggle,
244                 Auto *reference,
245                 int autogrouptype);
246
247 // Get x and y of a FloatAuto relative to center_pixel
248         void calculate_auto_position(double *x,
249                 double *y,
250                 double *in_x,
251                 double *in_y,
252                 double *out_x,
253                 double *out_y,
254                 Auto *current,
255                 double unit_start,
256                 double zoom_units,
257                 double yscale,
258                 int autogrouptype);
259         void synchronize_autos(float change, Track *skip, FloatAuto *fauto, int fill_gangs);
260
261
262         void draw_brender_start();
263         void draw_loop_points();
264         void draw_transitions();
265         void draw_drag_handle();
266         void draw_plugins();
267         void refresh_plugintoggles();
268         void update_edit_handles(Edit *edit, int64_t edit_x, int64_t edit_y, int64_t edit_w, int64_t edit_h);
269         void update_transitions();
270         void update_keyframe_handles(Track *track);
271 // Draw everything to synchronize with the view.
272         void draw(int mode = 0, int hide_cursor = 1);
273 // Draw resources during index building
274         void draw_indexes(Indexable *indexable);
275 // Get location of edit on screen without boundary checking
276         void edit_dimensions(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
277         void track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
278         void plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
279         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);
280         ResourcePixmap* create_pixmap(Edit *edit, int64_t edit_x, int64_t pixmap_x, int64_t pixmap_w, int64_t pixmap_h);
281         void update_cursor(int flush);
282 // Get edit and handle the cursor is over
283         int do_edit_handles(int cursor_x,
284                 int cursor_y,
285                 int button_press,
286                 int &rerender,
287                 int &update_overlay,
288                 int &new_cursor,
289                 int &update_cursor);
290 // Get plugin and handle the cursor if over
291         int do_plugin_handles(int cursor_x,
292                 int cursor_y,
293                 int button_press,
294                 int &rerender,
295                 int &update_overlay,
296                 int &new_cursor,
297                 int &update_cursor);
298 // Get edit the cursor is over
299         int do_edits(int cursor_x,
300                 int cursor_y,
301                 int button_press,
302                 int drag_start,
303                 int &redraw,
304                 int &rerender,
305                 int &new_cursor,
306                 int &update_cursor);
307         int do_tracks(int cursor_x,
308                 int cursor_y,
309                 int button_press);
310         int test_resources(int cursor_x, int cursor_y);
311         int do_plugins(int cursor_x,
312                 int cursor_y,
313                 int drag_start,
314                 int button_press,
315                 int &redraw,
316                 int &rerender);
317         int do_transitions(int cursor_x,
318                 int cursor_y,
319                 int button_press,
320                 int &new_cursor,
321                 int &update_cursor);
322         void draw_cropped_line(int x1,
323                 int y1,
324                 int x2,
325                 int y2,
326                 int min_y,
327                 int max_y);
328         int button_press_event();
329         int button_release_event();
330         int cursor_motion_event();
331         int activate();
332         int deactivate();
333         int repeat_event(int64_t duration);
334         void start_dragscroll();
335         void stop_dragscroll();
336         int start_selection(double position);
337         int drag_motion_event();
338         int drag_stop_event();
339         int drag_motion(Track **over_track,
340                 Edit **over_edit,
341                 PluginSet **over_pluginset,
342                 Plugin **over_plugin);
343         int drag_stop(int *redraw);
344         int64_t drop_edit_position (int *is_insertion, Edit *moved_edit, int64_t moved_edit_length);
345         int64_t drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin);
346         void end_edithandle_selection();
347         void end_pluginhandle_selection();
348 // Number of seconds spanned by the trackcanvas
349         double time_visible();
350         void update_drag_handle();
351         int update_drag_edit();
352         int update_drag_floatauto(int cursor_x, int cursor_y);
353         int update_drag_toggleauto(int cursor_x, int cursor_y);
354         int update_drag_auto(int cursor_x, int cursor_y);
355         int update_drag_pluginauto(int cursor_x, int cursor_y);
356         void show_message(Auto *current, int show_curve_type, const char *fmt, ...);
357
358 // Update status bar to reflect drag operation
359         void update_drag_caption();
360
361         int get_title_h();
362         int resource_h();
363
364 // Display hourglass if timer expired
365         void test_timer();
366 // get the relevant patchbay by traversing the panes
367 //      Patchbay* get_patchbay();
368
369         MWindow *mwindow;
370         MWindowGUI *gui;
371         TimelinePane *pane;
372 // Allows overlays to get redrawn without redrawing the resources
373         BC_Pixmap *background_pixmap;
374         BC_Pixmap *transition_pixmap;
375         EditHandles *edit_handles;
376 //      TransitionHandles *transition_handles;
377         BC_Pixmap *keyframe_pixmap;
378         BC_Pixmap *camerakeyframe_pixmap;
379         BC_Pixmap *modekeyframe_pixmap;
380         BC_Pixmap *pankeyframe_pixmap;
381         BC_Pixmap *projectorkeyframe_pixmap;
382         BC_Pixmap *maskkeyframe_pixmap;
383
384         int active;
385 // Currently in a drag scroll operation
386         int drag_scroll;
387 // Don't stop hourglass if it was never started before the operation.
388         int hourglass_enabled;
389 // position used by timebar, when the timebar needs to draw a highlight
390         double timebar_position;
391
392 // Temporary for picon drawing
393         VFrame *temp_picon;
394 // Timer for hourglass
395         Timer *resource_timer;
396         Timer *render_timer;
397
398 // Plugin toggle interfaces
399         ArrayList<PluginOn*> plugin_on_toggles;
400         ArrayList<PluginShow*> plugin_show_toggles;
401
402         static int auto_operations[];
403 // event handlers
404         void draw_paste_destination();
405
406         void draw_floatauto_ctrlpoint(int x, int y, int cp_x, int cp_y,
407                 int center_pixel, int zoom_track, int color);
408
409         float value_to_percentage(float auto_value, int autogrouptype);
410         // transforms automation value into current display coords
411         // dependant on current automation display range for given kind of automation
412
413 // ====================================== cursor selection type
414
415         double selection_midpoint;        // division between current ends
416
417 };
418
419 #endif