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"
28 #include "condition.h"
30 #include "cplayback.h"
32 #include "cwindowgui.h"
33 #include "cwindowtool.h"
35 #include "edlsession.h"
38 #include "floatauto.h"
39 #include "floatautos.h"
42 #include "localsession.h"
43 #include "mainsession.h"
46 #include "maskautos.h"
49 #include "mwindowgui.h"
53 #include "trackcanvas.h"
54 #include "transportque.h"
57 CWindowTool::CWindowTool(MWindow *mwindow, CWindowGUI *gui)
60 this->mwindow = mwindow;
64 current_tool = CWINDOW_NONE;
66 input_lock = new Condition(0, "CWindowTool::input_lock");
67 output_lock = new Condition(1, "CWindowTool::output_lock");
68 tool_gui_lock = new Mutex("CWindowTool::tool_gui_lock");
71 CWindowTool::~CWindowTool()
82 void CWindowTool::start_tool(int operation)
84 CWindowToolGUI *new_gui = 0;
87 //printf("CWindowTool::start_tool 1\n");
88 if(current_tool != operation)
90 int previous_tool = current_tool;
91 current_tool = operation;
95 new_gui = new CWindowEyedropGUI(mwindow, this);
98 new_gui = new CWindowCropGUI(mwindow, this);
101 new_gui = new CWindowCameraGUI(mwindow, this);
103 case CWINDOW_PROJECTOR:
104 new_gui = new CWindowProjectorGUI(mwindow, this);
107 new_gui = new CWindowMaskGUI(mwindow, this);
110 new_gui = new CWindowRulerGUI(mwindow, this);
112 case CWINDOW_PROTECT:
113 mwindow->edl->session->tool_window = 0;
114 gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(0);
122 //printf("CWindowTool::start_tool 1\n");
128 // Wait for previous tool GUI to finish
129 output_lock->lock("CWindowTool::start_tool");
130 this->tool_gui = new_gui;
131 tool_gui->create_objects();
132 if( previous_tool == CWINDOW_PROTECT || previous_tool == CWINDOW_NONE ) {
133 mwindow->edl->session->tool_window = 1;
134 gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(1);
136 update_show_window();
138 // Signal thread to run next tool GUI
139 input_lock->unlock();
141 //printf("CWindowTool::start_tool 1\n");
146 tool_gui->lock_window("CWindowTool::start_tool");
148 tool_gui->unlock_window();
151 //printf("CWindowTool::start_tool 2\n");
156 void CWindowTool::stop_tool()
160 tool_gui->lock_window("CWindowTool::stop_tool");
161 tool_gui->set_done(0);
162 tool_gui->unlock_window();
166 void CWindowTool::show_tool()
168 if(tool_gui && mwindow->edl->session->tool_window)
170 tool_gui->lock_window("CWindowTool::show_tool");
171 tool_gui->show_window();
172 tool_gui->unlock_window();
176 void CWindowTool::hide_tool()
178 if(tool_gui && mwindow->edl->session->tool_window)
180 tool_gui->lock_window("CWindowTool::show_tool");
181 tool_gui->hide_window();
182 tool_gui->unlock_window();
186 void CWindowTool::raise_tool()
188 if(tool_gui && mwindow->edl->session->tool_window)
190 tool_gui->lock_window("CWindowTool::show_tool");
191 tool_gui->raise_window();
192 tool_gui->unlock_window();
197 void CWindowTool::run()
201 input_lock->lock("CWindowTool::run");
204 tool_gui->run_window();
205 tool_gui_lock->lock("CWindowTool::run");
208 tool_gui_lock->unlock();
210 output_lock->unlock();
214 void CWindowTool::update_show_window()
218 tool_gui->lock_window("CWindowTool::update_show_window");
220 if(mwindow->edl->session->tool_window)
223 tool_gui->show_window();
226 tool_gui->hide_window();
229 tool_gui->unlock_window();
233 void CWindowTool::raise_window()
237 gui->unlock_window();
238 tool_gui->lock_window("CWindowTool::raise_window");
239 tool_gui->raise_window();
240 tool_gui->unlock_window();
241 gui->lock_window("CWindowTool::raise_window");
245 void CWindowTool::update_values()
247 tool_gui_lock->lock("CWindowTool::update_values");
250 tool_gui->lock_window("CWindowTool::update_values");
253 tool_gui->unlock_window();
255 tool_gui_lock->unlock();
264 CWindowToolGUI::CWindowToolGUI(MWindow *mwindow,
270 mwindow->session->ctool_x,
271 mwindow->session->ctool_y,
280 this->mwindow = mwindow;
281 this->thread = thread;
282 current_operation = 0;
285 CWindowToolGUI::~CWindowToolGUI()
289 int CWindowToolGUI::close_event()
293 mwindow->edl->session->tool_window = 0;
295 thread->gui->lock_window("CWindowToolGUI::close_event");
296 thread->gui->composite_panel->set_operation(mwindow->edl->session->cwindow_operation);
297 thread->gui->flush();
298 thread->gui->unlock_window();
299 lock_window("CWindowToolGUI::close_event");
303 int CWindowToolGUI::keypress_event()
307 switch( get_keypress() ) {
310 return close_event();
323 resend_event(thread->gui);
330 int CWindowToolGUI::translation_event()
332 mwindow->session->ctool_x = get_x();
333 mwindow->session->ctool_y = get_y();
338 void CWindowToolGUI::update_preview(int changed_edl)
341 draw_preview(changed_edl);
342 lock_window("CWindowToolGUI::update_preview");
345 void CWindowToolGUI::draw_preview(int changed_edl)
347 CWindowGUI *cgui = mwindow->cwindow->gui;
348 cgui->lock_window("CWindowToolGUI::draw_preview");
349 int change_type = !changed_edl ? CHANGE_PARAMS : CHANGE_EDL;
350 cgui->sync_parameters(change_type, 0, 1);
351 cgui->unlock_window();
355 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value, int log_increment = 0)
356 : BC_TumbleTextBox(gui, (float)value, (float)-65536, (float)65536, x, y, 70, 3)
359 set_log_floatincrement(log_increment);
362 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value)
363 : BC_TumbleTextBox(gui, (int64_t)value, (int64_t)-65536, (int64_t)65536, x, y, 70, 3)
367 int CWindowCoord::handle_event()
369 gui->event_caller = this;
375 CWindowCropApply::CWindowCropApply(MWindow *mwindow, CWindowCropGUI *crop_gui, int x, int y)
376 : BC_GenericButton(x, y, _("Apply"))
378 this->mwindow = mwindow;
379 this->crop_gui = crop_gui;
381 int CWindowCropApply::handle_event()
383 mwindow->crop_video(crop_gui->crop_mode->mode);
388 int CWindowCropApply::keypress_event()
390 if(get_keypress() == 0xd)
398 const char *CWindowCropOpMode::crop_ops[] = {
404 CWindowCropOpMode::CWindowCropOpMode(MWindow *mwindow, CWindowCropGUI *crop_gui,
405 int mode, int x, int y)
406 : BC_PopupMenu(x, y, 140, _(crop_ops[mode]), 1)
408 this->mwindow = mwindow;
409 this->crop_gui = crop_gui;
412 CWindowCropOpMode::~CWindowCropOpMode()
416 void CWindowCropOpMode::create_objects()
418 for( int id=0,nid=sizeof(crop_ops)/sizeof(crop_ops[0]); id<nid; ++id )
419 add_item(new CWindowCropOpItem(this, _(crop_ops[id]), id));
423 int CWindowCropOpMode::handle_event()
425 set_text(_(crop_ops[mode]));
429 CWindowCropOpItem::CWindowCropOpItem(CWindowCropOpMode *popup, const char *text, int id)
436 int CWindowCropOpItem::handle_event()
438 popup->set_text(get_text());
440 return popup->handle_event();
447 CWindowCropGUI::CWindowCropGUI(MWindow *mwindow, CWindowTool *thread)
448 : CWindowToolGUI(mwindow,
450 _(PROGRAM_NAME ": Crop"),
457 CWindowCropGUI::~CWindowCropGUI()
461 void CWindowCropGUI::create_objects()
466 lock_window("CWindowCropGUI::create_objects");
468 int pad = MAX(BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1),
469 BC_Title::calculate_h(this, "X")) + 5;
470 add_subwindow(title = new BC_Title(x, y, "X1:"));
471 column1 = MAX(column1, title->get_w());
473 add_subwindow(title = new BC_Title(x, y, _("W:")));
474 column1 = MAX(column1, title->get_w());
476 add_subwindow(new CWindowCropApply(mwindow, this, x, y));
480 x1 = new CWindowCoord(thread->tool_gui, x, y,
481 mwindow->edl->session->crop_x1);
482 x1->create_objects();
484 width = new CWindowCoord(thread->tool_gui, x, y,
485 mwindow->edl->session->crop_x2 - mwindow->edl->session->crop_x1);
486 width->create_objects();
489 x += x1->get_w() + 10;
492 add_subwindow(title = new BC_Title(x, y, "Y1:"));
493 column2 = MAX(column2, title->get_w());
495 add_subwindow(title = new BC_Title(x, y, _("H:")));
496 column2 = MAX(column2, title->get_w());
501 y1 = new CWindowCoord(thread->tool_gui, x, y,
502 mwindow->edl->session->crop_y1);
503 y1->create_objects();
506 height = new CWindowCoord(thread->tool_gui, x, y,
507 mwindow->edl->session->crop_y2 - mwindow->edl->session->crop_y1);
508 height->create_objects();
511 add_subwindow(crop_mode = new CWindowCropOpMode(mwindow, this,
512 CROP_REFORMAT, x, y));
513 crop_mode->create_objects();
518 void CWindowCropGUI::handle_event()
521 new_x1 = atol(x1->get_text());
522 new_y1 = atol(y1->get_text());
523 if(new_x1 != mwindow->edl->session->crop_x1)
525 mwindow->edl->session->crop_x2 = new_x1 +
526 mwindow->edl->session->crop_x2 -
527 mwindow->edl->session->crop_x1;
528 mwindow->edl->session->crop_x1 = new_x1;
530 if(new_y1 != mwindow->edl->session->crop_y1)
532 mwindow->edl->session->crop_y2 = new_y1 +
533 mwindow->edl->session->crop_y2 -
534 mwindow->edl->session->crop_y1;
535 mwindow->edl->session->crop_y1 = atol(y1->get_text());
537 mwindow->edl->session->crop_x2 = atol(width->get_text()) +
538 mwindow->edl->session->crop_x1;
539 mwindow->edl->session->crop_y2 = atol(height->get_text()) +
540 mwindow->edl->session->crop_y1;
542 mwindow->cwindow->gui->canvas->redraw(1);
545 void CWindowCropGUI::update()
547 x1->update((int64_t)mwindow->edl->session->crop_x1);
548 y1->update((int64_t)mwindow->edl->session->crop_y1);
549 width->update((int64_t)mwindow->edl->session->crop_x2 -
550 mwindow->edl->session->crop_x1);
551 height->update((int64_t)mwindow->edl->session->crop_y2 -
552 mwindow->edl->session->crop_y1);
556 CWindowEyedropGUI::CWindowEyedropGUI(MWindow *mwindow, CWindowTool *thread)
557 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Color"), 220, 290)
561 CWindowEyedropGUI::~CWindowEyedropGUI()
565 void CWindowEyedropGUI::create_objects()
567 int margin = mwindow->theme->widget_border;
570 int x2 = 70, x3 = x2 + 60;
571 lock_window("CWindowEyedropGUI::create_objects");
572 BC_Title *title0, *title1, *title2, *title3, *title4, *title5, *title6, *title7;
573 add_subwindow(title0 = new BC_Title(x, y,_("X,Y:")));
574 y += title0->get_h() + margin;
575 add_subwindow(title7 = new BC_Title(x, y, _("Radius:")));
576 y += BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1) + margin;
578 add_subwindow(title1 = new BC_Title(x, y, _("Red:")));
579 y += title1->get_h() + margin;
580 add_subwindow(title2 = new BC_Title(x, y, _("Green:")));
581 y += title2->get_h() + margin;
582 add_subwindow(title3 = new BC_Title(x, y, _("Blue:")));
583 y += title3->get_h() + margin;
585 add_subwindow(title4 = new BC_Title(x, y, "Y:"));
586 y += title4->get_h() + margin;
587 add_subwindow(title5 = new BC_Title(x, y, "U:"));
588 y += title5->get_h() + margin;
589 add_subwindow(title6 = new BC_Title(x, y, "V:"));
591 add_subwindow(current = new BC_Title(x2, title0->get_y(), ""));
593 radius = new CWindowCoord(this, x2, title7->get_y(),
594 mwindow->edl->session->eyedrop_radius);
595 radius->create_objects();
596 radius->set_boundaries((int64_t)0, (int64_t)255);
598 add_subwindow(red = new BC_Title(x2, title1->get_y(), "0"));
599 add_subwindow(green = new BC_Title(x2, title2->get_y(), "0"));
600 add_subwindow(blue = new BC_Title(x2, title3->get_y(), "0"));
601 add_subwindow(rgb_hex = new BC_Title(x3, red->get_y(), "#000000"));
603 add_subwindow(this->y = new BC_Title(x2, title4->get_y(), "0"));
604 add_subwindow(this->u = new BC_Title(x2, title5->get_y(), "0"));
605 add_subwindow(this->v = new BC_Title(x2, title6->get_y(), "0"));
606 add_subwindow(yuv_hex = new BC_Title(x3, this->y->get_y(), "#000000"));
608 y = title6->get_y() + this->v->get_h() + 2*margin;
609 add_subwindow(sample = new BC_SubWindow(x, y, 50, 50));
610 y += sample->get_h() + margin;
611 add_subwindow(use_max = new CWindowEyedropCheckBox(mwindow, this, x, y));
616 void CWindowEyedropGUI::update()
618 char string[BCTEXTLEN];
619 sprintf(string, "%d, %d",
620 thread->gui->eyedrop_x,
621 thread->gui->eyedrop_y);
622 current->update(string);
624 radius->update((int64_t)mwindow->edl->session->eyedrop_radius);
626 LocalSession *local_session = mwindow->edl->local_session;
627 int use_max = local_session->use_max;
628 float r = use_max ? local_session->red_max : local_session->red;
629 float g = use_max ? local_session->green_max : local_session->green;
630 float b = use_max ? local_session->blue_max : local_session->blue;
631 this->red->update(r);
632 this->green->update(g);
633 this->blue->update(b);
635 int rx = 255*r + 0.5; bclamp(rx,0,255);
636 int gx = 255*g + 0.5; bclamp(gx,0,255);
637 int bx = 255*b + 0.5; bclamp(bx,0,255);
638 char rgb_text[BCSTRLEN];
639 sprintf(rgb_text, "#%02x%02x%02x", rx, gx, bx);
640 rgb_hex->update(rgb_text);
643 YUV::yuv.rgb_to_yuv_f(r, g, b, y, u, v);
645 this->u->update(u); u += 0.5;
646 this->v->update(v); v += 0.5;
648 int yx = 255*y + 0.5; bclamp(yx,0,255);
649 int ux = 255*u + 0.5; bclamp(ux,0,255);
650 int vx = 255*v + 0.5; bclamp(vx,0,255);
651 char yuv_text[BCSTRLEN];
652 sprintf(yuv_text, "#%02x%02x%02x", yx, ux, vx);
653 yuv_hex->update(yuv_text);
655 int rgb = (rx << 16) | (gx << 8) | (bx << 0);
656 sample->set_color(rgb);
657 sample->draw_box(0, 0, sample->get_w(), sample->get_h());
658 sample->set_color(BLACK);
659 sample->draw_rectangle(0, 0, sample->get_w(), sample->get_h());
663 void CWindowEyedropGUI::handle_event()
665 int new_radius = atoi(radius->get_text());
666 if(new_radius != mwindow->edl->session->eyedrop_radius)
668 CWindowGUI *gui = mwindow->cwindow->gui;
669 if(gui->eyedrop_visible)
671 gui->lock_window("CWindowEyedropGUI::handle_event");
674 gui->canvas->do_eyedrop(rerender, 0, 1);
677 mwindow->edl->session->eyedrop_radius = new_radius;
679 if(gui->eyedrop_visible)
683 gui->canvas->do_eyedrop(rerender, 0, 1);
684 gui->unlock_window();
691 /* Buttons to control Keyframe-Curve-Mode for Projector or Camera */
693 // Configuration for all possible Keyframe Curve Mode toggles
695 FloatAuto::t_mode mode;
701 const _CVD Camera_Crv_Smooth =
705 N_("\"smooth\" Curve on current Camera Keyframes")
707 const _CVD Camera_Crv_Linear =
711 N_("\"linear\" Curve on current Camera Keyframes")
713 const _CVD Projector_Crv_Smooth =
717 N_("\"smooth\" Curve on current Projector Keyframes")
719 const _CVD Projector_Crv_Linear =
723 N_("\"linear\" Curve on current Projector Keyframes")
726 // Implementation Class für Keyframe Curve Mode buttons
728 // This button reflects the state of the "current" keyframe
729 // (the nearest keyframe on the left) for all three automation
730 // lines together. Clicking on this button (re)sets the curve
731 // mode for the three "current" keyframes simultanously, but
732 // never creates a new keyframe.
734 class CWindowCurveToggle : public BC_Toggle
737 CWindowCurveToggle(_CVD mode, MWindow *mwindow, CWindowToolGUI *gui, int x, int y);
738 void check_toggle_state(FloatAuto *x, FloatAuto *y, FloatAuto *z);
747 CWindowCurveToggle::CWindowCurveToggle(_CVD mode, MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
748 : BC_Toggle(x, y, mwindow->theme->get_image_set(mode.icon_id), false),
752 this->mwindow = mwindow;
753 set_tooltip(_(cfg.tooltip));
756 void CWindowCurveToggle::check_toggle_state(FloatAuto *x, FloatAuto *y, FloatAuto *z)
758 // the toggle state is only set to ON if all
759 // three automation lines have the same curve mode.
760 // For mixed states the toggle stays off.
761 set_value( x->curve_mode == this->cfg.mode &&
762 y->curve_mode == this->cfg.mode &&
763 z->curve_mode == this->cfg.mode
764 ,true // redraw to show new state
768 int CWindowCurveToggle::handle_event()
770 Track *track = mwindow->cwindow->calculate_affected_track();
772 FloatAuto *x=0, *y=0, *z=0;
773 mwindow->cwindow->calculate_affected_autos(track,
774 &x, &y, &z, cfg.use_camera, 0,0,0); // don't create new keyframe
775 if( x ) x->change_curve_mode(cfg.mode);
776 if( y ) y->change_curve_mode(cfg.mode);
777 if( z ) z->change_curve_mode(cfg.mode);
780 gui->update_preview();
787 CWindowEyedropCheckBox::CWindowEyedropCheckBox(MWindow *mwindow,
788 CWindowEyedropGUI *gui, int x, int y)
789 : BC_CheckBox(x, y, mwindow->edl->local_session->use_max, _("Use maximum"))
791 this->mwindow = mwindow;
795 int CWindowEyedropCheckBox::handle_event()
797 mwindow->edl->local_session->use_max = get_value();
804 CWindowCameraGUI::CWindowCameraGUI(MWindow *mwindow, CWindowTool *thread)
805 : CWindowToolGUI(mwindow,
807 _(PROGRAM_NAME ": Camera"),
812 CWindowCameraGUI::~CWindowCameraGUI()
816 void CWindowCameraGUI::create_objects()
818 int x = 10, y = 10, x1;
819 Track *track = mwindow->cwindow->calculate_affected_track();
820 FloatAuto *x_auto = 0, *y_auto = 0, *z_auto = 0;
824 lock_window("CWindowCameraGUI::create_objects");
826 mwindow->cwindow->calculate_affected_autos(track,
827 &x_auto, &y_auto, &z_auto, 1, 0, 0, 0);
830 add_subwindow(title = new BC_Title(x, y, "X:"));
832 this->x = new CWindowCoord(this, x, y,
833 x_auto ? x_auto->get_value() : (float)0);
834 this->x->create_objects();
839 add_subwindow(title = new BC_Title(x, y, "Y:"));
841 this->y = new CWindowCoord(this, x, y,
842 y_auto ? y_auto->get_value() : (float)0);
843 this->y->create_objects();
846 add_subwindow(title = new BC_Title(x, y, "Z:"));
848 this->z = new CWindowCoord(this, x, y,
849 z_auto ? z_auto->get_value() : (float)1);
850 this->z->create_objects();
851 this->z->set_increment(0.01);
855 add_subwindow(button = new CWindowCameraLeft(mwindow, this, x1, y));
856 x1 += button->get_w();
857 add_subwindow(button = new CWindowCameraCenter(mwindow, this, x1, y));
858 x1 += button->get_w();
859 add_subwindow(button = new CWindowCameraRight(mwindow, this, x1, y));
861 y += button->get_h();
863 add_subwindow(button = new CWindowCameraTop(mwindow, this, x1, y));
864 x1 += button->get_w();
865 add_subwindow(button = new CWindowCameraMiddle(mwindow, this, x1, y));
866 x1 += button->get_w();
867 add_subwindow(button = new CWindowCameraBottom(mwindow, this, x1, y));
868 // additional Buttons to control the curve mode of the "current" keyframe
869 x1 += button->get_w() + 15;
870 add_subwindow(this->t_smooth = new CWindowCurveToggle(Camera_Crv_Smooth, mwindow, this, x1, y));
871 x1 += button->get_w();
872 add_subwindow(this->t_linear = new CWindowCurveToggle(Camera_Crv_Linear, mwindow, this, x1, y));
874 // fill in current auto keyframe values, set toggle states.
879 void CWindowCameraGUI::handle_event()
881 FloatAuto *x_auto = 0;
882 FloatAuto *y_auto = 0;
883 FloatAuto *z_auto = 0;
884 Track *track = mwindow->cwindow->calculate_affected_track();
887 mwindow->undo->update_undo_before(_("camera"), this);
888 if(event_caller == x)
890 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
891 track->automation->autos[AUTOMATION_CAMERA_X],
895 x_auto->set_value(atof(x->get_text()));
901 if(event_caller == y)
903 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
904 track->automation->autos[AUTOMATION_CAMERA_Y],
908 y_auto->set_value(atof(y->get_text()));
914 if(event_caller == z)
916 z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
917 track->automation->autos[AUTOMATION_CAMERA_Z],
921 float zoom = atof(z->get_text());
922 if(zoom > 100.) zoom = 100.;
924 if(zoom < 0.01) zoom = 0.01;
925 // Doesn't allow user to enter from scratch
926 // if(zoom != atof(z->get_text()))
929 z_auto->set_value(zoom);
930 mwindow->gui->lock_window("CWindowCameraGUI::handle_event");
931 mwindow->gui->draw_overlays(1);
932 mwindow->gui->unlock_window();
938 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
942 void CWindowCameraGUI::update()
944 FloatAuto *x_auto = 0;
945 FloatAuto *y_auto = 0;
946 FloatAuto *z_auto = 0;
947 Track *track = mwindow->cwindow->calculate_affected_track();
949 mwindow->cwindow->calculate_affected_autos(track,
950 &x_auto, &y_auto, &z_auto, 1, 0, 0, 0);
954 x->update(x_auto->get_value());
956 y->update(y_auto->get_value());
958 float value = z_auto->get_value();
960 thread->gui->lock_window("CWindowCameraGUI::update");
961 thread->gui->composite_panel->cpanel_zoom->update(value);
962 thread->gui->unlock_window();
965 if( x_auto && y_auto && z_auto )
967 t_smooth->check_toggle_state(x_auto, y_auto, z_auto);
968 t_linear->check_toggle_state(x_auto, y_auto, z_auto);
975 CWindowCameraLeft::CWindowCameraLeft(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
976 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
979 this->mwindow = mwindow;
980 set_tooltip(_("Left justify"));
982 int CWindowCameraLeft::handle_event()
984 FloatAuto *x_auto = 0;
985 FloatAuto *z_auto = 0;
986 Track *track = mwindow->cwindow->calculate_affected_track();
988 mwindow->cwindow->calculate_affected_autos(track,
989 &x_auto, 0, &z_auto, 1, 1, 0, 0);
995 track->get_source_dimensions(
996 mwindow->edl->local_session->get_selectionstart(1),
1002 mwindow->undo->update_undo_before(_("camera"), 0);
1004 (double)track->track_w / z_auto->get_value() / 2 -
1006 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1008 gui->update_preview();
1016 CWindowCameraCenter::CWindowCameraCenter(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1017 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
1020 this->mwindow = mwindow;
1021 set_tooltip(_("Center horizontal"));
1023 int CWindowCameraCenter::handle_event()
1025 FloatAuto *x_auto = 0;
1026 Track *track = mwindow->cwindow->calculate_affected_track();
1028 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1029 track->automation->autos[AUTOMATION_CAMERA_X],
1034 mwindow->undo->update_undo_before(_("camera"), 0);
1035 x_auto->set_value(0);
1037 gui->update_preview();
1038 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1045 CWindowCameraRight::CWindowCameraRight(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1046 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
1049 this->mwindow = mwindow;
1050 set_tooltip(_("Right justify"));
1052 int CWindowCameraRight::handle_event()
1054 FloatAuto *x_auto = 0;
1055 FloatAuto *z_auto = 0;
1056 Track *track = mwindow->cwindow->calculate_affected_track();
1058 mwindow->cwindow->calculate_affected_autos(track,
1059 &x_auto, 0, &z_auto, 1, 1, 0, 0);
1062 if(x_auto && z_auto)
1065 track->get_source_dimensions(
1066 mwindow->edl->local_session->get_selectionstart(1),
1072 mwindow->undo->update_undo_before(_("camera"), 0);
1073 x_auto->set_value( -((double)track->track_w / z_auto->get_value() / 2 -
1076 gui->update_preview();
1077 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1085 CWindowCameraTop::CWindowCameraTop(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1086 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1089 this->mwindow = mwindow;
1090 set_tooltip(_("Top justify"));
1092 int CWindowCameraTop::handle_event()
1094 FloatAuto *y_auto = 0;
1095 FloatAuto *z_auto = 0;
1096 Track *track = mwindow->cwindow->calculate_affected_track();
1098 mwindow->cwindow->calculate_affected_autos(track,
1099 0, &y_auto, &z_auto, 1, 0, 1, 0);
1102 if(y_auto && z_auto)
1105 track->get_source_dimensions(
1106 mwindow->edl->local_session->get_selectionstart(1),
1112 mwindow->undo->update_undo_before(_("camera"), 0);
1113 y_auto->set_value((double)track->track_h / z_auto->get_value() / 2 -
1116 gui->update_preview();
1117 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1125 CWindowCameraMiddle::CWindowCameraMiddle(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1126 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1129 this->mwindow = mwindow;
1130 set_tooltip(_("Center vertical"));
1132 int CWindowCameraMiddle::handle_event()
1134 FloatAuto *y_auto = 0;
1135 Track *track = mwindow->cwindow->calculate_affected_track();
1137 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1138 track->automation->autos[AUTOMATION_CAMERA_Y], 1);
1142 mwindow->undo->update_undo_before(_("camera"), 0);
1143 y_auto->set_value(0);
1145 gui->update_preview();
1146 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1153 CWindowCameraBottom::CWindowCameraBottom(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1154 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1157 this->mwindow = mwindow;
1158 set_tooltip(_("Bottom justify"));
1160 int CWindowCameraBottom::handle_event()
1162 FloatAuto *y_auto = 0;
1163 FloatAuto *z_auto = 0;
1164 Track *track = mwindow->cwindow->calculate_affected_track();
1166 mwindow->cwindow->calculate_affected_autos(track,
1167 0, &y_auto, &z_auto, 1, 0, 1, 0);
1170 if(y_auto && z_auto)
1173 track->get_source_dimensions(
1174 mwindow->edl->local_session->get_selectionstart(1),
1180 mwindow->undo->update_undo_before(_("camera"), 0);
1181 y_auto->set_value(-((double)track->track_h / z_auto->get_value() / 2 -
1184 gui->update_preview();
1185 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1193 CWindowProjectorGUI::CWindowProjectorGUI(MWindow *mwindow, CWindowTool *thread)
1194 : CWindowToolGUI(mwindow,
1196 _(PROGRAM_NAME ": Projector"),
1201 CWindowProjectorGUI::~CWindowProjectorGUI()
1204 void CWindowProjectorGUI::create_objects()
1206 int x = 10, y = 10, x1;
1207 Track *track = mwindow->cwindow->calculate_affected_track();
1208 FloatAuto *x_auto = 0;
1209 FloatAuto *y_auto = 0;
1210 FloatAuto *z_auto = 0;
1214 lock_window("CWindowProjectorGUI::create_objects");
1216 mwindow->cwindow->calculate_affected_autos(track,
1217 &x_auto, &y_auto, &z_auto, 0, 0, 0, 0);
1220 add_subwindow(title = new BC_Title(x, y, "X:"));
1221 x += title->get_w();
1222 this->x = new CWindowCoord(this, x, y,
1223 x_auto ? x_auto->get_value() : (float)0);
1224 this->x->create_objects();
1227 add_subwindow(title = new BC_Title(x, y, "Y:"));
1228 x += title->get_w();
1229 this->y = new CWindowCoord(this, x, y,
1230 y_auto ? y_auto->get_value() : (float)0);
1231 this->y->create_objects();
1234 add_subwindow(title = new BC_Title(x, y, "Z:"));
1235 x += title->get_w();
1236 this->z = new CWindowCoord(this, x, y,
1237 z_auto ? z_auto->get_value() : (float)1);
1238 this->z->create_objects();
1239 this->z->set_increment(0.01);
1243 add_subwindow(button = new CWindowProjectorLeft(mwindow, this, x1, y));
1244 x1 += button->get_w();
1245 add_subwindow(button = new CWindowProjectorCenter(mwindow, this, x1, y));
1246 x1 += button->get_w();
1247 add_subwindow(button = new CWindowProjectorRight(mwindow, this, x1, y));
1249 y += button->get_h();
1251 add_subwindow(button = new CWindowProjectorTop(mwindow, this, x1, y));
1252 x1 += button->get_w();
1253 add_subwindow(button = new CWindowProjectorMiddle(mwindow, this, x1, y));
1254 x1 += button->get_w();
1255 add_subwindow(button = new CWindowProjectorBottom(mwindow, this, x1, y));
1257 // additional Buttons to control the curve mode of the "current" keyframe
1258 x1 += button->get_w() + 15;
1259 add_subwindow(this->t_smooth = new CWindowCurveToggle(Projector_Crv_Smooth, mwindow, this, x1, y));
1260 x1 += button->get_w();
1261 add_subwindow(this->t_linear = new CWindowCurveToggle(Projector_Crv_Linear, mwindow, this, x1, y));
1263 // fill in current auto keyframe values, set toggle states.
1268 void CWindowProjectorGUI::handle_event()
1270 FloatAuto *x_auto = 0;
1271 FloatAuto *y_auto = 0;
1272 FloatAuto *z_auto = 0;
1273 Track *track = mwindow->cwindow->calculate_affected_track();
1277 mwindow->undo->update_undo_before(_("projector"), this);
1278 if(event_caller == x)
1280 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1281 track->automation->autos[AUTOMATION_PROJECTOR_X],
1285 x_auto->set_value(atof(x->get_text()));
1291 if(event_caller == y)
1293 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1294 track->automation->autos[AUTOMATION_PROJECTOR_Y],
1298 y_auto->set_value(atof(y->get_text()));
1304 if(event_caller == z)
1306 z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1307 track->automation->autos[AUTOMATION_PROJECTOR_Z],
1311 float zoom = atof(z->get_text());
1312 if(zoom > 100.) zoom = 100.;
1313 else if(zoom < 0.01) zoom = 0.01;
1314 // if (zoom != atof(z->get_text()))
1316 z_auto->set_value(zoom);
1318 mwindow->gui->lock_window("CWindowProjectorGUI::handle_event");
1319 mwindow->gui->draw_overlays(1);
1320 mwindow->gui->unlock_window();
1326 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1330 void CWindowProjectorGUI::update()
1332 FloatAuto *x_auto = 0;
1333 FloatAuto *y_auto = 0;
1334 FloatAuto *z_auto = 0;
1335 Track *track = mwindow->cwindow->calculate_affected_track();
1337 mwindow->cwindow->calculate_affected_autos(track,
1338 &x_auto, &y_auto, &z_auto, 0, 0, 0, 0);
1342 x->update(x_auto->get_value());
1344 y->update(y_auto->get_value());
1346 float value = z_auto->get_value();
1348 thread->gui->lock_window("CWindowProjectorGUI::update");
1349 thread->gui->composite_panel->cpanel_zoom->update(value);
1350 thread->gui->unlock_window();
1353 if( x_auto && y_auto && z_auto )
1355 t_smooth->check_toggle_state(x_auto, y_auto, z_auto);
1356 t_linear->check_toggle_state(x_auto, y_auto, z_auto);
1360 CWindowProjectorLeft::CWindowProjectorLeft(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1361 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
1364 this->mwindow = mwindow;
1365 set_tooltip(_("Left justify"));
1367 int CWindowProjectorLeft::handle_event()
1369 FloatAuto *x_auto = 0;
1370 FloatAuto *z_auto = 0;
1371 Track *track = mwindow->cwindow->calculate_affected_track();
1373 mwindow->cwindow->calculate_affected_autos(track,
1374 &x_auto, 0, &z_auto, 0, 1, 0, 0);
1376 if(x_auto && z_auto)
1378 mwindow->undo->update_undo_before(_("projector"), 0);
1379 x_auto->set_value( (double)track->track_w * z_auto->get_value() / 2 -
1380 (double)mwindow->edl->session->output_w / 2 );
1382 gui->update_preview();
1383 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1390 CWindowProjectorCenter::CWindowProjectorCenter(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1391 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
1394 this->mwindow = mwindow;
1395 set_tooltip(_("Center horizontal"));
1397 int CWindowProjectorCenter::handle_event()
1399 FloatAuto *x_auto = 0;
1400 Track *track = mwindow->cwindow->calculate_affected_track();
1402 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1403 track->automation->autos[AUTOMATION_PROJECTOR_X],
1408 mwindow->undo->update_undo_before(_("projector"), 0);
1409 x_auto->set_value(0);
1411 gui->update_preview();
1412 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1419 CWindowProjectorRight::CWindowProjectorRight(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1420 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
1423 this->mwindow = mwindow;
1424 set_tooltip(_("Right justify"));
1426 int CWindowProjectorRight::handle_event()
1428 FloatAuto *x_auto = 0;
1429 FloatAuto *z_auto = 0;
1430 Track *track = mwindow->cwindow->calculate_affected_track();
1432 mwindow->cwindow->calculate_affected_autos(track,
1433 &x_auto, 0, &z_auto, 0, 1, 0, 0);
1436 if(x_auto && z_auto)
1438 mwindow->undo->update_undo_before(_("projector"), 0);
1439 x_auto->set_value( -((double)track->track_w * z_auto->get_value() / 2 -
1440 (double)mwindow->edl->session->output_w / 2));
1442 gui->update_preview();
1443 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1450 CWindowProjectorTop::CWindowProjectorTop(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1451 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1454 this->mwindow = mwindow;
1455 set_tooltip(_("Top justify"));
1457 int CWindowProjectorTop::handle_event()
1459 FloatAuto *y_auto = 0;
1460 FloatAuto *z_auto = 0;
1461 Track *track = mwindow->cwindow->calculate_affected_track();
1463 mwindow->cwindow->calculate_affected_autos(track,
1464 0, &y_auto, &z_auto, 0, 0, 1, 0);
1467 if(y_auto && z_auto)
1469 mwindow->undo->update_undo_before(_("projector"), 0);
1470 y_auto->set_value( (double)track->track_h * z_auto->get_value() / 2 -
1471 (double)mwindow->edl->session->output_h / 2 );
1473 gui->update_preview();
1474 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1481 CWindowProjectorMiddle::CWindowProjectorMiddle(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1482 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1485 this->mwindow = mwindow;
1486 set_tooltip(_("Center vertical"));
1488 int CWindowProjectorMiddle::handle_event()
1490 FloatAuto *y_auto = 0;
1491 Track *track = mwindow->cwindow->calculate_affected_track();
1493 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1494 track->automation->autos[AUTOMATION_PROJECTOR_Y], 1);
1498 mwindow->undo->update_undo_before(_("projector"), 0);
1499 y_auto->set_value(0);
1501 gui->update_preview();
1502 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1509 CWindowProjectorBottom::CWindowProjectorBottom(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1510 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1513 this->mwindow = mwindow;
1514 set_tooltip(_("Bottom justify"));
1516 int CWindowProjectorBottom::handle_event()
1518 FloatAuto *y_auto = 0;
1519 FloatAuto *z_auto = 0;
1520 Track *track = mwindow->cwindow->calculate_affected_track();
1522 mwindow->cwindow->calculate_affected_autos(track,
1523 0, &y_auto, &z_auto, 0, 0, 1, 0);
1526 if(y_auto && z_auto)
1528 mwindow->undo->update_undo_before(_("projector"), 0);
1529 y_auto->set_value( -((double)track->track_h * z_auto->get_value() / 2 -
1530 (double)mwindow->edl->session->output_h / 2));
1532 gui->update_preview();
1533 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1540 CWindowMaskOnTrack::CWindowMaskOnTrack(MWindow *mwindow, CWindowMaskGUI *gui,
1541 int x, int y, int w, const char *text)
1542 : BC_PopupTextBox(gui, 0, text, x, y, w, 120)
1544 this->mwindow = mwindow;
1548 CWindowMaskOnTrack::~CWindowMaskOnTrack()
1552 int CWindowMaskOnTrack::handle_event()
1554 CWindowMaskItem *track_item = 0;
1555 int k = get_number(), track_id = -1;
1556 //printf("selected %d = %s\n", k, k<0 ? "()" : track_items[k]->get_text());
1558 track_item = (CWindowMaskItem *)track_items[k];
1559 Track *track = track_item ? mwindow->edl->tracks->get_track_by_id(track_item->id) : 0;
1560 if( track && track->record ) track_id = track->get_id();
1563 track_id = mwindow->cwindow->mask_track_id;
1564 set_back_color(track_id >= 0 ?
1565 gui->get_resources()->text_background :
1566 gui->get_resources()->text_background_disarmed);
1567 if( mwindow->cwindow->mask_track_id != track_id )
1568 gui->mask_on_track->update(track_item ? track_item->get_text() : "");
1569 mwindow->cwindow->mask_track_id = track_id;
1570 mwindow->edl->local_session->solo_track_id = -1;
1571 gui->mask_solo_track->update(0);
1573 gui->update_preview(1);
1577 void CWindowMaskOnTrack::update_items()
1579 track_items.remove_all_objects();
1580 int high_color = gui->get_resources()->button_highlighted;
1581 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
1582 if( track->data_type != TRACK_VIDEO ) continue;
1583 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1584 int color = !track->record ? RED : mask_autos->first ? high_color : -1;
1585 MaskAuto *mask_auto = (MaskAuto*)mask_autos->default_auto;
1586 for( int i=0; color<0 && i<mask_auto->masks.size(); ++i )
1587 if( mask_auto->masks[i]->points.size() > 0 ) color = high_color;
1588 track_items.append(new CWindowMaskItem(track->title, track->get_id(), color));
1590 update_list(&track_items);
1593 CWindowMaskTrackTumbler::CWindowMaskTrackTumbler(MWindow *mwindow, CWindowMaskGUI *gui,
1597 this->mwindow = mwindow;
1600 CWindowMaskTrackTumbler::~CWindowMaskTrackTumbler()
1604 int CWindowMaskTrackTumbler::handle_up_event()
1609 int CWindowMaskTrackTumbler::handle_down_event()
1611 return do_event(-1);
1614 int CWindowMaskTrackTumbler::do_event(int dir)
1616 CWindowMaskItem *track_item = 0;
1617 CWindowMaskItem **items = (CWindowMaskItem**)&gui->mask_on_track->track_items[0];
1618 int n = gui->mask_on_track->track_items.size();
1619 int id = mwindow->cwindow->mask_track_id;
1622 while( --k >= 0 && items[k]->id != id );
1626 track_item = items[k];
1629 track_item = items[0];
1631 Track *track = track_item ? mwindow->edl->tracks->get_track_by_id(track_item->id) : 0;
1632 int track_id = track_item && track && track->record ? track_item->id : -1;
1633 gui->mask_on_track->set_back_color(track_id >= 0 ?
1634 gui->get_resources()->text_background :
1635 gui->get_resources()->text_background_disarmed);
1636 gui->mask_on_track->update(track_item ? track_item->get_text() : "");
1637 mwindow->cwindow->mask_track_id = track_item ? track_item->id : -1;
1638 mwindow->edl->local_session->solo_track_id = -1;
1639 gui->mask_solo_track->update(0);
1641 gui->update_preview(1);
1646 CWindowMaskName::CWindowMaskName(MWindow *mwindow, CWindowMaskGUI *gui,
1647 int x, int y, const char *text)
1648 : BC_PopupTextBox(gui, 0, text, x, y, 100, 160)
1650 this->mwindow = mwindow;
1654 CWindowMaskName::~CWindowMaskName()
1658 int CWindowMaskName::handle_event()
1665 //printf("CWindowMaskGUI::update 1\n");
1666 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
1668 int k = get_number();
1669 if( k < 0 ) k = mwindow->edl->session->cwindow_mask;
1670 else mwindow->edl->session->cwindow_mask = k;
1671 if( k >= 0 && k < mask_items.size() ) {
1672 mask_items[k]->set_text(get_text());
1673 update_list(&mask_items);
1675 #ifdef USE_KEYFRAME_SPANNING
1676 MaskAuto temp_keyframe(mwindow->edl, autos);
1677 temp_keyframe.copy_data(keyframe);
1678 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
1679 memset(submask->name, 0, sizeof(submask->name));
1680 strncpy(submask->name, get_text(), sizeof(submask->name)-1);
1681 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
1683 for(MaskAuto *current = (MaskAuto*)autos->default_auto; current; ) {
1684 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1685 memset(submask->name, 0, sizeof(submask->name));
1686 strncpy(submask->name, get_text(), sizeof(submask->name)-1);
1687 current = current == (MaskAuto*)autos->default_auto ?
1688 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
1692 gui->update_preview();
1697 void CWindowMaskName::update_items(MaskAuto *keyframe)
1699 mask_items.remove_all_objects();
1700 int sz = !keyframe ? 0 : keyframe->masks.size();
1701 for( int i=0; i<SUBMASKS; ++i ) {
1702 char text[BCSTRLEN]; memset(text, 0, sizeof(text));
1704 SubMask *sub_mask = keyframe->masks.get(i);
1705 strncpy(text, sub_mask->name, sizeof(text)-1);
1708 sprintf(text, "%d", i);
1709 mask_items.append(new CWindowMaskItem(text));
1711 update_list(&mask_items);
1715 CWindowMaskButton::CWindowMaskButton(MWindow *mwindow, CWindowMaskGUI *gui,
1716 int x, int y, int no, int v)
1717 : BC_CheckBox(x, y, v)
1719 this->mwindow = mwindow;
1724 CWindowMaskButton::~CWindowMaskButton()
1728 int CWindowMaskButton::handle_event()
1730 mwindow->edl->session->cwindow_mask = no;
1731 gui->mask_name->update(gui->mask_name->mask_items[no]->get_text());
1733 gui->update_preview();
1737 CWindowMaskThumbler::CWindowMaskThumbler(MWindow *mwindow, CWindowMaskGUI *gui,
1741 this->mwindow = mwindow;
1745 CWindowMaskThumbler::~CWindowMaskThumbler()
1749 int CWindowMaskThumbler::handle_up_event()
1754 int CWindowMaskThumbler::handle_down_event()
1756 return do_event(-1);
1759 int CWindowMaskThumbler::do_event(int dir)
1761 int k = mwindow->edl->session->cwindow_mask;
1762 if( (k+=dir) >= SUBMASKS ) k = 0;
1763 else if( k < 0 ) k = SUBMASKS-1;
1764 mwindow->edl->session->cwindow_mask = k;
1765 gui->mask_name->update(gui->mask_name->mask_items[k]->get_text());
1767 gui->update_preview();
1771 CWindowMaskEnable::CWindowMaskEnable(MWindow *mwindow, CWindowMaskGUI *gui,
1772 int x, int y, int no, int v)
1773 : BC_CheckBox(x, y, v)
1775 this->mwindow = mwindow;
1780 CWindowMaskEnable::~CWindowMaskEnable()
1784 int CWindowMaskEnable::handle_event()
1786 Track *track = mwindow->cwindow->calculate_mask_track();
1788 mwindow->undo->update_undo_before(_("mask enable"), this);
1791 track->masks |= bit;
1793 track->masks &= ~bit;
1795 gui->update_preview(1);
1796 mwindow->undo->update_undo_after(_("mask enable"), LOAD_PATCHES);
1801 CWindowMaskUnclear::CWindowMaskUnclear(MWindow *mwindow,
1802 CWindowMaskGUI *gui, int x, int y)
1803 : BC_Button(x, y, mwindow->theme->get_image_set("unclear_button"))
1805 this->mwindow = mwindow;
1807 set_tooltip(_("Show/Hide mask"));
1810 int CWindowMaskUnclear::handle_event()
1812 Track *track = mwindow->cwindow->calculate_mask_track();
1814 mwindow->undo->update_undo_before(_("mask enables"), this);
1815 int m = (1<<SUBMASKS)-1;
1816 if( track->masks == m )
1820 for( int i=0; i<SUBMASKS; ++i )
1821 gui->mask_enables[i]->update((track->masks>>i) & 1);
1822 gui->update_preview(1);
1823 mwindow->undo->update_undo_after(_("mask enables"), LOAD_PATCHES);
1828 CWindowMaskSoloTrack::CWindowMaskSoloTrack(MWindow *mwindow,
1829 CWindowMaskGUI *gui, int x, int y, int v)
1830 : BC_CheckBox(x, y, v, _("Solo"))
1832 this->mwindow = mwindow;
1834 set_tooltip(_("Solo video track"));
1837 int CWindowMaskSoloTrack::handle_event()
1839 mwindow->edl->local_session->solo_track_id =
1840 get_value() ? mwindow->cwindow->mask_track_id : -1;
1841 gui->update_preview(1);
1845 int CWindowMaskSoloTrack::calculate_w(BC_WindowBase *gui)
1848 calculate_extents(gui, &w, &h, _("Solo"));
1852 CWindowMaskDelMask::CWindowMaskDelMask(MWindow *mwindow,
1853 CWindowMaskGUI *gui, int x, int y)
1854 : BC_GenericButton(x, y, _("Delete"))
1856 this->mwindow = mwindow;
1858 set_tooltip(_("Delete mask"));
1861 int CWindowMaskDelMask::handle_event()
1870 // Get existing keyframe
1871 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
1874 mwindow->undo->update_undo_before(_("mask delete"), 0);
1876 #ifdef USE_KEYFRAME_SPANNING
1877 // Create temp keyframe
1878 MaskAuto temp_keyframe(mwindow->edl, autos);
1879 temp_keyframe.copy_data(keyframe);
1880 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
1881 submask->points.remove_all_objects();
1883 // Commit change to span of keyframes
1884 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
1886 for(MaskAuto *current = (MaskAuto*)autos->default_auto; current; ) {
1887 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1888 submask->points.remove_all_objects();
1889 current = current == (MaskAuto*)autos->default_auto ?
1890 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
1894 if( mwindow->cwindow->gui->affected_point >= total_points )
1895 mwindow->cwindow->gui->affected_point =
1896 total_points > 0 ? total_points-1 : 0;
1899 gui->update_preview();
1900 mwindow->undo->update_undo_after(_("mask delete"), LOAD_AUTOMATION);
1906 CWindowMaskDelPoint::CWindowMaskDelPoint(MWindow *mwindow,
1907 CWindowMaskGUI *gui, int x, int y)
1908 : BC_GenericButton(x, y, _("Delete"))
1910 this->mwindow = mwindow;
1912 set_tooltip(_("Delete point"));
1915 int CWindowMaskDelPoint::handle_event()
1924 // Get existing keyframe
1925 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
1927 mwindow->undo->update_undo_before(_("point delete"), 0);
1929 #ifdef USE_KEYFRAME_SPANNING
1930 // Create temp keyframe
1931 MaskAuto temp_keyframe(mwindow->edl, autos);
1932 temp_keyframe.copy_data(keyframe);
1934 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
1935 int i = mwindow->cwindow->gui->affected_point;
1936 for( ; i<submask->points.total-1; ++i )
1937 *submask->points.values[i] = *submask->points.values[i+1];
1938 if( submask->points.total > 0 ) {
1939 point = submask->points.values[submask->points.total-1];
1940 submask->points.remove_object(point);
1942 total_points = submask->points.total;
1944 // Commit change to span of keyframes
1945 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
1948 MaskAuto *current = (MaskAuto*)autos->default_auto;
1950 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1951 int i = mwindow->cwindow->gui->affected_point;
1952 for( ; i<submask->points.total-1; ++i )
1953 *submask->points.values[i] = *submask->points.values[i+1];
1954 if( submask->points.total > 0 ) {
1955 point = submask->points.values[submask->points.total-1];
1956 submask->points.remove_object(point);
1958 total_points = submask->points.total;
1959 current = current == (MaskAuto*)autos->default_auto ?
1960 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
1963 if( mwindow->cwindow->gui->affected_point >= total_points )
1964 mwindow->cwindow->gui->affected_point =
1965 total_points > 0 ? total_points-1 : 0;
1968 gui->update_preview();
1969 mwindow->undo->update_undo_after(_("point delete"), LOAD_AUTOMATION);
1976 CWindowMaskAffectedPoint::CWindowMaskAffectedPoint(MWindow *mwindow,
1977 CWindowMaskGUI *gui, int x, int y)
1978 : BC_TumbleTextBox(gui,
1979 (int64_t)mwindow->cwindow->gui->affected_point,
1980 (int64_t)0, INT64_MAX, x, y, 70)
1982 this->mwindow = mwindow;
1986 CWindowMaskAffectedPoint::~CWindowMaskAffectedPoint()
1990 int CWindowMaskAffectedPoint::handle_event()
1992 int total_points = 0;
1993 int affected_point = atol(get_text());
1994 Track *track = mwindow->cwindow->calculate_mask_track();
1996 MaskAutos *autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1997 MaskAuto *keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(autos, 0);
1999 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2000 total_points = mask->points.size();
2003 int active_point = affected_point;
2004 if( affected_point >= total_points )
2005 affected_point = total_points - 1;
2006 if( affected_point < 0 )
2008 if( active_point != affected_point )
2009 update((int64_t)affected_point);
2010 mwindow->cwindow->gui->affected_point = affected_point;
2012 gui->update_preview();
2017 CWindowMaskFocus::CWindowMaskFocus(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2018 : BC_CheckBox(x, y, gui->focused, _("Focus"))
2020 this->mwindow = mwindow;
2022 set_tooltip(_("Center for rotate/scale"));
2025 CWindowMaskFocus::~CWindowMaskFocus()
2029 int CWindowMaskFocus::handle_event()
2031 gui->focused = get_value();
2033 gui->update_preview();
2037 int CWindowMaskFocus::calculate_w(CWindowMaskGUI *gui)
2040 calculate_extents(gui, &w, &h, _("Focus"));
2044 CWindowMaskScaleXY::CWindowMaskScaleXY(MWindow *mwindow, CWindowMaskGUI *gui,
2045 int x, int y, VFrame **data, int v, int id, const char *tip)
2046 : BC_Toggle(x, y, data, v)
2049 this->mwindow = mwindow;
2054 CWindowMaskScaleXY::~CWindowMaskScaleXY()
2058 int CWindowMaskScaleXY::handle_event()
2060 gui->scale_mode = id;
2061 gui->mask_scale_x->update(id == MASK_SCALE_X);
2062 gui->mask_scale_y->update(id == MASK_SCALE_Y);
2063 gui->mask_scale_xy->update(id == MASK_SCALE_XY);
2067 CWindowMaskHelp::CWindowMaskHelp(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2068 : BC_CheckBox(x, y, 0, _("Help"))
2070 this->mwindow = mwindow;
2072 set_tooltip(_("Show help text"));
2075 CWindowMaskHelp::~CWindowMaskHelp()
2079 int CWindowMaskHelp::handle_event()
2081 gui->helped = get_value();
2082 gui->resize_window(gui->get_w(),
2083 gui->helped ? gui->help_h : gui->help_y);
2088 CWindowMaskDrawMarkers::CWindowMaskDrawMarkers(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2089 : BC_CheckBox(x, y, gui->markers, _("Markers"))
2091 this->mwindow = mwindow;
2093 set_tooltip("Display points");
2096 CWindowMaskDrawMarkers::~CWindowMaskDrawMarkers()
2100 int CWindowMaskDrawMarkers::handle_event()
2102 gui->markers = get_value();
2104 gui->update_preview();
2108 CWindowMaskDrawBoundary::CWindowMaskDrawBoundary(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2109 : BC_CheckBox(x, y, gui->boundary, _("Boundary"))
2111 this->mwindow = mwindow;
2113 set_tooltip("Display mask outline");
2116 CWindowMaskDrawBoundary::~CWindowMaskDrawBoundary()
2120 int CWindowMaskDrawBoundary::handle_event()
2122 gui->boundary = get_value();
2124 gui->update_preview();
2129 CWindowMaskFeather::CWindowMaskFeather(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2130 : BC_TumbleTextBox(gui, 0, INT_MIN, INT_MAX, x, y, 64, 2)
2132 this->mwindow = mwindow;
2135 CWindowMaskFeather::~CWindowMaskFeather()
2139 int CWindowMaskFeather::update(float v)
2141 gui->feather_slider->update(v);
2142 return BC_TumbleTextBox::update(v);
2145 int CWindowMaskFeather::update_value(float v)
2152 #ifdef USE_KEYFRAME_SPANNING
2158 mwindow->undo->update_undo_before(_("mask feather"), this);
2160 // Get existing keyframe
2161 gui->get_keyframe(track, autos, keyframe,
2162 mask, point, create_it);
2164 int gang = gui->gang_feather->get_value();
2165 #ifdef USE_KEYFRAME_SPANNING
2166 MaskAuto temp_keyframe(mwindow->edl, autos);
2167 temp_keyframe.copy_data(keyframe);
2168 keyframe = &temp_keyframe;
2170 float change = v - mask->feather;
2171 int k = mwindow->edl->session->cwindow_mask;
2172 int n = gang ? keyframe->masks.size() : k+1;
2173 for( int i=gang? 0 : k; i<n; ++i ) {
2174 if( !gui->mask_enables[i]->get_value() ) continue;
2175 SubMask *sub_mask = keyframe->get_submask(i);
2176 float feather = sub_mask->feather + change;
2177 sub_mask->feather = feather;
2179 #ifdef USE_KEYFRAME_SPANNING
2180 autos->update_parameter(keyframe);
2182 gui->update_preview();
2185 mwindow->undo->update_undo_after(_("mask feather"), LOAD_AUTOMATION);
2189 int CWindowMaskFeather::handle_event()
2191 float v = atof(get_text());
2192 if( fabsf(v) > MAX_FEATHER )
2193 BC_TumbleTextBox::update((float)(v>=0 ? MAX_FEATHER : -MAX_FEATHER));
2194 gui->feather_slider->update(v);
2195 return gui->feather->update_value(v);
2198 CWindowMaskFeatherSlider::CWindowMaskFeatherSlider(MWindow *mwindow,
2199 CWindowMaskGUI *gui, int x, int y, int w, float v)
2200 : BC_FSlider(x, y, 0, w, w, -FEATHER_MAX-5, FEATHER_MAX+5, v)
2202 this->mwindow = mwindow;
2204 set_precision(0.01);
2205 timer = new Timer();
2211 CWindowMaskFeatherSlider::~CWindowMaskFeatherSlider()
2216 int CWindowMaskFeatherSlider::handle_event()
2219 float v = get_value();
2220 if( fabsf(v) > MAX_FEATHER )
2221 v = v>=0 ? MAX_FEATHER : -MAX_FEATHER;
2222 if( stick && timer->get_difference() >= 250 )
2223 stick = 0; // no events for .25 sec
2224 if( stick && (last_v * (v-last_v)) < 0 )
2225 stick = 0; // dv changed direction
2234 if( max > MAX_FEATHER ) max = MAX_FEATHER;
2235 update(get_w(), v=last_v, -max-5, max+5);
2236 button_release_event();
2239 else if( v > max ) { v = max; sticky = 24; }
2240 else if( v < -max ) { v = -max; sticky = 24; }
2241 else if( v>=0 ? last_v<0 : last_v>=0 ) { v = 0; sticky = 16; }
2242 if( sticky ) { update(v); stick = sticky; timer->update(); }
2244 gui->feather->BC_TumbleTextBox::update(v);
2245 return gui->feather->update_value(v);
2248 int CWindowMaskFeatherSlider::update(float v)
2250 float vv = fabsf(v);
2251 if( vv > MAX_FEATHER ) vv = MAX_FEATHER;
2252 while( max < vv ) max *= 1.25;
2253 return update(get_w(), v, -max-5, max+5);
2255 int CWindowMaskFeatherSlider::update(int r, float v, float mn, float mx)
2257 return BC_FSlider::update(r, v, mn, mx);
2260 CWindowMaskFade::CWindowMaskFade(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2261 : BC_TumbleTextBox(gui, 0, -100.f, 100.f, x, y, 64, 2)
2263 this->mwindow = mwindow;
2266 CWindowMaskFade::~CWindowMaskFade()
2270 int CWindowMaskFade::update(float v)
2272 gui->fade_slider->update(v);
2273 return BC_TumbleTextBox::update(v);
2276 int CWindowMaskFade::update_value(float v)
2283 #ifdef USE_KEYFRAME_SPANNING
2289 mwindow->undo->update_undo_before(_("mask fade"), this);
2291 // Get existing keyframe
2292 gui->get_keyframe(track, autos, keyframe,
2293 mask, point, create_it);
2295 int gang = gui->gang_fader->get_value();
2296 #ifdef USE_KEYFRAME_SPANNING
2297 MaskAuto temp_keyframe(mwindow->edl, autos);
2298 temp_keyframe.copy_data(keyframe);
2299 keyframe = &temp_keyframe;
2301 float change = v - mask->fader;
2302 int k = mwindow->edl->session->cwindow_mask;
2303 int n = gang ? keyframe->masks.size() : k+1;
2304 for( int i=gang? 0 : k; i<n; ++i ) {
2305 if( !gui->mask_enables[i]->get_value() ) continue;
2306 SubMask *sub_mask = keyframe->get_submask(i);
2307 float fader = sub_mask->fader + change;
2308 bclamp(fader, -100.f, 100.f);
2309 sub_mask->fader = fader;
2311 #ifdef USE_KEYFRAME_SPANNING
2312 autos->update_parameter(keyframe);
2314 gui->update_preview();
2317 mwindow->undo->update_undo_after(_("mask fade"), LOAD_AUTOMATION);
2321 int CWindowMaskFade::handle_event()
2323 float v = atof(get_text());
2324 gui->fade_slider->update(v);
2325 return gui->fade->update_value(v);
2328 CWindowMaskFadeSlider::CWindowMaskFadeSlider(MWindow *mwindow, CWindowMaskGUI *gui,
2329 int x, int y, int w)
2330 : BC_ISlider(x, y, 0, w, w, -200, 200, 0)
2332 this->mwindow = mwindow;
2334 timer = new Timer();
2339 CWindowMaskFadeSlider::~CWindowMaskFadeSlider()
2344 int CWindowMaskFadeSlider::handle_event()
2346 float v = 100*get_value()/200;
2348 int64_t ms = timer->get_difference();
2349 if( ms < 250 && --stick > 0 ) {
2350 if( get_value() == 0 ) return 1;
2358 else if( (last_v>=0 && v<0) || (last_v<0 && v>=0) ) {
2365 gui->fade->BC_TumbleTextBox::update(v);
2366 return gui->fade->update_value(v);
2369 int CWindowMaskFadeSlider::update(int64_t v)
2371 return BC_ISlider::update(200*v/100);
2374 CWindowMaskGangFader::CWindowMaskGangFader(MWindow *mwindow,
2375 CWindowMaskGUI *gui, int x, int y)
2376 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2378 this->mwindow = mwindow;
2380 set_tooltip(_("Gang fader"));
2383 CWindowMaskGangFader::~CWindowMaskGangFader()
2387 int CWindowMaskGangFader::handle_event()
2392 CWindowMaskGangFocus::CWindowMaskGangFocus(MWindow *mwindow,
2393 CWindowMaskGUI *gui, int x, int y)
2394 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2396 this->mwindow = mwindow;
2398 set_tooltip(_("Gang rotate/scale/translate"));
2401 CWindowMaskGangFocus::~CWindowMaskGangFocus()
2405 int CWindowMaskGangFocus::handle_event()
2410 CWindowMaskGangPoint::CWindowMaskGangPoint(MWindow *mwindow,
2411 CWindowMaskGUI *gui, int x, int y)
2412 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2414 this->mwindow = mwindow;
2416 set_tooltip(_("Gang points"));
2419 CWindowMaskGangPoint::~CWindowMaskGangPoint()
2423 int CWindowMaskGangPoint::handle_event()
2429 CWindowMaskSmoothButton::CWindowMaskSmoothButton(MWindow *mwindow, CWindowMaskGUI *gui,
2430 const char *tip, int type, int on, int x, int y, const char *images)
2431 : BC_Button(x, y, mwindow->theme->get_image_set(images))
2433 this->mwindow = mwindow;
2440 int CWindowMaskSmoothButton::handle_event()
2442 return gui->smooth_mask(type, on);
2445 CWindowMaskBeforePlugins::CWindowMaskBeforePlugins(CWindowMaskGUI *gui, int x, int y)
2446 : BC_CheckBox(x, y, 1, _("Apply mask before plugins"))
2451 int CWindowMaskBeforePlugins::handle_event()
2458 gui->get_keyframe(track, autos, keyframe, mask, point, 1);
2461 int v = get_value();
2462 #ifdef USE_KEYFRAME_SPANNING
2463 MaskAuto temp_keyframe(gui->mwindow->edl, autos);
2464 temp_keyframe.copy_data(keyframe);
2465 temp_keyframe.apply_before_plugins = v;
2466 autos->update_parameter(&temp_keyframe);
2468 keyframe->apply_before_plugins = v;
2470 gui->update_preview();
2476 CWindowDisableOpenGLMasking::CWindowDisableOpenGLMasking(CWindowMaskGUI *gui, int x, int y)
2477 : BC_CheckBox(x, y, 1, _("Disable OpenGL masking"))
2482 int CWindowDisableOpenGLMasking::handle_event()
2489 gui->get_keyframe(track, autos, keyframe, mask, point, 1);
2492 int v = get_value();
2493 #ifdef USE_KEYFRAME_SPANNING
2494 MaskAuto temp_keyframe(gui->mwindow->edl, autos);
2495 temp_keyframe.copy_data(keyframe);
2496 temp_keyframe.disable_opengl_masking = v;
2497 autos->update_parameter(&temp_keyframe);
2499 keyframe->disable_opengl_masking = v;
2501 gui->update_preview();
2507 CWindowMaskClrMask::CWindowMaskClrMask(MWindow *mwindow,
2508 CWindowMaskGUI *gui, int x, int y)
2509 : BC_Button(x, y, mwindow->theme->get_image_set("reset_button"))
2511 this->mwindow = mwindow;
2513 set_tooltip(_("Delete all masks"));
2516 CWindowMaskClrMask::~CWindowMaskClrMask()
2520 int CWindowMaskClrMask::calculate_w(MWindow *mwindow)
2522 VFrame *vfrm = *mwindow->theme->get_image_set("reset_button");
2523 return vfrm->get_w();
2526 int CWindowMaskClrMask::handle_event()
2534 // Get existing keyframe
2535 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
2538 mwindow->undo->update_undo_before(_("del masks"), 0);
2539 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->clear_all();
2540 mwindow->undo->update_undo_after(_("del masks"), LOAD_AUTOMATION);
2544 gui->update_preview(1);
2548 CWindowMaskGangFeather::CWindowMaskGangFeather(MWindow *mwindow,
2549 CWindowMaskGUI *gui, int x, int y)
2550 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2552 this->mwindow = mwindow;
2554 set_tooltip(_("Gang feather"));
2557 CWindowMaskGangFeather::~CWindowMaskGangFeather()
2561 int CWindowMaskGangFeather::handle_event()
2566 CWindowMaskGUI::CWindowMaskGUI(MWindow *mwindow, CWindowTool *thread)
2567 : CWindowToolGUI(mwindow, thread,
2568 _(PROGRAM_NAME ": Mask"), 440, 700)
2570 this->mwindow = mwindow;
2571 this->thread = thread;
2581 CWindowMaskGUI::~CWindowMaskGUI()
2583 lock_window("CWindowMaskGUI::~CWindowMaskGUI");
2585 delete active_point;
2589 delete preset_dialog;
2592 void CWindowMaskGUI::create_objects()
2594 Theme *theme = mwindow->theme;
2595 int x = 10, y = 10, margin = theme->widget_border, t[SUBMASKS];
2596 int clr_w = CWindowMaskClrMask::calculate_w(mwindow);
2597 int clr_x = get_w()-x - clr_w;
2599 lock_window("CWindowMaskGUI::create_objects");
2600 BC_TitleBar *title_bar;
2601 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, 20, 10, _("Masks on Track")));
2602 y += title_bar->get_h() + margin;
2604 add_subwindow(title = new BC_Title(x,y, _("Track:")));
2605 int x1 = x + 90, ww = clr_x-2*margin - x1;
2606 for( int i=0,n=sizeof(t)/sizeof(t[0]); i<n; ++i ) t[i] = x1+(i*ww)/n;
2608 Track *track = mwindow->cwindow->calculate_affected_track();
2609 const char *text = track ? track->title : "";
2610 mwindow->cwindow->mask_track_id = track ? track->get_id() : -1;
2611 mask_on_track = new CWindowMaskOnTrack(mwindow, this, x1, y, 100, text);
2612 mask_on_track->create_objects();
2613 mask_on_track->set_tooltip(_("Video track"));
2614 int x2 = x1 + mask_on_track->get_w();
2615 add_subwindow(mask_track_tumbler = new CWindowMaskTrackTumbler(mwindow, this, x2, y));
2616 mwindow->edl->local_session->solo_track_id = -1;
2617 add_subwindow(mask_solo_track = new CWindowMaskSoloTrack(mwindow, this, del_x, y, 0));
2618 y += mask_on_track->get_h() + margin;
2619 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, 20, 10, _("Masks")));
2620 y += title_bar->get_h() + margin;
2621 add_subwindow(title = new BC_Title(x, y, _("Mask:")));
2622 mask_name = new CWindowMaskName(mwindow, this, x1, y, "");
2623 mask_name->create_objects();
2624 mask_name->set_tooltip(_("Mask name"));
2625 add_subwindow(mask_clr = new CWindowMaskClrMask(mwindow, this, clr_x, y));
2626 add_subwindow(mask_del = new CWindowMaskDelMask(mwindow, this, del_x, y));
2627 y += mask_name->get_h() + 2*margin;
2629 // add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
2630 // y += bar->get_h() + 2*margin;
2632 add_subwindow(title = new BC_Title(x, y, _("Select:")));
2634 BC_CheckBox::calculate_extents(this, &bw, &bh);
2635 for( int i=0; i<SUBMASKS; ++i ) {
2636 int v = i == mwindow->edl->session->cwindow_mask ? 1 : 0;
2637 mask_buttons[i] = new CWindowMaskButton(mwindow, this, t[i], y, i, v);
2638 add_subwindow(mask_buttons[i]);
2640 add_subwindow(mask_thumbler = new CWindowMaskThumbler(mwindow, this, clr_x, y));
2642 for( int i=0; i<SUBMASKS; ++i ) {
2643 char text[BCSTRLEN]; sprintf(text, "%d", i);
2644 int tx = (bw - get_text_width(MEDIUMFONT, text)) / 2;
2645 mask_blabels[i] = new BC_Title(t[i]+tx, y, text);
2646 add_subwindow(mask_blabels[i]);
2648 y += mask_blabels[0]->get_h() + margin;
2649 add_subwindow(title = new BC_Title(x, y, _("Enable:")));
2650 for( int i=0; i<SUBMASKS; ++i ) {
2651 mask_enables[i] = new CWindowMaskEnable(mwindow, this, t[i], y, i, 1);
2652 add_subwindow(mask_enables[i]);
2654 add_subwindow(mask_unclr = new CWindowMaskUnclear(mwindow, this, clr_x, y));
2655 y += mask_enables[0]->get_h() + 2*margin;
2656 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, 20, 10, _("Preset Shapes")));
2657 y += title_bar->get_h() + margin;
2658 add_subwindow(mask_shape_sqr = new CWindowMaskShape(mwindow, this,
2659 "mask_prst_sqr_images", MASK_SHAPE_SQUARE, t[0], y, _("Square")));
2660 add_subwindow(mask_shape_crc = new CWindowMaskShape(mwindow, this,
2661 "mask_prst_crc_images", MASK_SHAPE_CIRCLE, t[1], y, _("Circle")));
2662 add_subwindow(mask_shape_tri = new CWindowMaskShape(mwindow, this,
2663 "mask_prst_tri_images", MASK_SHAPE_TRIANGLE, t[2], y, _("Triangle")));
2664 add_subwindow(mask_shape_ovl = new CWindowMaskShape(mwindow, this,
2665 "mask_prst_ovl_images", MASK_SHAPE_OVAL, t[3], y, _("Oval")));
2666 add_subwindow(mask_load_list = new CWindowMaskLoadList(mwindow, this));
2667 add_subwindow(mask_load = new CWindowMaskLoad(mwindow, this, t[5], y, 80));
2668 add_subwindow(mask_save = new CWindowMaskSave(mwindow, this, t[6], y, 80));
2669 add_subwindow(mask_delete = new CWindowMaskDelete(mwindow, this, t[7], y, 80));
2670 y += mask_load->get_h() + 2*margin;
2671 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, 20, 10, _("Position & Scale")));
2672 y += title_bar->get_h() + 2*margin;
2673 add_subwindow(mask_center = new CWindowMaskCenter(mwindow, this, t[0], y, 80));
2674 add_subwindow(mask_normal = new CWindowMaskNormal(mwindow, this, t[1], y, 80));
2676 add_subwindow(mask_scale_x = new CWindowMaskScaleXY(mwindow, this,
2677 t[5], y, theme->get_image_set("mask_scale_x"), 0, MASK_SCALE_X, _("xlate/scale x")));
2678 add_subwindow(mask_scale_y = new CWindowMaskScaleXY(mwindow, this,
2679 t[6], y, theme->get_image_set("mask_scale_y"), 0, MASK_SCALE_Y, _("xlate/scale y")));
2680 add_subwindow(mask_scale_xy = new CWindowMaskScaleXY(mwindow, this,
2681 t[7], y, theme->get_image_set("mask_scale_xy"), 1, MASK_SCALE_XY, _("xlate/scale xy")));
2682 y += mask_center->get_h() + 2*margin;
2683 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, 20, 10, _("Fade & Feather")));
2684 y += title_bar->get_h() + 2*margin;
2686 add_subwindow(title = new BC_Title(x, y, _("Fade:")));
2687 fade = new CWindowMaskFade(mwindow, this, x1, y);
2688 fade->create_objects();
2689 x2 = x1 + fade->get_w() + 2*margin;
2690 int w2 = clr_x-2*margin - x2;
2691 add_subwindow(fade_slider = new CWindowMaskFadeSlider(mwindow, this, x2, y, w2));
2692 add_subwindow(gang_fader = new CWindowMaskGangFader(mwindow, this, clr_x, y));
2693 y += fade->get_h() + margin;
2694 add_subwindow(title = new BC_Title(x, y, _("Feather:")));
2695 feather = new CWindowMaskFeather(mwindow, this, x1, y);
2696 feather->create_objects();
2697 w2 = clr_x - 2*margin - x2;
2698 feather_slider = new CWindowMaskFeatherSlider(mwindow, this, x2, y, w2, 0);
2699 add_subwindow(feather_slider);
2700 add_subwindow(gang_feather = new CWindowMaskGangFeather(mwindow, this, clr_x, y));
2701 y += feather->get_h() + 2*margin;
2702 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, 20, 10, _("Mask Points")));
2703 y += title_bar->get_h() + margin;
2705 add_subwindow(title = new BC_Title(x, y, _("Point:")));
2706 active_point = new CWindowMaskAffectedPoint(mwindow, this, t[0], y);
2707 active_point->create_objects();
2708 // typ=0, this mask, this point
2709 add_subwindow(mask_pnt_linear = new CWindowMaskSmoothButton(mwindow, this,
2710 _("linear point"), 0, 0, t[3], y, "mask_pnt_linear_images"));
2711 add_subwindow(mask_pnt_smooth = new CWindowMaskSmoothButton(mwindow, this,
2712 _("smooth point"), 0, 1, t[4], y, "mask_pnt_smooth_images"));
2713 add_subwindow(del_point = new CWindowMaskDelPoint(mwindow, this, del_x, y));
2714 add_subwindow(gang_point = new CWindowMaskGangPoint(mwindow, this, clr_x, y));
2715 y += active_point->get_h() + margin;
2716 add_subwindow(title = new BC_Title(x, y, "X:"));
2717 this->x = new CWindowCoord(this, t[0], y, (float)0.0);
2718 this->x->create_objects();
2719 // typ>0, this mask, all points
2720 add_subwindow(mask_crv_linear = new CWindowMaskSmoothButton(mwindow, this,
2721 _("linear curve"), 1, 0, t[3], y, "mask_crv_linear_images"));
2722 add_subwindow(mask_crv_smooth = new CWindowMaskSmoothButton(mwindow, this,
2723 _("smooth curve"), 1, 1, t[4], y, "mask_crv_smooth_images"));
2724 add_subwindow(draw_markers = new CWindowMaskDrawMarkers(mwindow, this, del_x, y));
2725 y += this->x->get_h() + margin;
2726 add_subwindow(title = new BC_Title(x, y, "Y:"));
2727 this->y = new CWindowCoord(this, x1, y, (float)0.0);
2728 this->y->create_objects();
2729 // typ<0, all masks, all points
2730 add_subwindow(mask_all_linear = new CWindowMaskSmoothButton(mwindow, this,
2731 _("linear all"), -1, 0, t[3], y, "mask_all_linear_images"));
2732 add_subwindow(mask_all_smooth = new CWindowMaskSmoothButton(mwindow, this,
2733 _("smooth all"), -1, 1, t[4], y, "mask_all_smooth_images"));
2734 add_subwindow(draw_boundary = new CWindowMaskDrawBoundary(mwindow, this, del_x, y));
2735 y += this->y->get_h() + 2*margin;
2736 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, 20, 10, _("Pivot Point")));
2737 y += title_bar->get_h() + margin;
2739 add_subwindow(title = new BC_Title(x, y, "X:"));
2740 float cx = mwindow->edl->session->output_w / 2.f;
2741 focus_x = new CWindowCoord(this, x1, y, cx);
2742 focus_x->create_objects();
2743 add_subwindow(focus = new CWindowMaskFocus(mwindow, this, del_x, y));
2744 add_subwindow(gang_focus = new CWindowMaskGangFocus(mwindow, this, clr_x, y));
2745 y += focus_x->get_h() + margin;
2746 add_subwindow(title = new BC_Title(x, y, "Y:"));
2747 float cy = mwindow->edl->session->output_h / 2.f;
2748 focus_y = new CWindowCoord(this, x1, y, cy);
2749 focus_y->create_objects();
2750 y += focus_y->get_h() + 2*margin;
2751 add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
2752 y += bar->get_h() + margin;
2753 add_subwindow(this->apply_before_plugins = new CWindowMaskBeforePlugins(this, 10, y));
2754 y += this->apply_before_plugins->get_h();
2755 add_subwindow(this->disable_opengl_masking = new CWindowDisableOpenGLMasking(this, 10, y));
2756 add_subwindow(help = new CWindowMaskHelp(mwindow, this, del_x, y));
2757 y += this->disable_opengl_masking->get_h() + 2*margin;
2759 add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
2760 y += bar->get_h() + 2*margin;
2761 add_subwindow(title = new BC_Title(x, y, _(
2762 "Shift+LMB: move an end point\n"
2763 "Ctrl+LMB: move a control point\n"
2764 "Alt+LMB: to drag translate the mask\n"
2765 "Shift+MMB: Set Pivot Point at pointer\n"
2766 "Wheel: rotate around Pivot Point\n"
2767 "Shift+Wheel: scale around Pivot Point\n"
2768 "Ctrl+Wheel: rotate/scale around pointer")));
2769 help_h = y + title->get_h() + 2*margin;
2771 resize_window(get_w(), help_y);
2775 int CWindowMaskGUI::close_event()
2778 return CWindowToolGUI::close_event();
2781 void CWindowMaskGUI::done_event()
2783 if( mwindow->in_destructor ) return;
2784 int &solo_track_id = mwindow->edl->local_session->solo_track_id;
2785 if( solo_track_id >= 0 ) {
2791 void CWindowMaskGUI::get_keyframe(Track* &track,
2792 MaskAutos* &autos, MaskAuto* &keyframe,
2793 SubMask* &mask, MaskPoint* &point, int create_it)
2798 track = mwindow->cwindow->calculate_mask_track();
2800 track = mwindow->cwindow->calculate_affected_track();
2803 autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
2804 keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(
2809 mask = !keyframe ? 0 :
2810 keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2814 if( mwindow->cwindow->gui->affected_point < mask->points.total &&
2815 mwindow->cwindow->gui->affected_point >= 0 ) {
2816 point = mask->points.values[mwindow->cwindow->gui->affected_point];
2821 void CWindowMaskGUI::update()
2828 //printf("CWindowMaskGUI::update 1\n");
2829 get_keyframe(track, autos, keyframe, mask, point, 0);
2830 mwindow->cwindow->mask_track_id = track ? track->get_id() : -1;
2831 mask_on_track->set_back_color(!track || track->record ?
2832 get_resources()->text_background :
2833 get_resources()->text_background_disarmed);
2834 mask_on_track->update_items();
2835 mask_on_track->update(!track ? "" : track->title);
2836 mask_name->update_items(keyframe);
2837 const char *text = "";
2838 int sz = !keyframe ? 0 : keyframe->masks.size();
2839 int k = mwindow->edl->session->cwindow_mask;
2840 if( k >= 0 && k < sz )
2841 text = keyframe->masks[k]->name;
2843 k = mwindow->edl->session->cwindow_mask = 0;
2844 mask_name->update(text);
2845 update_buttons(keyframe, k);
2847 x->update(point->x);
2848 y->update(point->y);
2851 double position = mwindow->edl->local_session->get_selectionstart(1);
2852 int64_t position_i = track->to_units(position, 0);
2853 feather->update(autos->get_feather(position_i, k, PLAY_FORWARD));
2854 fade->update(autos->get_fader(position_i, k, PLAY_FORWARD));
2855 int show_mask = track->masks;
2856 for( int i=0; i<SUBMASKS; ++i )
2857 mask_enables[i]->update((show_mask>>i) & 1);
2860 apply_before_plugins->update(keyframe->apply_before_plugins);
2861 disable_opengl_masking->update(keyframe->disable_opengl_masking);
2863 active_point->update((int64_t)mwindow->cwindow->gui->affected_point);
2866 void CWindowMaskGUI::handle_event()
2869 if( event_caller == this->focus_x ||
2870 event_caller == this->focus_y ) {
2873 else if( event_caller == this->x ||
2874 event_caller == this->y ) {
2880 get_keyframe(track, autos, keyframe, mask, point, 0);
2882 mwindow->undo->update_undo_before(_("mask point"), this);
2885 float px = atof(x->get_text());
2886 float py = atof(y->get_text());
2887 float dx = px - point->x, dy = py - point->y;
2888 #ifdef USE_KEYFRAME_SPANNING
2889 // Create temp keyframe
2890 MaskAuto temp_keyframe(mwindow->edl, autos);
2891 temp_keyframe.copy_data(keyframe);
2892 // Get affected point in temp keyframe
2893 mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
2895 MaskPoints &points = mask->points;
2896 int gang = gang_point->get_value();
2897 int k = mwindow->cwindow->gui->affected_point;
2898 int n = gang ? points.size() : k+1;
2899 for( int i=gang? 0 : k; i<n; ++i ) {
2900 if( i < 0 || i >= points.size() ) continue;
2901 MaskPoint *point = points[i];
2902 point->x += dx; point->y += dy;
2904 #ifdef USE_KEYFRAME_SPANNING
2905 // Commit to spanned keyframes
2906 autos->update_parameter(&temp_keyframe);
2909 mwindow->undo->update_undo_after(_("mask point"), LOAD_AUTOMATION);
2917 void CWindowMaskGUI::set_focused(int v, float cx, float cy)
2919 CWindowGUI *cgui = mwindow->cwindow->gui;
2920 cgui->unlock_window();
2921 lock_window("CWindowMaskGUI::set_focused");
2923 focus->update(focused = v);
2924 focus_x->update(cx);
2925 focus_y->update(cy);
2927 cgui->lock_window("CWindowCanvas::set_focused");
2930 void CWindowMaskGUI::update_buttons(MaskAuto *keyframe, int k)
2932 int text_color = get_resources()->default_text_color;
2933 int high_color = get_resources()->button_highlighted;
2934 for( int i=0; i<SUBMASKS; ++i ) {
2935 int color = text_color;
2937 SubMask *submask = keyframe->get_submask(i);
2938 if( submask && submask->points.size() )
2941 mask_blabels[i]->set_color(color);
2942 mask_buttons[i]->update(i==k ? 1 : 0);
2946 // typ=0, this mask, this point
2947 // typ>0, this mask, all points
2948 // typ<0, all masks, all points
2949 // dxy= on? pt[+1]-pt[-1] : dxy=0
2950 int CWindowMaskGUI::smooth_mask(int typ, int on)
2957 #ifdef USE_KEYFRAME_SPANNING
2963 mwindow->undo->update_undo_before(_("mask smooth"), this);
2965 // Get existing keyframe
2966 get_keyframe(track, autos, keyframe,
2967 mask, point, create_it);
2969 #ifdef USE_KEYFRAME_SPANNING
2970 MaskAuto temp_keyframe(mwindow->edl, autos);
2971 temp_keyframe.copy_data(keyframe);
2972 keyframe = &temp_keyframe;
2974 int k = mwindow->edl->session->cwindow_mask;
2975 int n = typ>=0 ? k+1 : keyframe->masks.size();
2976 for( int j=typ<0? 0 : k; j<n; ++j ) {
2977 if( !mask_enables[j]->get_value() ) continue;
2978 SubMask *sub_mask = keyframe->get_submask(j);
2979 MaskPoints &points = sub_mask->points;
2980 int psz = points.size();
2981 if( psz < 3 ) continue;
2982 int l = mwindow->cwindow->gui->affected_point;
2983 if( l > psz ) l = psz;
2984 int m = typ ? psz : l+1;
2985 for( int i=typ ? 0 : l; i<m; ++i ) {
2986 int i0 = i-1, i1 = i+1;
2987 if( i0 < 0 ) i0 = psz-1;
2988 if( i1 >= psz ) i1 = 0;
2989 MaskPoint *p0 = points[i0];
2990 MaskPoint *p = points[i];
2991 MaskPoint *p1 = points[i1];
2992 float dx = !on ? 0 : p1->x - p0->x;
2993 float dy = !on ? 0 : p1->y - p0->y;
2994 p->control_x1 = -dx/4; p->control_y1 = -dy/4;
2995 p->control_x2 = dx/4; p->control_y2 = dy/4;
2998 #ifdef USE_KEYFRAME_SPANNING
2999 autos->update_parameter(keyframe);
3004 mwindow->undo->update_undo_after(_("mask smooth"), LOAD_AUTOMATION);
3008 int CWindowMaskGUI::save_mask(const char *nm)
3010 int k = mwindow->edl->session->cwindow_mask;
3016 get_keyframe(track, autos, keyframe, mask, point, 0);
3017 if( !track ) return 0;
3018 SubMask *sub_mask = keyframe->get_submask(k);
3019 ArrayList<SubMask *> masks;
3021 int i = masks.size();
3023 if( strcmp(masks[i]->name, nm) ) continue;
3024 masks.remove_object_number(i);
3026 mask = new SubMask(0, -1);
3027 strncpy(mask->name, nm, sizeof(mask->name)-1);
3028 mask->copy_from(*sub_mask, 0);
3031 masks.remove_all_objects();
3035 int CWindowMaskGUI::del_mask(const char *nm)
3037 ArrayList<SubMask *> masks;
3039 int i = masks.size();
3041 if( strcmp(masks[i]->name, nm) ) continue;
3042 masks.remove_object_number(i);
3045 masks.remove_all_objects();
3049 int CWindowMaskGUI::center_mask()
3051 int k = mwindow->edl->session->cwindow_mask;
3057 #ifdef USE_KEYFRAME_SPANNING
3062 get_keyframe(track, autos, keyframe,
3063 mask, point, create_it);
3064 if( !track ) return 0;
3065 mwindow->undo->update_undo_before(_("mask center"), this);
3067 // Get existing keyframe
3068 #ifdef USE_KEYFRAME_SPANNING
3069 MaskAuto temp_keyframe(mwindow->edl, autos);
3070 temp_keyframe.copy_data(keyframe);
3071 keyframe = &temp_keyframe;
3073 SubMask *sub_mask = keyframe->get_submask(k);
3074 MaskPoints &points = sub_mask->points;
3075 int psz = points.size();
3077 float cx = 0, cy = 0;
3078 for( int i=0; i<psz; ++i ) {
3079 MaskPoint *p = points[i];
3080 cx += p->x; cy += p->y;
3082 cx /= psz; cy /= psz;
3083 cx -= mwindow->edl->session->output_w / 2.f;
3084 cy -= mwindow->edl->session->output_h / 2.f;
3085 for( int i=0; i<psz; ++i ) {
3086 MaskPoint *p = points[i];
3087 p->x -= cx; p->y -= cy;
3090 #ifdef USE_KEYFRAME_SPANNING
3091 autos->update_parameter(keyframe);
3094 mwindow->undo->update_undo_after(_("mask center"), LOAD_AUTOMATION);
3098 int CWindowMaskGUI::normal_mask()
3100 int k = mwindow->edl->session->cwindow_mask;
3106 #ifdef USE_KEYFRAME_SPANNING
3111 // Get existing keyframe
3112 get_keyframe(track, autos, keyframe,
3113 mask, point, create_it);
3114 if( !track ) return 0;
3115 mwindow->undo->update_undo_before(_("mask normal"), this);
3117 #ifdef USE_KEYFRAME_SPANNING
3118 MaskAuto temp_keyframe(mwindow->edl, autos);
3119 temp_keyframe.copy_data(keyframe);
3120 keyframe = &temp_keyframe;
3122 SubMask *sub_mask = keyframe->get_submask(k);
3123 MaskPoints &points = sub_mask->points;
3124 int psz = points.size();
3125 float cx = 0, cy = 0;
3128 for( int i=0; i<psz; ++i ) {
3129 MaskPoint *p = points[i];
3130 cx += p->x; cy += p->y;
3132 cx /= psz; cy /= psz;
3133 for( int i=0; i<psz; ++i ) {
3134 MaskPoint *p = points[i];
3135 float dx = fabsf(p->x-cx), dy = fabsf(p->y-cy);
3136 double d = sqrt(dx*dx + dy*dy);
3137 if( dr < d ) dr = d;
3141 float out_w = mwindow->edl->session->output_w;
3142 float out_h = mwindow->edl->session->output_h;
3143 float r = bmax(out_w, out_h);
3144 float s = r / (4 * dr * sqrt(2.));
3145 for( int i=0; i<psz; ++i ) {
3146 MaskPoint *p = points[i];
3147 float x = p->x, y = p->y;
3148 p->x = (x-cx) * s + cx;
3149 p->y = (y-cy) * s + cy;
3150 p->control_x1 *= s; p->control_y1 *= s;
3151 p->control_x2 *= s; p->control_y2 *= s;
3154 #ifdef USE_KEYFRAME_SPANNING
3155 autos->update_parameter(keyframe);
3159 mwindow->undo->update_undo_after(_("mask normal"), LOAD_AUTOMATION);
3164 CWindowMaskLoadList::CWindowMaskLoadList(MWindow *mwindow, CWindowMaskGUI *gui)
3165 : BC_ListBox(-1, -1, 1, 1, LISTBOX_TEXT, 0, 0, 0, 1, 0, 1)
3167 this->mwindow = mwindow;
3172 CWindowMaskLoadList::~CWindowMaskLoadList()
3177 int CWindowMaskLoadList::handle_event()
3184 #ifdef USE_KEYFRAME_SPANNING
3190 mwindow->undo->update_undo_before(_("mask shape"), this);
3192 // Get existing keyframe
3193 gui->get_keyframe(track, autos, keyframe,
3194 mask, point, create_it);
3195 CWindowMaskItem *item = (CWindowMaskItem *) get_selection(0, 0);
3196 if( track && item ) {
3197 #ifdef USE_KEYFRAME_SPANNING
3198 MaskAuto temp_keyframe(mwindow->edl, autos);
3199 temp_keyframe.copy_data(keyframe);
3200 keyframe = &temp_keyframe;
3201 mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
3203 ArrayList<SubMask *> masks;
3204 gui->load_masks(masks);
3205 mask->copy_from(*masks[item->id], 0);
3206 masks.remove_all_objects();
3207 #ifdef USE_KEYFRAME_SPANNING
3208 autos->update_parameter(keyframe);
3211 gui->update_preview(1);
3213 mwindow->undo->update_undo_after(_("mask shape"), LOAD_AUTOMATION);
3217 void CWindowMaskLoadList::create_objects()
3219 shape_items.remove_all_objects();
3220 ArrayList<SubMask *> masks;
3221 gui->load_masks(masks);
3222 for( int i=0; i<masks.size(); ++i )
3223 shape_items.append(new CWindowMaskItem(masks[i]->name, i));
3224 masks.remove_all_objects();
3225 update(&shape_items, 0, 0, 1);
3228 CWindowMaskLoad::CWindowMaskLoad(MWindow *mwindow,
3229 CWindowMaskGUI *gui, int x, int y, int w)
3230 : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_load_images"))
3232 this->mwindow = mwindow;
3234 set_tooltip(_("Load preset"));
3237 int CWindowMaskLoad::handle_event()
3239 gui->mask_load_list->create_objects();
3241 get_abs_cursor(px, py);
3242 return gui->mask_load_list->activate(px, py, 120,160);
3246 CWindowMaskSave::CWindowMaskSave(MWindow *mwindow,
3247 CWindowMaskGUI *gui, int x, int y, int w)
3248 : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_save_images"))
3250 this->mwindow = mwindow;
3252 set_tooltip(_("Save preset"));
3255 CWindowMaskSave::~CWindowMaskSave()
3259 int CWindowMaskSave::handle_event()
3266 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
3269 gui->get_abs_cursor(sx, sy);
3270 if( !gui->preset_dialog )
3271 gui->preset_dialog = new CWindowMaskPresetDialog(mwindow, gui);
3272 gui->preset_dialog->start_dialog(sx, sy, keyframe);
3277 CWindowMaskPresetDialog::CWindowMaskPresetDialog(MWindow *mwindow, CWindowMaskGUI *gui)
3280 this->mwindow = mwindow;
3285 CWindowMaskPresetDialog::~CWindowMaskPresetDialog()
3290 void CWindowMaskPresetDialog::handle_close_event(int result)
3295 void CWindowMaskPresetDialog::handle_done_event(int result)
3297 if( result ) return;
3298 const char *nm = pgui->preset_text->get_text();
3305 BC_Window* CWindowMaskPresetDialog::new_gui()
3307 pgui = new CWindowMaskPresetGUI(this, sx, sy,
3308 keyframe ? _(PROGRAM_NAME ": Save Mask") :
3309 _(PROGRAM_NAME ": Delete Mask"));
3310 pgui->create_objects();
3314 void CWindowMaskPresetDialog::start_dialog(int sx, int sy, MaskAuto *keyframe)
3317 this->sx = sx; this->sy = sy;
3318 this->keyframe = keyframe;
3322 CWindowMaskPresetGUI::CWindowMaskPresetGUI(CWindowMaskPresetDialog *preset_dialog,
3323 int x, int y, const char *title)
3324 : BC_Window(title, x, y, 320, 100, 320, 100, 0, 0, 1)
3326 this->preset_dialog = preset_dialog;
3329 void CWindowMaskPresetGUI::create_objects()
3331 int x = 10, y = 10, pad = 8;
3332 lock_window("CWindowMaskPresetGUI::create_objects");
3334 add_subwindow(title = new BC_Title(x, y,
3335 preset_dialog->keyframe ? _("Save mask:") : _("Delete mask:")));
3336 int x1 = x + title->get_w() + pad;
3337 int x2 = get_w() - x - pad - x1 -
3338 BC_WindowBase::get_resources()->listbox_button[0]->get_w();
3339 CWindowMaskGUI *gui = preset_dialog->gui;
3340 preset_text = new CWindowMaskPresetText(this,
3341 x1, y, x2, 120, gui->mask_name->get_text());
3342 preset_text->create_objects();
3343 preset_text->set_tooltip(_("Mask name"));
3344 preset_text->update_items();
3345 add_subwindow(new BC_OKButton(this));
3346 add_subwindow(new BC_CancelButton(this));
3352 CWindowMaskPresetText::CWindowMaskPresetText(CWindowMaskPresetGUI *pgui,
3353 int x, int y, int w, int h, const char *text)
3354 : BC_PopupTextBox(pgui, 0, text, x, y, w, h)
3359 int CWindowMaskPresetText::handle_event()
3361 int k = get_number();
3362 if( k >= 0 && k<mask_items.size() )
3363 update(mask_items[k]->get_text());
3367 void CWindowMaskPresetText::update_items()
3369 mask_items.remove_all_objects();
3370 ArrayList<SubMask *> masks;
3371 pgui->preset_dialog->gui->load_masks(masks);
3372 for( int i=0; i<masks.size(); ++i ) {
3373 char text[BCSTRLEN]; memset(text, 0, sizeof(text));
3374 strncpy(text, masks[i]->name, sizeof(text)-1);
3375 mask_items.append(new CWindowMaskItem(text));
3377 masks.remove_all_objects();
3378 update_list(&mask_items);
3382 CWindowMaskDelete::CWindowMaskDelete(MWindow *mwindow,
3383 CWindowMaskGUI *gui, int x, int y, int w)
3384 : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_trsh_images"))
3386 this->mwindow = mwindow;
3388 set_tooltip(_("Delete preset"));
3391 int CWindowMaskDelete::handle_event()
3394 gui->get_abs_cursor(sx, sy);
3395 if( !gui->preset_dialog )
3396 gui->preset_dialog = new CWindowMaskPresetDialog(mwindow, gui);
3397 gui->preset_dialog->start_dialog(sx, sy, 0);
3402 CWindowMaskCenter::CWindowMaskCenter(MWindow *mwindow,
3403 CWindowMaskGUI *gui, int x, int y, int w)
3404 : BC_Button(x, y, mwindow->theme->get_image_set("mask_pstn_cen_images"))
3406 this->mwindow = mwindow;
3408 set_tooltip(_("center mask"));
3411 int CWindowMaskCenter::handle_event()
3413 return gui->center_mask();
3417 CWindowMaskNormal::CWindowMaskNormal(MWindow *mwindow,
3418 CWindowMaskGUI *gui, int x, int y, int w)
3419 : BC_Button(x, y, mwindow->theme->get_image_set("mask_pstn_nrm_images"))
3421 this->mwindow = mwindow;
3423 set_tooltip(_("normalize mask"));
3426 int CWindowMaskNormal::handle_event()
3428 return gui->normal_mask();
3432 CWindowMaskShape::CWindowMaskShape(MWindow *mwindow, CWindowMaskGUI *gui,
3433 const char *images, int shape, int x, int y, const char *tip)
3434 : BC_Button(x, y, mwindow->theme->get_image_set(images))
3436 this->mwindow = mwindow;
3438 this->shape = shape;
3442 CWindowMaskShape::~CWindowMaskShape()
3446 void CWindowMaskShape::builtin_shape(int i, SubMask *sub_mask)
3448 int out_w = mwindow->edl->session->output_w;
3449 int out_h = mwindow->edl->session->output_h;
3450 float cx = out_w/2.f, cy = out_h/2.f;
3451 float r = bmax(cx, cy) / 4.f;
3452 double c = 4*(sqrt(2.)-1)/3; // bezier aprox circle
3453 float r2 = r / 2.f, rc = r*c, r4 = r / 4.f;
3455 MaskPoints &points = sub_mask->points;
3456 points.remove_all_objects();
3458 case MASK_SHAPE_SQUARE:
3459 points.append(pt = new MaskPoint());
3460 pt->x = cx - r; pt->y = cy - r;
3461 points.append(pt = new MaskPoint());
3462 pt->x = cx + r; pt->y = cy - r;
3463 points.append(pt = new MaskPoint());
3464 pt->x = cx + r; pt->y = cy + r;
3465 points.append(pt = new MaskPoint());
3466 pt->x = cx - r; pt->y = cy + r;
3468 case MASK_SHAPE_CIRCLE:
3469 points.append(pt = new MaskPoint());
3470 pt->x = cx - r; pt->y = cy - r;
3471 pt->control_x1 = -rc; pt->control_y1 = rc;
3472 pt->control_x2 = rc; pt->control_y2 = -rc;
3473 points.append(pt = new MaskPoint());
3474 pt->x = cx + r; pt->y = cy - r;
3475 pt->control_x1 = -rc; pt->control_y1 = -rc;
3476 pt->control_x2 = rc; pt->control_y2 = rc;
3477 points.append(pt = new MaskPoint());
3478 pt->x = cx + r; pt->y = cy + r;
3479 pt->control_x1 = rc; pt->control_y1 = -rc;
3480 pt->control_x2 = -rc; pt->control_y2 = rc;
3481 points.append(pt = new MaskPoint());
3482 pt->x = cx - r; pt->y = cy + r;
3483 pt->control_x1 = rc; pt->control_y1 = rc;
3484 pt->control_x2 = -rc; pt->control_y2 = -rc;
3486 case MASK_SHAPE_TRIANGLE:
3487 points.append(pt = new MaskPoint());
3488 pt->x = cx + 0; pt->y = cy - r*(sqrt(3.)-1.);
3489 points.append(pt = new MaskPoint());
3490 pt->x = cx + r; pt->y = cy + r;
3491 points.append(pt = new MaskPoint());
3492 pt->x = cx - r; pt->y = cy + r;
3494 case MASK_SHAPE_OVAL:
3495 points.append(pt = new MaskPoint());
3496 pt->x = cx - r; pt->y = cy - r2;
3497 pt->control_x1 = -r2; pt->control_y1 = r4;
3498 pt->control_x2 = r2; pt->control_y2 = -r4;
3499 points.append(pt = new MaskPoint());
3500 pt->x = cx + r; pt->y = cy - r2;
3501 pt->control_x1 = -r2; pt->control_y1 = -r4;
3502 pt->control_x2 = r2; pt->control_y2 = r4;
3503 points.append(pt = new MaskPoint());
3504 pt->x = cx + r; pt->y = cy + r2;
3505 pt->control_x1 = r2; pt->control_y1 = -r4;
3506 pt->control_x2 = -r2; pt->control_y2 = r4;
3507 points.append(pt = new MaskPoint());
3508 pt->x = cx - r; pt->y = cy + r2;
3509 pt->control_x1 = r2; pt->control_y1 = r4;
3510 pt->control_x2 = -r2; pt->control_y2 = -r4;
3515 int CWindowMaskShape::handle_event()
3522 #ifdef USE_KEYFRAME_SPANNING
3528 mwindow->undo->update_undo_before(_("mask shape"), this);
3530 // Get existing keyframe
3531 gui->get_keyframe(track, autos, keyframe,
3532 mask, point, create_it);
3534 #ifdef USE_KEYFRAME_SPANNING
3535 MaskAuto temp_keyframe(mwindow->edl, autos);
3536 temp_keyframe.copy_data(keyframe);
3537 keyframe = &temp_keyframe;
3538 mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
3541 builtin_shape(shape, mask);
3542 #ifdef USE_KEYFRAME_SPANNING
3543 autos->update_parameter(keyframe);
3546 gui->update_preview(1);
3549 mwindow->undo->update_undo_after(_("mask shape"), LOAD_AUTOMATION);
3553 void CWindowMaskGUI::load_masks(ArrayList<SubMask *> &masks)
3555 char path[BCTEXTLEN];
3556 sprintf(path, "%s/%s", File::get_config_path(), MASKS_FILE);
3558 fs.complete_path(path);
3560 file.read_from_file(path, 1);
3562 masks.remove_all_objects();
3564 while( !(result = file.read_tag()) ) {
3565 if( file.tag.title_is("MASK") ) {
3566 SubMask *sub_mask = new SubMask(0, -1);
3567 char name[BCTEXTLEN]; name[0] = 0;
3568 file.tag.get_property("NAME", name);
3569 strncpy(sub_mask->name, name, sizeof(sub_mask->name));
3570 sub_mask->load(&file);
3571 masks.append(sub_mask);
3576 void CWindowMaskGUI::save_masks(ArrayList<SubMask *> &masks)
3579 for( int i=0; i<masks.size(); ++i ) {
3580 SubMask *sub_mask = masks[i];
3581 sub_mask->copy(&file);
3583 file.terminate_string();
3585 char path[BCTEXTLEN];
3586 sprintf(path, "%s/%s", File::get_config_path(), MASKS_FILE);
3588 fs.complete_path(path);
3589 file.write_to_file(path);
3593 CWindowRulerGUI::CWindowRulerGUI(MWindow *mwindow, CWindowTool *thread)
3594 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Ruler"), 320, 240)
3598 CWindowRulerGUI::~CWindowRulerGUI()
3602 void CWindowRulerGUI::create_objects()
3604 int x = 10, y = 10, x1 = 100;
3607 lock_window("CWindowRulerGUI::create_objects");
3608 add_subwindow(title = new BC_Title(x, y, _("Current:")));
3609 add_subwindow(current = new BC_TextBox(x1, y, 200, 1, ""));
3610 y += title->get_h() + 5;
3611 add_subwindow(title = new BC_Title(x, y, _("Point 1:")));
3612 add_subwindow(point1 = new BC_TextBox(x1, y, 200, 1, ""));
3613 y += title->get_h() + 5;
3614 add_subwindow(title = new BC_Title(x, y, _("Point 2:")));
3615 add_subwindow(point2 = new BC_TextBox(x1, y, 200, 1, ""));
3616 y += title->get_h() + 5;
3617 add_subwindow(title = new BC_Title(x, y, _("Deltas:")));
3618 add_subwindow(deltas = new BC_TextBox(x1, y, 200, 1, ""));
3619 y += title->get_h() + 5;
3620 add_subwindow(title = new BC_Title(x, y, _("Distance:")));
3621 add_subwindow(distance = new BC_TextBox(x1, y, 200, 1, ""));
3622 y += title->get_h() + 5;
3623 add_subwindow(title = new BC_Title(x, y, _("Angle:")));
3624 add_subwindow(angle = new BC_TextBox(x1, y, 200, 1, ""));
3625 y += title->get_h() + 10;
3626 char string[BCTEXTLEN];
3628 _("Press Ctrl to lock ruler to the\nnearest 45%c%c angle."),
3629 0xc2, 0xb0); // degrees utf
3630 add_subwindow(title = new BC_Title(x,
3633 y += title->get_h() + 10;
3634 sprintf(string, _("Press Alt to translate the ruler."));
3635 add_subwindow(title = new BC_Title(x,
3642 void CWindowRulerGUI::update()
3644 char string[BCTEXTLEN];
3645 int cx = mwindow->session->cwindow_output_x;
3646 int cy = mwindow->session->cwindow_output_y;
3647 sprintf(string, "%d, %d", cx, cy);
3648 current->update(string);
3649 double x1 = mwindow->edl->session->ruler_x1;
3650 double y1 = mwindow->edl->session->ruler_y1;
3651 sprintf(string, "%.0f, %.0f", x1, y1);
3652 point1->update(string);
3653 double x2 = mwindow->edl->session->ruler_x2;
3654 double y2 = mwindow->edl->session->ruler_y2;
3655 sprintf(string, "%.0f, %.0f", x2, y2);
3656 point2->update(string);
3657 double dx = x2 - x1, dy = y2 - y1;
3658 sprintf(string, "%s%.0f, %s%.0f", (dx>=0? "+":""), dx, (dy>=0? "+":""), dy);
3659 deltas->update(string);
3660 double d = sqrt(dx*dx + dy*dy);
3661 sprintf(string, _("%0.01f pixels"), d);
3662 distance->update(string);
3663 double a = d > 0 ? (atan2(-dy, dx) * 180/M_PI) : 0.;
3664 sprintf(string, "%0.02f %c%c", a, 0xc2, 0xb0);
3665 angle->update(string);
3668 void CWindowRulerGUI::handle_event()