4 * Copyright (C) 2008-2014 Adam Williams <broadcast at earthling dot net>
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.
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.
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
28 #include "bctimer.inc"
30 #include "edithandles.inc"
32 #include "floatauto.inc"
33 #include "floatautos.inc"
34 #include "intauto.inc"
36 #include "indexable.h"
37 #include "keyframe.inc"
38 #include "mwindow.inc"
39 #include "mwindowgui.inc"
41 #include "pluginset.inc"
42 #include "plugintoggles.inc"
43 #include "resourcepixmap.inc"
44 #include "timelinepane.inc"
47 #include "transitionhandles.inc"
48 #include "keyframe.inc"
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.
57 #define FORCE_REDRAW 2
58 #define IGNORE_THREAD 3
60 class TrackCanvas : public BC_SubWindow
63 TrackCanvas(MWindow *mwindow, MWindowGUI *gui);
64 TrackCanvas(MWindow *mwindow, TimelinePane *pane, int x, int y, int w, int h);
67 void create_objects();
69 int drag_start_event();
70 int cursor_leave_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);
82 // User can either call draw or draw_overlays to copy a fresh
83 // canvas and just draw the overlays over it
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,
94 int get_drag_values(float *percentage,
100 void draw_title(Edit *edit,
105 void draw_automation();
106 void draw_hard_edges();
107 void draw_inout_points();
108 void draw_auto(Auto *current,
113 void draw_floatauto(FloatAuto *current,
123 int test_auto(Auto *current,
131 int test_floatauto(FloatAuto *current,
144 void draw_floatline(int center_pixel,
157 int test_floatline(int center_pixel,
168 void draw_toggleline(int center_pixel,
173 int test_toggleline(Autos *autos,
182 int do_keyframes(int cursor_x,
190 int do_float_autos(Track *track,
199 Auto* &auto_instance,
201 int do_int_autos(Track *track,
210 Auto * &auto_instance);
211 int do_autos(Track *track,
218 Auto* &auto_instance,
220 int do_plugin_autos(Track *track,
225 Plugin* &keyframe_plugin,
226 KeyFrame* &keyframe_instance);
229 void calculate_viewport(Track *track,
239 // Convert percentage position inside track to value.
240 // if is_toggle is 1, the result is either 0 or 1.
241 // if reference is nonzero and a FloatAuto,
242 // the result is made relative to the value in reference.
243 float percentage_to_value(float percentage,
248 // Get x and y of a FloatAuto relative to center_pixel
249 void calculate_auto_position(double *x,
260 void synchronize_autos(float change, Track *skip, FloatAuto *fauto, int fill_gangs);
263 void draw_brender_range();
264 void draw_loop_points();
265 void draw_transitions();
266 void draw_drag_handle();
268 void refresh_plugintoggles();
269 void update_edit_handles(Edit *edit, int64_t edit_x, int64_t edit_y, int64_t edit_w, int64_t edit_h);
270 void update_transitions();
271 void update_keyframe_handles(Track *track);
272 // Draw everything to synchronize with the view.
273 void draw(int mode = 0, int hide_cursor = 1);
274 // Draw resources during index building
275 void draw_indexes(Indexable *indexable);
276 // Get location of edit on screen without boundary checking
277 void edit_dimensions(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
278 void track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
279 void plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
280 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);
281 ResourcePixmap* create_pixmap(Edit *edit, int64_t edit_x, int64_t pixmap_x, int64_t pixmap_w, int64_t pixmap_h);
282 void update_cursor(int flush);
283 // Get edit and handle the cursor is over
284 int do_edit_handles(int cursor_x,
291 // Get plugin and handle the cursor if over
292 int do_plugin_handles(int cursor_x,
299 // Get edit the cursor is over
300 int do_edits(int cursor_x,
308 int do_tracks(int cursor_x,
311 int test_resources(int cursor_x, int cursor_y);
312 int do_plugins(int cursor_x,
318 int do_transitions(int cursor_x,
323 void draw_cropped_line(int x1,
329 int button_press_event();
330 int button_release_event();
331 int cursor_motion_event();
334 int repeat_event(int64_t duration);
335 void start_dragscroll();
336 void stop_dragscroll();
337 int start_selection(double position);
338 int drag_motion_event();
339 int drag_stop_event();
340 int drag_motion(Track **over_track,
342 PluginSet **over_pluginset,
343 Plugin **over_plugin);
344 int drag_stop(int *redraw);
345 int64_t drop_edit_position (int *is_insertion, Edit *moved_edit, int64_t moved_edit_length);
346 int64_t drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin);
347 void end_edithandle_selection();
348 void end_pluginhandle_selection();
349 // Number of seconds spanned by the trackcanvas
350 double time_visible();
351 void update_drag_handle();
352 int update_drag_edit();
353 int update_drag_floatauto(int cursor_x, int cursor_y);
354 int update_drag_toggleauto(int cursor_x, int cursor_y);
355 int update_drag_auto(int cursor_x, int cursor_y);
356 int update_drag_pluginauto(int cursor_x, int cursor_y);
357 void show_message(Auto *current, int show_curve_type, const char *fmt, ...);
359 // Update status bar to reflect drag operation
360 void update_drag_caption();
365 // Display hourglass if timer expired
367 // get the relevant patchbay by traversing the panes
368 // Patchbay* get_patchbay();
373 // Allows overlays to get redrawn without redrawing the resources
374 BC_Pixmap *background_pixmap;
375 BC_Pixmap *transition_pixmap;
376 EditHandles *edit_handles;
377 // TransitionHandles *transition_handles;
378 BC_Pixmap *keyframe_pixmap;
379 BC_Pixmap *camerakeyframe_pixmap;
380 BC_Pixmap *modekeyframe_pixmap;
381 BC_Pixmap *pankeyframe_pixmap;
382 BC_Pixmap *projectorkeyframe_pixmap;
383 BC_Pixmap *maskkeyframe_pixmap;
386 // Currently in a drag scroll operation
388 // Don't stop hourglass if it was never started before the operation.
389 int hourglass_enabled;
390 // position used by timebar, when the timebar needs to draw a highlight
391 double timebar_position;
393 // Temporary for picon drawing
395 // Timer for hourglass
396 Timer *resource_timer;
399 // Plugin toggle interfaces
400 ArrayList<PluginOn*> plugin_on_toggles;
401 ArrayList<PluginShow*> plugin_show_toggles;
402 ArrayList<PluginPresetEdit*> preset_edit_buttons;
404 static int auto_operations[];
406 void draw_paste_destination();
408 void draw_floatauto_ctrlpoint(int x, int y, int cp_x, int cp_y,
409 int center_pixel, int zoom_track, int color);
411 float value_to_percentage(float auto_value, int autogrouptype);
412 // transforms automation value into current display coords
413 // dependant on current automation display range for given kind of automation
415 // ====================================== cursor selection type
417 double selection_midpoint; // division between current ends
418 int snapped; // drag handle snapping