1 #include "automation.h"
7 #include "cwindowgui.h"
8 #include "cwindowtool.h"
10 #include "edlsession.h"
11 #include "floatauto.h"
12 #include "floatautos.h"
15 #include "localsession.h"
16 #include "mainsession.h"
18 #include "maskautos.h"
21 #include "mwindowgui.h"
24 #include "trackcanvas.h"
25 #include "transportque.h"
28 CWindowTool::CWindowTool(MWindow *mwindow, CWindowGUI *gui)
31 this->mwindow = mwindow;
35 current_tool = CWINDOW_NONE;
37 input_lock = new Condition(0, "CWindowTool::input_lock");
38 output_lock = new Condition(1, "CWindowTool::output_lock");
39 tool_gui_lock = new Mutex("CWindowTool::tool_gui_lock");
42 CWindowTool::~CWindowTool()
53 void CWindowTool::start_tool(int operation)
55 CWindowToolGUI *new_gui = 0;
58 //printf("CWindowTool::start_tool 1\n");
59 if(current_tool != operation)
61 current_tool = operation;
65 new_gui = new CWindowEyedropGUI(mwindow, this);
68 new_gui = new CWindowCropGUI(mwindow, this);
71 new_gui = new CWindowCameraGUI(mwindow, this);
73 case CWINDOW_PROJECTOR:
74 new_gui = new CWindowProjectorGUI(mwindow, this);
77 new_gui = new CWindowMaskGUI(mwindow, this);
85 //printf("CWindowTool::start_tool 1\n");
91 // Wait for previous tool GUI to finish
92 output_lock->lock("CWindowTool::start_tool");
93 this->tool_gui = new_gui;
94 tool_gui->create_objects();
96 if(mwindow->edl->session->tool_window &&
97 mwindow->session->show_cwindow) tool_gui->show_window();
101 // Signal thread to run next tool GUI
102 input_lock->unlock();
104 //printf("CWindowTool::start_tool 1\n");
109 tool_gui->lock_window("CWindowTool::start_tool");
111 tool_gui->unlock_window();
114 //printf("CWindowTool::start_tool 2\n");
119 void CWindowTool::stop_tool()
123 tool_gui->lock_window("CWindowTool::stop_tool");
124 tool_gui->set_done(0);
125 tool_gui->unlock_window();
129 void CWindowTool::show_tool()
131 if(tool_gui && mwindow->edl->session->tool_window)
133 tool_gui->lock_window("CWindowTool::show_tool");
134 tool_gui->show_window();
135 tool_gui->unlock_window();
139 void CWindowTool::hide_tool()
141 if(tool_gui && mwindow->edl->session->tool_window)
143 tool_gui->lock_window("CWindowTool::show_tool");
144 tool_gui->hide_window();
145 tool_gui->unlock_window();
150 void CWindowTool::run()
154 input_lock->lock("CWindowTool::run");
157 tool_gui->run_window();
158 tool_gui_lock->lock("CWindowTool::run");
161 tool_gui_lock->unlock();
163 output_lock->unlock();
167 void CWindowTool::update_show_window()
171 tool_gui->lock_window("CWindowTool::update_show_window");
173 if(mwindow->edl->session->tool_window)
176 tool_gui->show_window();
179 tool_gui->hide_window();
182 tool_gui->unlock_window();
186 void CWindowTool::update_values()
188 tool_gui_lock->lock("CWindowTool::update_values");
191 tool_gui->lock_window("CWindowTool::update_values");
194 tool_gui->unlock_window();
196 tool_gui_lock->unlock();
205 CWindowToolGUI::CWindowToolGUI(MWindow *mwindow,
211 mwindow->session->ctool_x,
212 mwindow->session->ctool_y,
221 this->mwindow = mwindow;
222 this->thread = thread;
223 current_operation = 0;
226 CWindowToolGUI::~CWindowToolGUI()
230 int CWindowToolGUI::close_event()
234 mwindow->edl->session->tool_window = 0;
239 thread->gui->lock_window("CWindowToolGUI::close_event");
240 thread->gui->composite_panel->set_operation(mwindow->edl->session->cwindow_operation);
241 thread->gui->flush();
242 thread->gui->unlock_window();
244 lock_window("CWindowToolGUI::close_event");
248 int CWindowToolGUI::keypress_event()
250 if(get_keypress() == 'w' || get_keypress() == 'W')
251 return close_event();
255 int CWindowToolGUI::translation_event()
257 mwindow->session->ctool_x = get_x();
258 mwindow->session->ctool_y = get_y();
267 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value, int log_increment = 0)
268 : BC_TumbleTextBox(gui,
277 set_log_floatincrement(log_increment);
280 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value)
281 : BC_TumbleTextBox(gui,
291 int CWindowCoord::handle_event()
293 gui->event_caller = this;
299 CWindowCropOK::CWindowCropOK(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
300 : BC_GenericButton(x, y, _("Do it"))
302 this->mwindow = mwindow;
305 int CWindowCropOK::handle_event()
307 mwindow->crop_video();
312 int CWindowCropOK::keypress_event()
314 if(get_keypress() == 0xd)
328 CWindowCropGUI::CWindowCropGUI(MWindow *mwindow, CWindowTool *thread)
329 : CWindowToolGUI(mwindow,
331 PROGRAM_NAME ": Crop",
338 CWindowCropGUI::~CWindowCropGUI()
342 void CWindowCropGUI::create_objects()
345 BC_TumbleTextBox *textbox;
349 int pad = MAX(BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1),
350 BC_Title::calculate_h(this, "X")) + 5;
351 add_subwindow(title = new BC_Title(x, y, _("X1:")));
352 column1 = MAX(column1, title->get_w());
354 add_subwindow(title = new BC_Title(x, y, _("W:")));
355 column1 = MAX(column1, title->get_w());
357 add_subwindow(new CWindowCropOK(mwindow, thread->tool_gui, x, y));
361 x1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_x1);
362 x1->create_objects();
364 width = new CWindowCoord(thread->tool_gui,
367 mwindow->edl->session->crop_x2 -
368 mwindow->edl->session->crop_x1);
369 width->create_objects();
372 x += x1->get_w() + 10;
375 add_subwindow(title = new BC_Title(x, y, _("Y1:")));
376 column2 = MAX(column2, title->get_w());
378 add_subwindow(title = new BC_Title(x, y, _("H:")));
379 column2 = MAX(column2, title->get_w());
384 y1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_y1);
385 y1->create_objects();
387 height = new CWindowCoord(thread->tool_gui,
390 mwindow->edl->session->crop_y2 -
391 mwindow->edl->session->crop_y1);
392 height->create_objects();
395 void CWindowCropGUI::handle_event()
398 new_x1 = atol(x1->get_text());
399 new_y1 = atol(y1->get_text());
400 if(new_x1 != mwindow->edl->session->crop_x1)
402 mwindow->edl->session->crop_x2 = new_x1 +
403 mwindow->edl->session->crop_x2 -
404 mwindow->edl->session->crop_x1;
405 mwindow->edl->session->crop_x1 = new_x1;
407 if(new_y1 != mwindow->edl->session->crop_y1)
409 mwindow->edl->session->crop_y2 = new_y1 +
410 mwindow->edl->session->crop_y2 -
411 mwindow->edl->session->crop_y1;
412 mwindow->edl->session->crop_y1 = atol(y1->get_text());
414 mwindow->edl->session->crop_x2 = atol(width->get_text()) +
415 mwindow->edl->session->crop_x1;
416 mwindow->edl->session->crop_y2 = atol(height->get_text()) +
417 mwindow->edl->session->crop_y1;
419 mwindow->cwindow->gui->lock_window("CWindowCropGUI::handle_event");
420 mwindow->cwindow->gui->canvas->draw_refresh();
421 mwindow->cwindow->gui->unlock_window();
424 void CWindowCropGUI::update()
426 x1->update((int64_t)mwindow->edl->session->crop_x1);
427 y1->update((int64_t)mwindow->edl->session->crop_y1);
428 width->update((int64_t)mwindow->edl->session->crop_x2 -
429 mwindow->edl->session->crop_x1);
430 height->update((int64_t)mwindow->edl->session->crop_y2 -
431 mwindow->edl->session->crop_y1);
439 CWindowEyedropGUI::CWindowEyedropGUI(MWindow *mwindow, CWindowTool *thread)
440 : CWindowToolGUI(mwindow,
442 PROGRAM_NAME ": Color",
448 CWindowEyedropGUI::~CWindowEyedropGUI()
452 void CWindowEyedropGUI::create_objects()
457 BC_Title *title1, *title2, *title3;
458 add_subwindow(title1 = new BC_Title(x, y, "Red:"));
459 y += title1->get_h() + 5;
460 add_subwindow(title2 = new BC_Title(x, y, "Green:"));
461 y += title2->get_h() + 5;
462 add_subwindow(title3 = new BC_Title(x, y, "Blue:"));
465 add_subwindow(red = new BC_Title(x2, title1->get_y(), "0"));
466 add_subwindow(green = new BC_Title(x2, title2->get_y(), "0"));
467 add_subwindow(blue = new BC_Title(x2, title3->get_y(), "0"));
469 y = blue->get_y() + blue->get_h() + 5;
470 add_subwindow(sample = new BC_SubWindow(x, y, 50, 50));
474 void CWindowEyedropGUI::update()
476 red->update(mwindow->edl->local_session->red);
477 green->update(mwindow->edl->local_session->green);
478 blue->update(mwindow->edl->local_session->blue);
480 int red = (int)(CLIP(mwindow->edl->local_session->red, 0, 1) * 0xff);
481 int green = (int)(CLIP(mwindow->edl->local_session->green, 0, 1) * 0xff);
482 int blue = (int)(CLIP(mwindow->edl->local_session->blue, 0, 1) * 0xff);
483 sample->set_color((red << 16) | (green << 8) | blue);
484 sample->draw_box(0, 0, sample->get_w(), sample->get_h());
485 sample->set_color(BLACK);
486 sample->draw_rectangle(0, 0, sample->get_w(), sample->get_h());
498 CWindowCameraGUI::CWindowCameraGUI(MWindow *mwindow, CWindowTool *thread)
499 : CWindowToolGUI(mwindow,
501 PROGRAM_NAME ": Camera",
506 CWindowCameraGUI::~CWindowCameraGUI()
510 void CWindowCameraGUI::create_objects()
512 int x = 10, y = 10, x1;
513 Track *track = mwindow->cwindow->calculate_affected_track();
514 FloatAuto *x_auto = 0;
515 FloatAuto *y_auto = 0;
516 FloatAuto *z_auto = 0;
522 mwindow->cwindow->calculate_affected_autos(&x_auto,
532 add_subwindow(title = new BC_Title(x, y, _("X:")));
534 this->x = new CWindowCoord(this,
537 x_auto ? x_auto->value : (float)0);
538 this->x->create_objects();
541 add_subwindow(title = new BC_Title(x, y, _("Y:")));
543 this->y = new CWindowCoord(this,
546 y_auto ? y_auto->value : (float)0);
547 this->y->create_objects();
550 add_subwindow(title = new BC_Title(x, y, _("Z:")));
552 this->z = new CWindowCoord(this,
555 z_auto ? z_auto->value : (float)1,
557 this->z->create_objects();
558 this->z->set_boundaries((float).0001, (float)256.0);
562 add_subwindow(button = new CWindowCameraLeft(mwindow, this, x1, y));
563 x1 += button->get_w();
564 add_subwindow(button = new CWindowCameraCenter(mwindow, this, x1, y));
565 x1 += button->get_w();
566 add_subwindow(button = new CWindowCameraRight(mwindow, this, x1, y));
568 y += button->get_h();
570 add_subwindow(button = new CWindowCameraTop(mwindow, this, x1, y));
571 x1 += button->get_w();
572 add_subwindow(button = new CWindowCameraMiddle(mwindow, this, x1, y));
573 x1 += button->get_w();
574 add_subwindow(button = new CWindowCameraBottom(mwindow, this, x1, y));
578 void CWindowCameraGUI::update_preview()
580 mwindow->restart_brender();
581 mwindow->sync_parameters(CHANGE_PARAMS);
583 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
587 mwindow->cwindow->gui->lock_window("CWindowCameraGUI::update_preview");
588 mwindow->cwindow->gui->canvas->draw_refresh();
589 mwindow->cwindow->gui->unlock_window();
593 void CWindowCameraGUI::handle_event()
595 FloatAuto *x_auto = 0;
596 FloatAuto *y_auto = 0;
597 FloatAuto *z_auto = 0;
598 Track *track = mwindow->cwindow->calculate_affected_track();
601 if(event_caller == x)
603 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
604 track->automation->autos[AUTOMATION_CAMERA_X],
608 x_auto->value = atof(x->get_text());
613 if(event_caller == y)
615 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
616 track->automation->autos[AUTOMATION_CAMERA_Y],
620 y_auto->value = atof(y->get_text());
625 if(event_caller == z)
627 z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
628 track->automation->autos[AUTOMATION_CAMERA_Z],
632 float zoom = atof(z->get_text());
633 if(zoom > 10) zoom = 10;
635 if(zoom < 0) zoom = 0;
636 // Doesn't allow user to enter from scratch
637 // if(zoom != atof(z->get_text()))
640 z_auto->value = zoom;
641 mwindow->gui->lock_window("CWindowCameraGUI::handle_event");
642 mwindow->gui->canvas->draw_overlays();
643 mwindow->gui->canvas->flash();
644 mwindow->gui->unlock_window();
651 void CWindowCameraGUI::update()
653 FloatAuto *x_auto = 0;
654 FloatAuto *y_auto = 0;
655 FloatAuto *z_auto = 0;
656 Track *track = mwindow->cwindow->calculate_affected_track();
660 mwindow->cwindow->calculate_affected_autos(&x_auto,
671 x->update(x_auto->value);
673 y->update(y_auto->value);
675 z->update(z_auto->value);
678 // BezierAuto* CWindowCameraGUI::get_keyframe()
680 // BezierAuto *keyframe = 0;
681 // Track *track = mwindow->cwindow->calculate_affected_track();
683 // keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
684 // track->automation->autos[AUTOMATION_CAMERA]);
690 CWindowCameraLeft::CWindowCameraLeft(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
691 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
694 this->mwindow = mwindow;
695 set_tooltip(_("Left justify"));
697 int CWindowCameraLeft::handle_event()
699 FloatAuto *x_auto = 0;
700 FloatAuto *z_auto = 0;
701 Track *track = mwindow->cwindow->calculate_affected_track();
704 mwindow->cwindow->calculate_affected_autos(&x_auto,
717 track->get_source_dimensions(
718 mwindow->edl->local_session->get_selectionstart(1),
725 (double)track->track_w / z_auto->value / 2 -
728 gui->update_preview();
736 CWindowCameraCenter::CWindowCameraCenter(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
737 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
740 this->mwindow = mwindow;
741 set_tooltip(_("Center horizontal"));
743 int CWindowCameraCenter::handle_event()
745 FloatAuto *x_auto = 0;
746 Track *track = mwindow->cwindow->calculate_affected_track();
748 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
749 track->automation->autos[AUTOMATION_CAMERA_X],
756 gui->update_preview();
763 CWindowCameraRight::CWindowCameraRight(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
764 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
767 this->mwindow = mwindow;
768 set_tooltip(_("Right justify"));
770 int CWindowCameraRight::handle_event()
772 FloatAuto *x_auto = 0;
773 FloatAuto *z_auto = 0;
774 Track *track = mwindow->cwindow->calculate_affected_track();
777 mwindow->cwindow->calculate_affected_autos(&x_auto,
790 track->get_source_dimensions(
791 mwindow->edl->local_session->get_selectionstart(1),
797 x_auto->value = -((double)track->track_w / z_auto->value / 2 -
800 gui->update_preview();
808 CWindowCameraTop::CWindowCameraTop(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
809 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
812 this->mwindow = mwindow;
813 set_tooltip(_("Top justify"));
815 int CWindowCameraTop::handle_event()
817 FloatAuto *y_auto = 0;
818 FloatAuto *z_auto = 0;
819 Track *track = mwindow->cwindow->calculate_affected_track();
822 mwindow->cwindow->calculate_affected_autos(0,
835 track->get_source_dimensions(
836 mwindow->edl->local_session->get_selectionstart(1),
842 y_auto->value = (double)track->track_h / z_auto->value / 2 -
845 gui->update_preview();
853 CWindowCameraMiddle::CWindowCameraMiddle(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
854 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
857 this->mwindow = mwindow;
858 set_tooltip(_("Center vertical"));
860 int CWindowCameraMiddle::handle_event()
862 FloatAuto *y_auto = 0;
863 Track *track = mwindow->cwindow->calculate_affected_track();
865 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
866 track->automation->autos[AUTOMATION_CAMERA_Y], 1);
872 gui->update_preview();
879 CWindowCameraBottom::CWindowCameraBottom(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
880 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
883 this->mwindow = mwindow;
884 set_tooltip(_("Bottom justify"));
886 int CWindowCameraBottom::handle_event()
888 FloatAuto *y_auto = 0;
889 FloatAuto *z_auto = 0;
890 Track *track = mwindow->cwindow->calculate_affected_track();
893 mwindow->cwindow->calculate_affected_autos(0,
906 track->get_source_dimensions(
907 mwindow->edl->local_session->get_selectionstart(1),
913 y_auto->value = -((double)track->track_h / z_auto->value / 2 -
916 gui->update_preview();
939 CWindowProjectorGUI::CWindowProjectorGUI(MWindow *mwindow, CWindowTool *thread)
940 : CWindowToolGUI(mwindow,
942 PROGRAM_NAME ": Projector",
947 CWindowProjectorGUI::~CWindowProjectorGUI()
950 void CWindowProjectorGUI::create_objects()
952 int x = 10, y = 10, x1;
953 Track *track = mwindow->cwindow->calculate_affected_track();
954 FloatAuto *x_auto = 0;
955 FloatAuto *y_auto = 0;
956 FloatAuto *z_auto = 0;
962 mwindow->cwindow->calculate_affected_autos(&x_auto,
972 add_subwindow(title = new BC_Title(x, y, _("X:")));
974 this->x = new CWindowCoord(this,
977 x_auto ? x_auto->value : (float)0);
978 this->x->create_objects();
981 add_subwindow(title = new BC_Title(x, y, _("Y:")));
983 this->y = new CWindowCoord(this,
986 y_auto ? y_auto->value : (float)0);
987 this->y->create_objects();
990 add_subwindow(title = new BC_Title(x, y, _("Z:")));
992 this->z = new CWindowCoord(this,
995 z_auto ? z_auto->value : (float)1,
997 this->z->create_objects();
998 this->z->set_boundaries((float).0001, (float)256.0);
1002 add_subwindow(button = new CWindowProjectorLeft(mwindow, this, x1, y));
1003 x1 += button->get_w();
1004 add_subwindow(button = new CWindowProjectorCenter(mwindow, this, x1, y));
1005 x1 += button->get_w();
1006 add_subwindow(button = new CWindowProjectorRight(mwindow, this, x1, y));
1008 y += button->get_h();
1010 add_subwindow(button = new CWindowProjectorTop(mwindow, this, x1, y));
1011 x1 += button->get_w();
1012 add_subwindow(button = new CWindowProjectorMiddle(mwindow, this, x1, y));
1013 x1 += button->get_w();
1014 add_subwindow(button = new CWindowProjectorBottom(mwindow, this, x1, y));
1018 void CWindowProjectorGUI::update_preview()
1020 mwindow->restart_brender();
1021 mwindow->sync_parameters(CHANGE_PARAMS);
1022 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1026 mwindow->cwindow->gui->lock_window("CWindowProjectorGUI::update_preview");
1027 mwindow->cwindow->gui->canvas->draw_refresh();
1028 mwindow->cwindow->gui->unlock_window();
1031 void CWindowProjectorGUI::handle_event()
1033 FloatAuto *x_auto = 0;
1034 FloatAuto *y_auto = 0;
1035 FloatAuto *z_auto = 0;
1036 Track *track = mwindow->cwindow->calculate_affected_track();
1040 if(event_caller == x)
1042 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1043 track->automation->autos[AUTOMATION_PROJECTOR_X],
1047 x_auto->value = atof(x->get_text());
1052 if(event_caller == y)
1054 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1055 track->automation->autos[AUTOMATION_PROJECTOR_Y],
1059 y_auto->value = atof(y->get_text());
1064 if(event_caller == z)
1066 z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1067 track->automation->autos[AUTOMATION_PROJECTOR_Z],
1071 float zoom = atof(z->get_text());
1072 if(zoom > 10000) zoom = 10000;
1074 if(zoom < 0) zoom = 0;
1075 // if (zoom != atof(z->get_text()))
1077 z_auto->value = zoom;
1079 mwindow->gui->lock_window("CWindowProjectorGUI::handle_event");
1080 mwindow->gui->canvas->draw_overlays();
1081 mwindow->gui->canvas->flash();
1082 mwindow->gui->unlock_window();
1090 void CWindowProjectorGUI::update()
1092 FloatAuto *x_auto = 0;
1093 FloatAuto *y_auto = 0;
1094 FloatAuto *z_auto = 0;
1095 Track *track = mwindow->cwindow->calculate_affected_track();
1099 mwindow->cwindow->calculate_affected_autos(&x_auto,
1110 x->update(x_auto->value);
1112 y->update(y_auto->value);
1114 z->update(z_auto->value);
1117 // BezierAuto* CWindowProjectorGUI::get_keyframe()
1119 // BezierAuto *keyframe = 0;
1120 // Track *track = mwindow->cwindow->calculate_affected_track();
1122 // keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
1123 // track->automation->autos[AUTOMATION_PROJECTOR]);
1164 CWindowProjectorLeft::CWindowProjectorLeft(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1165 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
1168 this->mwindow = mwindow;
1169 set_tooltip(_("Left justify"));
1171 int CWindowProjectorLeft::handle_event()
1173 FloatAuto *x_auto = 0;
1174 FloatAuto *z_auto = 0;
1175 Track *track = mwindow->cwindow->calculate_affected_track();
1178 mwindow->cwindow->calculate_affected_autos(&x_auto,
1187 if(x_auto && z_auto)
1189 x_auto->value = (double)track->track_w * z_auto->value / 2 -
1190 (double)mwindow->edl->session->output_w / 2;
1192 gui->update_preview();
1199 CWindowProjectorCenter::CWindowProjectorCenter(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1200 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
1203 this->mwindow = mwindow;
1204 set_tooltip(_("Center horizontal"));
1206 int CWindowProjectorCenter::handle_event()
1208 FloatAuto *x_auto = 0;
1209 Track *track = mwindow->cwindow->calculate_affected_track();
1211 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1212 track->automation->autos[AUTOMATION_PROJECTOR_X],
1219 gui->update_preview();
1226 CWindowProjectorRight::CWindowProjectorRight(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1227 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
1230 this->mwindow = mwindow;
1231 set_tooltip(_("Right justify"));
1233 int CWindowProjectorRight::handle_event()
1235 FloatAuto *x_auto = 0;
1236 FloatAuto *z_auto = 0;
1237 Track *track = mwindow->cwindow->calculate_affected_track();
1240 mwindow->cwindow->calculate_affected_autos(&x_auto,
1250 if(x_auto && z_auto)
1252 x_auto->value = -((double)track->track_w * z_auto->value / 2 -
1253 (double)mwindow->edl->session->output_w / 2);
1255 gui->update_preview();
1262 CWindowProjectorTop::CWindowProjectorTop(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1263 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1266 this->mwindow = mwindow;
1267 set_tooltip(_("Top justify"));
1269 int CWindowProjectorTop::handle_event()
1271 FloatAuto *y_auto = 0;
1272 FloatAuto *z_auto = 0;
1273 Track *track = mwindow->cwindow->calculate_affected_track();
1276 mwindow->cwindow->calculate_affected_autos(0,
1286 if(y_auto && z_auto)
1288 y_auto->value = (double)track->track_h * z_auto->value / 2 -
1289 (double)mwindow->edl->session->output_h / 2;
1291 gui->update_preview();
1298 CWindowProjectorMiddle::CWindowProjectorMiddle(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1299 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1302 this->mwindow = mwindow;
1303 set_tooltip(_("Center vertical"));
1305 int CWindowProjectorMiddle::handle_event()
1307 FloatAuto *y_auto = 0;
1308 Track *track = mwindow->cwindow->calculate_affected_track();
1310 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1311 track->automation->autos[AUTOMATION_PROJECTOR_Y], 1);
1317 gui->update_preview();
1324 CWindowProjectorBottom::CWindowProjectorBottom(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1325 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1328 this->mwindow = mwindow;
1329 set_tooltip(_("Bottom justify"));
1331 int CWindowProjectorBottom::handle_event()
1333 FloatAuto *y_auto = 0;
1334 FloatAuto *z_auto = 0;
1335 Track *track = mwindow->cwindow->calculate_affected_track();
1338 mwindow->cwindow->calculate_affected_autos(0,
1348 if(y_auto && z_auto)
1350 y_auto->value = -((double)track->track_h * z_auto->value / 2 -
1351 (double)mwindow->edl->session->output_h / 2);
1353 gui->update_preview();
1366 CWindowMaskMode::CWindowMaskMode(MWindow *mwindow,
1367 CWindowToolGUI *gui,
1377 this->mwindow = mwindow;
1381 void CWindowMaskMode::create_objects()
1383 add_item(new BC_MenuItem(mode_to_text(MASK_MULTIPLY_ALPHA)));
1384 add_item(new BC_MenuItem(mode_to_text(MASK_SUBTRACT_ALPHA)));
1387 char* CWindowMaskMode::mode_to_text(int mode)
1391 case MASK_MULTIPLY_ALPHA:
1392 return _("Multiply alpha");
1395 case MASK_SUBTRACT_ALPHA:
1396 return _("Subtract alpha");
1400 return _("Subtract alpha");
1403 int CWindowMaskMode::text_to_mode(char *text)
1405 if(!strcasecmp(text, _("Multiply alpha")))
1406 return MASK_MULTIPLY_ALPHA;
1408 if(!strcasecmp(text, _("Subtract alpha")))
1409 return MASK_SUBTRACT_ALPHA;
1411 return MASK_SUBTRACT_ALPHA;
1414 int CWindowMaskMode::handle_event()
1420 ((CWindowMaskGUI*)gui)->get_keyframe(track,
1428 ((MaskAuto*)track->automation->autos[AUTOMATION_MASK]->default_auto)->mode =
1429 text_to_mode(get_text());
1432 //printf("CWindowMaskMode::handle_event 1\n");
1433 gui->update_preview();
1444 CWindowMaskDelete::CWindowMaskDelete(MWindow *mwindow,
1445 CWindowToolGUI *gui,
1448 : BC_GenericButton(x, y, _("Delete"))
1450 this->mwindow = mwindow;
1454 int CWindowMaskDelete::handle_event()
1457 Track *track = mwindow->cwindow->calculate_affected_track();
1464 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1465 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1468 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1472 for(int i = mwindow->cwindow->gui->affected_point;
1473 i < submask->points.total - 1;
1476 *submask->points.values[i] = *submask->points.values[i + 1];
1479 if(submask->points.total)
1481 submask->points.remove_object(
1482 submask->points.values[submask->points.total - 1]);
1486 if(current == (MaskAuto*)mask_autos->default_auto)
1487 current = (MaskAuto*)mask_autos->first;
1489 current = (MaskAuto*)NEXT;
1492 gui->update_preview();
1496 // ((CWindowMaskGUI*)gui)->get_keyframe(track,
1502 // Need to apply to every keyframe
1506 // for(int i = mwindow->cwindow->gui->affected_point;
1507 // i < mask->points.total - 1;
1510 // *mask->points.values[i] = *mask->points.values[i + 1];
1513 // if(mask->points.total)
1515 // mask->points.remove_object(mask->points.values[mask->points.total - 1]);
1519 // gui->update_preview();
1525 int CWindowMaskDelete::keypress_event()
1527 if(get_keypress() == BACKSPACE ||
1528 get_keypress() == DELETE)
1529 return handle_event();
1534 CWindowMaskCycleNext::CWindowMaskCycleNext(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1535 : BC_GenericButton(x, y, _("Cycle next"))
1537 this->mwindow = mwindow;
1540 int CWindowMaskCycleNext::handle_event()
1546 ((CWindowMaskGUI*)gui)->get_keyframe(track,
1554 // Should apply to all keyframes
1555 if(keyframe && mask->points.total)
1557 temp = mask->points.values[0];
1559 for(int i = 0; i < mask->points.total - 1; i++)
1561 mask->points.values[i] = mask->points.values[i + 1];
1563 mask->points.values[mask->points.total - 1] = temp;
1565 mwindow->cwindow->gui->affected_point--;
1566 if(mwindow->cwindow->gui->affected_point < 0)
1567 mwindow->cwindow->gui->affected_point = mask->points.total - 1;
1570 gui->update_preview();
1576 CWindowMaskCyclePrev::CWindowMaskCyclePrev(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1577 : BC_GenericButton(x, y, _("Cycle prev"))
1579 this->mwindow = mwindow;
1582 int CWindowMaskCyclePrev::handle_event()
1588 ((CWindowMaskGUI*)gui)->get_keyframe(track,
1594 // Should apply to all keyframes
1596 if(keyframe && mask->points.total)
1598 temp = mask->points.values[mask->points.total - 1];
1600 for(int i = mask->points.total - 1; i > 0; i--)
1602 mask->points.values[i] = mask->points.values[i - 1];
1604 mask->points.values[0] = temp;
1606 mwindow->cwindow->gui->affected_point++;
1607 if(mwindow->cwindow->gui->affected_point >= mask->points.total)
1608 mwindow->cwindow->gui->affected_point = 0;
1611 gui->update_preview();
1617 CWindowMaskNumber::CWindowMaskNumber(MWindow *mwindow,
1618 CWindowToolGUI *gui,
1621 : BC_TumbleTextBox(gui,
1622 (int64_t)mwindow->edl->session->cwindow_mask,
1624 (int64_t)SUBMASKS - 1,
1629 this->mwindow = mwindow;
1633 CWindowMaskNumber::~CWindowMaskNumber()
1637 int CWindowMaskNumber::handle_event()
1639 mwindow->edl->session->cwindow_mask = atol(get_text());
1641 gui->update_preview();
1649 CWindowMaskFeather::CWindowMaskFeather(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1650 : BC_TumbleTextBox(gui,
1658 this->mwindow = mwindow;
1661 CWindowMaskFeather::~CWindowMaskFeather()
1664 int CWindowMaskFeather::handle_event()
1670 ((CWindowMaskGUI*)gui)->get_keyframe(track,
1676 keyframe->feather = atof(get_text());
1677 gui->update_preview();
1681 CWindowMaskValue::CWindowMaskValue(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1691 this->mwindow = mwindow;
1695 CWindowMaskValue::~CWindowMaskValue()
1699 int CWindowMaskValue::handle_event()
1705 ((CWindowMaskGUI*)gui)->get_keyframe(track,
1711 keyframe->value = get_value();
1712 gui->update_preview();
1718 CWindowMaskBeforePlugins::CWindowMaskBeforePlugins(CWindowToolGUI *gui, int x, int y)
1722 _("Apply mask before plugins"))
1727 int CWindowMaskBeforePlugins::handle_event()
1733 ((CWindowMaskGUI*)gui)->get_keyframe(track,
1739 keyframe->apply_before_plugins = get_value();
1740 gui->update_preview();
1751 CWindowMaskGUI::CWindowMaskGUI(MWindow *mwindow, CWindowTool *thread)
1752 : CWindowToolGUI(mwindow,
1754 PROGRAM_NAME ": Mask",
1758 this->mwindow = mwindow;
1759 this->thread = thread;
1761 CWindowMaskGUI::~CWindowMaskGUI()
1767 void CWindowMaskGUI::create_objects()
1770 MaskAuto *keyframe = 0;
1771 Track *track = mwindow->cwindow->calculate_affected_track();
1773 keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(track->automation->autos[AUTOMATION_MASK], 0);
1776 add_subwindow(title = new BC_Title(x, y, _("Mode:")));
1777 add_subwindow(mode = new CWindowMaskMode(mwindow,
1782 mode->create_objects();
1784 add_subwindow(new BC_Title(x, y, _("Value:")));
1785 add_subwindow(value = new CWindowMaskValue(mwindow, this, x + 50, y));
1787 add_subwindow(delete_point = new CWindowMaskDelete(mwindow, this, x, y));
1789 add_subwindow(new BC_Title(x, y, _("Mask number:")));
1790 number = new CWindowMaskNumber(mwindow,
1794 number->create_objects();
1796 add_subwindow(new BC_Title(x, y, _("Feather:")));
1797 feather = new CWindowMaskFeather(mwindow,
1801 feather->create_objects();
1803 add_subwindow(title = new BC_Title(x, y, _("X:")));
1804 x += title->get_w();
1805 this->x = new CWindowCoord(this,
1809 this->x->create_objects();
1811 add_subwindow(title = new BC_Title(x, y, _("Y:")));
1812 x += title->get_w();
1813 this->y = new CWindowCoord(this,
1817 this->y->create_objects();
1820 // add_subwindow(title = new BC_Title(x, y, _("Apply mask before plugins:")));
1822 add_subwindow(this->apply_before_plugins = new CWindowMaskBeforePlugins(this,
1825 // this->apply_before_plugins->create_objects();
1831 void CWindowMaskGUI::get_keyframe(Track* &track,
1832 MaskAuto* &keyframe,
1838 track = mwindow->cwindow->calculate_affected_track();
1840 keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(track->automation->autos[AUTOMATION_MASK], create_it);
1845 mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1852 if(mwindow->cwindow->gui->affected_point < mask->points.total &&
1853 mwindow->cwindow->gui->affected_point >= 0)
1855 point = mask->points.values[mwindow->cwindow->gui->affected_point];
1860 void CWindowMaskGUI::update()
1866 //printf("CWindowMaskGUI::update 1\n");
1873 //printf("CWindowMaskGUI::update 1\n");
1876 x->update(point->x);
1877 y->update(point->y);
1879 //printf("CWindowMaskGUI::update 1\n");
1883 feather->update((int64_t)keyframe->feather);
1884 value->update((int64_t)keyframe->value);
1885 apply_before_plugins->update((int64_t)keyframe->apply_before_plugins);
1887 //printf("CWindowMaskGUI::update 1\n");
1889 number->update((int64_t)mwindow->edl->session->cwindow_mask);
1891 //printf("CWindowMaskGUI::update 1\n");
1895 CWindowMaskMode::mode_to_text(((MaskAuto*)track->automation->autos[AUTOMATION_MASK]->default_auto)->mode));
1897 //printf("CWindowMaskGUI::update 2\n");
1900 void CWindowMaskGUI::handle_event()
1914 point->x = atof(x->get_text());
1915 point->y = atof(y->get_text());
1921 void CWindowMaskGUI::update_preview()
1923 mwindow->restart_brender();
1924 mwindow->sync_parameters(CHANGE_PARAMS);
1925 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1929 mwindow->cwindow->gui->lock_window("CWindowMaskGUI::update_preview");
1930 mwindow->cwindow->gui->canvas->draw_refresh();
1931 mwindow->cwindow->gui->unlock_window();
1946 // c-file-style: "linux"