3 * Copyright (C) 2008-2017 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "automation.h"
27 #include "condition.h"
29 #include "cplayback.h"
31 #include "cwindowgui.h"
32 #include "cwindowtool.h"
34 #include "edlsession.h"
35 #include "floatauto.h"
36 #include "floatautos.h"
39 #include "localsession.h"
40 #include "mainsession.h"
43 #include "maskautos.h"
46 #include "mwindowgui.h"
49 #include "trackcanvas.h"
50 #include "transportque.h"
53 CWindowTool::CWindowTool(MWindow *mwindow, CWindowGUI *gui)
56 this->mwindow = mwindow;
60 current_tool = CWINDOW_NONE;
62 input_lock = new Condition(0, "CWindowTool::input_lock");
63 output_lock = new Condition(1, "CWindowTool::output_lock");
64 tool_gui_lock = new Mutex("CWindowTool::tool_gui_lock");
67 CWindowTool::~CWindowTool()
78 void CWindowTool::start_tool(int operation)
80 CWindowToolGUI *new_gui = 0;
83 //printf("CWindowTool::start_tool 1\n");
84 if(current_tool != operation)
86 int previous_tool = current_tool;
87 current_tool = operation;
91 new_gui = new CWindowEyedropGUI(mwindow, this);
94 new_gui = new CWindowCropGUI(mwindow, this);
97 new_gui = new CWindowCameraGUI(mwindow, this);
99 case CWINDOW_PROJECTOR:
100 new_gui = new CWindowProjectorGUI(mwindow, this);
103 new_gui = new CWindowMaskGUI(mwindow, this);
106 new_gui = new CWindowRulerGUI(mwindow, this);
108 case CWINDOW_PROTECT:
109 mwindow->edl->session->tool_window = 0;
110 gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(0);
118 //printf("CWindowTool::start_tool 1\n");
124 // Wait for previous tool GUI to finish
125 output_lock->lock("CWindowTool::start_tool");
126 this->tool_gui = new_gui;
127 tool_gui->create_objects();
128 if( previous_tool == CWINDOW_PROTECT || previous_tool == CWINDOW_NONE ) {
129 mwindow->edl->session->tool_window = 1;
130 gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(1);
132 update_show_window();
134 // Signal thread to run next tool GUI
135 input_lock->unlock();
137 //printf("CWindowTool::start_tool 1\n");
142 tool_gui->lock_window("CWindowTool::start_tool");
144 tool_gui->unlock_window();
147 //printf("CWindowTool::start_tool 2\n");
152 void CWindowTool::stop_tool()
156 tool_gui->lock_window("CWindowTool::stop_tool");
157 tool_gui->set_done(0);
158 tool_gui->unlock_window();
162 void CWindowTool::show_tool()
164 if(tool_gui && mwindow->edl->session->tool_window)
166 tool_gui->lock_window("CWindowTool::show_tool");
167 tool_gui->show_window();
168 tool_gui->unlock_window();
172 void CWindowTool::hide_tool()
174 if(tool_gui && mwindow->edl->session->tool_window)
176 tool_gui->lock_window("CWindowTool::show_tool");
177 tool_gui->hide_window();
178 tool_gui->unlock_window();
183 void CWindowTool::run()
187 input_lock->lock("CWindowTool::run");
190 tool_gui->run_window();
191 tool_gui_lock->lock("CWindowTool::run");
194 tool_gui_lock->unlock();
196 output_lock->unlock();
200 void CWindowTool::update_show_window()
204 tool_gui->lock_window("CWindowTool::update_show_window");
206 if(mwindow->edl->session->tool_window)
209 tool_gui->show_window();
212 tool_gui->hide_window();
215 tool_gui->unlock_window();
219 void CWindowTool::raise_window()
223 gui->unlock_window();
224 tool_gui->lock_window("CWindowTool::raise_window");
225 tool_gui->raise_window();
226 tool_gui->unlock_window();
227 gui->lock_window("CWindowTool::raise_window");
231 void CWindowTool::update_values()
233 tool_gui_lock->lock("CWindowTool::update_values");
236 tool_gui->lock_window("CWindowTool::update_values");
239 tool_gui->unlock_window();
241 tool_gui_lock->unlock();
250 CWindowToolGUI::CWindowToolGUI(MWindow *mwindow,
256 mwindow->session->ctool_x,
257 mwindow->session->ctool_y,
266 this->mwindow = mwindow;
267 this->thread = thread;
268 current_operation = 0;
271 CWindowToolGUI::~CWindowToolGUI()
275 int CWindowToolGUI::close_event()
279 mwindow->edl->session->tool_window = 0;
284 thread->gui->lock_window("CWindowToolGUI::close_event");
285 thread->gui->composite_panel->set_operation(mwindow->edl->session->cwindow_operation);
286 thread->gui->flush();
287 thread->gui->unlock_window();
289 lock_window("CWindowToolGUI::close_event");
293 int CWindowToolGUI::keypress_event()
297 switch( get_keypress() ) {
300 return close_event();
313 resend_event(thread->gui);
320 int CWindowToolGUI::translation_event()
322 mwindow->session->ctool_x = get_x();
323 mwindow->session->ctool_y = get_y();
332 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value, int log_increment = 0)
333 : BC_TumbleTextBox(gui, (float)value, (float)-65536, (float)65536, x, y, 100, 3)
336 set_log_floatincrement(log_increment);
339 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value)
340 : BC_TumbleTextBox(gui, (int64_t)value, (int64_t)-65536, (int64_t)65536, x, y, 100, 3)
344 int CWindowCoord::handle_event()
346 gui->event_caller = this;
352 CWindowCropOK::CWindowCropOK(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
353 : BC_GenericButton(x, y, _("Do it"))
355 this->mwindow = mwindow;
358 int CWindowCropOK::handle_event()
360 mwindow->crop_video();
365 int CWindowCropOK::keypress_event()
367 if(get_keypress() == 0xd)
381 CWindowCropGUI::CWindowCropGUI(MWindow *mwindow, CWindowTool *thread)
382 : CWindowToolGUI(mwindow,
384 _(PROGRAM_NAME ": Crop"),
391 CWindowCropGUI::~CWindowCropGUI()
395 void CWindowCropGUI::create_objects()
400 lock_window("CWindowCropGUI::create_objects");
402 int pad = MAX(BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1),
403 BC_Title::calculate_h(this, "X")) + 5;
404 add_subwindow(title = new BC_Title(x, y, "X1:"));
405 column1 = MAX(column1, title->get_w());
407 add_subwindow(title = new BC_Title(x, y, _("W:")));
408 column1 = MAX(column1, title->get_w());
410 add_subwindow(new CWindowCropOK(mwindow, thread->tool_gui, x, y));
414 x1 = new CWindowCoord(thread->tool_gui, x, y,
415 mwindow->edl->session->crop_x1);
416 x1->create_objects();
418 width = new CWindowCoord(thread->tool_gui, x, y,
419 mwindow->edl->session->crop_x2 - mwindow->edl->session->crop_x1);
420 width->create_objects();
423 x += x1->get_w() + 10;
426 add_subwindow(title = new BC_Title(x, y, "Y1:"));
427 column2 = MAX(column2, title->get_w());
429 add_subwindow(title = new BC_Title(x, y, _("H:")));
430 column2 = MAX(column2, title->get_w());
435 y1 = new CWindowCoord(thread->tool_gui, x, y,
436 mwindow->edl->session->crop_y1);
437 y1->create_objects();
439 height = new CWindowCoord(thread->tool_gui, x, y,
440 mwindow->edl->session->crop_y2 - mwindow->edl->session->crop_y1);
441 height->create_objects();
445 void CWindowCropGUI::handle_event()
448 new_x1 = atol(x1->get_text());
449 new_y1 = atol(y1->get_text());
450 if(new_x1 != mwindow->edl->session->crop_x1)
452 mwindow->edl->session->crop_x2 = new_x1 +
453 mwindow->edl->session->crop_x2 -
454 mwindow->edl->session->crop_x1;
455 mwindow->edl->session->crop_x1 = new_x1;
457 if(new_y1 != mwindow->edl->session->crop_y1)
459 mwindow->edl->session->crop_y2 = new_y1 +
460 mwindow->edl->session->crop_y2 -
461 mwindow->edl->session->crop_y1;
462 mwindow->edl->session->crop_y1 = atol(y1->get_text());
464 mwindow->edl->session->crop_x2 = atol(width->get_text()) +
465 mwindow->edl->session->crop_x1;
466 mwindow->edl->session->crop_y2 = atol(height->get_text()) +
467 mwindow->edl->session->crop_y1;
469 mwindow->cwindow->gui->canvas->redraw(1);
472 void CWindowCropGUI::update()
474 x1->update((int64_t)mwindow->edl->session->crop_x1);
475 y1->update((int64_t)mwindow->edl->session->crop_y1);
476 width->update((int64_t)mwindow->edl->session->crop_x2 -
477 mwindow->edl->session->crop_x1);
478 height->update((int64_t)mwindow->edl->session->crop_y2 -
479 mwindow->edl->session->crop_y1);
483 CWindowEyedropGUI::CWindowEyedropGUI(MWindow *mwindow, CWindowTool *thread)
484 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Color"), 220, 290)
488 CWindowEyedropGUI::~CWindowEyedropGUI()
492 void CWindowEyedropGUI::create_objects()
494 int margin = mwindow->theme->widget_border;
497 int x2 = 70, x3 = x2 + 60;
498 lock_window("CWindowEyedropGUI::create_objects");
499 BC_Title *title0, *title1, *title2, *title3, *title4, *title5, *title6, *title7;
500 add_subwindow(title0 = new BC_Title(x, y,_("X,Y:")));
501 y += title0->get_h() + margin;
502 add_subwindow(title7 = new BC_Title(x, y, _("Radius:")));
503 y += BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1) + margin;
505 add_subwindow(title1 = new BC_Title(x, y, _("Red:")));
506 y += title1->get_h() + margin;
507 add_subwindow(title2 = new BC_Title(x, y, _("Green:")));
508 y += title2->get_h() + margin;
509 add_subwindow(title3 = new BC_Title(x, y, _("Blue:")));
510 y += title3->get_h() + margin;
512 add_subwindow(title4 = new BC_Title(x, y, "Y:"));
513 y += title4->get_h() + margin;
514 add_subwindow(title5 = new BC_Title(x, y, "U:"));
515 y += title5->get_h() + margin;
516 add_subwindow(title6 = new BC_Title(x, y, "V:"));
518 add_subwindow(current = new BC_Title(x2, title0->get_y(), ""));
520 radius = new CWindowCoord(this, x2, title7->get_y(),
521 mwindow->edl->session->eyedrop_radius);
522 radius->create_objects();
523 radius->set_boundaries((int64_t)0, (int64_t)255);
525 add_subwindow(red = new BC_Title(x2, title1->get_y(), "0"));
526 add_subwindow(green = new BC_Title(x2, title2->get_y(), "0"));
527 add_subwindow(blue = new BC_Title(x2, title3->get_y(), "0"));
528 add_subwindow(rgb_hex = new BC_Title(x3, red->get_y(), "#000000"));
530 add_subwindow(this->y = new BC_Title(x2, title4->get_y(), "0"));
531 add_subwindow(this->u = new BC_Title(x2, title5->get_y(), "0"));
532 add_subwindow(this->v = new BC_Title(x2, title6->get_y(), "0"));
533 add_subwindow(yuv_hex = new BC_Title(x3, this->y->get_y(), "#000000"));
535 y = title6->get_y() + this->v->get_h() + 2*margin;
536 add_subwindow(sample = new BC_SubWindow(x, y, 50, 50));
537 y += sample->get_h() + margin;
538 add_subwindow(use_max = new CWindowEyedropCheckBox(mwindow, this, x, y));
543 void CWindowEyedropGUI::update()
545 char string[BCTEXTLEN];
546 sprintf(string, "%d, %d",
547 thread->gui->eyedrop_x,
548 thread->gui->eyedrop_y);
549 current->update(string);
551 radius->update((int64_t)mwindow->edl->session->eyedrop_radius);
553 LocalSession *local_session = mwindow->edl->local_session;
554 int use_max = local_session->use_max;
555 float r = use_max ? local_session->red_max : local_session->red;
556 float g = use_max ? local_session->green_max : local_session->green;
557 float b = use_max ? local_session->blue_max : local_session->blue;
558 this->red->update(r);
559 this->green->update(g);
560 this->blue->update(b);
562 int rx = 255*r + 0.5; bclamp(rx,0,255);
563 int gx = 255*g + 0.5; bclamp(gx,0,255);
564 int bx = 255*b + 0.5; bclamp(bx,0,255);
565 char rgb_text[BCSTRLEN];
566 sprintf(rgb_text, "#%02x%02x%02x", rx, gx, bx);
567 rgb_hex->update(rgb_text);
570 YUV::yuv.rgb_to_yuv_f(r, g, b, y, u, v);
572 this->u->update(u); u += 0.5;
573 this->v->update(v); v += 0.5;
575 int yx = 255*y + 0.5; bclamp(yx,0,255);
576 int ux = 255*u + 0.5; bclamp(ux,0,255);
577 int vx = 255*v + 0.5; bclamp(vx,0,255);
578 char yuv_text[BCSTRLEN];
579 sprintf(yuv_text, "#%02x%02x%02x", yx, ux, vx);
580 yuv_hex->update(yuv_text);
582 int rgb = (rx << 16) | (gx << 8) | (bx << 0);
583 sample->set_color(rgb);
584 sample->draw_box(0, 0, sample->get_w(), sample->get_h());
585 sample->set_color(BLACK);
586 sample->draw_rectangle(0, 0, sample->get_w(), sample->get_h());
590 void CWindowEyedropGUI::handle_event()
592 int new_radius = atoi(radius->get_text());
593 if(new_radius != mwindow->edl->session->eyedrop_radius)
595 CWindowGUI *gui = mwindow->cwindow->gui;
596 if(gui->eyedrop_visible)
598 gui->lock_window("CWindowEyedropGUI::handle_event");
601 gui->canvas->do_eyedrop(rerender, 0, 1);
604 mwindow->edl->session->eyedrop_radius = new_radius;
606 if(gui->eyedrop_visible)
610 gui->canvas->do_eyedrop(rerender, 0, 1);
611 gui->unlock_window();
618 /* Buttons to control Keyframe-Curve-Mode for Projector or Camera */
620 // Configuration for all possible Keyframe Curve Mode toggles
622 FloatAuto::t_mode mode;
628 const _CVD Camera_Crv_Smooth =
632 N_("\"smooth\" Curve on current Camera Keyframes")
634 const _CVD Camera_Crv_Linear =
638 N_("\"linear\" Curve on current Camera Keyframes")
640 const _CVD Projector_Crv_Smooth =
644 N_("\"smooth\" Curve on current Projector Keyframes")
646 const _CVD Projector_Crv_Linear =
650 N_("\"linear\" Curve on current Projector Keyframes")
653 // Implementation Class für Keyframe Curve Mode buttons
655 // This button reflects the state of the "current" keyframe
656 // (the nearest keyframe on the left) for all three automation
657 // lines together. Clicking on this button (re)sets the curve
658 // mode for the three "current" keyframes simultanously, but
659 // never creates a new keyframe.
661 class CWindowCurveToggle : public BC_Toggle
664 CWindowCurveToggle(_CVD mode, MWindow *mwindow, CWindowToolGUI *gui, int x, int y);
665 void check_toggle_state(FloatAuto *x, FloatAuto *y, FloatAuto *z);
674 CWindowCurveToggle::CWindowCurveToggle(_CVD mode, MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
675 : BC_Toggle(x, y, mwindow->theme->get_image_set(mode.icon_id), false),
679 this->mwindow = mwindow;
680 set_tooltip(_(cfg.tooltip));
683 void CWindowCurveToggle::check_toggle_state(FloatAuto *x, FloatAuto *y, FloatAuto *z)
685 // the toggle state is only set to ON if all
686 // three automation lines have the same curve mode.
687 // For mixed states the toggle stays off.
688 set_value( x->curve_mode == this->cfg.mode &&
689 y->curve_mode == this->cfg.mode &&
690 z->curve_mode == this->cfg.mode
691 ,true // redraw to show new state
695 int CWindowCurveToggle::handle_event()
697 Track *track = mwindow->cwindow->calculate_affected_track();
699 FloatAuto *x=0, *y=0, *z=0;
700 mwindow->cwindow->calculate_affected_autos(track,
701 &x, &y, &z, cfg.use_camera, 0,0,0); // don't create new keyframe
702 if( x ) x->change_curve_mode(cfg.mode);
703 if( y ) y->change_curve_mode(cfg.mode);
704 if( z ) z->change_curve_mode(cfg.mode);
707 gui->update_preview();
714 CWindowEyedropCheckBox::CWindowEyedropCheckBox(MWindow *mwindow,
715 CWindowEyedropGUI *gui, int x, int y)
716 : BC_CheckBox(x, y, mwindow->edl->local_session->use_max, _("Use maximum"))
718 this->mwindow = mwindow;
722 int CWindowEyedropCheckBox::handle_event()
724 mwindow->edl->local_session->use_max = get_value();
731 CWindowCameraGUI::CWindowCameraGUI(MWindow *mwindow, CWindowTool *thread)
732 : CWindowToolGUI(mwindow,
734 _(PROGRAM_NAME ": Camera"),
739 CWindowCameraGUI::~CWindowCameraGUI()
743 void CWindowCameraGUI::create_objects()
745 int x = 10, y = 10, x1;
746 Track *track = mwindow->cwindow->calculate_affected_track();
747 FloatAuto *x_auto = 0, *y_auto = 0, *z_auto = 0;
751 lock_window("CWindowCameraGUI::create_objects");
753 mwindow->cwindow->calculate_affected_autos(track,
754 &x_auto, &y_auto, &z_auto, 1, 0, 0, 0);
757 add_subwindow(title = new BC_Title(x, y, "X:"));
759 this->x = new CWindowCoord(this, x, y,
760 x_auto ? x_auto->get_value() : (float)0);
761 this->x->create_objects();
766 add_subwindow(title = new BC_Title(x, y, "Y:"));
768 this->y = new CWindowCoord(this, x, y,
769 y_auto ? y_auto->get_value() : (float)0);
770 this->y->create_objects();
773 add_subwindow(title = new BC_Title(x, y, "Z:"));
775 this->z = new CWindowCoord(this, x, y,
776 z_auto ? z_auto->get_value() : (float)1);
777 this->z->create_objects();
778 this->z->set_increment(0.01);
782 add_subwindow(button = new CWindowCameraLeft(mwindow, this, x1, y));
783 x1 += button->get_w();
784 add_subwindow(button = new CWindowCameraCenter(mwindow, this, x1, y));
785 x1 += button->get_w();
786 add_subwindow(button = new CWindowCameraRight(mwindow, this, x1, y));
788 y += button->get_h();
790 add_subwindow(button = new CWindowCameraTop(mwindow, this, x1, y));
791 x1 += button->get_w();
792 add_subwindow(button = new CWindowCameraMiddle(mwindow, this, x1, y));
793 x1 += button->get_w();
794 add_subwindow(button = new CWindowCameraBottom(mwindow, this, x1, y));
795 // additional Buttons to control the curve mode of the "current" keyframe
796 x1 += button->get_w() + 15;
797 add_subwindow(this->t_smooth = new CWindowCurveToggle(Camera_Crv_Smooth, mwindow, this, x1, y));
798 x1 += button->get_w();
799 add_subwindow(this->t_linear = new CWindowCurveToggle(Camera_Crv_Linear, mwindow, this, x1, y));
801 // fill in current auto keyframe values, set toggle states.
806 void CWindowCameraGUI::update_preview()
808 CWindowGUI *cgui = mwindow->cwindow->gui;
809 cgui->lock_window("CWindowCameraGUI::update_preview");
810 cgui->sync_parameters(CHANGE_PARAMS, 0, 1);
811 cgui->unlock_window();
815 void CWindowCameraGUI::handle_event()
817 FloatAuto *x_auto = 0;
818 FloatAuto *y_auto = 0;
819 FloatAuto *z_auto = 0;
820 Track *track = mwindow->cwindow->calculate_affected_track();
823 mwindow->undo->update_undo_before(_("camera"), this);
824 if(event_caller == x)
826 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
827 track->automation->autos[AUTOMATION_CAMERA_X],
831 x_auto->set_value(atof(x->get_text()));
837 if(event_caller == y)
839 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
840 track->automation->autos[AUTOMATION_CAMERA_Y],
844 y_auto->set_value(atof(y->get_text()));
850 if(event_caller == z)
852 z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
853 track->automation->autos[AUTOMATION_CAMERA_Z],
857 float zoom = atof(z->get_text());
858 if(zoom > 100.) zoom = 100.;
860 if(zoom < 0.01) zoom = 0.01;
861 // Doesn't allow user to enter from scratch
862 // if(zoom != atof(z->get_text()))
865 z_auto->set_value(zoom);
866 mwindow->gui->lock_window("CWindowCameraGUI::handle_event");
867 mwindow->gui->draw_overlays(1);
868 mwindow->gui->unlock_window();
874 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
878 void CWindowCameraGUI::update()
880 FloatAuto *x_auto = 0;
881 FloatAuto *y_auto = 0;
882 FloatAuto *z_auto = 0;
883 Track *track = mwindow->cwindow->calculate_affected_track();
885 mwindow->cwindow->calculate_affected_autos(track,
886 &x_auto, &y_auto, &z_auto, 1, 0, 0, 0);
890 x->update(x_auto->get_value());
892 y->update(y_auto->get_value());
894 float value = z_auto->get_value();
896 thread->gui->lock_window("CWindowCameraGUI::update");
897 thread->gui->composite_panel->cpanel_zoom->update(value);
898 thread->gui->unlock_window();
901 if( x_auto && y_auto && z_auto )
903 t_smooth->check_toggle_state(x_auto, y_auto, z_auto);
904 t_linear->check_toggle_state(x_auto, y_auto, z_auto);
911 CWindowCameraLeft::CWindowCameraLeft(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
912 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
915 this->mwindow = mwindow;
916 set_tooltip(_("Left justify"));
918 int CWindowCameraLeft::handle_event()
920 FloatAuto *x_auto = 0;
921 FloatAuto *z_auto = 0;
922 Track *track = mwindow->cwindow->calculate_affected_track();
924 mwindow->cwindow->calculate_affected_autos(track,
925 &x_auto, 0, &z_auto, 1, 1, 0, 0);
931 track->get_source_dimensions(
932 mwindow->edl->local_session->get_selectionstart(1),
938 mwindow->undo->update_undo_before(_("camera"), 0);
940 (double)track->track_w / z_auto->get_value() / 2 -
942 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
944 gui->update_preview();
952 CWindowCameraCenter::CWindowCameraCenter(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
953 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
956 this->mwindow = mwindow;
957 set_tooltip(_("Center horizontal"));
959 int CWindowCameraCenter::handle_event()
961 FloatAuto *x_auto = 0;
962 Track *track = mwindow->cwindow->calculate_affected_track();
964 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
965 track->automation->autos[AUTOMATION_CAMERA_X],
970 mwindow->undo->update_undo_before(_("camera"), 0);
971 x_auto->set_value(0);
973 gui->update_preview();
974 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
981 CWindowCameraRight::CWindowCameraRight(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
982 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
985 this->mwindow = mwindow;
986 set_tooltip(_("Right justify"));
988 int CWindowCameraRight::handle_event()
990 FloatAuto *x_auto = 0;
991 FloatAuto *z_auto = 0;
992 Track *track = mwindow->cwindow->calculate_affected_track();
994 mwindow->cwindow->calculate_affected_autos(track,
995 &x_auto, 0, &z_auto, 1, 1, 0, 0);
1001 track->get_source_dimensions(
1002 mwindow->edl->local_session->get_selectionstart(1),
1008 mwindow->undo->update_undo_before(_("camera"), 0);
1009 x_auto->set_value( -((double)track->track_w / z_auto->get_value() / 2 -
1012 gui->update_preview();
1013 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1021 CWindowCameraTop::CWindowCameraTop(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1022 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1025 this->mwindow = mwindow;
1026 set_tooltip(_("Top justify"));
1028 int CWindowCameraTop::handle_event()
1030 FloatAuto *y_auto = 0;
1031 FloatAuto *z_auto = 0;
1032 Track *track = mwindow->cwindow->calculate_affected_track();
1034 mwindow->cwindow->calculate_affected_autos(track,
1035 0, &y_auto, &z_auto, 1, 0, 1, 0);
1038 if(y_auto && z_auto)
1041 track->get_source_dimensions(
1042 mwindow->edl->local_session->get_selectionstart(1),
1048 mwindow->undo->update_undo_before(_("camera"), 0);
1049 y_auto->set_value((double)track->track_h / z_auto->get_value() / 2 -
1052 gui->update_preview();
1053 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1061 CWindowCameraMiddle::CWindowCameraMiddle(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1062 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1065 this->mwindow = mwindow;
1066 set_tooltip(_("Center vertical"));
1068 int CWindowCameraMiddle::handle_event()
1070 FloatAuto *y_auto = 0;
1071 Track *track = mwindow->cwindow->calculate_affected_track();
1073 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1074 track->automation->autos[AUTOMATION_CAMERA_Y], 1);
1078 mwindow->undo->update_undo_before(_("camera"), 0);
1079 y_auto->set_value(0);
1081 gui->update_preview();
1082 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1089 CWindowCameraBottom::CWindowCameraBottom(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1090 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1093 this->mwindow = mwindow;
1094 set_tooltip(_("Bottom justify"));
1096 int CWindowCameraBottom::handle_event()
1098 FloatAuto *y_auto = 0;
1099 FloatAuto *z_auto = 0;
1100 Track *track = mwindow->cwindow->calculate_affected_track();
1102 mwindow->cwindow->calculate_affected_autos(track,
1103 0, &y_auto, &z_auto, 1, 0, 1, 0);
1106 if(y_auto && z_auto)
1109 track->get_source_dimensions(
1110 mwindow->edl->local_session->get_selectionstart(1),
1116 mwindow->undo->update_undo_before(_("camera"), 0);
1117 y_auto->set_value(-((double)track->track_h / z_auto->get_value() / 2 -
1120 gui->update_preview();
1121 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1129 CWindowProjectorGUI::CWindowProjectorGUI(MWindow *mwindow, CWindowTool *thread)
1130 : CWindowToolGUI(mwindow,
1132 _(PROGRAM_NAME ": Projector"),
1137 CWindowProjectorGUI::~CWindowProjectorGUI()
1140 void CWindowProjectorGUI::create_objects()
1142 int x = 10, y = 10, x1;
1143 Track *track = mwindow->cwindow->calculate_affected_track();
1144 FloatAuto *x_auto = 0;
1145 FloatAuto *y_auto = 0;
1146 FloatAuto *z_auto = 0;
1150 lock_window("CWindowProjectorGUI::create_objects");
1152 mwindow->cwindow->calculate_affected_autos(track,
1153 &x_auto, &y_auto, &z_auto, 0, 0, 0, 0);
1156 add_subwindow(title = new BC_Title(x, y, "X:"));
1157 x += title->get_w();
1158 this->x = new CWindowCoord(this, x, y,
1159 x_auto ? x_auto->get_value() : (float)0);
1160 this->x->create_objects();
1163 add_subwindow(title = new BC_Title(x, y, "Y:"));
1164 x += title->get_w();
1165 this->y = new CWindowCoord(this, x, y,
1166 y_auto ? y_auto->get_value() : (float)0);
1167 this->y->create_objects();
1170 add_subwindow(title = new BC_Title(x, y, "Z:"));
1171 x += title->get_w();
1172 this->z = new CWindowCoord(this, x, y,
1173 z_auto ? z_auto->get_value() : (float)1);
1174 this->z->create_objects();
1175 this->z->set_increment(0.01);
1179 add_subwindow(button = new CWindowProjectorLeft(mwindow, this, x1, y));
1180 x1 += button->get_w();
1181 add_subwindow(button = new CWindowProjectorCenter(mwindow, this, x1, y));
1182 x1 += button->get_w();
1183 add_subwindow(button = new CWindowProjectorRight(mwindow, this, x1, y));
1185 y += button->get_h();
1187 add_subwindow(button = new CWindowProjectorTop(mwindow, this, x1, y));
1188 x1 += button->get_w();
1189 add_subwindow(button = new CWindowProjectorMiddle(mwindow, this, x1, y));
1190 x1 += button->get_w();
1191 add_subwindow(button = new CWindowProjectorBottom(mwindow, this, x1, y));
1193 // additional Buttons to control the curve mode of the "current" keyframe
1194 x1 += button->get_w() + 15;
1195 add_subwindow(this->t_smooth = new CWindowCurveToggle(Projector_Crv_Smooth, mwindow, this, x1, y));
1196 x1 += button->get_w();
1197 add_subwindow(this->t_linear = new CWindowCurveToggle(Projector_Crv_Linear, mwindow, this, x1, y));
1199 // fill in current auto keyframe values, set toggle states.
1204 void CWindowProjectorGUI::update_preview()
1206 CWindowGUI *cgui = mwindow->cwindow->gui;
1207 cgui->lock_window("CWindowProjectorGUI::update_preview");
1208 cgui->sync_parameters(CHANGE_PARAMS, 0, 1);
1209 cgui->unlock_window();
1212 void CWindowProjectorGUI::handle_event()
1214 FloatAuto *x_auto = 0;
1215 FloatAuto *y_auto = 0;
1216 FloatAuto *z_auto = 0;
1217 Track *track = mwindow->cwindow->calculate_affected_track();
1221 mwindow->undo->update_undo_before(_("projector"), this);
1222 if(event_caller == x)
1224 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1225 track->automation->autos[AUTOMATION_PROJECTOR_X],
1229 x_auto->set_value(atof(x->get_text()));
1235 if(event_caller == y)
1237 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1238 track->automation->autos[AUTOMATION_PROJECTOR_Y],
1242 y_auto->set_value(atof(y->get_text()));
1248 if(event_caller == z)
1250 z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1251 track->automation->autos[AUTOMATION_PROJECTOR_Z],
1255 float zoom = atof(z->get_text());
1256 if(zoom > 100.) zoom = 100.;
1257 else if(zoom < 0.01) zoom = 0.01;
1258 // if (zoom != atof(z->get_text()))
1260 z_auto->set_value(zoom);
1262 mwindow->gui->lock_window("CWindowProjectorGUI::handle_event");
1263 mwindow->gui->draw_overlays(1);
1264 mwindow->gui->unlock_window();
1270 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1274 void CWindowProjectorGUI::update()
1276 FloatAuto *x_auto = 0;
1277 FloatAuto *y_auto = 0;
1278 FloatAuto *z_auto = 0;
1279 Track *track = mwindow->cwindow->calculate_affected_track();
1281 mwindow->cwindow->calculate_affected_autos(track,
1282 &x_auto, &y_auto, &z_auto, 0, 0, 0, 0);
1286 x->update(x_auto->get_value());
1288 y->update(y_auto->get_value());
1290 float value = z_auto->get_value();
1292 thread->gui->lock_window("CWindowProjectorGUI::update");
1293 thread->gui->composite_panel->cpanel_zoom->update(value);
1294 thread->gui->unlock_window();
1297 if( x_auto && y_auto && z_auto )
1299 t_smooth->check_toggle_state(x_auto, y_auto, z_auto);
1300 t_linear->check_toggle_state(x_auto, y_auto, z_auto);
1304 CWindowProjectorLeft::CWindowProjectorLeft(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1305 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
1308 this->mwindow = mwindow;
1309 set_tooltip(_("Left justify"));
1311 int CWindowProjectorLeft::handle_event()
1313 FloatAuto *x_auto = 0;
1314 FloatAuto *z_auto = 0;
1315 Track *track = mwindow->cwindow->calculate_affected_track();
1317 mwindow->cwindow->calculate_affected_autos(track,
1318 &x_auto, 0, &z_auto, 0, 1, 0, 0);
1320 if(x_auto && z_auto)
1322 mwindow->undo->update_undo_before(_("projector"), 0);
1323 x_auto->set_value( (double)track->track_w * z_auto->get_value() / 2 -
1324 (double)mwindow->edl->session->output_w / 2 );
1326 gui->update_preview();
1327 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1334 CWindowProjectorCenter::CWindowProjectorCenter(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1335 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
1338 this->mwindow = mwindow;
1339 set_tooltip(_("Center horizontal"));
1341 int CWindowProjectorCenter::handle_event()
1343 FloatAuto *x_auto = 0;
1344 Track *track = mwindow->cwindow->calculate_affected_track();
1346 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1347 track->automation->autos[AUTOMATION_PROJECTOR_X],
1352 mwindow->undo->update_undo_before(_("projector"), 0);
1353 x_auto->set_value(0);
1355 gui->update_preview();
1356 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1363 CWindowProjectorRight::CWindowProjectorRight(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1364 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
1367 this->mwindow = mwindow;
1368 set_tooltip(_("Right justify"));
1370 int CWindowProjectorRight::handle_event()
1372 FloatAuto *x_auto = 0;
1373 FloatAuto *z_auto = 0;
1374 Track *track = mwindow->cwindow->calculate_affected_track();
1376 mwindow->cwindow->calculate_affected_autos(track,
1377 &x_auto, 0, &z_auto, 0, 1, 0, 0);
1380 if(x_auto && z_auto)
1382 mwindow->undo->update_undo_before(_("projector"), 0);
1383 x_auto->set_value( -((double)track->track_w * z_auto->get_value() / 2 -
1384 (double)mwindow->edl->session->output_w / 2));
1386 gui->update_preview();
1387 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1394 CWindowProjectorTop::CWindowProjectorTop(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1395 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1398 this->mwindow = mwindow;
1399 set_tooltip(_("Top justify"));
1401 int CWindowProjectorTop::handle_event()
1403 FloatAuto *y_auto = 0;
1404 FloatAuto *z_auto = 0;
1405 Track *track = mwindow->cwindow->calculate_affected_track();
1407 mwindow->cwindow->calculate_affected_autos(track,
1408 0, &y_auto, &z_auto, 0, 0, 1, 0);
1411 if(y_auto && z_auto)
1413 mwindow->undo->update_undo_before(_("projector"), 0);
1414 y_auto->set_value( (double)track->track_h * z_auto->get_value() / 2 -
1415 (double)mwindow->edl->session->output_h / 2 );
1417 gui->update_preview();
1418 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1425 CWindowProjectorMiddle::CWindowProjectorMiddle(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1426 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1429 this->mwindow = mwindow;
1430 set_tooltip(_("Center vertical"));
1432 int CWindowProjectorMiddle::handle_event()
1434 FloatAuto *y_auto = 0;
1435 Track *track = mwindow->cwindow->calculate_affected_track();
1437 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1438 track->automation->autos[AUTOMATION_PROJECTOR_Y], 1);
1442 mwindow->undo->update_undo_before(_("projector"), 0);
1443 y_auto->set_value(0);
1445 gui->update_preview();
1446 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1453 CWindowProjectorBottom::CWindowProjectorBottom(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1454 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1457 this->mwindow = mwindow;
1458 set_tooltip(_("Bottom justify"));
1460 int CWindowProjectorBottom::handle_event()
1462 FloatAuto *y_auto = 0;
1463 FloatAuto *z_auto = 0;
1464 Track *track = mwindow->cwindow->calculate_affected_track();
1466 mwindow->cwindow->calculate_affected_autos(track,
1467 0, &y_auto, &z_auto, 0, 0, 1, 0);
1470 if(y_auto && z_auto)
1472 mwindow->undo->update_undo_before(_("projector"), 0);
1473 y_auto->set_value( -((double)track->track_h * z_auto->get_value() / 2 -
1474 (double)mwindow->edl->session->output_h / 2));
1476 gui->update_preview();
1477 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1484 CWindowMaskName::CWindowMaskName(MWindow *mwindow,
1485 CWindowToolGUI *gui, int x, int y, const char *text)
1486 : BC_PopupTextBox(gui, 0, text, x, y, 100, 160)
1488 this->mwindow = mwindow;
1492 CWindowMaskName::~CWindowMaskName()
1496 int CWindowMaskName::handle_event()
1503 //printf("CWindowMaskGUI::update 1\n");
1504 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 0);
1506 int k = get_number();
1507 if( k < 0 ) k = mwindow->edl->session->cwindow_mask;
1508 else mwindow->edl->session->cwindow_mask = k;
1509 if( k >= 0 && k < mask_items.size() ) {
1510 mask_items[k]->set_text(get_text());
1511 update_list(&mask_items);
1513 #ifdef USE_KEYFRAME_SPANNING
1514 MaskAuto temp_keyframe(mwindow->edl, autos);
1515 temp_keyframe.copy_data(keyframe);
1516 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
1517 memset(submask->name, 0, sizeof(submask->name));
1518 strncpy(submask->name, get_text(), sizeof(submask->name)-1);
1519 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
1521 for(MaskAuto *current = (MaskAuto*)autos->default_auto; current; ) {
1522 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1523 memset(submask->name, 0, sizeof(submask->name));
1524 strncpy(submask->name, get_text(), sizeof(submask->name));
1525 current = current == (MaskAuto*)autos->default_auto ?
1526 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
1530 gui->update_preview();
1535 void CWindowMaskName::update_items(MaskAuto *keyframe)
1537 mask_items.remove_all_objects();
1538 int sz = keyframe->masks.size();
1539 for( int i=0; i<sz; ++i ) {
1540 SubMask *sub_mask = keyframe->masks.get(i);
1541 char *text = sub_mask->name;
1542 mask_items.append(new BC_ListBoxItem(text));
1544 update_list(&mask_items);
1548 CWindowMaskDelMask::CWindowMaskDelMask(MWindow *mwindow,
1549 CWindowToolGUI *gui, int x, int y)
1550 : BC_GenericButton(x, y, _("Delete"))
1552 this->mwindow = mwindow;
1554 set_tooltip(_("Delete mask"));
1557 int CWindowMaskDelMask::handle_event()
1565 // Get existing keyframe
1566 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 0);
1569 mwindow->undo->update_undo_before(_("mask delete"), 0);
1571 #ifdef USE_KEYFRAME_SPANNING
1572 // Create temp keyframe
1573 MaskAuto temp_keyframe(mwindow->edl, autos);
1574 temp_keyframe.copy_data(keyframe);
1576 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
1577 submask->points.remove_all_objects();
1578 // Commit change to span of keyframes
1579 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
1581 for(MaskAuto *current = (MaskAuto*)autos->default_auto; current; ) {
1582 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1583 submask->points.remove_all_objects();
1584 current = current == (MaskAuto*)autos->default_auto ?
1585 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
1589 gui->update_preview();
1590 mwindow->undo->update_undo_after(_("mask delete"), LOAD_AUTOMATION);
1596 CWindowMaskDelPoint::CWindowMaskDelPoint(MWindow *mwindow,
1597 CWindowToolGUI *gui, int x, int y)
1598 : BC_GenericButton(x, y, _("Delete"))
1600 this->mwindow = mwindow;
1602 set_tooltip(_("Delete point"));
1605 int CWindowMaskDelPoint::handle_event()
1614 // Get existing keyframe
1615 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 0);
1617 mwindow->undo->update_undo_before(_("point delete"), 0);
1619 #ifdef USE_KEYFRAME_SPANNING
1620 // Create temp keyframe
1621 MaskAuto temp_keyframe(mwindow->edl, autos);
1622 temp_keyframe.copy_data(keyframe);
1624 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
1625 int i = mwindow->cwindow->gui->affected_point;
1626 for( ; i<submask->points.total-1; ++i )
1627 *submask->points.values[i] = *submask->points.values[i+1];
1628 if( submask->points.total > 0 ) {
1629 point = submask->points.values[submask->points.total-1];
1630 submask->points.remove_object(point);
1632 total_points = submask->points.total;
1634 // Commit change to span of keyframes
1635 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
1637 MaskAuto *current = (MaskAuto*)autos->default_auto;
1639 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1640 int i = mwindow->cwindow->gui->affected_point;
1641 for( ; i<submask->points.total-1; ++i ) {
1642 *submask->points.values[i] = *submask->points.values[i+1];
1643 if( submask->points.total > 0 ) {
1644 point = submask->points.values[submask->points.total-1];
1645 submask->points.remove_object(point);
1647 total_points = submask->points.total;
1648 current = current == (MaskAuto*)autos->default_auto ?
1649 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
1652 if( mwindow->cwindow->gui->affected_point >= total_points )
1653 mwindow->cwindow->gui->affected_point =
1654 total_points > 0 ? total_points-1 : 0;
1657 gui->update_preview();
1658 mwindow->undo->update_undo_after(_("mask delete"), LOAD_AUTOMATION);
1664 int CWindowMaskDelPoint::keypress_event()
1666 if( get_keypress() == BACKSPACE ||
1667 get_keypress() == DELETE )
1668 return handle_event();
1675 CWindowMaskAffectedPoint::CWindowMaskAffectedPoint(MWindow *mwindow,
1676 CWindowToolGUI *gui, int x, int y)
1677 : BC_TumbleTextBox(gui,
1678 (int64_t)mwindow->cwindow->gui->affected_point,
1679 (int64_t)0, INT64_MAX, x, y, 100)
1681 this->mwindow = mwindow;
1685 CWindowMaskAffectedPoint::~CWindowMaskAffectedPoint()
1689 int CWindowMaskAffectedPoint::handle_event()
1691 int total_points = 0;
1692 int affected_point = atol(get_text());
1693 Track *track = mwindow->cwindow->calculate_affected_track();
1695 MaskAutos *autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1696 MaskAuto *keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(autos, 0);
1698 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1699 total_points = mask->points.size();
1702 int active_point = affected_point;
1703 if( affected_point >= total_points )
1704 affected_point = total_points - 1;
1705 else if( affected_point < 0 )
1707 if( active_point != affected_point )
1708 update((int64_t)affected_point);
1709 mwindow->cwindow->gui->affected_point = affected_point;
1711 gui->update_preview();
1716 CWindowMaskFeather::CWindowMaskFeather(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1717 : BC_TumbleTextBox(gui, 0, 0, 0xff, x, y, 64, 2)
1719 this->mwindow = mwindow;
1722 CWindowMaskFeather::~CWindowMaskFeather()
1726 int CWindowMaskFeather::update(float v)
1728 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*)gui;
1729 mask_gui->feather_slider->update(v);
1730 return BC_TumbleTextBox::update(v);
1733 int CWindowMaskFeather::update_value(float v)
1740 #ifdef USE_KEYFRAME_SPANNING
1746 mwindow->undo->update_undo_before(_("mask feather"), this);
1748 // Get existing keyframe
1749 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe,
1750 mask, point, create_it);
1752 #ifdef USE_KEYFRAME_SPANNING
1753 // Create temp keyframe
1754 MaskAuto temp_keyframe(mwindow->edl, autos);
1755 temp_keyframe.copy_data(keyframe);
1757 temp_keyframe.feather = v;
1758 // Commit change to span of keyframes
1759 autos->update_parameter(&temp_keyframe);
1761 keyframe->feather = v;
1764 gui->update_preview();
1767 mwindow->undo->update_undo_after(_("mask feather"), LOAD_AUTOMATION);
1771 int CWindowMaskFeather::handle_event()
1773 float v = atof(get_text());
1774 CWindowMaskGUI * mask_gui = (CWindowMaskGUI*)gui;
1775 mask_gui->feather_slider->update(v);
1776 return mask_gui->feather->update_value(v);
1779 CWindowMaskFeatherSlider::CWindowMaskFeatherSlider(MWindow *mwindow,
1780 CWindowToolGUI *gui, int x, int y, int w, float v)
1781 : BC_FSlider(x, y, 0, w, w, 0.f, 255.f, v)
1783 this->mwindow = mwindow;
1785 set_precision(0.01);
1788 CWindowMaskFeatherSlider::~CWindowMaskFeatherSlider()
1792 int CWindowMaskFeatherSlider::handle_event()
1794 float v = get_value();
1795 CWindowMaskGUI * mask_gui = (CWindowMaskGUI*)gui;
1796 mask_gui->feather->update(v);
1797 return mask_gui->feather->update_value(v);
1800 int CWindowMaskFeatherSlider::update(float v)
1802 return BC_FSlider::update(v);
1805 CWindowMaskFade::CWindowMaskFade(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1806 : BC_TumbleTextBox(gui, 0, -100.f, 100.f, x, y, 64, 2)
1808 this->mwindow = mwindow;
1811 CWindowMaskFade::~CWindowMaskFade()
1815 int CWindowMaskFade::update(float v)
1817 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*)gui;
1818 mask_gui->fade_slider->update(v);
1819 return BC_TumbleTextBox::update(v);
1822 int CWindowMaskFade::update_value(float v)
1829 #ifdef USE_KEYFRAME_SPANNING
1835 mwindow->undo->update_undo_before(_("mask fade"), this);
1837 // Get existing keyframe
1838 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe,
1839 mask, point, create_it);
1841 #ifdef USE_KEYFRAME_SPANNING
1842 // Create temp keyframe
1843 MaskAuto temp_keyframe(mwindow->edl, autos);
1844 temp_keyframe.copy_data(keyframe);
1846 temp_keyframe.value = v;
1847 // Commit change to span of keyframes
1848 autos->update_parameter(&temp_keyframe);
1850 keyframe->value = v;
1853 gui->update_preview();
1856 mwindow->undo->update_undo_after(_("mask fade"), LOAD_AUTOMATION);
1860 int CWindowMaskFade::handle_event()
1862 float v = atof(get_text());
1863 CWindowMaskGUI * mask_gui = (CWindowMaskGUI*)gui;
1864 mask_gui->fade_slider->update(v);
1865 return mask_gui->fade->update_value(v);
1868 CWindowMaskFadeSlider::CWindowMaskFadeSlider(MWindow *mwindow, CWindowToolGUI *gui,
1869 int x, int y, int w)
1870 : BC_ISlider(x, y, 0, w, w, -200, 200, 0)
1872 this->mwindow = mwindow;
1876 CWindowMaskFadeSlider::~CWindowMaskFadeSlider()
1880 int CWindowMaskFadeSlider::handle_event()
1882 float v = 100*get_value()/200;
1883 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*)gui;
1884 mask_gui->fade->BC_TumbleTextBox::update(v);
1885 return mask_gui->fade->update_value(v);
1888 int CWindowMaskFadeSlider::update(int64_t v)
1890 return BC_ISlider::update(200*v/100);
1893 CWindowMaskMode::CWindowMaskMode(MWindow *mwindow,
1894 CWindowToolGUI *gui, int x, int y)
1895 : BC_Toggle(x, y, mwindow->theme->mask_mode_toggle, 0)
1897 this->mwindow = mwindow;
1899 set_tooltip(_("Mode"));
1902 CWindowMaskMode::~CWindowMaskMode()
1906 int CWindowMaskMode::handle_event()
1913 // Get existing keyframe
1914 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 0);
1916 mwindow->undo->update_undo_before(_("mask mode"), 0);
1917 #ifdef USE_KEYFRAME_SPANNING
1918 // Create temp keyframe
1919 MaskAuto temp_keyframe(mwindow->edl, autos);
1920 temp_keyframe.copy_data(keyframe);
1922 temp_keyframe.mode = get_value();
1923 // Commit change to span of keyframes
1924 autos->update_parameter(&temp_keyframe);
1926 ((MaskAuto*)autos->default_auto)->mode = get_value();
1928 mwindow->undo->update_undo_after(_("mask mode"), LOAD_AUTOMATION);
1931 //printf("CWindowMaskMode::handle_event 1\n");
1932 gui->update_preview();
1937 CWindowMaskBeforePlugins::CWindowMaskBeforePlugins(CWindowToolGUI *gui, int x, int y)
1941 _("Apply mask before plugins"))
1946 int CWindowMaskBeforePlugins::handle_event()
1953 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 1);
1956 keyframe->apply_before_plugins = get_value();
1957 gui->update_preview();
1963 CWindowDisableOpenGLMasking::CWindowDisableOpenGLMasking(CWindowToolGUI *gui, int x, int y)
1964 : BC_CheckBox(x, y, 1, _("Disable OpenGL masking"))
1969 int CWindowDisableOpenGLMasking::handle_event()
1976 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 1);
1979 keyframe->disable_opengl_masking = get_value();
1980 gui->update_preview();
1986 CWindowMaskClrMask::CWindowMaskClrMask(MWindow *mwindow,
1987 CWindowMaskGUI *gui, int x, int y)
1988 : BC_Button(x, y, mwindow->theme->get_image_set("reset_button"))
1990 this->mwindow = mwindow;
1992 set_tooltip(_("Delete all masks"));
1995 CWindowMaskClrMask::~CWindowMaskClrMask()
1999 int CWindowMaskClrMask::calculate_w(MWindow *mwindow)
2001 VFrame *vfrm = *mwindow->theme->get_image_set("reset_button");
2002 return vfrm->get_w();
2005 int CWindowMaskClrMask::handle_event()
2013 // Get existing keyframe
2014 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 0);
2017 mwindow->undo->update_undo_before(_("del masks"), 0);
2018 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->clear_all();
2020 gui->update_preview();
2021 mwindow->undo->update_undo_after(_("del masks"), LOAD_AUTOMATION);
2027 CWindowMaskClrPoint::CWindowMaskClrPoint(MWindow *mwindow,
2028 CWindowMaskGUI *gui, int x, int y)
2029 : BC_Button(x, y, mwindow->theme->get_image_set("reset_button"))
2031 this->mwindow = mwindow;
2033 set_tooltip(_("Delete all points"));
2036 CWindowMaskClrPoint::~CWindowMaskClrPoint()
2040 int CWindowMaskClrPoint::handle_event()
2049 // Get existing keyframe
2050 ((CWindowMaskGUI*)gui)->get_keyframe(track, autos, keyframe, mask, point, 0);
2052 mwindow->undo->update_undo_before(_("clr points"), 0);
2053 #ifdef USE_KEYFRAME_SPANNING
2054 // Create temp keyframe
2055 MaskAuto temp_keyframe(mwindow->edl, autos);
2056 temp_keyframe.copy_data(keyframe);
2057 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
2058 submask->points.remove_all_objects();
2060 // Commit change to span of keyframes
2061 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
2063 MaskAuto *current = (MaskAuto*)autos->default_auto;
2065 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
2066 submask->points.clear();
2067 current = current == (MaskAuto*)autos->default_auto ?
2068 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
2072 if( mwindow->cwindow->gui->affected_point >= total_points )
2073 mwindow->cwindow->gui->affected_point =
2074 total_points > 0 ? total_points-1 : 0;
2077 gui->update_preview();
2078 mwindow->undo->update_undo_after(_("clr points"), LOAD_AUTOMATION);
2085 CWindowMaskGUI::CWindowMaskGUI(MWindow *mwindow, CWindowTool *thread)
2086 : CWindowToolGUI(mwindow, thread,
2087 _(PROGRAM_NAME ": Mask"), 340, 350)
2089 this->mwindow = mwindow;
2090 this->thread = thread;
2095 CWindowMaskGUI::~CWindowMaskGUI()
2097 lock_window("CWindowMaskGUI::~CWindowMaskGUI");
2098 delete active_point;
2104 void CWindowMaskGUI::create_objects()
2106 int x = 10, y = 10, margin = mwindow->theme->widget_border;
2107 int clr_x = get_w()-x - CWindowMaskClrMask::calculate_w(mwindow);
2108 int del_x = clr_x-margin - CWindowMaskDelMask::calculate_w(this,_("Delete"));
2109 //MaskAuto *keyframe = 0;
2110 //Track *track = mwindow->cwindow->calculate_affected_track();
2112 // keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(track->automation->autos[AUTOMATION_MASK], 0);
2114 lock_window("CWindowMaskGUI::create_objects");
2116 add_subwindow(title = new BC_Title(x, y, _("Mask:")));
2117 int x1 = x + title->get_w() + margin;
2118 name = new CWindowMaskName(mwindow, this, x + title->get_w() + margin, y, "");
2119 name->create_objects();
2120 x1 = x + name->get_w() + 2*margin;
2121 add_subwindow(clr_mask = new CWindowMaskClrMask(mwindow, this, clr_x, y));
2122 add_subwindow(del_mask = new CWindowMaskDelMask(mwindow, this, del_x, y));
2123 y += name->get_h() + margin;
2124 add_subwindow(title = new BC_Title(x, y, _("Fade:")));
2125 x1 = x + title->get_w() + margin;
2126 fade = new CWindowMaskFade(mwindow, this, x1, y);
2127 fade->create_objects();
2128 x1 += fade->get_w() + 2*margin;
2129 int w1 = clr_x-2*margin - x1;
2130 add_subwindow(fade_slider = new CWindowMaskFadeSlider(mwindow, this, x1, y, w1));
2131 x1 += fade_slider->get_w() + 2*margin;
2132 add_subwindow(mode = new CWindowMaskMode(mwindow, this, clr_x, y));
2133 y += fade->get_h() + 3*margin;
2134 add_subwindow(title = new BC_Title(x, y, _("Point:")));
2135 x1 = x + title->get_w() + margin;
2136 active_point = new CWindowMaskAffectedPoint(mwindow, this, x1, y);
2137 active_point->create_objects();
2138 x1 += active_point->get_w() + margin;
2139 add_subwindow(clr_point = new CWindowMaskClrPoint(mwindow, this, clr_x, y));
2140 add_subwindow(del_point = new CWindowMaskDelPoint(mwindow, this, del_x, y));
2141 y += active_point->get_h() + margin;
2142 add_subwindow(title = new BC_Title(x, y, "X:"));
2143 x1 = x + title->get_w() + margin;
2144 this->x = new CWindowCoord(this, x1, y, (float)0.0);
2145 this->x->create_objects();
2146 x1 += this->x->get_w() + 3*margin;
2147 add_subwindow(title = new BC_Title(x1, y, "Y:"));
2148 x1 += title->get_w() + margin;
2149 this->y = new CWindowCoord(this, x1, y, (float)0.0);
2150 this->y->create_objects();
2151 y += this->x->get_h() + 3*margin;
2152 add_subwindow(title = new BC_Title(x, y, _("Feather:")));
2153 x1 = x + title->get_w() + margin;
2154 feather = new CWindowMaskFeather(mwindow, this, x1, y);
2155 feather->create_objects();
2156 x1 += feather->get_w() + margin;
2157 feather_slider = new CWindowMaskFeatherSlider(mwindow, this, x1, y, 140, 0);
2158 add_subwindow(feather_slider);
2159 y += feather->get_h() + margin;
2160 add_subwindow(this->apply_before_plugins = new CWindowMaskBeforePlugins(this, 10, y));
2161 y += this->apply_before_plugins->get_h() + margin;
2162 add_subwindow(this->disable_opengl_masking = new CWindowDisableOpenGLMasking(this, 10, y));
2163 y += this->disable_opengl_masking->get_h() + 3*margin;
2164 add_subwindow(new BC_Bar(x, y, get_w()-2*x));
2166 add_subwindow(title = new BC_Title(x, y, _(
2167 "Shift+LMB: move an end point\n"
2168 "Ctrl+LMB: move a control point\n"
2169 "Wheel Up/Dn: rotate around pointer\n"
2170 "Shift+Wheel Up/Dn: scale around pointer\n"
2171 "Alt+LMB: to drag translate the mask\n"
2172 "Shift+Key Delete to delete the mask")));
2177 void CWindowMaskGUI::get_keyframe(Track* &track,
2179 MaskAuto* &keyframe,
2187 track = mwindow->cwindow->calculate_affected_track();
2190 autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
2191 keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(
2197 mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2204 if(mwindow->cwindow->gui->affected_point < mask->points.total &&
2205 mwindow->cwindow->gui->affected_point >= 0)
2207 point = mask->points.values[mwindow->cwindow->gui->affected_point];
2212 void CWindowMaskGUI::update()
2219 //printf("CWindowMaskGUI::update 1\n");
2220 get_keyframe(track, autos, keyframe, mask, point, 0);
2222 double position = mwindow->edl->local_session->get_selectionstart(1);
2223 position = mwindow->edl->align_to_frame(position, 0);
2226 int64_t position_i = track->to_units(position, 0);
2230 x->update(point->x);
2231 y->update(point->y);
2236 feather->update(autos->get_feather(position_i, PLAY_FORWARD));
2237 fade->update(autos->get_value(position_i, PLAY_FORWARD));
2238 apply_before_plugins->update(keyframe->apply_before_plugins);
2239 disable_opengl_masking->update(keyframe->disable_opengl_masking);
2243 //printf("CWindowMaskGUI::update 1\n");
2244 active_point->update((int64_t)mwindow->cwindow->gui->affected_point);
2245 name->update_items(keyframe);
2246 int k = mwindow->edl->session->cwindow_mask;
2247 const char *text = k >= 0 && k < keyframe->masks.size() ?
2248 keyframe->masks[k]->name : "";
2251 //printf("CWindowMaskGUI::update 1\n");
2253 #ifdef USE_KEYFRAME_SPANNING
2254 mode->update(keyframe->mode);
2256 mode->set_text(((MaskAuto*)autos->default_auto)->mode);
2259 //printf("CWindowMaskGUI::update 2\n");
2262 void CWindowMaskGUI::handle_event()
2269 get_keyframe(track, autos, keyframe, mask, point, 0);
2271 mwindow->undo->update_undo_before(_("mask point"), this);
2275 #ifdef USE_KEYFRAME_SPANNING
2276 // Create temp keyframe
2277 MaskAuto temp_keyframe(mwindow->edl, autos);
2278 temp_keyframe.copy_data(keyframe);
2279 // Get affected point in temp keyframe
2280 mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
2281 if(mwindow->cwindow->gui->affected_point < mask->points.total &&
2282 mwindow->cwindow->gui->affected_point >= 0)
2284 point = mask->points.values[mwindow->cwindow->gui->affected_point];
2289 point->x = atof(x->get_text());
2290 point->y = atof(y->get_text());
2291 // Commit to spanned keyframes
2292 autos->update_parameter(&temp_keyframe);
2295 point->x = atof(x->get_text());
2296 point->y = atof(y->get_text());
2301 mwindow->undo->update_undo_after(_("mask point"), LOAD_AUTOMATION);
2304 void CWindowMaskGUI::update_preview()
2307 CWindowGUI *cgui = mwindow->cwindow->gui;
2308 cgui->lock_window("CWindowMaskGUI::update_preview");
2309 cgui->sync_parameters(CHANGE_PARAMS, 0, 1);
2310 cgui->unlock_window();
2311 lock_window("CWindowMaskGUI::update_preview");
2315 CWindowRulerGUI::CWindowRulerGUI(MWindow *mwindow, CWindowTool *thread)
2316 : CWindowToolGUI(mwindow,
2318 _(PROGRAM_NAME ": Ruler"),
2324 CWindowRulerGUI::~CWindowRulerGUI()
2328 void CWindowRulerGUI::create_objects()
2330 int x = 10, y = 10, x1 = 100;
2333 lock_window("CWindowRulerGUI::create_objects");
2334 add_subwindow(title = new BC_Title(x, y, _("Current:")));
2335 add_subwindow(current = new BC_TextBox(x1, y, 200, 1, ""));
2336 y += title->get_h() + 5;
2337 add_subwindow(title = new BC_Title(x, y, _("Point 1:")));
2338 add_subwindow(point1 = new BC_TextBox(x1, y, 200, 1, ""));
2339 y += title->get_h() + 5;
2340 add_subwindow(title = new BC_Title(x, y, _("Point 2:")));
2341 add_subwindow(point2 = new BC_TextBox(x1, y, 200, 1, ""));
2342 y += title->get_h() + 5;
2343 add_subwindow(title = new BC_Title(x, y, _("Deltas:")));
2344 add_subwindow(deltas = new BC_TextBox(x1, y, 200, 1, ""));
2345 y += title->get_h() + 5;
2346 add_subwindow(title = new BC_Title(x, y, _("Distance:")));
2347 add_subwindow(distance = new BC_TextBox(x1, y, 200, 1, ""));
2348 y += title->get_h() + 5;
2349 add_subwindow(title = new BC_Title(x, y, _("Angle:")));
2350 add_subwindow(angle = new BC_TextBox(x1, y, 200, 1, ""));
2351 y += title->get_h() + 10;
2352 char string[BCTEXTLEN];
2354 _("Press Ctrl to lock ruler to the\nnearest 45%c%c angle."),
2355 0xc2, 0xb0); // degrees utf
2356 add_subwindow(title = new BC_Title(x,
2359 y += title->get_h() + 10;
2360 sprintf(string, _("Press Alt to translate the ruler."));
2361 add_subwindow(title = new BC_Title(x,
2368 void CWindowRulerGUI::update()
2370 char string[BCTEXTLEN];
2371 int cx = mwindow->session->cwindow_output_x;
2372 int cy = mwindow->session->cwindow_output_y;
2373 sprintf(string, "%d, %d", cx, cy);
2374 current->update(string);
2375 double x1 = mwindow->edl->session->ruler_x1;
2376 double y1 = mwindow->edl->session->ruler_y1;
2377 sprintf(string, "%.0f, %.0f", x1, y1);
2378 point1->update(string);
2379 double x2 = mwindow->edl->session->ruler_x2;
2380 double y2 = mwindow->edl->session->ruler_y2;
2381 sprintf(string, "%.0f, %.0f", x2, y2);
2382 point2->update(string);
2383 double dx = x2 - x1, dy = y2 - y1;
2384 sprintf(string, "%s%.0f, %s%.0f", (dx>=0? "+":""), dx, (dy>=0? "+":""), dy);
2385 deltas->update(string);
2386 double d = sqrt(dx*dx + dy*dy);
2387 sprintf(string, _("%0.01f pixels"), d);
2388 distance->update(string);
2389 double a = d > 0 ? (atan2(-dy, dx) * 180/M_PI) : 0.;
2390 sprintf(string, "%0.02f %c%c", a, 0xc2, 0xb0);
2391 angle->update(string);
2394 void CWindowRulerGUI::handle_event()