splashgui text clr, faders/speed keyframe popup slider rework, reticle rework
[goodguy/history.git] / cinelerra-5.1 / cinelerra / editpopup.C
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 #include "asset.h"
23 #include "assets.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "edit.h"
27 #include "edits.h"
28 #include "editpopup.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "file.h"
32 #include "keys.h"
33 #include "language.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainsession.h"
37 #include "mwindow.h"
38 #include "mwindowgui.h"
39 #include "plugindialog.h"
40 #include "resizetrackthread.h"
41 #include "track.h"
42 #include "tracks.h"
43 #include "trackcanvas.h"
44
45 #include <string.h>
46
47 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
48  : BC_PopupMenu(0, 0, 0, "", 0)
49 {
50         this->mwindow = mwindow;
51         this->gui = gui;
52 }
53
54 EditPopup::~EditPopup()
55 {
56 }
57
58 void EditPopup::create_objects()
59 {
60         add_item(new EditAttachEffect(mwindow, this));
61         add_item(new EditMoveTrackUp(mwindow, this));
62         add_item(new EditMoveTrackDown(mwindow, this));
63         add_item(new EditPopupDeleteTrack(mwindow, this));
64         add_item(new EditPopupAddTrack(mwindow, this));
65         add_item(new EditPopupFindAsset(mwindow, this));
66         add_item(new EditPopupTitle(mwindow, this));
67         add_item(new EditPopupShow(mwindow, this));
68         resize_option = 0;
69         matchsize_option = 0;
70 }
71
72 int EditPopup::update(Track *track, Edit *edit)
73 {
74         this->edit = edit;
75         this->track = track;
76
77         if(track->data_type == TRACK_VIDEO && !resize_option)
78         {
79                 add_item(resize_option = new EditPopupResize(mwindow, this));
80                 add_item(matchsize_option = new EditPopupMatchSize(mwindow, this));
81         }
82         else
83         if(track->data_type == TRACK_AUDIO && resize_option)
84         {
85                 del_item(resize_option);     resize_option = 0;
86                 del_item(matchsize_option);  matchsize_option = 0;
87         }
88         return 0;
89 }
90
91
92 EditAttachEffect::EditAttachEffect(MWindow *mwindow, EditPopup *popup)
93  : BC_MenuItem(_("Attach effect..."))
94 {
95         this->mwindow = mwindow;
96         this->popup = popup;
97         dialog_thread = new PluginDialogThread(mwindow);
98 }
99
100 EditAttachEffect::~EditAttachEffect()
101 {
102         delete dialog_thread;
103 }
104
105 int EditAttachEffect::handle_event()
106 {
107         dialog_thread->start_window(popup->track,
108                 0, _(PROGRAM_NAME ": Attach Effect"),
109                 0, popup->track->data_type);
110         return 1;
111 }
112
113
114 EditMoveTrackUp::EditMoveTrackUp(MWindow *mwindow, EditPopup *popup)
115  : BC_MenuItem(_("Move up"))
116 {
117         this->mwindow = mwindow;
118         this->popup = popup;
119 }
120 EditMoveTrackUp::~EditMoveTrackUp()
121 {
122 }
123 int EditMoveTrackUp::handle_event()
124 {
125         mwindow->move_track_up(popup->track);
126         return 1;
127 }
128
129
130
131 EditMoveTrackDown::EditMoveTrackDown(MWindow *mwindow, EditPopup *popup)
132  : BC_MenuItem(_("Move down"))
133 {
134         this->mwindow = mwindow;
135         this->popup = popup;
136 }
137 EditMoveTrackDown::~EditMoveTrackDown()
138 {
139 }
140 int EditMoveTrackDown::handle_event()
141 {
142         mwindow->move_track_down(popup->track);
143         return 1;
144 }
145
146
147 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
148  : BC_MenuItem(_("Resize track..."))
149 {
150         this->mwindow = mwindow;
151         this->popup = popup;
152         dialog_thread = new ResizeTrackThread(mwindow);
153 }
154 EditPopupResize::~EditPopupResize()
155 {
156         delete dialog_thread;
157 }
158
159 int EditPopupResize::handle_event()
160 {
161         dialog_thread->start_window(popup->track);
162         return 1;
163 }
164
165
166 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
167  : BC_MenuItem(_("Match output size"))
168 {
169         this->mwindow = mwindow;
170         this->popup = popup;
171 }
172 EditPopupMatchSize::~EditPopupMatchSize()
173 {
174 }
175
176 int EditPopupMatchSize::handle_event()
177 {
178         mwindow->match_output_size(popup->track);
179         return 1;
180 }
181
182
183 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
184  : BC_MenuItem(_("Delete track"))
185 {
186         this->mwindow = mwindow;
187         this->popup = popup;
188 }
189 int EditPopupDeleteTrack::handle_event()
190 {
191         mwindow->delete_track(popup->track);
192         return 1;
193 }
194
195
196 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
197  : BC_MenuItem(_("Add track"))
198 {
199         this->mwindow = mwindow;
200         this->popup = popup;
201 }
202
203 int EditPopupAddTrack::handle_event()
204 {
205         switch( popup->track->data_type ) {
206         case TRACK_AUDIO:
207                 mwindow->add_audio_track_entry(1, popup->track);
208                 break;
209         case TRACK_VIDEO:
210                 mwindow->add_video_track_entry(popup->track);
211                 break;
212         case TRACK_SUBTITLE:
213                 mwindow->add_subttl_track_entry(popup->track);
214                 break;
215         }
216         return 1;
217 }
218
219 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
220  : BC_MenuItem(_("Find in Resources"))
221 {
222         this->mwindow = mwindow;
223         this->popup = popup;
224 }
225
226 int EditPopupFindAsset::handle_event()
227 {
228         Edit *edit = popup->edit;
229         if( edit ) {
230                 Indexable *idxbl = (Indexable *)edit->asset;
231                 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
232                 if( idxbl ) {
233                         AWindowGUI *agui = mwindow->awindow->gui;
234                         agui->lock_window("EditPopupFindAsset::handle_event");
235                         AssetPicon *picon = 0;
236                         for( int i=0, n=agui->assets.size(); i<n; ++i ) {
237                                 AssetPicon *ap = (AssetPicon *)agui->assets[i];
238                                 int found = ap->indexable && ( idxbl == ap->indexable ||
239                                         !strcmp(idxbl->path, ap->indexable->path) );
240                                 if( found && !picon ) picon = ap;
241                                 ap->set_selected(found);
242                         }
243                         if( picon ) {
244                                 int selected_folder = picon->indexable->awindow_folder;
245                                 mwindow->edl->session->awindow_folder = selected_folder;
246                                 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
247                                         AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
248                                         int selected = folder_item->foldernum == selected_folder ? 1 : 0;
249                                         folder_item->set_selected(selected);
250                                 }
251                         }
252                         agui->unlock_window();
253                         agui->async_update_assets();
254                 }
255         }
256         return 1;
257 }
258
259
260 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
261  : BC_MenuItem(_("User title..."))
262 {
263         this->mwindow = mwindow;
264         this->popup = popup;
265         dialog_thread = new EditTitleDialogThread(this);
266 }
267
268 EditPopupTitle::~EditPopupTitle()
269 {
270         delete dialog_thread;
271 }
272
273 int EditPopupTitle::handle_event()
274 {
275         if( popup->edit ) {
276                 dialog_thread->close_window();
277                 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
278                 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
279                 dialog_thread->start(wx, wy);
280         }
281         return 1;
282 }
283
284 void EditTitleDialogThread::start(int wx, int wy)
285 {
286         this->wx = wx;  this->wy = wy;
287         BC_DialogThread::start();
288 }
289
290 EditTitleDialogThread::EditTitleDialogThread(EditPopupTitle *edit_title)
291 {
292         this->edit_title = edit_title;
293         window = 0;
294 }
295 EditTitleDialogThread::~EditTitleDialogThread()
296 {
297         close_window();
298 }
299
300 BC_Window* EditTitleDialogThread::new_gui()
301 {
302         MWindow *mwindow = edit_title->mwindow;
303         EditPopup *popup = edit_title->popup;
304         window = new EditPopupTitleWindow(mwindow, popup, wx, wy);
305         window->create_objects();
306         return window;
307 }
308
309 void EditTitleDialogThread::handle_close_event(int result)
310 {
311         window = 0;
312 }
313
314 void EditTitleDialogThread::handle_done_event(int result)
315 {
316         if( result ) return;
317         MWindow *mwindow = edit_title->mwindow;
318         EditPopup *popup = edit_title->popup;
319         strcpy(popup->edit->user_title, window->title_text->get_text());
320         mwindow->gui->lock_window("EditTitleDialogThread::handle_done_event");
321         mwindow->gui->draw_canvas(1, 0);
322         mwindow->gui->flash_canvas(1);
323         mwindow->gui->unlock_window();
324 }
325
326 EditPopupTitleWindow::EditPopupTitleWindow(MWindow *mwindow,
327                 EditPopup *popup, int wx, int wy)
328  : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
329         300, 130, 300, 130, 0, 0, 1)
330 {
331         this->mwindow = mwindow;
332         this->popup = popup;
333         strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
334 }
335
336 EditPopupTitleWindow::~EditPopupTitleWindow()
337 {
338 }
339
340 void EditPopupTitleWindow::create_objects()
341 {
342         lock_window("EditPopupTitleWindow::create_objects");
343         int x = 10, y = 10;
344         add_subwindow(new BC_Title(x, y, _("User title:")));
345         title_text = new EditPopupTitleText(this, mwindow, x+15, y+20, new_text);
346         add_subwindow(title_text);
347         add_tool(new BC_OKButton(this));
348         add_tool(new BC_CancelButton(this));
349
350
351         show_window();
352         flush();
353         unlock_window();
354 }
355
356
357 EditPopupTitleText::EditPopupTitleText(EditPopupTitleWindow *window,
358         MWindow *mwindow, int x, int y, const char *text)
359  : BC_TextBox(x, y, 250, 1, text)
360 {
361         this->window = window;
362         this->mwindow = mwindow;
363 }
364
365 EditPopupTitleText::~EditPopupTitleText()
366 {
367 }
368
369 int EditPopupTitleText::handle_event()
370 {
371         if( get_keypress() == RETURN )
372                 window->set_done(0);
373         return 1;
374 }
375
376
377 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
378  : BC_MenuItem(_("Show edit"))
379 {
380         this->mwindow = mwindow;
381         this->popup = popup;
382         dialog_thread = new EditShowDialogThread(this);
383 }
384
385 EditPopupShow::~EditPopupShow()
386 {
387         delete dialog_thread;
388 }
389
390 int EditPopupShow::handle_event()
391 {
392         if( popup->edit ) {
393                 dialog_thread->close_window();
394                 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
395                 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
396                 dialog_thread->start(wx, wy);
397         }
398         return 1;
399 }
400
401 void EditShowDialogThread::start(int wx, int wy)
402 {
403         this->wx = wx;  this->wy = wy;
404         BC_DialogThread::start();
405 }
406
407 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
408 {
409         this->edit_show = edit_show;
410         window = 0;
411 }
412 EditShowDialogThread::~EditShowDialogThread()
413 {
414         close_window();
415 }
416
417 BC_Window* EditShowDialogThread::new_gui()
418 {
419         MWindow *mwindow = edit_show->mwindow;
420         EditPopup *popup = edit_show->popup;
421         window = new EditPopupShowWindow(mwindow, popup, wx, wy);
422         window->create_objects();
423         return window;
424 }
425
426 void EditShowDialogThread::handle_close_event(int result)
427 {
428         window = 0;
429 }
430
431 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
432                 EditPopup *popup, int wx, int wy)
433  : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
434         300, 220, 300, 220, 0, 0, 1)
435 {
436         this->mwindow = mwindow;
437         this->popup = popup;
438 }
439
440 EditPopupShowWindow::~EditPopupShowWindow()
441 {
442 }
443
444 void EditPopupShowWindow::create_objects()
445 {
446         lock_window("EditPopupShowWindow::create_objects");
447         int x = 10, y = 10;
448         BC_Title *title;
449         char text[BCTEXTLEN];
450         Track *track = popup->track;
451         Edit *edit = popup->edit;
452         sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
453         add_subwindow(title = new BC_Title(x, y, text));
454         int x1 = x + title->get_w() + 10;
455         int tw = get_w() - x1 - 20;
456         truncate_text(text, track->title, tw);
457         add_subwindow(new BC_Title(x1, y, text));
458         y += title->get_h() + 5;
459         sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
460         add_subwindow(title = new BC_Title(x, y, text));
461         char edit_title[BCTEXTLEN];
462         edit->get_title(edit_title);
463         truncate_text(text, edit_title, tw);
464         add_subwindow(new BC_Title(x1, y, text));
465         y += title->get_h() + 5;
466
467         EDLSession *session = mwindow->edl->session;
468         int time_format = session->time_format;
469         int sample_rate = session->sample_rate;
470         double frame_rate = session->frame_rate;
471         double frames_per_foot = session->frames_per_foot;
472
473         double startsource = track->from_units(edit->startsource);
474         double startproject = track->from_units(edit->startproject);
475         double length = track->from_units(edit->length);
476
477         char text_startsource[BCSTRLEN];
478         char text_startproject[BCSTRLEN];
479         char text_length[BCSTRLEN];
480         sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
481                 Units::totext(text_startsource, startsource,
482                         time_format, sample_rate, frame_rate, frames_per_foot),
483                 Units::totext(text_startproject, startproject,
484                         time_format, sample_rate, frame_rate, frames_per_foot),
485                 Units::totext(text_length, length,
486                         time_format, sample_rate, frame_rate, frames_per_foot));
487         show_text = new EditPopupShowText(this, mwindow, x+15, y+10, text);
488         add_subwindow(show_text);
489         add_tool(new BC_OKButton(this));
490
491         show_window();
492         flush();
493         unlock_window();
494 }
495
496
497 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
498         MWindow *mwindow, int x, int y, const char *text)
499  : BC_TextBox(x, y, 250, 4, text)
500 {
501         this->window = window;
502         this->mwindow = mwindow;
503 }
504
505 EditPopupShowText::~EditPopupShowText()
506 {
507 }
508