4 * Copyright (C) 2008 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
25 #include "awindowgui.h"
29 #include "edlsession.h"
33 #include "localsession.h"
34 #include "mainerror.h"
35 #include "mainsession.h"
37 #include "mwindowgui.h"
38 #include "plugindialog.h"
39 #include "resizetrackthread.h"
43 #include "trackpopup.h"
44 #include "trackcanvas.h"
48 TrackPopup::TrackPopup(MWindow *mwindow, MWindowGUI *gui)
49 : BC_PopupMenu(0, 0, 0, "", 0)
51 this->mwindow = mwindow;
60 TrackPopup::~TrackPopup()
64 void TrackPopup::create_objects()
66 add_item(new TrackAttachEffect(mwindow, this));
67 add_item(new TrackMoveUp(mwindow, this));
68 add_item(new TrackMoveDown(mwindow, this));
69 add_item(new TrackRollUp(mwindow, this));
70 add_item(new TrackRollDown(mwindow, this));
71 add_item(new TrackPopupDeleteTrack(mwindow, this));
72 add_item(new TrackPopupAddTrack(mwindow, this));
73 add_item(new TrackPopupFindAsset(mwindow, this));
74 add_item(new TrackPopupShow(mwindow, this));
75 add_item(new TrackPopupUserTitle(mwindow, this));
76 add_item(new TrackPopupTitleColor(mwindow, this));
81 int TrackPopup::activate_menu(Track *track, Edit *edit,
82 PluginSet *pluginset, Plugin *plugin, double position)
86 this->pluginset = pluginset;
87 this->plugin = plugin;
88 this->position = position;
90 if( track->data_type == TRACK_VIDEO && !resize_option ) {
91 add_item(resize_option = new TrackPopupResize(mwindow, this));
92 add_item(matchsize_option = new TrackPopupMatchSize(mwindow, this));
94 else if( track->data_type == TRACK_AUDIO && resize_option ) {
95 del_item(resize_option); resize_option = 0;
96 del_item(matchsize_option); matchsize_option = 0;
99 return BC_PopupMenu::activate_menu();
103 TrackAttachEffect::TrackAttachEffect(MWindow *mwindow, TrackPopup *popup)
104 : BC_MenuItem(_("Attach effect..."))
106 this->mwindow = mwindow;
108 dialog_thread = new PluginDialogThread(mwindow);
111 TrackAttachEffect::~TrackAttachEffect()
113 delete dialog_thread;
116 int TrackAttachEffect::handle_event()
118 dialog_thread->start_window(popup->track,
119 0, _(PROGRAM_NAME ": Attach Effect"),
120 0, popup->track->data_type);
125 TrackMoveUp::TrackMoveUp(MWindow *mwindow, TrackPopup *popup)
126 : BC_MenuItem(_("Move up"))
128 this->mwindow = mwindow;
131 TrackMoveUp::~TrackMoveUp()
134 int TrackMoveUp::handle_event()
136 mwindow->move_track_up(popup->track);
140 TrackMoveDown::TrackMoveDown(MWindow *mwindow, TrackPopup *popup)
141 : BC_MenuItem(_("Move down"))
143 this->mwindow = mwindow;
146 TrackMoveDown::~TrackMoveDown()
149 int TrackMoveDown::handle_event()
151 mwindow->move_track_down(popup->track);
156 TrackRollUp::TrackRollUp(MWindow *mwindow, TrackPopup *popup)
157 : BC_MenuItem(_("Roll up"))
159 this->mwindow = mwindow;
162 TrackRollUp::~TrackRollUp()
165 int TrackRollUp::handle_event()
167 mwindow->roll_track_up(popup->track);
171 TrackRollDown::TrackRollDown(MWindow *mwindow, TrackPopup *popup)
172 : BC_MenuItem(_("Roll down"))
174 this->mwindow = mwindow;
177 TrackRollDown::~TrackRollDown()
180 int TrackRollDown::handle_event()
182 mwindow->roll_track_down(popup->track);
187 TrackPopupResize::TrackPopupResize(MWindow *mwindow, TrackPopup *popup)
188 : BC_MenuItem(_("Resize track..."))
190 this->mwindow = mwindow;
192 dialog_thread = new ResizeTrackThread(mwindow);
194 TrackPopupResize::~TrackPopupResize()
196 delete dialog_thread;
199 int TrackPopupResize::handle_event()
201 dialog_thread->start_window(popup->track);
206 TrackPopupMatchSize::TrackPopupMatchSize(MWindow *mwindow, TrackPopup *popup)
207 : BC_MenuItem(_("Match output size"))
209 this->mwindow = mwindow;
212 TrackPopupMatchSize::~TrackPopupMatchSize()
216 int TrackPopupMatchSize::handle_event()
218 mwindow->match_output_size(popup->track);
223 TrackPopupDeleteTrack::TrackPopupDeleteTrack(MWindow *mwindow, TrackPopup *popup)
224 : BC_MenuItem(_("Delete track"))
226 this->mwindow = mwindow;
229 int TrackPopupDeleteTrack::handle_event()
231 mwindow->delete_track(popup->track);
236 TrackPopupAddTrack::TrackPopupAddTrack(MWindow *mwindow, TrackPopup *popup)
237 : BC_MenuItem(_("Add track"))
239 this->mwindow = mwindow;
243 int TrackPopupAddTrack::handle_event()
245 switch( popup->track->data_type ) {
247 mwindow->add_audio_track_entry(1, popup->track);
250 mwindow->add_video_track_entry(1, popup->track);
253 mwindow->add_subttl_track_entry(1, popup->track);
259 TrackPopupFindAsset::TrackPopupFindAsset(MWindow *mwindow, TrackPopup *popup)
260 : BC_MenuItem(_("Find in Resources"))
262 this->mwindow = mwindow;
266 int TrackPopupFindAsset::handle_event()
268 Edit *edit = popup->edit;
270 Indexable *idxbl = (Indexable *)edit->asset;
271 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
273 AWindowGUI *agui = mwindow->awindow->gui;
274 agui->lock_window("TrackPopupFindAsset::handle_event");
275 AssetPicon *picon = 0;
276 for( int i=0, n=agui->assets.size(); i<n; ++i ) {
277 AssetPicon *ap = (AssetPicon *)agui->assets[i];
278 int found = ap->indexable && ( idxbl == ap->indexable ||
279 !strcmp(idxbl->path, ap->indexable->path) );
280 if( found && !picon ) picon = ap;
281 ap->set_selected(found);
284 int selected_folder = picon->indexable->folder_no;
285 mwindow->edl->session->awindow_folder = selected_folder;
286 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
287 AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
288 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
289 folder_item->set_selected(selected);
292 agui->unlock_window();
293 agui->async_update_assets();
300 TrackPopupUserTitle::TrackPopupUserTitle(MWindow *mwindow, TrackPopup *popup)
301 : BC_MenuItem(_("User title..."))
303 this->mwindow = mwindow;
305 dialog_thread = new TrackUserTitleDialogThread(this);
308 TrackPopupUserTitle::~TrackPopupUserTitle()
310 delete dialog_thread;
313 #define TTW_W xS(300)
314 #define TTW_H yS(130)
316 int TrackPopupUserTitle::handle_event()
319 dialog_thread->close_window();
320 int wx = mwindow->gui->get_abs_cursor_x(0) - TTW_W / 2;
321 int wy = mwindow->gui->get_abs_cursor_y(0) - TTW_H / 2;
322 dialog_thread->start(wx, wy);
327 void TrackUserTitleDialogThread::start(int wx, int wy)
329 this->wx = wx; this->wy = wy;
330 BC_DialogThread::start();
333 TrackUserTitleDialogThread::TrackUserTitleDialogThread(TrackPopupUserTitle *edit_title)
335 this->edit_title = edit_title;
338 TrackUserTitleDialogThread::~TrackUserTitleDialogThread()
343 BC_Window* TrackUserTitleDialogThread::new_gui()
345 MWindow *mwindow = edit_title->mwindow;
346 TrackPopup *popup = edit_title->popup;
347 window = new TrackPopupUserTitleWindow(mwindow, popup, wx, wy);
348 window->create_objects();
352 void TrackUserTitleDialogThread::handle_close_event(int result)
357 void TrackUserTitleDialogThread::handle_done_event(int result)
360 MWindow *mwindow = edit_title->mwindow;
361 TrackPopup *popup = edit_title->popup;
362 EDL *edl = mwindow->edl;
363 const char *text = window->title_text->get_text();
365 for( Track *track=edl->tracks->first; track; track=track->next ) {
366 if( !track->is_armed() ) continue;
367 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
368 if( !edit->is_selected ) continue;
369 strcpy(edit->user_title, text);
374 edl->tracks->clear_selected_edits();
375 else if( popup->edit ) {
376 strcpy(popup->edit->user_title, text);
378 mwindow->gui->lock_window("TrackUserTitleDialogThread::handle_done_event");
379 mwindow->gui->draw_canvas(1, 0);
380 mwindow->gui->flash_canvas(1);
381 mwindow->gui->unlock_window();
384 TrackPopupUserTitleWindow::TrackPopupUserTitleWindow(MWindow *mwindow,
385 TrackPopup *popup, int wx, int wy)
386 : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
387 TTW_W, TTW_H, TTW_W, TTW_H, 0, 0, 1)
389 this->mwindow = mwindow;
391 strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
392 // *** CONTEXT_HELP ***
393 context_help_set_keyword("Track Popup Menu");
396 TrackPopupUserTitleWindow::~TrackPopupUserTitleWindow()
400 void TrackPopupUserTitleWindow::create_objects()
402 lock_window("TrackPopupUserTitleWindow::create_objects");
403 int x = xS(10), y = yS(10), x1;
404 BC_Title *title = new BC_Title(x1=x, y, _("User title:"));
405 add_subwindow(title); x1 += title->get_w() + xS(10);
406 title_text = new TrackPopupUserTitleText(this, mwindow, x1, y, new_text);
407 add_subwindow(title_text);
409 add_tool(new BC_OKButton(this));
410 add_tool(new BC_CancelButton(this));
419 TrackPopupUserTitleText::TrackPopupUserTitleText(TrackPopupUserTitleWindow *window,
420 MWindow *mwindow, int x, int y, const char *text)
421 : BC_TextBox(x, y, window->get_w()-x-xS(15), 1, text)
423 this->window = window;
424 this->mwindow = mwindow;
427 TrackPopupUserTitleText::~TrackPopupUserTitleText()
431 int TrackPopupUserTitleText::handle_event()
433 if( get_keypress() == RETURN )
439 TrackPopupTitleColor::TrackPopupTitleColor(MWindow *mwindow, TrackPopup *popup)
440 : BC_MenuItem(_("Bar Color..."))
442 this->mwindow = mwindow;
446 TrackPopupTitleColor::~TrackPopupTitleColor()
451 int TrackPopupTitleColor::handle_event()
454 int color = popup->mwindow->get_title_color(popup->edit);
455 if( !color ) color = popup->mwindow->theme->get_color_title_bg();
457 color_picker = new TrackTitleColorPicker(popup, color);
458 int alpha = (~color>>24) & 0xff;
459 color_picker->start_window(color & 0xffffff, alpha, 1);
464 TrackTitleColorDefault::TrackTitleColorDefault(
465 TrackTitleColorPicker *color_picker, int x, int y)
466 : BC_GenericButton(x, y, _("default"))
468 this->color_picker = color_picker;
471 int TrackTitleColorDefault::handle_event()
473 const unsigned color = 0, alpha = 0xff;
474 color_picker->color = color | (~alpha << 24);
475 color_picker->update_gui(color, alpha);
479 TrackTitleColorPicker::TrackTitleColorPicker(TrackPopup *popup, int color)
480 : ColorPicker(1, _("Bar Color"))
485 TrackTitleColorPicker::~TrackTitleColorPicker()
488 void TrackTitleColorPicker::create_objects(ColorWindow *gui)
490 gui->lock_window("TrackTitleColorPicker::create_objects");
491 int y = gui->get_h() - BC_CancelButton::calculate_h() + yS(10);
492 int x = gui->get_w() - BC_CancelButton::calculate_w() - xS(10);
493 x -= BC_GenericButton::calculate_w(gui, _("default")) + xS(15);
494 gui->add_subwindow(new TrackTitleColorDefault(this, x, y));
495 gui->unlock_window();
498 int TrackTitleColorPicker::handle_new_color(int color, int alpha)
500 this->color = color | (~alpha << 24);
504 void TrackTitleColorPicker::handle_done_event(int result)
507 EDL *edl = popup->mwindow->edl;
509 for( Track *track=edl->tracks->first; track; track=track->next ) {
510 if( !track->is_armed() ) continue;
511 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
512 if( !edit->is_selected ) continue;
518 edl->tracks->clear_selected_edits();
520 popup->edit->color = color;
522 MWindowGUI *mwindow_gui = popup->mwindow->gui;
523 mwindow_gui->lock_window("GWindowColorUpdate::run");
524 mwindow_gui->draw_trackmovement();
525 mwindow_gui->unlock_window();
529 #define TPW_W xS(300)
530 #define TPW_H yS(220)
532 TrackPopupShow::TrackPopupShow(MWindow *mwindow, TrackPopup *popup)
533 : BC_MenuItem(_("Show edit"))
535 this->mwindow = mwindow;
537 dialog_thread = new TrackShowDialogThread(this);
540 TrackPopupShow::~TrackPopupShow()
542 delete dialog_thread;
545 int TrackPopupShow::handle_event()
548 dialog_thread->close_window();
549 int wx = mwindow->gui->get_abs_cursor_x(0) - TPW_W / 2;
550 int wy = mwindow->gui->get_abs_cursor_y(0) - TPW_H / 2;
551 dialog_thread->start(wx, wy);
556 void TrackShowDialogThread::start(int wx, int wy)
558 this->wx = wx; this->wy = wy;
559 BC_DialogThread::start();
562 TrackShowDialogThread::TrackShowDialogThread(TrackPopupShow *edit_show)
564 this->edit_show = edit_show;
567 TrackShowDialogThread::~TrackShowDialogThread()
572 BC_Window* TrackShowDialogThread::new_gui()
574 MWindow *mwindow = edit_show->mwindow;
575 TrackPopup *popup = edit_show->popup;
576 window = new TrackPopupShowWindow(mwindow, popup, wx, wy);
577 window->create_objects();
581 void TrackShowDialogThread::handle_close_event(int result)
586 TrackPopupShowWindow::TrackPopupShowWindow(MWindow *mwindow,
587 TrackPopup *popup, int wx, int wy)
588 : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
589 TPW_W, TPW_H, TPW_W, TPW_H, 0, 0, 1)
591 this->mwindow = mwindow;
593 // *** CONTEXT_HELP ***
594 context_help_set_keyword("Track Popup Menu");
597 TrackPopupShowWindow::~TrackPopupShowWindow()
601 void TrackPopupShowWindow::create_objects()
603 lock_window("TrackPopupShowWindow::create_objects");
604 int x = xS(10), y = yS(10);
606 char text[BCTEXTLEN];
607 Edit *edit = popup->edit;
608 Track *track = edit->track;
609 sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
610 add_subwindow(title = new BC_Title(x, y, text));
611 int x1 = x + title->get_w() + xS(10);
612 int tw = get_w() - x1 - xS(20);
613 char *track_title = get_truncated_text(MEDIUMFONT, track->title, tw);
614 add_subwindow(new BC_Title(x1, y, track_title));
615 delete [] track_title;
616 y += title->get_h() + 5;
617 sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
618 add_subwindow(title = new BC_Title(x, y, text));
619 edit->get_title(text);
620 char *edit_title = get_truncated_text(MEDIUMFONT, text, tw);
621 add_subwindow(new BC_Title(x1, y, edit_title));
622 delete [] edit_title;
623 y += title->get_h() + 5;
625 EDLSession *session = mwindow->edl->session;
626 int time_format = session->time_format;
627 int sample_rate = session->sample_rate;
628 double frame_rate = session->frame_rate;
629 double frames_per_foot = session->frames_per_foot;
631 double startsource = track->from_units(edit->startsource);
632 double startproject = track->from_units(edit->startproject);
633 double length = track->from_units(edit->length);
635 char text_startsource[BCSTRLEN];
636 char text_startproject[BCSTRLEN];
637 char text_length[BCSTRLEN];
638 sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
639 Units::totext(text_startsource, startsource,
640 time_format, sample_rate, frame_rate, frames_per_foot),
641 Units::totext(text_startproject, startproject,
642 time_format, sample_rate, frame_rate, frames_per_foot),
643 Units::totext(text_length, length,
644 time_format, sample_rate, frame_rate, frames_per_foot));
645 show_text = new TrackPopupShowText(this, mwindow, x+xS(15), y+yS(10), text);
646 add_subwindow(show_text);
647 add_tool(new BC_OKButton(this));
655 TrackPopupShowText::TrackPopupShowText(TrackPopupShowWindow *window,
656 MWindow *mwindow, int x, int y, const char *text)
657 : BC_TextBox(x, y, xS(250), 4, text)
659 this->window = window;
660 this->mwindow = mwindow;
663 TrackPopupShowText::~TrackPopupShowText()