add edit drag-handle constraits, add plugin/attach dialog apply btn
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / awindowgui.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 AWINDOWGUI_H
23 #define AWINDOWGUI_H
24
25 #include "arraylist.h"
26 #include "bcdialog.h"
27 #include "binfolder.inc"
28 #include "assetpopup.inc"
29 #include "asset.inc"
30 #include "assets.inc"
31 #include "audiodevice.inc"
32 #include "awindow.inc"
33 #include "awindowgui.inc"
34 #include "clippopup.inc"
35 #include "edl.inc"
36 #include "effectlist.inc"
37 #include "folderlistmenu.inc"
38 #include "garbage.h"
39 #include "guicast.h"
40 #include "labeledit.inc"
41 #include "labelpopup.inc"
42 #include "labels.h"
43 #include "indexable.inc"
44 #include "mwindow.inc"
45 #include "mutex.inc"
46 #include "pluginserver.inc"
47 #include "preferences.inc"
48 #include "proxypopup.inc"
49 #include "renderengine.inc"
50 #include "samples.inc"
51 #include "vicon.h"
52
53 #define SELECT_ALL 0
54 #define SELECT_USED 1
55 #define SELECT_UNUSED 2
56 #define SELECT_NONE 3
57
58 // in percent view_h
59 #define VIEW_POPUP_BAR_H 15
60
61 #define ASSET_VIEW_NONE 0
62 #define ASSET_VIEW_ICON 1
63 #define ASSET_VIEW_MEDIA 2
64 #define ASSET_VIEW_MEDIA_MAP 3
65 #define ASSET_VIEW_FULL 4
66
67 #define AVICON_FULL_PLAY   0
68 #define AVICON_MOUSE_OVER  1
69 #define AVICON_SRC_TARGET  2
70 #define AVICON_NO_PLAY     3
71 #define AVICON_PLAY_MODES  4
72
73 class AWindowFolderItem : public BC_ListBoxItem
74 {
75 public:
76         AWindowFolderItem();
77         AWindowFolderItem(const char *text, int color = -1);
78         AWindowFolderItem(const char *text, BC_Pixmap *icon, int color = -1);
79
80         AssetPicon *get_picon();
81         int matches(const char *text);
82
83         AWindowFolderItem *parent;
84 };
85
86 class AssetPicon : public AWindowFolderItem
87 {
88 public:
89         AssetPicon(MWindow *mwindow, AWindowGUI *gui, Indexable *indexable);
90         AssetPicon(MWindow *mwindow, AWindowGUI *gui, EDL *edl);
91         AssetPicon(MWindow *mwindow, AWindowGUI *gui, PluginServer *plugin);
92         AssetPicon(MWindow *mwindow, AWindowGUI *gui, Label *plugin);
93         AssetPicon(MWindow *mwindow, AWindowGUI *gui, int folder, int persist);
94         AssetPicon(MWindow *mwindow, AWindowGUI *gui, int folder, const char *title);
95         virtual ~AssetPicon();
96
97         void create_objects();
98         void reset();
99         static void draw_hue_bar(VFrame *frame, double t);
100         static void draw_wave(VFrame *frame, double *dp, int len,
101                 int base_color, int line_color, int x, int y, int w, int h);
102         static void draw_wave(VFrame *frame, double *dp, int len,
103                 int base_color, int line_color, int x=0, int y=0) {
104           draw_wave(frame, dp, len, base_color, line_color,
105                 x,y,frame->get_w(),frame->get_h());
106         }
107         void open_render_engine(EDL *edl, int is_audio);
108         void close_render_engine();
109         void render_video(int64_t pos, VFrame *vfrm);
110         void render_audio(int64_t pos, Samples **samples, int len);
111         VFrame *get_vicon_frame();
112
113         MWindow *mwindow;
114         AWindowGUI *gui;
115         BC_Pixmap *icon;
116         VFrame *icon_vframe;
117         VFrame *vicon_frame;
118         int foldernum;
119 // sublist items if set
120         AWindowFolderSubItems *sub_items;
121
122 // ID of thing pointed to
123         int id;
124
125 // Check ID first.  Update these next before dereferencing
126 // Asset if asset
127         Indexable *indexable;
128 // EDL if clip
129         EDL *edl;
130
131         int in_use;
132         int persistent;
133         time_t comments_time;
134         double sort_key;
135         PluginServer *plugin;
136         Label *label;
137         AssetVIcon *vicon;
138         RenderEngine *render_engine;
139 };
140
141 typedef int16_t vicon_audio_t;
142
143 class AssetVIconAudio : public Thread
144 {
145 public:
146         AssetVIconAudio(AWindowGUI *gui);
147         ~AssetVIconAudio();
148
149         void run();
150         void start(AssetVIcon *vicon);
151         void stop(int wait);
152
153         AWindowGUI *gui;
154         AudioDevice *audio;
155         AssetVIcon *vicon;
156         int interrupted;
157         int audio_pos;
158 };
159
160 class AssetVIcon : public VIcon, public Garbage {
161 public:
162         AssetPicon *picon;
163         VFrame *temp;
164         int64_t length;
165
166         VFrame *frame();
167         int64_t set_seq_no(int64_t no);
168         int get_vx();
169         int get_vy();
170         void load_audio();
171         void start_audio();
172         void stop_audio();
173
174         AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length);
175         ~AssetVIcon();
176 };
177
178 class AssetViewPopup : public ViewPopup
179 {
180 public:
181         AssetViewPopup(VIconThread *vt, int draw_mode,
182                         int x, int y, int w, int h);
183         ~AssetViewPopup();
184
185         int reposition_window(int x, int y, int w, int h);
186         int button_press_event();
187         int button_release_event();
188         int cursor_motion_event();
189         int keypress_event();
190
191         void draw_vframe(VFrame *frame);
192
193         int bar_h;
194         int draw_mode;
195         int dragging;
196 };
197
198 class AssetVIconThread : public VIconThread
199 {
200 public:
201         AssetVIconThread(AWindowGUI *gui, Preferences *preferences);
202         ~AssetVIconThread();
203
204         void set_view_popup(AssetVIcon *v, int draw_mode);
205         void set_view_popup(AssetVIcon *v);
206         ViewPopup *new_view_window(ViewPopup *popup);
207         void drawing_started();
208         void drawing_stopped();
209         void close_view_popup();
210
211         AWindowGUI *gui;
212         int draw_mode;
213         int vicon_cmodel;
214         Mutex *draw_lock;
215 };
216
217
218 class AWindowRemovePlugin;
219
220 class AWindowRemovePluginGUI : public BC_Window {
221 public:
222         AWindow *awindow;
223         AWindowRemovePlugin *thread;
224         PluginServer *plugin;
225         ArrayList<BC_ListBoxItem*> plugin_list;
226         BC_Pixmap *icon;
227         VFrame *icon_vframe;
228         BC_ListBox *list;
229
230         void create_objects();
231
232         AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
233                  int x, int y, PluginServer *plugin);
234         ~AWindowRemovePluginGUI();
235 };
236
237 class AWindowRemovePlugin : public BC_DialogThread {
238 public:
239         AWindow *awindow;
240         PluginServer *plugin;
241         BC_Window* new_gui();
242         void handle_close_event(int result);
243         int remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder);
244
245         AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin);
246         ~AWindowRemovePlugin();
247 };
248
249 class AWindowGUI : public BC_Window
250 {
251 public:
252         AWindowGUI(MWindow *mwindow, AWindow *awindow);
253         ~AWindowGUI();
254
255         void create_objects();
256         int resize_event(int w, int h);
257         int translation_event();
258         int close_event();
259         int keypress_event();
260         void async_update_assets();     // Sends update asset event
261         void update_effects();
262         void sort_assets();
263         void sort_folders();
264         void reposition_objects();
265 // Call back for MWindow entry point
266         int drag_motion();
267         int drag_stop();
268 // Collect items into the drag vectors of MainSession
269         void collect_assets(int proxy=0);
270         EDL *collect_proxy(Indexable *indexable);
271         void create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
272                 int do_audio,
273                 int do_video,
274                 int is_realtime,
275                 int is_transition);
276         void create_label_folder();
277         void copy_picons(AssetPicon *picon, ArrayList<BC_ListBoxItem*> *src);
278         void sort_picons(ArrayList<BC_ListBoxItem*> *src);
279 // Return the selected asset in asset_list
280         Indexable* selected_asset();
281         PluginServer* selected_plugin();
282         AssetPicon* selected_folder();
283         bool protected_pixmap(BC_Pixmap *pixmap);
284         int save_defaults(BC_Hash *defaults);
285         int load_defaults(BC_Hash *defaults);
286         int start_vicon_drawing();
287         int stop_vicon_drawing();
288         void close_view_popup();
289         void update_picon(Indexable *indexable);
290         int cycle_assetlist_format();
291
292         VFrame *get_picon(const char *name, const char *plugin_icons);
293         VFrame *get_picon(const char *name);
294         void resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx);
295         void theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn);
296         void plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png);
297
298         MWindow *mwindow;
299         AWindow *awindow;
300
301         AWindowAssets *asset_list;
302         AWindowFolders *folder_list;
303         AWindowDivider *divider;
304         AWindowSearchText *search_text;
305         Mutex *folder_lock;
306
307 // Store data to speed up responses
308 // Persistant data for listboxes
309 // All assets in current EDL
310         ArrayList<BC_ListBoxItem*> assets;
311         ArrayList<BC_ListBoxItem*> folders;
312         ArrayList<BC_ListBoxItem*> aeffects;
313         ArrayList<BC_ListBoxItem*> veffects;
314         ArrayList<BC_ListBoxItem*> atransitions;
315         ArrayList<BC_ListBoxItem*> vtransitions;
316         ArrayList<BC_ListBoxItem*> labellist;
317
318 // Currently displayed data for listboxes
319 // Currently displayed assets + comments
320         ArrayList<BC_ListBoxItem*> displayed_assets[2];
321         const char *asset_titles[ASSET_COLUMNS];
322         int displayed_folder;
323
324         BC_Hash *defaults;
325 // Persistent icons
326         BC_Pixmap *aeffect_folder_icon;      VFrame *aeffect_folder_vframe;
327         BC_Pixmap *atransition_folder_icon;  VFrame *atransition_folder_vframe;
328         BC_Pixmap *clip_folder_icon;         VFrame *clip_folder_vframe;
329         BC_Pixmap *label_folder_icon;        VFrame *label_folder_vframe;
330         BC_Pixmap *media_folder_icon;        VFrame *media_folder_vframe;
331         BC_Pixmap *proxy_folder_icon;        VFrame *proxy_folder_vframe;
332         BC_Pixmap *veffect_folder_icon;      VFrame *veffect_folder_vframe;
333         BC_Pixmap *vtransition_folder_icon;  VFrame *vtransition_folder_vframe;
334         BC_Pixmap *folder_icons[AWINDOW_FOLDERS];
335
336         BC_Pixmap *folder_icon;       VFrame *folder_vframe;
337         BC_Pixmap *file_icon;         VFrame *file_vframe;
338         BC_Pixmap *audio_icon;        VFrame *audio_vframe;
339         BC_Pixmap *video_icon;        VFrame *video_vframe;
340         BC_Pixmap *label_icon;        VFrame *label_vframe;
341         BC_Pixmap *clip_icon;         VFrame *clip_vframe;
342         BC_Pixmap *atransition_icon;  VFrame *atransition_vframe;
343         BC_Pixmap *vtransition_icon;  VFrame *vtransition_vframe;
344         BC_Pixmap *aeffect_icon;      VFrame *aeffect_vframe;
345         BC_Pixmap *veffect_icon;      VFrame *veffect_vframe;
346         BC_Pixmap *ladspa_icon;       VFrame *ladspa_vframe;
347         BC_Pixmap *ff_aud_icon;       VFrame *ff_aud_vframe;
348         BC_Pixmap *ff_vid_icon;       VFrame *ff_vid_vframe;
349
350 // Popup menus
351         AssetPopup *asset_menu;
352         ClipPopup *clip_menu;
353         LabelPopup *label_menu;
354         ProxyPopup *proxy_menu;
355         EffectListMenu *effectlist_menu;
356         AssetListMenu *assetlist_menu;
357         ClipListMenu *cliplist_menu;
358         LabelListMenu *labellist_menu;
359         ProxyListMenu *proxylist_menu;
360         FolderListMenu *folderlist_menu;
361         AddTools *add_tools;
362 // Temporary for reading picons from files
363         VFrame *temp_picon;
364         AssetVIconThread *vicon_thread;
365         AssetVIconAudio *vicon_audio;
366
367         int64_t plugin_visibility;
368         AWindowRemovePlugin *remove_plugin;
369
370         AVIconDrawing *avicon_drawing;
371         int avicon_w, avicon_h;
372         int vicon_drawing, play_off;
373         int allow_iconlisting;
374
375 // Create custom atoms to be used for async messages between windows
376         int create_custom_xatoms();
377 // Function to overload to receive customly defined atoms
378         virtual int receive_custom_xatoms(xatom_event *event);
379         static const char *folder_names[];
380         NewFolderThread *new_folder_thread;
381         ModifyFolderThread *modify_folder_thread;
382
383 private:
384         void update_folder_list();
385         void update_asset_list();
386         void filter_displayed_assets();
387         Atom UpdateAssetsXAtom;
388         void update_assets();
389
390 };
391
392 class AWindowAssets : public BC_ListBox
393 {
394 public:
395         AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h);
396         ~AWindowAssets();
397
398         int handle_event();
399         int selection_changed();
400         void draw_background();
401         int drag_start_event();
402         int drag_motion_event();
403         int drag_stop_event();
404         int button_press_event();
405         int column_resize_event();
406         int cursor_enter_event();
407         int cursor_leave_event();
408         int focus_out_event();
409         void update_vicon_area();
410         int mouse_over_event(int no);
411
412         MWindow *mwindow;
413         AWindowGUI *gui;
414 };
415
416 class AWindowDivider : public BC_SubWindow
417 {
418 public:
419         AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h);
420         ~AWindowDivider();
421
422         int button_press_event();
423         int cursor_motion_event();
424         int button_release_event();
425
426         MWindow *mwindow;
427         AWindowGUI *gui;
428 };
429
430 class AWindowSubFolderNames : public ArrayList<const char *>
431 {
432 public:
433         AWindowSubFolderNames() { set_array_delete(); }
434         ~AWindowSubFolderNames() { remove_all_objects(); }
435 };
436
437 class AWindowFolderSubItems : public AWindowFolderItem
438 {
439 public:
440         AWindowFolderSubItems(AWindowFolderItem *parent, const char *text);
441         int matches(const char *text);
442
443         AWindowSubFolderNames names;
444 };
445
446 class AWindowFolders : public BC_ListBox
447 {
448 public:
449         AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h);
450         ~AWindowFolders();
451
452         int selection_changed();
453         int button_press_event();
454         int drag_stop();
455         int load_expanders();
456
457         MWindow *mwindow;
458         AWindowGUI *gui;
459 // last selection
460         AWindowFolderItem *last_item0, *last_item1;
461 };
462
463 class AWindowSearchTextBox : public BC_TextBox
464 {
465 public:
466         AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w);
467         int handle_event();
468
469         AWindowSearchText *search_text;
470 };
471
472 class AWindowSearchText
473 {
474 public:
475         AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y);
476
477         int handle_event();
478         void create_objects();
479         int get_w();
480         int get_h();
481         void reposition_window(int x, int y, int w);
482         const char *get_text();
483         void clear();
484
485         MWindow *mwindow;
486         AWindowGUI *gui;
487         int x, y;
488         BC_Title *text_title;
489         BC_TextBox *text_box;
490 };
491
492 class AWindowDeleteDisk : public BC_Button
493 {
494 public:
495         AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y);
496         int handle_event();
497         MWindow *mwindow;
498         AWindowGUI *gui;
499         int x, y;
500 };
501
502 class AWindowDeleteProject : public BC_Button
503 {
504 public:
505         AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y);
506         int handle_event();
507         MWindow *mwindow;
508         AWindowGUI *gui;
509         int x, y;
510 };
511
512 class AWindowInfo : public BC_Button
513 {
514 public:
515         AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y);
516         int handle_event();
517         MWindow *mwindow;
518         AWindowGUI *gui;
519         int x, y;
520 };
521
522 class AWindowRedrawIndex : public BC_Button
523 {
524 public:
525         AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y);
526         int handle_event();
527         MWindow *mwindow;
528         AWindowGUI *gui;
529         int x, y;
530 };
531
532 class AWindowPaste : public BC_Button
533 {
534 public:
535         AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y);
536         int handle_event();
537         MWindow *mwindow;
538         AWindowGUI *gui;
539         int x, y;
540 };
541
542 class AWindowAppend : public BC_Button
543 {
544 public:
545         AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y);
546         int handle_event();
547         MWindow *mwindow;
548         AWindowGUI *gui;
549         int x, y;
550 };
551
552 class AWindowView : public BC_Button
553 {
554 public:
555         AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y);
556         int handle_event();
557         MWindow *mwindow;
558         AWindowGUI *gui;
559         int x, y;
560 };
561
562 class AddTools : public BC_PopupMenu
563 {
564 public:
565         AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title);
566         void create_objects();
567
568         MWindow *mwindow;
569         AWindowGUI *gui;
570 };
571
572 class AddPluginItem : public BC_MenuItem
573 {
574 public:
575         AddPluginItem(AddTools *menu, const char *text, int idx);
576         int handle_event();
577
578         AddTools *menu;
579         int idx;
580 };
581
582 class AVIconDrawingItem : public BC_MenuItem
583 {
584 public:
585         AVIconDrawingItem(AVIconDrawing *avicon, const char *text, int id);
586         int handle_event();
587
588         AVIconDrawing *avicon;
589         int id;
590 };
591
592 class AVIconDrawing : public BC_PopupMenu
593 {
594 public:
595         AVIconDrawing(AWindowGUI *agui, int x, int y, int w, const char *text);
596         ~AVIconDrawing();
597
598         static const char *avicon_names[];
599         void create_objects();
600         int button_press_event();
601         int draw_face(int dx, int color);
602
603         AWindowGUI *agui;
604 };
605
606
607 class AWindowListFormat : public BC_MenuItem
608 {
609 public:
610         AWindowListFormat(MWindow *mwindow, AWindowGUI *gui);
611
612         void update();
613         int handle_event();
614         MWindow *mwindow;
615         AWindowGUI *gui;
616 };
617
618
619 class AWindowListSort : public BC_MenuItem
620 {
621 public:
622         AWindowListSort(MWindow *mwindow, AWindowGUI *gui);
623
624         void update();
625         int handle_event();
626         MWindow *mwindow;
627         AWindowGUI *gui;
628 };
629
630 class AssetSelectUsedItem : public BC_MenuItem
631 {
632 public:
633         AssetSelectUsedItem(AssetSelectUsed *select_used, const char *text, int action);
634         int handle_event();
635
636         int action;
637         AssetSelectUsed *select_used;
638 };
639
640 class AssetSelectUsed : public BC_MenuItem
641 {
642 public:
643         AssetSelectUsed(MWindow *mwindow, AWindowGUI *gui);
644
645         MWindow *mwindow;
646         AWindowGUI *gui;
647 };
648
649 #endif