make kfrm operator= illegal, use copy_from instead
[goodguy/cinelerra.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, int show);
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(Edit *edit,
88                 int64_t &x, int64_t &y, int64_t &w, int64_t &h);
89         void get_handle_coords(Edit *edit,
90                 int64_t &x,
91                 int64_t &y,
92                 int64_t &w,
93                 int64_t &h,
94                 int side);
95         int get_drag_values(float *percentage,
96                 int64_t *position,
97                 int do_clamp,
98                 int cursor_x,
99                 int cursor_y,
100                 Auto *current);
101         void draw_title(Edit *edit,
102                 int64_t edit_x,
103                 int64_t edit_y,
104                 int64_t edit_w,
105                 int64_t edit_h);
106         void draw_automation();
107         void draw_hard_edges();
108         void draw_inout_points();
109         void draw_auto(Auto *current,
110                 int x,
111                 int y,
112                 int center_pixel,
113                 int zoom_track);
114         void draw_floatauto(FloatAuto *current,
115                 int x,
116                 int y,
117                 int in_x,
118                 int in_y,
119                 int out_x,
120                 int out_y,
121                 int center_pixel,
122                 int zoom_track,
123                 int color);
124         int test_auto(Auto *current,
125                 int x,
126                 int y,
127                 int center_pixel,
128                 int zoom_track,
129                 int cursor_x,
130                 int cursor_y,
131                 int buttonpress);
132         int test_floatauto(FloatAuto *current,
133                 int x,
134                 int y,
135                 int in_x,
136                 int in_y,
137                 int out_x,
138                 int out_y,
139                 int center_pixel,
140                 int zoom_track,
141                 int cursor_x,
142                 int cursor_y,
143                 int buttonpress,
144                 int autogrouptype);
145         void draw_floatline(int center_pixel,
146                 FloatAuto *previous,
147                 FloatAuto *current,
148                 FloatAutos *autos,
149                 double unit_start,
150                 double zoom_units,
151                 double yscale,
152                 int ax,
153                 int ay,
154                 int ax2,
155                 int ay2,
156                 int color,
157                 int autogrouptype);
158         int test_floatline(int center_pixel,
159                 FloatAutos *autos,
160                 double unit_start,
161                 double zoom_units,
162                 double yscale,
163                 int x1,
164                 int x2,
165                 int cursor_x,
166                 int cursor_y,
167                 int buttonpress,
168                 int autogrouptype);
169         void draw_toggleline(int center_pixel,
170                 int ax,
171                 int ay,
172                 int ax2,
173                 int ay2);
174         int test_toggleline(Autos *autos,
175                 int center_pixel,
176                 int x1,
177                 int y1,
178                 int x2,
179                 int y2,
180                 int cursor_x,
181                 int cursor_y,
182                 int buttonpress);
183         int do_keyframes(int cursor_x,
184                 int cursor_y,
185                 int draw,
186                 int buttonpress,
187                 int &new_cursor,
188                 int &update_cursor,
189                 int &rerender);
190
191         int do_float_autos(Track *track,
192                 Autos *autos,
193                 int cursor_x,
194                 int cursor_y,
195                 int draw,
196                 int buttonpress,
197                 int x_offset,
198                 int y_offset,
199                 int color,
200                 Auto* &auto_instance,
201                 int autogrouptype);
202         int do_int_autos(Track *track,
203                 Autos *autos,
204                 int cursor_x,
205                 int cursor_y,
206                 int draw,
207                 int buttonpress,
208                 int x_offset,
209                 int y_offset,
210                 int color,
211                 Auto * &auto_instance);
212         int do_autos(Track *track,
213                 Autos *autos,
214                 int cursor_x,
215                 int cursor_y,
216                 int draw,
217                 int buttonpress,
218                 BC_Pixmap *pixmap,
219                 Auto* &auto_instance,
220                 int &rerender);
221         int do_plugin_autos(Track *track,
222                 int cursor_x,
223                 int cursor_y,
224                 int draw,
225                 int buttonpress,
226                 Plugin* &keyframe_plugin,
227                 KeyFrame* &keyframe_instance);
228
229
230         void calculate_viewport(Track *track,
231                 double &view_start,
232                 double &unit_start,
233                 double &view_end,
234                 double &unit_end,
235                 double &yscale,
236                 int &center_pixel,
237                 double &zoom_sample,
238                 double &zoom_units);
239
240 // Convert percentage position inside track to value.
241 // if is_toggle is 1, the result is either 0 or 1.
242 // if reference is nonzero and a FloatAuto,
243 //     the result is made relative to the value in reference.
244         float percentage_to_value(float percentage,
245                 int is_toggle,
246                 Auto *reference,
247                 int autogrouptype);
248
249 // Get x and y of a FloatAuto relative to center_pixel
250         void calculate_auto_position(double *x,
251                 double *y,
252                 double *in_x,
253                 double *in_y,
254                 double *out_x,
255                 double *out_y,
256                 Auto *current,
257                 double unit_start,
258                 double zoom_units,
259                 double yscale,
260                 int autogrouptype);
261
262         void fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto);
263         void update_ganged_autos(float change, Track *skip, FloatAuto *fauto);
264         void clear_ganged_autos();
265
266         void draw_brender_range();
267         void draw_loop_points();
268         void draw_transitions();
269         void draw_drag_handle();
270         void draw_plugins();
271         void refresh_plugintoggles();
272         void update_edit_handles(Edit *edit, int64_t edit_x, int64_t edit_y, int64_t edit_w, int64_t edit_h);
273         void update_transitions();
274         void update_keyframe_handles(Track *track);
275 // Draw everything to synchronize with the view.
276         void draw(int mode = 0, int hide_cursor = 1);
277 // Draw resources during index building
278         void draw_indexes(Indexable *indexable);
279 // Get location of edit on screen without boundary checking
280         void edit_dimensions(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
281         void track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
282         void plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
283         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);
284         ResourcePixmap* create_pixmap(Edit *edit, int64_t edit_x, int64_t pixmap_x, int64_t pixmap_w, int64_t pixmap_h);
285         void update_cursor(int flush);
286 // Get edit and handle the cursor is over
287         int do_edit_handles(int cursor_x,
288                 int cursor_y,
289                 int button_press,
290                 int &rerender,
291                 int &update_overlay,
292                 int &new_cursor,
293                 int &update_cursor);
294 // Get plugin and handle the cursor if over
295         int do_plugin_handles(int cursor_x,
296                 int cursor_y,
297                 int button_press,
298                 int &rerender,
299                 int &update_overlay,
300                 int &new_cursor,
301                 int &update_cursor);
302 // Get edit the cursor is over
303         int do_edits(int cursor_x,
304                 int cursor_y,
305                 int button_press,
306                 int drag_start,
307                 int &redraw,
308                 int &rerender,
309                 int &new_cursor,
310                 int &update_cursor);
311         int do_tracks(int cursor_x,
312                 int cursor_y,
313                 int button_press);
314         int test_resources(int cursor_x, int cursor_y);
315         int do_plugins(int cursor_x,
316                 int cursor_y,
317                 int drag_start,
318                 int button_press,
319                 int &redraw,
320                 int &rerender);
321         int do_transitions(int cursor_x,
322                 int cursor_y,
323                 int button_press,
324                 int &new_cursor,
325                 int &update_cursor);
326         void draw_cropped_line(int x1,
327                 int y1,
328                 int x2,
329                 int y2,
330                 int min_y,
331                 int max_y);
332         int button_press_event();
333         int button_release_event();
334         int cursor_update(int in_motion);
335         int cursor_motion_event();
336         int activate();
337         int deactivate();
338         int repeat_event(int64_t duration);
339         void start_dragscroll();
340         void stop_dragscroll();
341         int start_selection(double position);
342         int drag_motion_event();
343         int drag_stop_event();
344         int drag_motion(Track **over_track,
345                 Edit **over_edit,
346                 PluginSet **over_pluginset,
347                 Plugin **over_plugin);
348         int drag_stop(int *redraw);
349         int64_t drop_edit_position (int *is_insertion, Edit *moved_edit, int64_t moved_edit_length);
350         int64_t drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin);
351         void end_edithandle_selection();
352         void end_pluginhandle_selection();
353 // Number of seconds spanned by the trackcanvas
354         double time_visible();
355         void update_drag_handle();
356         int update_drag_edit();
357         int render_handle_frame(EDL *edl, int64_t pos, int mode);
358         int update_drag_floatauto(int cursor_x, int cursor_y);
359         int update_drag_toggleauto(int cursor_x, int cursor_y);
360         int update_drag_auto(int cursor_x, int cursor_y);
361         int update_drag_pluginauto(int cursor_x, int cursor_y);
362         void show_message(Auto *current, int show_curve_type, const char *fmt, ...);
363
364 // Update status bar to reflect drag operation
365         void update_drag_caption();
366
367         int get_title_h();
368         int resource_h();
369
370 // Display hourglass if timer expired
371         void test_timer();
372 // get the relevant patchbay by traversing the panes
373 //      Patchbay* get_patchbay();
374
375         MWindow *mwindow;
376         MWindowGUI *gui;
377         TimelinePane *pane;
378 // Allows overlays to get redrawn without redrawing the resources
379         BC_Pixmap *background_pixmap;
380         BC_Pixmap *transition_pixmap;
381         EditHandles *edit_handles;
382 //      TransitionHandles *transition_handles;
383         BC_Pixmap *keyframe_pixmap;
384         BC_Pixmap *camerakeyframe_pixmap;
385         BC_Pixmap *modekeyframe_pixmap;
386         BC_Pixmap *pankeyframe_pixmap;
387         BC_Pixmap *projectorkeyframe_pixmap;
388         BC_Pixmap *maskkeyframe_pixmap;
389
390         int active;
391 // Currently in a drag scroll operation
392         int drag_scroll;
393 // Don't stop hourglass if it was never started before the operation.
394         int hourglass_enabled;
395 // position used by timebar, when the timebar needs to draw a highlight
396         double timebar_position;
397
398 // Temporary for picon drawing
399         VFrame *temp_picon;
400 // Timer for hourglass
401         Timer *resource_timer;
402         Timer *render_timer;
403
404 // Plugin toggle interfaces
405         ArrayList<PluginOn*> plugin_on_toggles;
406         ArrayList<PluginShow*> plugin_show_toggles;
407         ArrayList<PluginPresetEdit*> preset_edit_buttons;
408
409         static int auto_operations[];
410 // event handlers
411         void draw_paste_destination();
412
413         void draw_floatauto_ctrlpoint(int x, int y, int cp_x, int cp_y,
414                 int center_pixel, int zoom_track, int color);
415
416         float value_to_percentage(float auto_value, int autogrouptype);
417         // transforms automation value into current display coords
418         // dependant on current automation display range for given kind of automation
419
420 // ====================================== cursor selection type
421
422         double selection_midpoint;        // division between current ends
423         int snapped;                    // drag handle snapping
424         EDL *speed_edl;                 // drag speed handle start edl
425 };
426
427 #endif