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"
40 #include "gwindowgui.h"
43 #include "localsession.h"
44 #include "mainsession.h"
47 #include "maskautos.h"
50 #include "mwindowgui.h"
54 #include "trackcanvas.h"
55 #include "transportque.h"
59 CWindowTool::CWindowTool(MWindow *mwindow, CWindowGUI *gui)
62 this->mwindow = mwindow;
66 current_tool = CWINDOW_NONE;
68 input_lock = new Condition(0, "CWindowTool::input_lock");
69 output_lock = new Condition(1, "CWindowTool::output_lock");
70 tool_gui_lock = new Mutex("CWindowTool::tool_gui_lock");
73 CWindowTool::~CWindowTool()
84 void CWindowTool::start_tool(int operation)
86 CWindowToolGUI *new_gui = 0;
89 //printf("CWindowTool::start_tool 1\n");
90 if(current_tool != operation)
92 int previous_tool = current_tool;
93 current_tool = operation;
97 new_gui = new CWindowEyedropGUI(mwindow, this);
100 new_gui = new CWindowCropGUI(mwindow, this);
103 new_gui = new CWindowCameraGUI(mwindow, this);
105 case CWINDOW_PROJECTOR:
106 new_gui = new CWindowProjectorGUI(mwindow, this);
109 new_gui = new CWindowMaskGUI(mwindow, this);
112 new_gui = new CWindowRulerGUI(mwindow, this);
114 case CWINDOW_PROTECT:
115 mwindow->edl->session->tool_window = 0;
116 gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(0);
124 //printf("CWindowTool::start_tool 1\n");
130 // Wait for previous tool GUI to finish
131 output_lock->lock("CWindowTool::start_tool");
132 this->tool_gui = new_gui;
133 tool_gui->create_objects();
134 if( previous_tool == CWINDOW_PROTECT || previous_tool == CWINDOW_NONE ) {
135 mwindow->edl->session->tool_window = 1;
136 gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(1);
138 mwindow->edl->session->tool_window = new_gui ? 1 : 0;
139 update_show_window();
141 // Signal thread to run next tool GUI
142 input_lock->unlock();
144 //printf("CWindowTool::start_tool 1\n");
149 tool_gui->lock_window("CWindowTool::start_tool");
151 tool_gui->unlock_window();
154 //printf("CWindowTool::start_tool 2\n");
159 void CWindowTool::stop_tool()
163 tool_gui->lock_window("CWindowTool::stop_tool");
164 tool_gui->set_done(0);
165 tool_gui->unlock_window();
169 void CWindowTool::show_tool()
171 if(tool_gui && mwindow->edl->session->tool_window)
173 tool_gui->lock_window("CWindowTool::show_tool");
174 tool_gui->show_window();
175 tool_gui->unlock_window();
179 void CWindowTool::hide_tool()
181 if(tool_gui && mwindow->edl->session->tool_window)
183 tool_gui->lock_window("CWindowTool::show_tool");
184 tool_gui->hide_window();
185 tool_gui->unlock_window();
189 void CWindowTool::raise_tool()
191 if(tool_gui && mwindow->edl->session->tool_window)
193 tool_gui->lock_window("CWindowTool::show_tool");
194 tool_gui->raise_window();
195 tool_gui->unlock_window();
200 void CWindowTool::run()
204 input_lock->lock("CWindowTool::run");
207 tool_gui->run_window();
208 tool_gui_lock->lock("CWindowTool::run");
211 tool_gui_lock->unlock();
213 output_lock->unlock();
217 void CWindowTool::update_show_window()
221 tool_gui->lock_window("CWindowTool::update_show_window");
223 if(mwindow->edl->session->tool_window)
226 tool_gui->show_window();
229 tool_gui->hide_window();
232 tool_gui->unlock_window();
236 void CWindowTool::raise_window()
240 gui->unlock_window();
241 tool_gui->lock_window("CWindowTool::raise_window");
242 tool_gui->raise_window();
243 tool_gui->unlock_window();
244 gui->lock_window("CWindowTool::raise_window");
248 void CWindowTool::update_values()
250 tool_gui_lock->lock("CWindowTool::update_values");
253 tool_gui->lock_window("CWindowTool::update_values");
256 tool_gui->unlock_window();
258 tool_gui_lock->unlock();
267 CWindowToolGUI::CWindowToolGUI(MWindow *mwindow,
268 CWindowTool *thread, const char *title, int w, int h)
270 mwindow->session->ctool_x, mwindow->session->ctool_y,
273 this->mwindow = mwindow;
274 this->thread = thread;
275 current_operation = 0;
279 CWindowToolGUI::~CWindowToolGUI()
283 int CWindowToolGUI::close_event()
287 mwindow->edl->session->tool_window = 0;
289 thread->gui->lock_window("CWindowToolGUI::close_event");
290 thread->gui->composite_panel->set_operation(mwindow->edl->session->cwindow_operation);
291 thread->gui->flush();
292 thread->gui->unlock_window();
293 lock_window("CWindowToolGUI::close_event");
297 int CWindowToolGUI::keypress_event()
301 switch( get_keypress() ) {
304 return close_event();
317 resend_event(thread->gui);
321 if( result ) return result;
322 return context_help_check_and_show();
325 int CWindowToolGUI::translation_event()
327 mwindow->session->ctool_x = get_x();
328 mwindow->session->ctool_y = get_y();
332 void CWindowToolGUI::update_auto(Track *track, int idx, CWindowCoord *vp)
334 FloatAuto *float_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
335 track->automation->autos[idx], 1);
336 if( !float_auto ) return;
337 float v = float_auto->get_value(edge);
338 float t = atof(vp->get_text());
340 float_auto->bump_value(t, edge, span);
341 if( idx == AUTOMATION_PROJECTOR_Z || idx == AUTOMATION_CAMERA_Z ) {
342 mwindow->gui->lock_window("CWindowToolGUI::update_auto");
343 mwindow->gui->draw_overlays(1);
344 mwindow->gui->unlock_window();
350 void CWindowToolGUI::update_preview(int changed_edl)
353 draw_preview(changed_edl);
354 lock_window("CWindowToolGUI::update_preview");
357 void CWindowToolGUI::draw_preview(int changed_edl)
359 CWindowGUI *cgui = mwindow->cwindow->gui;
360 cgui->lock_window("CWindowToolGUI::draw_preview");
361 int change_type = !changed_edl ? CHANGE_PARAMS : CHANGE_EDL;
362 cgui->sync_parameters(change_type, 0, 1);
363 cgui->unlock_window();
367 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value, int type)
368 : BC_TumbleTextBox(gui, (float)value, (float)-65536, (float)65536, x, y, xS(70), 3)
376 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value, int type)
377 : BC_TumbleTextBox(gui, (int64_t)value, (int64_t)-65536, (int64_t)65536, x, y, xS(70))
385 void CWindowCoord::create_objects()
387 BC_TumbleTextBox::create_objects();
389 float v = atof(get_text());
391 int x1 = get_x() + BC_TumbleTextBox::get_w() + xs10, y1 = get_y();
392 gui->add_subwindow(min_tumbler = new CWindowToolAutoRangeTumbler(this, x1, y1,
394 x1 += min_tumbler->get_w() + xs10;
395 int group = Automation::autogrouptype(type, 0);
396 float min = gui->mwindow->edl->local_session->automation_mins[group];
397 float max = gui->mwindow->edl->local_session->automation_maxs[group];
398 gui->add_subwindow(slider = new CWindowCoordSlider(this,
399 x1, y1, xS(150), min, max, v));
400 x1 += slider->get_w() + xS(10);
401 gui->add_subwindow(max_tumbler = new CWindowToolAutoRangeTumbler(this, x1, y1,
403 x1 += max_tumbler->get_w() + xS(10);
404 gui->add_subwindow(range_reset = new CWindowToolAutoRangeReset(this, x1, y1));
405 x1 += range_reset->get_w() + xS(10);
406 gui->add_subwindow(range_text = new CWindowToolAutoRangeTextBox(this, x1, y1));
407 range_text->update_range();
408 x1 += range_text->get_w() + xS(10);
409 gui->add_subwindow(range = new CWindowCoordRangeTumbler(this, x1, y1));
413 void CWindowCoord::update_gui(float value)
415 BC_TumbleTextBox::update(value);
417 int group = Automation::autogrouptype(type, 0);
418 LocalSession *local_session = gui->mwindow->edl->local_session;
419 slider->update(slider->get_pointer_motion_range(), value,
420 local_session->automation_mins[group],
421 local_session->automation_maxs[group]);
422 int x1 = range->get_x() + range->get_w() + xS(5);
423 int y1 = range->get_y() + yS(5), d = xS(16);
424 gui->set_color(GWindowGUI::auto_colors[type]);
425 gui->draw_disc(x1, y1, d, d);
429 int CWindowCoord::handle_event()
432 slider->update(atof(get_text()));
433 gui->event_caller = this;
438 CWindowCoordSlider::CWindowCoordSlider(CWindowCoord *coord,
439 int x, int y, int w, float mn, float mx, float value)
440 : BC_FSlider(x, y, 0, w, w, mn, mx, value)
446 CWindowCoordSlider::~CWindowCoordSlider()
450 int CWindowCoordSlider::handle_event()
452 float value = get_value();
453 coord->update(value);
454 coord->gui->event_caller = coord;
455 coord->gui->handle_event();
459 CWindowCoordRangeTumbler::CWindowCoordRangeTumbler(CWindowCoord *coord, int x, int y)
464 CWindowCoordRangeTumbler::~CWindowCoordRangeTumbler()
468 int CWindowCoordRangeTumbler::update(float scale)
470 CWindowCoordSlider *slider = coord->slider;
471 MWindow *mwindow = coord->gui->mwindow;
472 LocalSession *local_session = mwindow->edl->local_session;
473 int group = Automation::autogrouptype(coord->type, 0);
474 float min = local_session->automation_mins[group];
475 float max = local_session->automation_maxs[group];
478 case AUTOGROUPTYPE_ZOOM: min = 0.005; max = 5.0; break;
479 case AUTOGROUPTYPE_X: min = -1000; max = 1000; break;
480 case AUTOGROUPTYPE_Y: min = -1000; max = 1000; break;
484 case AUTOGROUPTYPE_ZOOM: { // exp
485 float lmin = log(min), lmax = log(max);
486 float lr = (lmax - lmin) * scale;
487 if( (min = exp(lmin - lr)) < ZOOM_MIN ) min = ZOOM_MIN;
488 if( (max = exp(lmax + lr)) > ZOOM_MAX ) max = ZOOM_MAX;
490 case AUTOGROUPTYPE_X:
491 case AUTOGROUPTYPE_Y: { // linear
492 float dr = (max - min) * scale;
493 if( (min -= dr) < XY_MIN ) min = XY_MIN;
494 if( (max += dr) > XY_MAX ) max = XY_MAX;
497 slider->update(slider->get_pointer_motion_range(),
498 slider->get_value(), min, max);
500 MWindowGUI *mgui = mwindow->gui;
501 mgui->lock_window("CWindowCoordRangeTumbler::update");
502 local_session->zoombar_showautotype = group;
503 local_session->automation_mins[group] = min;
504 local_session->automation_maxs[group] = max;
505 mgui->zoombar->update_autozoom();
506 mgui->draw_overlays(0);
507 mgui->update_patchbay();
508 mgui->flash_canvas(1);
509 mgui->unlock_window();
510 lock_window("CWindowCoordRangeTumbler::update");
511 return coord->range_text->update_range();
514 int CWindowCoordRangeTumbler::handle_up_event()
516 return update(0.125);
518 int CWindowCoordRangeTumbler::handle_down_event()
523 CWindowCropApply::CWindowCropApply(MWindow *mwindow, CWindowCropGUI *crop_gui, int x, int y)
524 : BC_GenericButton(x, y, _("Apply"))
526 this->mwindow = mwindow;
527 this->crop_gui = crop_gui;
529 int CWindowCropApply::handle_event()
531 mwindow->crop_video(crop_gui->crop_mode->mode);
536 int CWindowCropApply::keypress_event()
538 if(get_keypress() == 0xd)
543 return context_help_check_and_show();
546 const char *CWindowCropOpMode::crop_ops[] = {
552 CWindowCropOpMode::CWindowCropOpMode(MWindow *mwindow, CWindowCropGUI *crop_gui,
553 int mode, int x, int y)
554 : BC_PopupMenu(x, y, xS(140), _(crop_ops[mode]), 1)
556 this->mwindow = mwindow;
557 this->crop_gui = crop_gui;
560 CWindowCropOpMode::~CWindowCropOpMode()
564 void CWindowCropOpMode::create_objects()
566 for( int id=0,nid=sizeof(crop_ops)/sizeof(crop_ops[0]); id<nid; ++id )
567 add_item(new CWindowCropOpItem(this, _(crop_ops[id]), id));
571 int CWindowCropOpMode::handle_event()
573 set_text(_(crop_ops[mode]));
577 CWindowCropOpItem::CWindowCropOpItem(CWindowCropOpMode *popup, const char *text, int id)
584 int CWindowCropOpItem::handle_event()
586 popup->set_text(get_text());
588 return popup->handle_event();
595 CWindowCropGUI::CWindowCropGUI(MWindow *mwindow, CWindowTool *thread)
596 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Crop"), xS(330), yS(100))
598 // *** CONTEXT_HELP ***
599 context_help_set_keyword("Cropping");
603 CWindowCropGUI::~CWindowCropGUI()
607 void CWindowCropGUI::create_objects()
609 int xs5 = xS(5), xs10 = xS(10);
610 int ys5 = yS(5), ys10 = yS(10);
611 int x = xs10, y = ys10;
614 lock_window("CWindowCropGUI::create_objects");
616 int pad = MAX(BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1),
617 BC_Title::calculate_h(this, "X")) + ys5;
618 add_subwindow(title = new BC_Title(x, y, "X1:"));
619 column1 = MAX(column1, title->get_w());
621 add_subwindow(title = new BC_Title(x, y, _("W:")));
622 column1 = MAX(column1, title->get_w());
624 add_subwindow(new CWindowCropApply(mwindow, this, x, y));
628 x1 = new CWindowCoord(thread->tool_gui, x, y,
629 mwindow->edl->session->crop_x1);
630 x1->create_objects();
631 x1->set_boundaries((int64_t)0, (int64_t)65536);
633 width = new CWindowCoord(thread->tool_gui, x, y,
634 mwindow->edl->session->crop_x2 - mwindow->edl->session->crop_x1);
635 width->create_objects();
636 width->set_boundaries((int64_t)1, (int64_t)65536);
639 x += x1->get_w() + xs10;
642 add_subwindow(title = new BC_Title(x, y, "Y1:"));
643 column2 = MAX(column2, title->get_w());
645 add_subwindow(title = new BC_Title(x, y, _("H:")));
646 column2 = MAX(column2, title->get_w());
651 y1 = new CWindowCoord(thread->tool_gui, x, y,
652 mwindow->edl->session->crop_y1);
653 y1->create_objects();
654 y1->set_boundaries((int64_t)0, (int64_t)65536);
657 height = new CWindowCoord(thread->tool_gui, x, y,
658 mwindow->edl->session->crop_y2 - mwindow->edl->session->crop_y1);
659 height->create_objects();
660 height->set_boundaries((int64_t)1, (int64_t)65536);
663 add_subwindow(crop_mode = new CWindowCropOpMode(mwindow, this,
664 CROP_REFORMAT, x, y));
665 crop_mode->create_objects();
670 void CWindowCropGUI::handle_event()
673 new_x1 = atol(x1->get_text());
674 new_y1 = atol(y1->get_text());
675 if(new_x1 != mwindow->edl->session->crop_x1)
677 mwindow->edl->session->crop_x2 = new_x1 +
678 mwindow->edl->session->crop_x2 -
679 mwindow->edl->session->crop_x1;
680 mwindow->edl->session->crop_x1 = new_x1;
682 if(new_y1 != mwindow->edl->session->crop_y1)
684 mwindow->edl->session->crop_y2 = new_y1 +
685 mwindow->edl->session->crop_y2 -
686 mwindow->edl->session->crop_y1;
687 mwindow->edl->session->crop_y1 = atol(y1->get_text());
689 mwindow->edl->session->crop_x2 = atol(width->get_text()) +
690 mwindow->edl->session->crop_x1;
691 mwindow->edl->session->crop_y2 = atol(height->get_text()) +
692 mwindow->edl->session->crop_y1;
694 mwindow->cwindow->gui->canvas->redraw(1);
697 void CWindowCropGUI::update()
699 x1->update((int64_t)mwindow->edl->session->crop_x1);
700 y1->update((int64_t)mwindow->edl->session->crop_y1);
701 width->update((int64_t)mwindow->edl->session->crop_x2 -
702 mwindow->edl->session->crop_x1);
703 height->update((int64_t)mwindow->edl->session->crop_y2 -
704 mwindow->edl->session->crop_y1);
708 CWindowEyedropGUI::CWindowEyedropGUI(MWindow *mwindow, CWindowTool *thread)
709 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Color"), xS(220), yS(290))
711 // *** CONTEXT_HELP ***
712 context_help_set_keyword("Compositor Toolbar");
715 CWindowEyedropGUI::~CWindowEyedropGUI()
719 void CWindowEyedropGUI::create_objects()
721 int xs10 = xS(10), ys10 = yS(10);
722 int margin = mwindow->theme->widget_border;
723 int x = xs10 + margin;
724 int y = ys10 + margin;
725 int x2 = xS(70), x3 = x2 + xS(60);
726 lock_window("CWindowEyedropGUI::create_objects");
727 BC_Title *title0, *title1, *title2, *title3, *title4, *title5, *title6, *title7;
728 add_subwindow(title0 = new BC_Title(x, y,_("X,Y:")));
729 y += title0->get_h() + margin;
730 add_subwindow(title7 = new BC_Title(x, y, _("Radius:")));
731 y += BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1) + margin;
733 add_subwindow(title1 = new BC_Title(x, y, _("Red:")));
734 y += title1->get_h() + margin;
735 add_subwindow(title2 = new BC_Title(x, y, _("Green:")));
736 y += title2->get_h() + margin;
737 add_subwindow(title3 = new BC_Title(x, y, _("Blue:")));
738 y += title3->get_h() + margin;
740 add_subwindow(title4 = new BC_Title(x, y, "Y:"));
741 y += title4->get_h() + margin;
742 add_subwindow(title5 = new BC_Title(x, y, "U:"));
743 y += title5->get_h() + margin;
744 add_subwindow(title6 = new BC_Title(x, y, "V:"));
746 add_subwindow(current = new BC_Title(x2, title0->get_y(), ""));
748 radius = new CWindowCoord(this, x2, title7->get_y(),
749 mwindow->edl->session->eyedrop_radius);
750 radius->create_objects();
751 radius->set_boundaries((int64_t)0, (int64_t)255);
753 add_subwindow(red = new BC_Title(x2, title1->get_y(), "0"));
754 add_subwindow(green = new BC_Title(x2, title2->get_y(), "0"));
755 add_subwindow(blue = new BC_Title(x2, title3->get_y(), "0"));
756 add_subwindow(rgb_hex = new BC_Title(x3, red->get_y(), "#000000"));
758 add_subwindow(this->y = new BC_Title(x2, title4->get_y(), "0"));
759 add_subwindow(this->u = new BC_Title(x2, title5->get_y(), "0"));
760 add_subwindow(this->v = new BC_Title(x2, title6->get_y(), "0"));
761 add_subwindow(yuv_hex = new BC_Title(x3, this->y->get_y(), "#000000"));
763 y = title6->get_y() + this->v->get_h() + 2*margin;
764 add_subwindow(sample = new BC_SubWindow(x, y, xS(50), yS(50)));
765 y += sample->get_h() + margin;
766 add_subwindow(use_max = new CWindowEyedropCheckBox(mwindow, this, x, y));
771 void CWindowEyedropGUI::update()
773 char string[BCTEXTLEN];
774 sprintf(string, "%d, %d",
775 thread->gui->eyedrop_x,
776 thread->gui->eyedrop_y);
777 current->update(string);
779 radius->update((int64_t)mwindow->edl->session->eyedrop_radius);
781 LocalSession *local_session = mwindow->edl->local_session;
782 int use_max = local_session->use_max;
783 float r = use_max ? local_session->red_max : local_session->red;
784 float g = use_max ? local_session->green_max : local_session->green;
785 float b = use_max ? local_session->blue_max : local_session->blue;
786 this->red->update(r);
787 this->green->update(g);
788 this->blue->update(b);
790 int rx = 255*r + 0.5; bclamp(rx,0,255);
791 int gx = 255*g + 0.5; bclamp(gx,0,255);
792 int bx = 255*b + 0.5; bclamp(bx,0,255);
793 char rgb_text[BCSTRLEN];
794 sprintf(rgb_text, "#%02x%02x%02x", rx, gx, bx);
795 rgb_hex->update(rgb_text);
798 YUV::yuv.rgb_to_yuv_f(r, g, b, y, u, v);
800 this->u->update(u += 0.5);
801 this->v->update(v += 0.5);
803 int yx = 255*y + 0.5; bclamp(yx,0,255);
804 int ux = 255*u + 0.5; bclamp(ux,0,255);
805 int vx = 255*v + 0.5; bclamp(vx,0,255);
806 char yuv_text[BCSTRLEN];
807 sprintf(yuv_text, "#%02x%02x%02x", yx, ux, vx);
808 yuv_hex->update(yuv_text);
810 int rgb = (rx << 16) | (gx << 8) | (bx << 0);
811 sample->set_color(rgb);
812 sample->draw_box(0, 0, sample->get_w(), sample->get_h());
813 sample->set_color(BLACK);
814 sample->draw_rectangle(0, 0, sample->get_w(), sample->get_h());
818 void CWindowEyedropGUI::handle_event()
820 int new_radius = atoi(radius->get_text());
821 if(new_radius != mwindow->edl->session->eyedrop_radius)
823 CWindowGUI *gui = mwindow->cwindow->gui;
824 if(gui->eyedrop_visible)
826 gui->lock_window("CWindowEyedropGUI::handle_event");
829 gui->canvas->do_eyedrop(rerender, 0, 1);
832 mwindow->edl->session->eyedrop_radius = new_radius;
834 if(gui->eyedrop_visible)
838 gui->canvas->do_eyedrop(rerender, 0, 1);
839 gui->unlock_window();
846 /* Buttons to control Keyframe-Curve-Mode for Projector or Camera */
848 // Configuration for all possible Keyframe Curve Mode toggles
850 FloatAuto::t_mode mode;
856 const _CVD Camera_Crv_Smooth = { FloatAuto::SMOOTH, true, "tan_smooth",
857 N_("\"smooth\" Curve on current Camera Keyframes") };
858 const _CVD Camera_Crv_Linear = { FloatAuto::LINEAR, true, "tan_linear",
859 N_("\"linear\" Curve on current Camera Keyframes") };
860 const _CVD Camera_Crv_Tangent = { FloatAuto::TFREE, true, "tan_tangent",
861 N_("\"tangent\" Curve on current Camera Keyframes") };
862 const _CVD Camera_Crv_Free = { FloatAuto::FREE, true, "tan_free",
863 N_("\"free\" Curve on current Camera Keyframes") };
864 const _CVD Camera_Crv_Bump = { FloatAuto::BUMP, true, "tan_bump",
865 N_("\"bump\" Curve on current Camera Keyframes") };
867 const _CVD Projector_Crv_Smooth = { FloatAuto::SMOOTH, false, "tan_smooth",
868 N_("\"smooth\" Curve on current Projector Keyframes") };
869 const _CVD Projector_Crv_Linear = { FloatAuto::LINEAR, false, "tan_linear",
870 N_("\"linear\" Curve on current Projector Keyframes") };
871 const _CVD Projector_Crv_Tangent = { FloatAuto::TFREE, false, "tan_tangent",
872 N_("\"tangent\" Curve on current Projector Keyframes") };
873 const _CVD Projector_Crv_Free = { FloatAuto::FREE, false, "tan_free",
874 N_("\"free\" Curve on current Projector Keyframes") };
875 const _CVD Projector_Crv_Bump = { FloatAuto::BUMP, false, "tan_bump",
876 N_("\"bump\" Curve on current Projector Keyframes") };
878 // Implementation Class für Keyframe Curve Mode buttons
880 // This button reflects the state of the "current" keyframe
881 // (the nearest keyframe on the left) for all three automation
882 // lines together. Clicking on this button (re)sets the curve
883 // mode for the three "current" keyframes simultanously, but
884 // never creates a new keyframe.
886 class CWindowCurveToggle : public BC_Toggle
889 CWindowCurveToggle(const _CVD &mode,
890 MWindow *mwindow, CWindowToolGUI *gui, int x, int y);
891 void check_toggle_state(FloatAuto *x, FloatAuto *y, FloatAuto *z);
900 CWindowCurveToggle::CWindowCurveToggle(const _CVD &mode,
901 MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
902 : BC_Toggle(x, y, mwindow->theme->get_image_set(mode.icon_id), false),
906 this->mwindow = mwindow;
907 set_tooltip(_(cfg.tooltip));
910 void CWindowCurveToggle::check_toggle_state(FloatAuto *x, FloatAuto *y, FloatAuto *z)
912 // the toggle state is only set to ON if all
913 // three automation lines have the same curve mode.
914 // For mixed states the toggle stays off.
915 set_value( x->curve_mode == this->cfg.mode &&
916 y->curve_mode == this->cfg.mode &&
917 z->curve_mode == this->cfg.mode
918 ,true // redraw to show new state
922 int CWindowCurveToggle::handle_event()
924 Track *track = mwindow->cwindow->calculate_affected_track();
926 FloatAuto *x=0, *y=0, *z=0;
927 mwindow->cwindow->calculate_affected_autos(track,
928 &x, &y, &z, cfg.use_camera, 0,0,0); // don't create new keyframe
929 if( x ) x->change_curve_mode(cfg.mode);
930 if( y ) y->change_curve_mode(cfg.mode);
931 if( z ) z->change_curve_mode(cfg.mode);
934 gui->update_preview();
941 CWindowEyedropCheckBox::CWindowEyedropCheckBox(MWindow *mwindow,
942 CWindowEyedropGUI *gui, int x, int y)
943 : BC_CheckBox(x, y, mwindow->edl->local_session->use_max, _("Use maximum"))
945 this->mwindow = mwindow;
949 int CWindowEyedropCheckBox::handle_event()
951 mwindow->edl->local_session->use_max = get_value();
958 CWindowCameraGUI::CWindowCameraGUI(MWindow *mwindow, CWindowTool *thread)
959 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Camera"), xS(580), yS(200))
961 // *** CONTEXT_HELP ***
962 context_help_set_keyword("Camera and Projector");
964 CWindowCameraGUI::~CWindowCameraGUI()
968 void CWindowCameraGUI::create_objects()
970 int xs5 = xS(5), xs10 = xS(10), xs15 = xS(15), xs25 = xS(25);
971 int ys10 = yS(10), ys30 = yS(30);
972 int x = xs10, y = ys10;
973 Track *track = mwindow->cwindow->calculate_affected_track();
974 FloatAuto *x_auto = 0, *y_auto = 0, *z_auto = 0;
979 lock_window("CWindowCameraGUI::create_objects");
981 mwindow->cwindow->calculate_affected_autos(track,
982 &x_auto, &y_auto, &z_auto, 1, 0, 0, 0);
985 add_subwindow(bar1 = new BC_TitleBar(x1, y, xS(340), xs10, xs10, _("Position")));
986 x1 += bar1->get_w() + xS(35);
987 add_subwindow(bar2 = new BC_TitleBar(x1, y, get_w()-x1-xs10, xs10, xs10, _("Range")));
988 y += bar1->get_h() + ys10;
990 add_subwindow(title = new BC_Title(x, y, "X:"));
991 x1 = x + title->get_w() + xS(3);
992 float xvalue = x_auto ? x_auto->get_value() : 0;
993 this->x = new CWindowCoord(this, x1, y, xvalue, AUTOMATION_CAMERA_X);
994 this->x->create_objects();
995 this->x->range->set_tooltip(_("expand X range"));
997 add_subwindow(title = new BC_Title(x = xs10, y, "Y:"));
998 float yvalue = y_auto ? y_auto->get_value() : 0;
999 this->y = new CWindowCoord(this, x1, y, yvalue, AUTOMATION_CAMERA_Y);
1000 this->y->create_objects();
1001 this->y->range->set_tooltip(_("expand Y range"));
1003 add_subwindow(title = new BC_Title(x = xs10, y, "Z:"));
1004 float zvalue = z_auto ? z_auto->get_value() : 1;
1005 this->z = new CWindowCoord(this, x1, y, zvalue, AUTOMATION_CAMERA_Z);
1006 this->z->create_objects();
1007 this->z->set_increment(0.01);
1008 this->z->range->set_tooltip(_("expand Zoom range"));
1012 add_subwindow(bar3 = new BC_TitleBar(x1, y, xS(180)-x1, xs5, xs5, _("Justify")));
1013 x1 += bar3->get_w() + xS(35);
1014 add_subwindow(bar4 = new BC_TitleBar(x1, y, xS(375)-x1, xs5, xs5, _("Curve type")));
1015 bar4->context_help_set_keyword("Using Autos");
1016 x1 += bar4->get_w() + xS(25);
1017 add_subwindow(bar5 = new BC_TitleBar(x1, y, get_w()-xS(60)-x1, xs5, xs5, _("Keyframe")));
1018 bar5->context_help_set_keyword("Using Autos");
1019 y += bar3->get_h() + ys10;
1022 add_subwindow(button = new CWindowCameraLeft(mwindow, this, x1, y));
1023 x1 += button->get_w();
1024 add_subwindow(button = new CWindowCameraCenter(mwindow, this, x1, y));
1025 x1 += button->get_w();
1026 add_subwindow(button = new CWindowCameraRight(mwindow, this, x1, y));
1027 x1 += button->get_w() + xs25;
1028 add_subwindow(button = new CWindowCameraTop(mwindow, this, x1, y));
1029 x1 += button->get_w();
1030 add_subwindow(button = new CWindowCameraMiddle(mwindow, this, x1, y));
1031 x1 += button->get_w();
1032 add_subwindow(button = new CWindowCameraBottom(mwindow, this, x1, y));
1033 x1 += button->get_w() + xS(35);
1034 add_subwindow(t_smooth = new CWindowCurveToggle(Camera_Crv_Smooth, mwindow, this, x1, y));
1035 t_smooth->context_help_set_keyword("Using Autos");
1036 x1 += t_smooth->get_w() + xs10;
1037 add_subwindow(t_linear = new CWindowCurveToggle(Camera_Crv_Linear, mwindow, this, x1, y));
1038 t_linear->context_help_set_keyword("Using Autos");
1039 x1 += t_linear->get_w() + xs10;
1040 add_subwindow(t_tangent = new CWindowCurveToggle(Camera_Crv_Tangent, mwindow, this, x1, y));
1041 t_tangent->context_help_set_keyword("Using Autos");
1042 x1 += t_tangent->get_w() + xs10;
1043 add_subwindow(t_free = new CWindowCurveToggle(Camera_Crv_Free, mwindow, this, x1, y));
1044 t_free->context_help_set_keyword("Using Autos");
1045 x1 += t_free->get_w() + xs10;
1046 add_subwindow(t_bump = new CWindowCurveToggle(Camera_Crv_Bump, mwindow, this, x1, y));
1047 t_bump->context_help_set_keyword("Bump autos");
1048 x1 += button->get_w() + xs25;
1050 add_subwindow(add_keyframe = new CWindowCameraAddKeyframe(mwindow, this, x1, y));
1051 add_keyframe->context_help_set_keyword("Using Autos");
1052 x1 += add_keyframe->get_w() + xs15;
1053 add_subwindow(auto_edge = new CWindowCurveAutoEdge(mwindow, this, x1, y));
1054 auto_edge->context_help_set_keyword("Bump autos");
1055 x1 += auto_edge->get_w() + xs10;
1056 add_subwindow(auto_span = new CWindowCurveAutoSpan(mwindow, this, x1, y));
1057 auto_span->context_help_set_keyword("Bump autos");
1058 x1 += auto_span->get_w() + xS(50);
1059 add_subwindow(reset = new CWindowCameraReset(mwindow, this, x1, y));
1061 // fill in current auto keyframe values, set toggle states.
1066 void CWindowCameraGUI::handle_event()
1068 Track *track = mwindow->cwindow->calculate_affected_track();
1069 if( !track ) return;
1070 mwindow->undo->update_undo_before(_("camera"), this);
1071 if( event_caller == x )
1072 update_auto(track, AUTOMATION_CAMERA_X, x);
1073 else if( event_caller == y )
1074 update_auto(track, AUTOMATION_CAMERA_Y, y);
1075 else if( event_caller == z )
1076 update_auto(track, AUTOMATION_CAMERA_Z, z);
1077 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1080 void CWindowCameraGUI::update()
1082 FloatAuto *x_auto = 0;
1083 FloatAuto *y_auto = 0;
1084 FloatAuto *z_auto = 0;
1085 Track *track = mwindow->cwindow->calculate_affected_track();
1086 int bg_color = get_resources()->text_background;
1087 int hi_color = bg_color ^ 0x444444;
1089 mwindow->cwindow->calculate_affected_autos(track,
1090 &x_auto, &y_auto, &z_auto, 1, 0, 0, 0);
1094 int color = (edge || span) && x_auto->curve_mode == FloatAuto::BUMP ?
1095 hi_color : bg_color;
1096 x->get_textbox()->set_back_color(color);
1097 float xvalue = x_auto->get_value(edge);
1098 x->update_gui(xvalue);
1101 int color = (edge || span) && y_auto->curve_mode == FloatAuto::BUMP ?
1102 hi_color : bg_color;
1103 y->get_textbox()->set_back_color(color);
1104 float yvalue = y_auto->get_value(edge);
1105 y->update_gui(yvalue);
1108 int color = (edge || span) && z_auto->curve_mode == FloatAuto::BUMP ?
1109 hi_color : bg_color;
1110 z->get_textbox()->set_back_color(color);
1111 float zvalue = z_auto->get_value(edge);
1112 z->update_gui(zvalue);
1113 thread->gui->lock_window("CWindowCameraGUI::update");
1114 thread->gui->composite_panel->cpanel_zoom->update(zvalue);
1115 thread->gui->unlock_window();
1118 if( x_auto && y_auto && z_auto ) {
1119 t_smooth->check_toggle_state(x_auto, y_auto, z_auto);
1120 t_linear->check_toggle_state(x_auto, y_auto, z_auto);
1121 t_tangent->check_toggle_state(x_auto, y_auto, z_auto);
1122 t_free->check_toggle_state(x_auto, y_auto, z_auto);
1123 t_bump->check_toggle_state(x_auto, y_auto, z_auto);
1125 x->range_text->update_range();
1126 y->range_text->update_range();
1127 z->range_text->update_range();
1130 CWindowToolAutoRangeTumbler::CWindowToolAutoRangeTumbler(CWindowCoord *coord, int x, int y,
1131 int use_max, const char *tip)
1132 : BC_Tumbler(x, y, coord->gui->mwindow->theme->get_image_set("auto_range"),
1135 this->coord = coord;
1136 this->use_max = use_max;
1140 int CWindowToolAutoRangeTumbler::handle_up_event()
1142 coord->gui->mwindow->update_autorange(coord->type, 1, use_max);
1143 coord->range_text->update_range();
1147 int CWindowToolAutoRangeTumbler::handle_down_event()
1149 coord->gui->mwindow->update_autorange(coord->type, 0, use_max);
1150 coord->range_text->update_range();
1154 CWindowToolAutoRangeReset::CWindowToolAutoRangeReset(CWindowCoord *coord, int x, int y)
1155 : BC_Button(x, y, coord->gui->mwindow->theme->get_image_set("reset_button"))
1157 this->coord = coord;
1158 set_tooltip(_("Reset"));
1161 int CWindowToolAutoRangeReset::handle_event()
1164 int group = Automation::autogrouptype(coord->type, 0);
1165 MWindow *mwindow = coord->gui->mwindow;
1166 LocalSession *local_session = mwindow->edl->local_session;
1167 float min = local_session->automation_mins[group];
1168 float max = local_session->automation_maxs[group];
1170 case AUTOGROUPTYPE_ZOOM: // exp
1171 min = 0.005; max= 5.000; v = 1;
1173 case AUTOGROUPTYPE_X:
1174 max = mwindow->edl->session->output_w;
1177 case AUTOGROUPTYPE_Y:
1178 max = mwindow->edl->session->output_h;
1182 local_session->automation_mins[group] = min;
1183 local_session->automation_maxs[group] = max;
1184 coord->range_text->update_range();
1186 MWindowGUI *mgui = mwindow->gui;
1187 mgui->lock_window("CWindowToolAutoRangeReset::update");
1188 int color = GWindowGUI::auto_colors[coord->type];
1189 mgui->zoombar->update_autozoom(group, color);
1190 mgui->draw_overlays(0);
1191 mgui->update_patchbay();
1192 mgui->flash_canvas(1);
1193 mgui->unlock_window();
1194 mwindow->save_backup();
1195 lock_window("CWindowToolAutoRangeReset::update");
1196 CWindowCoordSlider *slider = coord->slider;
1197 slider->update(slider->get_pointer_motion_range(), v, min, max);
1198 return slider->handle_event();
1201 CWindowToolAutoRangeTextBox::CWindowToolAutoRangeTextBox(CWindowCoord *coord, int x, int y)
1202 : BC_TextBox(x, y, xS(130), 1, "0.000 to 0.000")
1204 this->coord = coord;
1205 set_tooltip(_("Automation range"));
1208 int CWindowToolAutoRangeTextBox::button_press_event()
1210 if (!is_event_win()) return 0;
1211 int use_max = get_cursor_x() < get_w()/2 ? 0 : 1;
1212 switch( get_buttonpress() ) {
1214 coord->gui->mwindow->update_autorange(coord->type, 1, use_max);
1217 coord->gui->mwindow->update_autorange(coord->type, 0, use_max);
1220 return BC_TextBox::button_press_event();
1222 return coord->range_text->update_range();
1225 int CWindowToolAutoRangeTextBox::handle_event()
1228 if( sscanf(this->get_text(),"%f to%f",&imin, &imax) == 2 ) {
1229 MWindow *mwindow = coord->gui->mwindow;
1230 int group = Automation::autogrouptype(coord->type, 0);
1231 LocalSession *local_session = mwindow->edl->local_session;
1232 float min = imin, max = imax;
1234 case AUTOGROUPTYPE_ZOOM:
1235 if( min < ZOOM_MIN ) min = ZOOM_MIN;
1236 if( max > ZOOM_MAX ) max = ZOOM_MAX;
1238 case AUTOGROUPTYPE_X:
1239 case AUTOGROUPTYPE_Y:
1240 if( min < XY_MIN ) min = XY_MIN;
1241 if( max > XY_MAX ) max = XY_MAX;
1245 local_session->automation_mins[group] = min;
1246 local_session->automation_maxs[group] = max;
1247 if( min != imin || max != imax ) update_range();
1248 mwindow->gui->lock_window("CWindowToolAutoRangeTextBox::handle_event");
1249 int color = GWindowGUI::auto_colors[coord->type];
1250 mwindow->gui->zoombar->update_autozoom(group, color);
1251 mwindow->gui->draw_overlays(0);
1252 mwindow->gui->update_patchbay();
1253 mwindow->gui->flash_canvas(1);
1254 mwindow->gui->unlock_window();
1260 int CWindowToolAutoRangeTextBox::update_range()
1262 char string[BCSTRLEN];
1263 LocalSession *local_session = coord->gui->mwindow->edl->local_session;
1264 int group = Automation::autogrouptype(coord->type, 0);
1265 float min = local_session->automation_mins[group];
1266 float max = local_session->automation_maxs[group];
1268 case AUTOGROUPTYPE_ZOOM:
1269 sprintf(string, "%0.03f to %0.03f\n", min, max);
1271 case AUTOGROUPTYPE_X:
1272 case AUTOGROUPTYPE_Y:
1273 sprintf(string, "%0.0f to %.0f\n", min, max);
1281 CWindowCameraLeft::CWindowCameraLeft(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1282 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
1285 this->mwindow = mwindow;
1286 set_tooltip(_("Left justify"));
1288 int CWindowCameraLeft::handle_event()
1290 FloatAuto *x_auto = 0;
1291 FloatAuto *z_auto = 0;
1292 Track *track = mwindow->cwindow->calculate_affected_track();
1294 mwindow->cwindow->calculate_affected_autos(track,
1295 &x_auto, 0, &z_auto, 1, 1, 0, 0);
1298 if(x_auto && z_auto)
1301 track->get_source_dimensions(
1302 mwindow->edl->local_session->get_selectionstart(1),
1307 mwindow->undo->update_undo_before(_("camera"), 0);
1309 (double)track->track_w / z_auto->get_value() / 2 -
1311 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1313 gui->update_preview();
1321 CWindowCameraCenter::CWindowCameraCenter(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1322 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
1325 this->mwindow = mwindow;
1326 set_tooltip(_("Center horizontal"));
1328 int CWindowCameraCenter::handle_event()
1330 FloatAuto *x_auto = 0;
1331 Track *track = mwindow->cwindow->calculate_affected_track();
1333 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1334 track->automation->autos[AUTOMATION_CAMERA_X], 1);
1338 mwindow->undo->update_undo_before(_("camera"), 0);
1339 x_auto->set_value(0);
1341 gui->update_preview();
1342 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1349 CWindowCameraRight::CWindowCameraRight(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1350 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
1353 this->mwindow = mwindow;
1354 set_tooltip(_("Right justify"));
1356 int CWindowCameraRight::handle_event()
1358 FloatAuto *x_auto = 0;
1359 FloatAuto *z_auto = 0;
1360 Track *track = mwindow->cwindow->calculate_affected_track();
1362 mwindow->cwindow->calculate_affected_autos(track,
1363 &x_auto, 0, &z_auto, 1, 1, 0, 0);
1366 if(x_auto && z_auto)
1369 track->get_source_dimensions(
1370 mwindow->edl->local_session->get_selectionstart(1),
1375 mwindow->undo->update_undo_before(_("camera"), 0);
1376 x_auto->set_value( -((double)track->track_w / z_auto->get_value() / 2 -
1379 gui->update_preview();
1380 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1388 CWindowCameraTop::CWindowCameraTop(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1389 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1392 this->mwindow = mwindow;
1393 set_tooltip(_("Top justify"));
1395 int CWindowCameraTop::handle_event()
1397 FloatAuto *y_auto = 0;
1398 FloatAuto *z_auto = 0;
1399 Track *track = mwindow->cwindow->calculate_affected_track();
1401 mwindow->cwindow->calculate_affected_autos(track,
1402 0, &y_auto, &z_auto, 1, 0, 1, 0);
1405 if(y_auto && z_auto)
1408 track->get_source_dimensions(
1409 mwindow->edl->local_session->get_selectionstart(1),
1414 mwindow->undo->update_undo_before(_("camera"), 0);
1415 y_auto->set_value((double)track->track_h / z_auto->get_value() / 2 -
1418 gui->update_preview();
1419 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1427 CWindowCameraMiddle::CWindowCameraMiddle(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1428 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1431 this->mwindow = mwindow;
1432 set_tooltip(_("Center vertical"));
1434 int CWindowCameraMiddle::handle_event()
1436 FloatAuto *y_auto = 0;
1437 Track *track = mwindow->cwindow->calculate_affected_track();
1439 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1440 track->automation->autos[AUTOMATION_CAMERA_Y], 1);
1444 mwindow->undo->update_undo_before(_("camera"), 0);
1445 y_auto->set_value(0);
1447 gui->update_preview();
1448 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1455 CWindowCameraBottom::CWindowCameraBottom(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
1456 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1459 this->mwindow = mwindow;
1460 set_tooltip(_("Bottom justify"));
1462 int CWindowCameraBottom::handle_event()
1464 FloatAuto *y_auto = 0;
1465 FloatAuto *z_auto = 0;
1466 Track *track = mwindow->cwindow->calculate_affected_track();
1468 mwindow->cwindow->calculate_affected_autos(track,
1469 0, &y_auto, &z_auto, 1, 0, 1, 0);
1472 if(y_auto && z_auto)
1475 track->get_source_dimensions(
1476 mwindow->edl->local_session->get_selectionstart(1),
1481 mwindow->undo->update_undo_before(_("camera"), 0);
1482 y_auto->set_value(-((double)track->track_h / z_auto->get_value() / 2 -
1485 gui->update_preview();
1486 mwindow->undo->update_undo_after(_("camera"), LOAD_ALL);
1493 CWindowCameraAddKeyframe::CWindowCameraAddKeyframe(MWindow *mwindow,
1494 CWindowToolGUI *gui, int x, int y)
1495 : BC_Button(x, y, mwindow->theme->get_image_set("keyframe_button"))
1497 this->mwindow = mwindow;
1499 set_tooltip(_("Add Keyframe: Shift-F11"));
1502 int CWindowCameraAddKeyframe::handle_event()
1504 return gui->press(&CWindowCanvas::camera_keyframe);
1507 CWindowCameraReset::CWindowCameraReset(MWindow *mwindow,
1508 CWindowToolGUI *gui, int x, int y)
1509 : BC_Button(x, y, mwindow->theme->get_image_set("reset_button"))
1511 this->mwindow = mwindow;
1513 set_tooltip(_("Reset Camera: F11"));
1516 int CWindowCameraReset::handle_event()
1518 mwindow->edl->local_session->reset_view_limits();
1519 CWindowCameraGUI *gui = (CWindowCameraGUI *)this->gui;
1520 return gui->press(&CWindowCanvas::reset_camera);
1523 CWindowCurveAutoEdge::CWindowCurveAutoEdge(MWindow *mwindow,
1524 CWindowToolGUI *gui, int x, int y)
1525 : BC_Toggle(x, y, mwindow->theme->get_image_set("bump_edge"), gui->edge)
1527 this->mwindow = mwindow;
1529 set_tooltip(_("Bump edit edge left/right"));
1532 int CWindowCurveAutoEdge::handle_event()
1534 gui->edge = get_value();
1539 CWindowCurveAutoSpan::CWindowCurveAutoSpan(MWindow *mwindow,
1540 CWindowToolGUI *gui, int x, int y)
1541 : BC_Toggle(x, y, mwindow->theme->get_image_set("bump_span"), gui->span)
1543 this->mwindow = mwindow;
1545 set_tooltip(_("Bump spans to next/prev"));
1548 int CWindowCurveAutoSpan::handle_event()
1550 gui->span = get_value();
1556 CWindowProjectorGUI::CWindowProjectorGUI(MWindow *mwindow, CWindowTool *thread)
1557 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Projector"), xS(580), yS(200))
1559 // *** CONTEXT_HELP ***
1560 context_help_set_keyword("Camera and Projector");
1562 CWindowProjectorGUI::~CWindowProjectorGUI()
1565 void CWindowProjectorGUI::create_objects()
1567 int xs5 = xS(5), xs10 = xS(10), xs15 = xS(15), xs25 = xS(25);
1568 int ys10 = yS(10), ys30 = yS(30);
1569 int x = xs10, y = ys10;
1570 Track *track = mwindow->cwindow->calculate_affected_track();
1571 FloatAuto *x_auto = 0;
1572 FloatAuto *y_auto = 0;
1573 FloatAuto *z_auto = 0;
1578 lock_window("CWindowProjectorGUI::create_objects");
1580 mwindow->cwindow->calculate_affected_autos(track,
1581 &x_auto, &y_auto, &z_auto, 0, 0, 0, 0);
1584 add_subwindow(bar1 = new BC_TitleBar(x1, y, xS(340), xs10, xs10, _("Position")));
1585 x1 += bar1->get_w() + xS(35);
1586 add_subwindow(bar2 = new BC_TitleBar(x1, y, get_w()-x1-xs10, xs10, xs10, _("Range")));
1587 y += bar1->get_h() + ys10;
1588 add_subwindow(title = new BC_Title(x = xs10, y, "X:"));
1589 x1 = x + title->get_w() + xS(3);
1590 float xvalue = x_auto ? x_auto->get_value() : 0;
1591 this->x = new CWindowCoord(this, x1, y, xvalue, AUTOMATION_PROJECTOR_X);
1592 this->x->create_objects();
1593 this->x->range->set_tooltip(_("expand X range"));
1595 add_subwindow(title = new BC_Title(x = xs10, y, "Y:"));
1596 float yvalue = y_auto ? y_auto->get_value() : 0;
1597 this->y = new CWindowCoord(this, x1, y, yvalue, AUTOMATION_PROJECTOR_Y);
1598 this->y->create_objects();
1599 this->y->range->set_tooltip(_("expand Y range"));
1601 add_subwindow(title = new BC_Title(x = xs10, y, "Z:"));
1602 float zvalue = z_auto ? z_auto->get_value() : 1;
1603 this->z = new CWindowCoord(this, x1, y, zvalue, AUTOMATION_PROJECTOR_Z);
1604 this->z->create_objects();
1605 this->z->range->set_tooltip(_("expand Zoom range"));
1606 this->z->set_increment(0.01);
1610 add_subwindow(bar3 = new BC_TitleBar(x1, y, xS(180)-x1, xs5, xs5, _("Justify")));
1611 x1 += bar3->get_w() + xS(35);
1612 add_subwindow(bar4 = new BC_TitleBar(x1, y, xS(375)-x1, xs5, xs5, _("Curve type")));
1613 bar4->context_help_set_keyword("Using Autos");
1614 x1 += bar4->get_w() + xS(25);
1615 add_subwindow(bar5 = new BC_TitleBar(x1, y, get_w()-xS(60)-x1, xs5, xs5, _("Keyframe")));
1616 bar5->context_help_set_keyword("Using Autos");
1617 y += bar3->get_h() + ys10;
1620 add_subwindow(button = new CWindowProjectorLeft(mwindow, this, x1, y));
1621 x1 += button->get_w();
1622 add_subwindow(button = new CWindowProjectorCenter(mwindow, this, x1, y));
1623 x1 += button->get_w();
1624 add_subwindow(button = new CWindowProjectorRight(mwindow, this, x1, y));
1625 x1 += button->get_w() + xs25;
1626 add_subwindow(button = new CWindowProjectorTop(mwindow, this, x1, y));
1627 x1 += button->get_w();
1628 add_subwindow(button = new CWindowProjectorMiddle(mwindow, this, x1, y));
1629 x1 += button->get_w();
1630 add_subwindow(button = new CWindowProjectorBottom(mwindow, this, x1, y));
1631 x1 += button->get_w() + xS(35);
1632 add_subwindow(t_smooth = new CWindowCurveToggle(Projector_Crv_Smooth, mwindow, this, x1, y));
1633 t_smooth->context_help_set_keyword("Using Autos");
1634 x1 += t_smooth->get_w() + xs10;
1635 add_subwindow(t_linear = new CWindowCurveToggle(Projector_Crv_Linear, mwindow, this, x1, y));
1636 t_linear->context_help_set_keyword("Using Autos");
1637 x1 += t_linear->get_w() + xs10;
1638 add_subwindow(t_tangent = new CWindowCurveToggle(Projector_Crv_Tangent, mwindow, this, x1, y));
1639 t_tangent->context_help_set_keyword("Using Autos");
1640 x1 += t_tangent->get_w() + xs10;
1641 add_subwindow(t_free = new CWindowCurveToggle(Projector_Crv_Free, mwindow, this, x1, y));
1642 t_free->context_help_set_keyword("Using Autos");
1643 x1 += t_free->get_w() + xs10;
1644 add_subwindow(t_bump = new CWindowCurveToggle(Projector_Crv_Bump, mwindow, this, x1, y));
1645 t_bump->context_help_set_keyword("Bump autos");
1646 x1 += button->get_w() + xs25;
1648 add_subwindow(add_keyframe = new CWindowProjectorAddKeyframe(mwindow, this, x1, y));
1649 add_keyframe->context_help_set_keyword("Using Autos");
1650 x1 += add_keyframe->get_w() + xs15;
1651 add_subwindow(auto_edge = new CWindowCurveAutoEdge(mwindow, this, x1, y));
1652 auto_edge->context_help_set_keyword("Bump autos");
1653 x1 += auto_edge->get_w() + xs10;
1654 add_subwindow(auto_span = new CWindowCurveAutoSpan(mwindow, this, x1, y));
1655 auto_span->context_help_set_keyword("Bump autos");
1656 x1 += auto_span->get_w() + xS(50);
1657 add_subwindow(reset = new CWindowProjectorReset(mwindow, this, x1, y));
1659 // fill in current auto keyframe values, set toggle states.
1664 void CWindowProjectorGUI::handle_event()
1666 Track *track = mwindow->cwindow->calculate_affected_track();
1667 if( !track ) return;
1668 mwindow->undo->update_undo_before(_("projector"), this);
1669 if( event_caller == x )
1670 update_auto(track, AUTOMATION_PROJECTOR_X, x);
1671 else if( event_caller == y )
1672 update_auto(track, AUTOMATION_PROJECTOR_Y, y);
1673 else if( event_caller == z )
1674 update_auto(track, AUTOMATION_PROJECTOR_Z, z);
1675 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1678 void CWindowProjectorGUI::update()
1680 FloatAuto *x_auto = 0;
1681 FloatAuto *y_auto = 0;
1682 FloatAuto *z_auto = 0;
1683 Track *track = mwindow->cwindow->calculate_affected_track();
1684 int bg_color = get_resources()->text_background;
1685 int hi_color = bg_color ^ 0x444444;
1687 mwindow->cwindow->calculate_affected_autos(track,
1688 &x_auto, &y_auto, &z_auto, 0, 0, 0, 0);
1692 int color = (edge || span) && x_auto->curve_mode == FloatAuto::BUMP ?
1693 hi_color : bg_color;
1694 x->get_textbox()->set_back_color(color);
1695 float xvalue = x_auto->get_value(edge);
1696 x->update_gui(xvalue);
1699 int color = (edge || span) && y_auto->curve_mode == FloatAuto::BUMP ?
1700 hi_color : bg_color;
1701 y->get_textbox()->set_back_color(color);
1702 float yvalue = y_auto->get_value(edge);
1703 y->update_gui(yvalue);
1706 int color = (edge || span) && z_auto->curve_mode == FloatAuto::BUMP ?
1707 hi_color : bg_color;
1708 z->get_textbox()->set_back_color(color);
1709 float zvalue = z_auto->get_value(edge);
1710 z->update_gui(zvalue);
1711 thread->gui->lock_window("CWindowProjectorGUI::update");
1712 thread->gui->composite_panel->cpanel_zoom->update(zvalue);
1713 thread->gui->unlock_window();
1716 if( x_auto && y_auto && z_auto ) {
1717 t_smooth->check_toggle_state(x_auto, y_auto, z_auto);
1718 t_linear->check_toggle_state(x_auto, y_auto, z_auto);
1719 t_tangent->check_toggle_state(x_auto, y_auto, z_auto);
1720 t_free->check_toggle_state(x_auto, y_auto, z_auto);
1721 t_bump->check_toggle_state(x_auto, y_auto, z_auto);
1723 x->range_text->update_range();
1724 y->range_text->update_range();
1725 z->range_text->update_range();
1728 CWindowProjectorLeft::CWindowProjectorLeft(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1729 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
1732 this->mwindow = mwindow;
1733 set_tooltip(_("Left justify"));
1735 int CWindowProjectorLeft::handle_event()
1737 FloatAuto *x_auto = 0;
1738 FloatAuto *z_auto = 0;
1739 Track *track = mwindow->cwindow->calculate_affected_track();
1741 mwindow->cwindow->calculate_affected_autos(track,
1742 &x_auto, 0, &z_auto, 0, 1, 0, 0);
1744 if(x_auto && z_auto)
1746 mwindow->undo->update_undo_before(_("projector"), 0);
1747 x_auto->set_value( (double)track->track_w * z_auto->get_value() / 2 -
1748 (double)mwindow->edl->session->output_w / 2 );
1750 gui->update_preview();
1751 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1758 CWindowProjectorCenter::CWindowProjectorCenter(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1759 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
1762 this->mwindow = mwindow;
1763 set_tooltip(_("Center horizontal"));
1765 int CWindowProjectorCenter::handle_event()
1767 FloatAuto *x_auto = 0;
1768 Track *track = mwindow->cwindow->calculate_affected_track();
1770 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1771 track->automation->autos[AUTOMATION_PROJECTOR_X], 1);
1775 mwindow->undo->update_undo_before(_("projector"), 0);
1776 x_auto->set_value(0);
1778 gui->update_preview();
1779 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1786 CWindowProjectorRight::CWindowProjectorRight(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1787 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
1790 this->mwindow = mwindow;
1791 set_tooltip(_("Right justify"));
1793 int CWindowProjectorRight::handle_event()
1795 FloatAuto *x_auto = 0;
1796 FloatAuto *z_auto = 0;
1797 Track *track = mwindow->cwindow->calculate_affected_track();
1799 mwindow->cwindow->calculate_affected_autos(track,
1800 &x_auto, 0, &z_auto, 0, 1, 0, 0);
1803 if(x_auto && z_auto)
1805 mwindow->undo->update_undo_before(_("projector"), 0);
1806 x_auto->set_value( -((double)track->track_w * z_auto->get_value() / 2 -
1807 (double)mwindow->edl->session->output_w / 2));
1809 gui->update_preview();
1810 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1817 CWindowProjectorTop::CWindowProjectorTop(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1818 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1821 this->mwindow = mwindow;
1822 set_tooltip(_("Top justify"));
1824 int CWindowProjectorTop::handle_event()
1826 FloatAuto *y_auto = 0;
1827 FloatAuto *z_auto = 0;
1828 Track *track = mwindow->cwindow->calculate_affected_track();
1830 mwindow->cwindow->calculate_affected_autos(track,
1831 0, &y_auto, &z_auto, 0, 0, 1, 0);
1834 if(y_auto && z_auto)
1836 mwindow->undo->update_undo_before(_("projector"), 0);
1837 y_auto->set_value( (double)track->track_h * z_auto->get_value() / 2 -
1838 (double)mwindow->edl->session->output_h / 2 );
1840 gui->update_preview();
1841 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1848 CWindowProjectorMiddle::CWindowProjectorMiddle(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1849 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1852 this->mwindow = mwindow;
1853 set_tooltip(_("Center vertical"));
1855 int CWindowProjectorMiddle::handle_event()
1857 FloatAuto *y_auto = 0;
1858 Track *track = mwindow->cwindow->calculate_affected_track();
1860 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1861 track->automation->autos[AUTOMATION_PROJECTOR_Y], 1);
1865 mwindow->undo->update_undo_before(_("projector"), 0);
1866 y_auto->set_value(0);
1868 gui->update_preview();
1869 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1876 CWindowProjectorBottom::CWindowProjectorBottom(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1877 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1880 this->mwindow = mwindow;
1881 set_tooltip(_("Bottom justify"));
1883 int CWindowProjectorBottom::handle_event()
1885 FloatAuto *y_auto = 0;
1886 FloatAuto *z_auto = 0;
1887 Track *track = mwindow->cwindow->calculate_affected_track();
1889 mwindow->cwindow->calculate_affected_autos(track,
1890 0, &y_auto, &z_auto, 0, 0, 1, 0);
1893 if(y_auto && z_auto)
1895 mwindow->undo->update_undo_before(_("projector"), 0);
1896 y_auto->set_value( -((double)track->track_h * z_auto->get_value() / 2 -
1897 (double)mwindow->edl->session->output_h / 2));
1899 gui->update_preview();
1900 mwindow->undo->update_undo_after(_("projector"), LOAD_ALL);
1906 CWindowProjectorAddKeyframe::CWindowProjectorAddKeyframe(MWindow *mwindow,
1907 CWindowToolGUI *gui, int x, int y)
1908 : BC_Button(x, y, mwindow->theme->get_image_set("keyframe_button"))
1910 this->mwindow = mwindow;
1912 set_tooltip(_("Add Keyframe: Shift-F12"));
1915 int CWindowProjectorAddKeyframe::handle_event()
1917 return gui->press(&CWindowCanvas::projector_keyframe);
1920 CWindowProjectorReset::CWindowProjectorReset(MWindow *mwindow,
1921 CWindowToolGUI *gui, int x, int y)
1922 : BC_Button(x, y, mwindow->theme->get_image_set("reset_button"))
1924 this->mwindow = mwindow;
1926 set_tooltip(_("Reset Projector: F12"));
1929 int CWindowProjectorReset::handle_event()
1931 mwindow->edl->local_session->reset_view_limits();
1932 CWindowProjectorGUI *gui = (CWindowProjectorGUI *)this->gui;
1933 return gui->press(&CWindowCanvas::reset_projector);
1936 int CWindowToolGUI::press(void (CWindowCanvas::*fn)())
1939 CWindowGUI *cw_gui = thread->gui;
1940 cw_gui->lock_window("CWindowGUI::press");
1941 (cw_gui->canvas->*fn)();
1942 cw_gui->unlock_window();
1943 lock_window("CWindowToolGUI::press");
1947 CWindowMaskOnTrack::CWindowMaskOnTrack(MWindow *mwindow, CWindowMaskGUI *gui,
1948 int x, int y, int w, const char *text)
1949 : BC_PopupTextBox(gui, 0, text, x, y, w, yS(120))
1951 this->mwindow = mwindow;
1955 CWindowMaskOnTrack::~CWindowMaskOnTrack()
1959 int CWindowMaskOnTrack::handle_event()
1961 CWindowMaskItem *track_item = 0;
1962 int k = get_number(), track_id = -1;
1963 //printf("selected %d = %s\n", k, k<0 ? "()" : track_items[k]->get_text());
1965 track_item = (CWindowMaskItem *)track_items[k];
1966 Track *track = track_item ? mwindow->edl->tracks->get_track_by_id(track_item->id) : 0;
1967 if( track && track->is_armed() ) track_id = track->get_id();
1970 track_id = mwindow->cwindow->mask_track_id;
1971 set_back_color(track_id >= 0 ?
1972 gui->get_resources()->text_background :
1973 gui->get_resources()->text_background_disarmed);
1974 if( mwindow->cwindow->mask_track_id != track_id )
1975 gui->mask_on_track->update(track_item ? track_item->get_text() : "");
1976 mwindow->cwindow->mask_track_id = track_id;
1977 mwindow->edl->local_session->solo_track_id = -1;
1978 gui->mask_solo_track->update(0);
1980 gui->update_preview(1);
1984 void CWindowMaskOnTrack::update_items()
1986 track_items.remove_all_objects();
1987 int high_color = gui->get_resources()->button_highlighted;
1988 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
1989 if( track->data_type != TRACK_VIDEO ) continue;
1990 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1991 int color = !track->is_armed() ? RED : mask_autos->first ? high_color : -1;
1992 MaskAuto *mask_auto = (MaskAuto*)mask_autos->default_auto;
1993 for( int i=0; color<0 && i<mask_auto->masks.size(); ++i )
1994 if( mask_auto->masks[i]->points.size() > 0 ) color = high_color;
1995 track_items.append(new CWindowMaskItem(track->title, track->get_id(), color));
1997 update_list(&track_items);
2000 CWindowMaskTrackTumbler::CWindowMaskTrackTumbler(MWindow *mwindow, CWindowMaskGUI *gui,
2004 this->mwindow = mwindow;
2007 CWindowMaskTrackTumbler::~CWindowMaskTrackTumbler()
2011 int CWindowMaskTrackTumbler::handle_up_event()
2016 int CWindowMaskTrackTumbler::handle_down_event()
2018 return do_event(-1);
2021 int CWindowMaskTrackTumbler::do_event(int dir)
2023 CWindowMaskItem *track_item = 0;
2024 CWindowMaskItem **items = (CWindowMaskItem**)&gui->mask_on_track->track_items[0];
2025 int n = gui->mask_on_track->track_items.size();
2026 int id = mwindow->cwindow->mask_track_id;
2029 while( --k >= 0 && items[k]->id != id );
2033 track_item = items[k];
2036 track_item = items[0];
2038 Track *track = track_item ? mwindow->edl->tracks->get_track_by_id(track_item->id) : 0;
2039 int track_id = track_item && track && track->is_armed() ? track_item->id : -1;
2040 gui->mask_on_track->set_back_color(track_id >= 0 ?
2041 gui->get_resources()->text_background :
2042 gui->get_resources()->text_background_disarmed);
2043 gui->mask_on_track->update(track_item ? track_item->get_text() : "");
2044 mwindow->cwindow->mask_track_id = track_item ? track_item->id : -1;
2045 mwindow->edl->local_session->solo_track_id = -1;
2046 gui->mask_solo_track->update(0);
2048 gui->update_preview(1);
2053 CWindowMaskName::CWindowMaskName(MWindow *mwindow, CWindowMaskGUI *gui,
2054 int x, int y, const char *text)
2055 : BC_PopupTextBox(gui, 0, text, x, y, xS(100), yS(160))
2057 this->mwindow = mwindow;
2061 CWindowMaskName::~CWindowMaskName()
2065 int CWindowMaskName::handle_event()
2072 //printf("CWindowMaskGUI::update 1\n");
2073 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
2075 int k = get_number();
2076 if( k < 0 ) k = mwindow->edl->session->cwindow_mask;
2077 else mwindow->edl->session->cwindow_mask = k;
2078 if( k >= 0 && k < mask_items.size() ) {
2079 mask_items[k]->set_text(get_text());
2080 update_list(&mask_items);
2082 #ifdef USE_KEYFRAME_SPANNING
2083 MaskAuto temp_keyframe(mwindow->edl, autos);
2084 temp_keyframe.copy_data(keyframe);
2085 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
2086 memset(submask->name, 0, sizeof(submask->name));
2087 strncpy(submask->name, get_text(), sizeof(submask->name)-1);
2088 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
2090 for(MaskAuto *current = (MaskAuto*)autos->default_auto; current; ) {
2091 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
2092 memset(submask->name, 0, sizeof(submask->name));
2093 strncpy(submask->name, get_text(), sizeof(submask->name)-1);
2094 current = current == (MaskAuto*)autos->default_auto ?
2095 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
2099 gui->update_preview();
2104 void CWindowMaskName::update_items(MaskAuto *keyframe)
2106 mask_items.remove_all_objects();
2107 int sz = !keyframe ? 0 : keyframe->masks.size();
2108 for( int i=0; i<SUBMASKS; ++i ) {
2109 char text[BCSTRLEN]; memset(text, 0, sizeof(text));
2111 SubMask *sub_mask = keyframe->masks.get(i);
2112 strncpy(text, sub_mask->name, sizeof(text)-1);
2115 sprintf(text, "%d", i);
2116 mask_items.append(new CWindowMaskItem(text));
2118 update_list(&mask_items);
2122 CWindowMaskButton::CWindowMaskButton(MWindow *mwindow, CWindowMaskGUI *gui,
2123 int x, int y, int no, int v)
2124 : BC_CheckBox(x, y, v)
2126 this->mwindow = mwindow;
2131 CWindowMaskButton::~CWindowMaskButton()
2135 int CWindowMaskButton::handle_event()
2137 mwindow->edl->session->cwindow_mask = no;
2138 gui->mask_name->update(gui->mask_name->mask_items[no]->get_text());
2140 gui->update_preview();
2144 CWindowMaskThumbler::CWindowMaskThumbler(MWindow *mwindow, CWindowMaskGUI *gui,
2148 this->mwindow = mwindow;
2152 CWindowMaskThumbler::~CWindowMaskThumbler()
2156 int CWindowMaskThumbler::handle_up_event()
2161 int CWindowMaskThumbler::handle_down_event()
2163 return do_event(-1);
2166 int CWindowMaskThumbler::do_event(int dir)
2168 int k = mwindow->edl->session->cwindow_mask;
2169 if( (k+=dir) >= SUBMASKS ) k = 0;
2170 else if( k < 0 ) k = SUBMASKS-1;
2171 mwindow->edl->session->cwindow_mask = k;
2172 gui->mask_name->update(gui->mask_name->mask_items[k]->get_text());
2174 gui->update_preview();
2178 CWindowMaskEnable::CWindowMaskEnable(MWindow *mwindow, CWindowMaskGUI *gui,
2179 int x, int y, int no, int v)
2180 : BC_CheckBox(x, y, v)
2182 this->mwindow = mwindow;
2187 CWindowMaskEnable::~CWindowMaskEnable()
2191 int CWindowMaskEnable::handle_event()
2193 Track *track = mwindow->cwindow->calculate_mask_track();
2195 mwindow->undo->update_undo_before(_("mask enable"), this);
2198 track->masks |= bit;
2200 track->masks &= ~bit;
2202 gui->update_preview(1);
2203 mwindow->undo->update_undo_after(_("mask enable"), LOAD_PATCHES);
2208 CWindowMaskUnclear::CWindowMaskUnclear(MWindow *mwindow,
2209 CWindowMaskGUI *gui, int x, int y)
2210 : BC_Button(x, y, mwindow->theme->get_image_set("unclear_button"))
2212 this->mwindow = mwindow;
2214 set_tooltip(_("Show/Hide mask"));
2217 int CWindowMaskUnclear::handle_event()
2219 Track *track = mwindow->cwindow->calculate_mask_track();
2221 mwindow->undo->update_undo_before(_("mask enables"), this);
2222 int m = (1<<SUBMASKS)-1;
2223 if( track->masks == m )
2227 for( int i=0; i<SUBMASKS; ++i )
2228 gui->mask_enables[i]->update((track->masks>>i) & 1);
2229 gui->update_preview(1);
2230 mwindow->undo->update_undo_after(_("mask enables"), LOAD_PATCHES);
2235 CWindowMaskSoloTrack::CWindowMaskSoloTrack(MWindow *mwindow,
2236 CWindowMaskGUI *gui, int x, int y, int v)
2237 : BC_CheckBox(x, y, v, _("Solo"))
2239 this->mwindow = mwindow;
2241 set_tooltip(_("Solo video track"));
2244 int CWindowMaskSoloTrack::handle_event()
2246 mwindow->edl->local_session->solo_track_id =
2247 get_value() ? mwindow->cwindow->mask_track_id : -1;
2248 gui->update_preview(1);
2252 int CWindowMaskSoloTrack::calculate_w(BC_WindowBase *gui)
2255 calculate_extents(gui, &w, &h, _("Solo"));
2259 CWindowMaskDelMask::CWindowMaskDelMask(MWindow *mwindow,
2260 CWindowMaskGUI *gui, int x, int y)
2261 : BC_GenericButton(x, y, _("Delete"))
2263 this->mwindow = mwindow;
2265 set_tooltip(_("Delete mask"));
2268 int CWindowMaskDelMask::handle_event()
2277 // Get existing keyframe
2278 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
2281 mwindow->undo->update_undo_before(_("mask delete"), 0);
2283 #ifdef USE_KEYFRAME_SPANNING
2284 // Create temp keyframe
2285 MaskAuto temp_keyframe(mwindow->edl, autos);
2286 temp_keyframe.copy_data(keyframe);
2287 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
2288 submask->points.remove_all_objects();
2290 // Commit change to span of keyframes
2291 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
2293 for(MaskAuto *current = (MaskAuto*)autos->default_auto; current; ) {
2294 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
2295 submask->points.remove_all_objects();
2296 current = current == (MaskAuto*)autos->default_auto ?
2297 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
2301 if( mwindow->cwindow->gui->affected_point >= total_points )
2302 mwindow->cwindow->gui->affected_point =
2303 total_points > 0 ? total_points-1 : 0;
2306 gui->update_preview();
2307 mwindow->undo->update_undo_after(_("mask delete"), LOAD_AUTOMATION);
2313 CWindowMaskDelPoint::CWindowMaskDelPoint(MWindow *mwindow,
2314 CWindowMaskGUI *gui, int x, int y)
2315 : BC_GenericButton(x, y, _("Delete"))
2317 this->mwindow = mwindow;
2319 set_tooltip(_("Delete point"));
2322 int CWindowMaskDelPoint::handle_event()
2331 // Get existing keyframe
2332 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
2334 mwindow->undo->update_undo_before(_("point delete"), 0);
2336 #ifdef USE_KEYFRAME_SPANNING
2337 // Create temp keyframe
2338 MaskAuto temp_keyframe(mwindow->edl, autos);
2339 temp_keyframe.copy_data(keyframe);
2341 SubMask *submask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
2342 int i = mwindow->cwindow->gui->affected_point;
2343 for( ; i<submask->points.total-1; ++i )
2344 *submask->points.values[i] = *submask->points.values[i+1];
2345 if( submask->points.total > 0 ) {
2346 point = submask->points.values[submask->points.total-1];
2347 submask->points.remove_object(point);
2349 total_points = submask->points.total;
2351 // Commit change to span of keyframes
2352 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->update_parameter(&temp_keyframe);
2355 MaskAuto *current = (MaskAuto*)autos->default_auto;
2357 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
2358 int i = mwindow->cwindow->gui->affected_point;
2359 for( ; i<submask->points.total-1; ++i )
2360 *submask->points.values[i] = *submask->points.values[i+1];
2361 if( submask->points.total > 0 ) {
2362 point = submask->points.values[submask->points.total-1];
2363 submask->points.remove_object(point);
2365 total_points = submask->points.total;
2366 current = current == (MaskAuto*)autos->default_auto ?
2367 (MaskAuto*)autos->first : (MaskAuto*)NEXT;
2370 if( mwindow->cwindow->gui->affected_point >= total_points )
2371 mwindow->cwindow->gui->affected_point =
2372 total_points > 0 ? total_points-1 : 0;
2375 gui->update_preview();
2376 mwindow->undo->update_undo_after(_("point delete"), LOAD_AUTOMATION);
2383 CWindowMaskAffectedPoint::CWindowMaskAffectedPoint(MWindow *mwindow,
2384 CWindowMaskGUI *gui, int x, int y)
2385 : BC_TumbleTextBox(gui,
2386 (int64_t)mwindow->cwindow->gui->affected_point,
2387 (int64_t)0, INT64_MAX, x, y, xS(70))
2389 this->mwindow = mwindow;
2393 CWindowMaskAffectedPoint::~CWindowMaskAffectedPoint()
2397 int CWindowMaskAffectedPoint::handle_event()
2399 int total_points = 0;
2400 int affected_point = atol(get_text());
2401 Track *track = mwindow->cwindow->calculate_mask_track();
2403 MaskAutos *autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
2404 MaskAuto *keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(autos, 0);
2406 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2407 total_points = mask->points.size();
2410 int active_point = affected_point;
2411 if( affected_point >= total_points )
2412 affected_point = total_points - 1;
2413 if( affected_point < 0 )
2415 if( active_point != affected_point )
2416 update((int64_t)affected_point);
2417 mwindow->cwindow->gui->affected_point = affected_point;
2419 gui->update_preview();
2424 CWindowMaskFocus::CWindowMaskFocus(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2425 : BC_CheckBox(x, y, gui->focused, _("Focus"))
2427 this->mwindow = mwindow;
2429 set_tooltip(_("Center for rotate/scale"));
2432 CWindowMaskFocus::~CWindowMaskFocus()
2436 int CWindowMaskFocus::handle_event()
2438 gui->focused = get_value();
2440 gui->update_preview();
2444 int CWindowMaskFocus::calculate_w(CWindowMaskGUI *gui)
2447 calculate_extents(gui, &w, &h, _("Focus"));
2451 CWindowMaskScaleXY::CWindowMaskScaleXY(MWindow *mwindow, CWindowMaskGUI *gui,
2452 int x, int y, VFrame **data, int v, int id, const char *tip)
2453 : BC_Toggle(x, y, data, v)
2456 this->mwindow = mwindow;
2461 CWindowMaskScaleXY::~CWindowMaskScaleXY()
2465 int CWindowMaskScaleXY::handle_event()
2467 gui->scale_mode = id;
2468 gui->mask_scale_x->update(id == MASK_SCALE_X);
2469 gui->mask_scale_y->update(id == MASK_SCALE_Y);
2470 gui->mask_scale_xy->update(id == MASK_SCALE_XY);
2474 CWindowMaskHelp::CWindowMaskHelp(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2475 : BC_CheckBox(x, y, 0, _("Help"))
2477 this->mwindow = mwindow;
2479 set_tooltip(_("Show help text"));
2482 CWindowMaskHelp::~CWindowMaskHelp()
2486 int CWindowMaskHelp::handle_event()
2488 gui->helped = get_value();
2489 gui->resize_window(gui->get_w(),
2490 gui->helped ? gui->help_h : gui->help_y);
2495 CWindowMaskDrawMarkers::CWindowMaskDrawMarkers(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2496 : BC_CheckBox(x, y, gui->markers, _("Markers"))
2498 this->mwindow = mwindow;
2500 set_tooltip("Display points");
2503 CWindowMaskDrawMarkers::~CWindowMaskDrawMarkers()
2507 int CWindowMaskDrawMarkers::handle_event()
2509 gui->markers = get_value();
2511 gui->update_preview();
2515 CWindowMaskDrawBoundary::CWindowMaskDrawBoundary(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2516 : BC_CheckBox(x, y, gui->boundary, _("Boundary"))
2518 this->mwindow = mwindow;
2520 set_tooltip("Display mask outline");
2523 CWindowMaskDrawBoundary::~CWindowMaskDrawBoundary()
2527 int CWindowMaskDrawBoundary::handle_event()
2529 gui->boundary = get_value();
2531 gui->update_preview();
2536 CWindowMaskFeather::CWindowMaskFeather(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2537 : BC_TumbleTextBox(gui, 0, INT_MIN, INT_MAX, x, y, xS(64), 2)
2539 this->mwindow = mwindow;
2542 CWindowMaskFeather::~CWindowMaskFeather()
2546 int CWindowMaskFeather::update(float v)
2548 gui->feather_slider->update(v);
2549 return BC_TumbleTextBox::update(v);
2552 int CWindowMaskFeather::update_value(float v)
2559 #ifdef USE_KEYFRAME_SPANNING
2565 mwindow->undo->update_undo_before(_("mask feather"), this);
2567 // Get existing keyframe
2568 gui->get_keyframe(track, autos, keyframe,
2569 mask, point, create_it);
2571 int gang = gui->gang_feather->get_value();
2572 #ifdef USE_KEYFRAME_SPANNING
2573 MaskAuto temp_keyframe(mwindow->edl, autos);
2574 temp_keyframe.copy_data(keyframe);
2575 keyframe = &temp_keyframe;
2577 float change = v - mask->feather;
2578 int k = mwindow->edl->session->cwindow_mask;
2579 int n = gang ? keyframe->masks.size() : k+1;
2580 for( int i=gang? 0 : k; i<n; ++i ) {
2581 if( !gui->mask_enables[i]->get_value() ) continue;
2582 SubMask *sub_mask = keyframe->get_submask(i);
2583 float feather = sub_mask->feather + change;
2584 sub_mask->feather = feather;
2586 #ifdef USE_KEYFRAME_SPANNING
2587 autos->update_parameter(keyframe);
2589 gui->update_preview();
2592 mwindow->undo->update_undo_after(_("mask feather"), LOAD_AUTOMATION);
2596 int CWindowMaskFeather::handle_event()
2598 float v = atof(get_text());
2599 if( fabsf(v) > MAX_FEATHER )
2600 BC_TumbleTextBox::update((float)(v>=0 ? MAX_FEATHER : -MAX_FEATHER));
2601 gui->feather_slider->update(v);
2602 return gui->feather->update_value(v);
2605 CWindowMaskFeatherSlider::CWindowMaskFeatherSlider(MWindow *mwindow,
2606 CWindowMaskGUI *gui, int x, int y, int w, float v)
2607 : BC_FSlider(x, y, 0, w, w, -FEATHER_MAX-5, FEATHER_MAX+5, v)
2609 this->mwindow = mwindow;
2611 set_precision(0.01);
2612 timer = new Timer();
2618 CWindowMaskFeatherSlider::~CWindowMaskFeatherSlider()
2623 int CWindowMaskFeatherSlider::handle_event()
2626 float v = get_value();
2627 if( fabsf(v) > MAX_FEATHER )
2628 v = v>=0 ? MAX_FEATHER : -MAX_FEATHER;
2629 if( stick && timer->get_difference() >= 250 )
2630 stick = 0; // no events for .25 sec
2631 if( stick && (last_v * (v-last_v)) < 0 )
2632 stick = 0; // dv changed direction
2641 if( max > MAX_FEATHER ) max = MAX_FEATHER;
2642 update(get_w(), v=last_v, -max-5, max+5);
2643 button_release_event();
2646 else if( v > max ) { v = max; sticky = 24; }
2647 else if( v < -max ) { v = -max; sticky = 24; }
2648 else if( v>=0 ? last_v<0 : last_v>=0 ) { v = 0; sticky = 16; }
2649 if( sticky ) { update(v); stick = sticky; timer->update(); }
2651 gui->feather->BC_TumbleTextBox::update(v);
2652 return gui->feather->update_value(v);
2655 int CWindowMaskFeatherSlider::update(float v)
2657 float vv = fabsf(v);
2658 if( vv > MAX_FEATHER ) vv = MAX_FEATHER;
2659 while( max < vv ) max *= 1.25;
2660 return update(get_w(), v, -max-5, max+5);
2662 int CWindowMaskFeatherSlider::update(int r, float v, float mn, float mx)
2664 return BC_FSlider::update(r, v, mn, mx);
2667 CWindowMaskFade::CWindowMaskFade(MWindow *mwindow, CWindowMaskGUI *gui, int x, int y)
2668 : BC_TumbleTextBox(gui, 0, -100.f, 100.f, x, y, xS(64), 2)
2670 this->mwindow = mwindow;
2673 CWindowMaskFade::~CWindowMaskFade()
2677 int CWindowMaskFade::update(float v)
2679 gui->fade_slider->update(v);
2680 return BC_TumbleTextBox::update(v);
2683 int CWindowMaskFade::update_value(float v)
2690 #ifdef USE_KEYFRAME_SPANNING
2696 mwindow->undo->update_undo_before(_("mask fade"), this);
2698 // Get existing keyframe
2699 gui->get_keyframe(track, autos, keyframe,
2700 mask, point, create_it);
2702 int gang = gui->gang_fader->get_value();
2703 #ifdef USE_KEYFRAME_SPANNING
2704 MaskAuto temp_keyframe(mwindow->edl, autos);
2705 temp_keyframe.copy_data(keyframe);
2706 keyframe = &temp_keyframe;
2708 float change = v - mask->fader;
2709 int k = mwindow->edl->session->cwindow_mask;
2710 int n = gang ? keyframe->masks.size() : k+1;
2711 for( int i=gang? 0 : k; i<n; ++i ) {
2712 if( !gui->mask_enables[i]->get_value() ) continue;
2713 SubMask *sub_mask = keyframe->get_submask(i);
2714 float fader = sub_mask->fader + change;
2715 bclamp(fader, -100.f, 100.f);
2716 sub_mask->fader = fader;
2718 #ifdef USE_KEYFRAME_SPANNING
2719 autos->update_parameter(keyframe);
2721 gui->update_preview();
2724 mwindow->undo->update_undo_after(_("mask fade"), LOAD_AUTOMATION);
2728 int CWindowMaskFade::handle_event()
2730 float v = atof(get_text());
2731 gui->fade_slider->update(v);
2732 return gui->fade->update_value(v);
2735 CWindowMaskFadeSlider::CWindowMaskFadeSlider(MWindow *mwindow, CWindowMaskGUI *gui,
2736 int x, int y, int w)
2737 : BC_ISlider(x, y, 0, w, w, -200, 200, 0)
2739 this->mwindow = mwindow;
2741 timer = new Timer();
2746 CWindowMaskFadeSlider::~CWindowMaskFadeSlider()
2751 int CWindowMaskFadeSlider::handle_event()
2753 float v = 100*get_value()/200;
2755 int64_t ms = timer->get_difference();
2756 if( ms < 250 && --stick > 0 ) {
2757 if( get_value() == 0 ) return 1;
2765 else if( (last_v>=0 && v<0) || (last_v<0 && v>=0) ) {
2772 gui->fade->BC_TumbleTextBox::update(v);
2773 return gui->fade->update_value(v);
2776 int CWindowMaskFadeSlider::update(int64_t v)
2778 return BC_ISlider::update(200*v/100);
2781 CWindowMaskGangFader::CWindowMaskGangFader(MWindow *mwindow,
2782 CWindowMaskGUI *gui, int x, int y)
2783 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2785 this->mwindow = mwindow;
2787 set_tooltip(_("Gang fader"));
2790 CWindowMaskGangFader::~CWindowMaskGangFader()
2794 int CWindowMaskGangFader::handle_event()
2799 CWindowMaskGangFocus::CWindowMaskGangFocus(MWindow *mwindow,
2800 CWindowMaskGUI *gui, int x, int y)
2801 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2803 this->mwindow = mwindow;
2805 set_tooltip(_("Gang rotate/scale/translate"));
2808 CWindowMaskGangFocus::~CWindowMaskGangFocus()
2812 int CWindowMaskGangFocus::handle_event()
2817 CWindowMaskGangPoint::CWindowMaskGangPoint(MWindow *mwindow,
2818 CWindowMaskGUI *gui, int x, int y)
2819 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2821 this->mwindow = mwindow;
2823 set_tooltip(_("Gang points"));
2826 CWindowMaskGangPoint::~CWindowMaskGangPoint()
2830 int CWindowMaskGangPoint::handle_event()
2836 CWindowMaskSmoothButton::CWindowMaskSmoothButton(MWindow *mwindow, CWindowMaskGUI *gui,
2837 const char *tip, int type, int on, int x, int y, const char *images)
2838 : BC_Button(x, y, mwindow->theme->get_image_set(images))
2840 this->mwindow = mwindow;
2847 int CWindowMaskSmoothButton::handle_event()
2849 return gui->smooth_mask(type, on);
2852 CWindowMaskBeforePlugins::CWindowMaskBeforePlugins(CWindowMaskGUI *gui, int x, int y)
2853 : BC_CheckBox(x, y, 1, _("Apply mask before plugins"))
2858 int CWindowMaskBeforePlugins::handle_event()
2865 gui->get_keyframe(track, autos, keyframe, mask, point, 1);
2868 int v = get_value();
2869 #ifdef USE_KEYFRAME_SPANNING
2870 MaskAuto temp_keyframe(gui->mwindow->edl, autos);
2871 temp_keyframe.copy_data(keyframe);
2872 temp_keyframe.apply_before_plugins = v;
2873 autos->update_parameter(&temp_keyframe);
2875 keyframe->apply_before_plugins = v;
2877 gui->update_preview();
2883 CWindowDisableOpenGLMasking::CWindowDisableOpenGLMasking(CWindowMaskGUI *gui, int x, int y)
2884 : BC_CheckBox(x, y, 1, _("Disable OpenGL masking"))
2889 int CWindowDisableOpenGLMasking::handle_event()
2896 gui->get_keyframe(track, autos, keyframe, mask, point, 1);
2899 int v = get_value();
2900 #ifdef USE_KEYFRAME_SPANNING
2901 MaskAuto temp_keyframe(gui->mwindow->edl, autos);
2902 temp_keyframe.copy_data(keyframe);
2903 temp_keyframe.disable_opengl_masking = v;
2904 autos->update_parameter(&temp_keyframe);
2906 keyframe->disable_opengl_masking = v;
2908 gui->update_preview();
2914 CWindowMaskClrMask::CWindowMaskClrMask(MWindow *mwindow,
2915 CWindowMaskGUI *gui, int x, int y)
2916 : BC_Button(x, y, mwindow->theme->get_image_set("reset_button"))
2918 this->mwindow = mwindow;
2920 set_tooltip(_("Delete all masks"));
2923 CWindowMaskClrMask::~CWindowMaskClrMask()
2927 int CWindowMaskClrMask::calculate_w(MWindow *mwindow)
2929 VFrame *vfrm = *mwindow->theme->get_image_set("reset_button");
2930 return vfrm->get_w();
2933 int CWindowMaskClrMask::handle_event()
2941 // Get existing keyframe
2942 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
2945 mwindow->undo->update_undo_before(_("del masks"), 0);
2946 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->clear_all();
2947 mwindow->undo->update_undo_after(_("del masks"), LOAD_AUTOMATION);
2951 gui->update_preview(1);
2955 CWindowMaskGangFeather::CWindowMaskGangFeather(MWindow *mwindow,
2956 CWindowMaskGUI *gui, int x, int y)
2957 : BC_Toggle(x, y, mwindow->theme->get_image_set("gangpatch_data"), 0)
2959 this->mwindow = mwindow;
2961 set_tooltip(_("Gang feather"));
2964 CWindowMaskGangFeather::~CWindowMaskGangFeather()
2968 int CWindowMaskGangFeather::handle_event()
2973 CWindowMaskGUI::CWindowMaskGUI(MWindow *mwindow, CWindowTool *thread)
2974 : CWindowToolGUI(mwindow, thread,
2975 _(PROGRAM_NAME ": Mask"), xS(440), yS(700))
2977 this->mwindow = mwindow;
2978 this->thread = thread;
2987 // *** CONTEXT_HELP ***
2988 context_help_set_keyword("Masks");
2990 CWindowMaskGUI::~CWindowMaskGUI()
2992 lock_window("CWindowMaskGUI::~CWindowMaskGUI");
2994 delete active_point;
2998 delete preset_dialog;
3001 void CWindowMaskGUI::create_objects()
3004 Theme *theme = mwindow->theme;
3005 int xs10 = xS(10), ys10 = yS(10);
3006 int x = xs10, y = ys10;
3007 int margin = theme->widget_border;
3008 int clr_w = CWindowMaskClrMask::calculate_w(mwindow);
3009 int clr_x = get_w()-x - clr_w;
3011 lock_window("CWindowMaskGUI::create_objects");
3012 BC_TitleBar *title_bar;
3013 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xS(20), xS(10),
3014 _("Masks on Track")));
3015 y += title_bar->get_h() + margin;
3017 add_subwindow(title = new BC_Title(x,y, _("Track:")));
3018 int x1 = x + xS(90), ww = clr_x-2*margin - x1;
3019 for( int i=0,n=sizeof(t)/sizeof(t[0]); i<n; ++i ) t[i] = x1+(i*ww)/n;
3021 Track *track = mwindow->cwindow->calculate_affected_track();
3022 const char *text = track ? track->title : "";
3023 mwindow->cwindow->mask_track_id = track ? track->get_id() : -1;
3024 mask_on_track = new CWindowMaskOnTrack(mwindow, this, x1, y, xS(100), text);
3025 mask_on_track->create_objects();
3026 mask_on_track->set_tooltip(_("Video track"));
3027 int x2 = x1 + mask_on_track->get_w();
3028 add_subwindow(mask_track_tumbler = new CWindowMaskTrackTumbler(mwindow, this, x2, y));
3029 mwindow->edl->local_session->solo_track_id = -1;
3030 add_subwindow(mask_solo_track = new CWindowMaskSoloTrack(mwindow, this, del_x, y, 0));
3031 y += mask_on_track->get_h() + margin;
3032 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xS(20), xS(10),
3034 y += title_bar->get_h() + margin;
3035 add_subwindow(title = new BC_Title(x, y, _("Mask:")));
3036 mask_name = new CWindowMaskName(mwindow, this, x1, y, "");
3037 mask_name->create_objects();
3038 mask_name->set_tooltip(_("Mask name"));
3039 add_subwindow(mask_clr = new CWindowMaskClrMask(mwindow, this, clr_x, y));
3040 add_subwindow(mask_del = new CWindowMaskDelMask(mwindow, this, del_x, y));
3041 y += mask_name->get_h() + 2*margin;
3043 // add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
3044 // y += bar->get_h() + 2*margin;
3046 add_subwindow(title = new BC_Title(x, y, _("Select:")));
3048 BC_CheckBox::calculate_extents(this, &bw, &bh);
3049 for( int i=0; i<SUBMASKS; ++i ) {
3050 int v = i == mwindow->edl->session->cwindow_mask ? 1 : 0;
3051 mask_buttons[i] = new CWindowMaskButton(mwindow, this, t[i], y, i, v);
3052 add_subwindow(mask_buttons[i]);
3054 add_subwindow(mask_thumbler = new CWindowMaskThumbler(mwindow, this, clr_x, y));
3056 for( int i=0; i<SUBMASKS; ++i ) {
3057 char text[BCSTRLEN]; sprintf(text, "%d", i);
3058 int tx = (bw - get_text_width(MEDIUMFONT, text)) / 2;
3059 mask_blabels[i] = new BC_Title(t[i]+tx, y, text);
3060 add_subwindow(mask_blabels[i]);
3062 y += mask_blabels[0]->get_h() + margin;
3063 add_subwindow(title = new BC_Title(x, y, _("Enable:")));
3064 for( int i=0; i<SUBMASKS; ++i ) {
3065 mask_enables[i] = new CWindowMaskEnable(mwindow, this, t[i], y, i, 1);
3066 add_subwindow(mask_enables[i]);
3068 add_subwindow(mask_unclr = new CWindowMaskUnclear(mwindow, this, clr_x, y));
3069 y += mask_enables[0]->get_h() + 2*margin;
3070 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xS(20), xS(10),
3071 _("Preset Shapes")));
3072 y += title_bar->get_h() + margin;
3073 add_subwindow(mask_shape_sqr = new CWindowMaskShape(mwindow, this,
3074 "mask_prst_sqr_images", MASK_SHAPE_SQUARE, t[0], y, _("Square")));
3075 add_subwindow(mask_shape_crc = new CWindowMaskShape(mwindow, this,
3076 "mask_prst_crc_images", MASK_SHAPE_CIRCLE, t[1], y, _("Circle")));
3077 add_subwindow(mask_shape_tri = new CWindowMaskShape(mwindow, this,
3078 "mask_prst_tri_images", MASK_SHAPE_TRIANGLE, t[2], y, _("Triangle")));
3079 add_subwindow(mask_shape_ovl = new CWindowMaskShape(mwindow, this,
3080 "mask_prst_ovl_images", MASK_SHAPE_OVAL, t[3], y, _("Oval")));
3081 add_subwindow(mask_load_list = new CWindowMaskLoadList(mwindow, this));
3082 add_subwindow(mask_load = new CWindowMaskLoad(mwindow, this, t[5], y, xS(80)));
3083 add_subwindow(mask_save = new CWindowMaskSave(mwindow, this, t[6], y, xS(80)));
3084 add_subwindow(mask_delete = new CWindowMaskDelete(mwindow, this, t[7], y, xS(80)));
3085 y += mask_load->get_h() + 2*margin;
3086 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xS(20), xS(10),
3087 _("Position & Scale")));
3088 y += title_bar->get_h() + 2*margin;
3089 add_subwindow(mask_center = new CWindowMaskCenter(mwindow, this, t[0], y, xS(80)));
3090 add_subwindow(mask_normal = new CWindowMaskNormal(mwindow, this, t[1], y, xS(80)));
3092 add_subwindow(mask_scale_x = new CWindowMaskScaleXY(mwindow, this,
3093 t[5], y, theme->get_image_set("mask_scale_x"), 0, MASK_SCALE_X, _("xlate/scale x")));
3094 add_subwindow(mask_scale_y = new CWindowMaskScaleXY(mwindow, this,
3095 t[6], y, theme->get_image_set("mask_scale_y"), 0, MASK_SCALE_Y, _("xlate/scale y")));
3096 add_subwindow(mask_scale_xy = new CWindowMaskScaleXY(mwindow, this,
3097 t[7], y, theme->get_image_set("mask_scale_xy"), 1, MASK_SCALE_XY, _("xlate/scale xy")));
3098 y += mask_center->get_h() + 2*margin;
3099 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xS(20), xS(10),
3100 _("Fade & Feather")));
3101 y += title_bar->get_h() + 2*margin;
3103 add_subwindow(title = new BC_Title(x, y, _("Fade:")));
3104 fade = new CWindowMaskFade(mwindow, this, x1, y);
3105 fade->create_objects();
3106 x2 = x1 + fade->get_w() + 2*margin;
3107 int w2 = clr_x-2*margin - x2;
3108 add_subwindow(fade_slider = new CWindowMaskFadeSlider(mwindow, this, x2, y, w2));
3109 add_subwindow(gang_fader = new CWindowMaskGangFader(mwindow, this, clr_x, y));
3110 y += fade->get_h() + margin;
3111 add_subwindow(title = new BC_Title(x, y, _("Feather:")));
3112 feather = new CWindowMaskFeather(mwindow, this, x1, y);
3113 feather->create_objects();
3114 w2 = clr_x - 2*margin - x2;
3115 feather_slider = new CWindowMaskFeatherSlider(mwindow, this, x2, y, w2, 0);
3116 add_subwindow(feather_slider);
3117 add_subwindow(gang_feather = new CWindowMaskGangFeather(mwindow, this, clr_x, y));
3118 y += feather->get_h() + 2*margin;
3119 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xS(20), xS(10),
3121 y += title_bar->get_h() + margin;
3123 add_subwindow(title = new BC_Title(x, y, _("Point:")));
3124 active_point = new CWindowMaskAffectedPoint(mwindow, this, t[0], y);
3125 active_point->create_objects();
3126 // typ=0, this mask, this point
3127 add_subwindow(mask_pnt_linear = new CWindowMaskSmoothButton(mwindow, this,
3128 _("linear point"), 0, 0, t[3], y, "mask_pnt_linear_images"));
3129 add_subwindow(mask_pnt_smooth = new CWindowMaskSmoothButton(mwindow, this,
3130 _("smooth point"), 0, 1, t[4], y, "mask_pnt_smooth_images"));
3131 add_subwindow(del_point = new CWindowMaskDelPoint(mwindow, this, del_x, y));
3132 add_subwindow(gang_point = new CWindowMaskGangPoint(mwindow, this, clr_x, y));
3133 y += active_point->get_h() + margin;
3134 add_subwindow(title = new BC_Title(x, y, "X:"));
3135 this->x = new CWindowCoord(this, t[0], y, (float)0.0);
3136 this->x->create_objects();
3137 // typ>0, this mask, all points
3138 add_subwindow(mask_crv_linear = new CWindowMaskSmoothButton(mwindow, this,
3139 _("linear curve"), 1, 0, t[3], y, "mask_crv_linear_images"));
3140 add_subwindow(mask_crv_smooth = new CWindowMaskSmoothButton(mwindow, this,
3141 _("smooth curve"), 1, 1, t[4], y, "mask_crv_smooth_images"));
3142 add_subwindow(draw_markers = new CWindowMaskDrawMarkers(mwindow, this, del_x, y));
3143 y += this->x->get_h() + margin;
3144 add_subwindow(title = new BC_Title(x, y, "Y:"));
3145 this->y = new CWindowCoord(this, x1, y, (float)0.0);
3146 this->y->create_objects();
3147 // typ<0, all masks, all points
3148 add_subwindow(mask_all_linear = new CWindowMaskSmoothButton(mwindow, this,
3149 _("linear all"), -1, 0, t[3], y, "mask_all_linear_images"));
3150 add_subwindow(mask_all_smooth = new CWindowMaskSmoothButton(mwindow, this,
3151 _("smooth all"), -1, 1, t[4], y, "mask_all_smooth_images"));
3152 add_subwindow(draw_boundary = new CWindowMaskDrawBoundary(mwindow, this, del_x, y));
3153 y += this->y->get_h() + 2*margin;
3154 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xS(20), xS(10),
3156 y += title_bar->get_h() + margin;
3158 add_subwindow(title = new BC_Title(x, y, "X:"));
3159 float cx = mwindow->edl->session->output_w / 2.f;
3160 focus_x = new CWindowCoord(this, x1, y, cx);
3161 focus_x->create_objects();
3162 add_subwindow(focus = new CWindowMaskFocus(mwindow, this, del_x, y));
3163 add_subwindow(gang_focus = new CWindowMaskGangFocus(mwindow, this, clr_x, y));
3164 y += focus_x->get_h() + margin;
3165 add_subwindow(title = new BC_Title(x, y, "Y:"));
3166 float cy = mwindow->edl->session->output_h / 2.f;
3167 focus_y = new CWindowCoord(this, x1, y, cy);
3168 focus_y->create_objects();
3169 y += focus_y->get_h() + 2*margin;
3170 add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
3171 y += bar->get_h() + margin;
3172 add_subwindow(this->apply_before_plugins = new CWindowMaskBeforePlugins(this, x, y));
3173 y += this->apply_before_plugins->get_h();
3174 add_subwindow(this->disable_opengl_masking = new CWindowDisableOpenGLMasking(this, x, y));
3175 add_subwindow(help = new CWindowMaskHelp(mwindow, this, del_x, y));
3176 y += this->disable_opengl_masking->get_h() + 2*margin;
3178 add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
3179 y += bar->get_h() + 2*margin;
3180 add_subwindow(title = new BC_Title(x, y, _(
3181 "Shift+LMB: move an end point\n"
3182 "Ctrl+LMB: move a control point\n"
3183 "Alt+LMB: to drag translate the mask\n"
3184 "Shift+MMB: Set Pivot Point at pointer\n"
3185 "Wheel: rotate around Pivot Point\n"
3186 "Shift+Wheel: scale around Pivot Point\n"
3187 "Ctrl+Wheel: rotate/scale around pointer")));
3188 help_h = y + title->get_h() + 2*margin;
3190 resize_window(get_w(), help_y);
3194 int CWindowMaskGUI::close_event()
3197 return CWindowToolGUI::close_event();
3200 void CWindowMaskGUI::done_event()
3202 if( mwindow->in_destructor ) return;
3203 int &solo_track_id = mwindow->edl->local_session->solo_track_id;
3204 if( solo_track_id >= 0 ) {
3210 void CWindowMaskGUI::get_keyframe(Track* &track,
3211 MaskAutos* &autos, MaskAuto* &keyframe,
3212 SubMask* &mask, MaskPoint* &point, int create_it)
3217 track = mwindow->cwindow->calculate_mask_track();
3219 track = mwindow->cwindow->calculate_affected_track();
3222 autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
3223 keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(
3228 mask = !keyframe ? 0 :
3229 keyframe->get_submask(mwindow->edl->session->cwindow_mask);
3233 if( mwindow->cwindow->gui->affected_point < mask->points.total &&
3234 mwindow->cwindow->gui->affected_point >= 0 ) {
3235 point = mask->points.values[mwindow->cwindow->gui->affected_point];
3240 void CWindowMaskGUI::update()
3247 //printf("CWindowMaskGUI::update 1\n");
3248 get_keyframe(track, autos, keyframe, mask, point, 0);
3249 mwindow->cwindow->mask_track_id = track ? track->get_id() : -1;
3250 mask_on_track->set_back_color(!track || track->is_armed() ?
3251 get_resources()->text_background :
3252 get_resources()->text_background_disarmed);
3253 mask_on_track->update_items();
3254 mask_on_track->update(!track ? "" : track->title);
3255 mask_name->update_items(keyframe);
3256 const char *text = "";
3257 int sz = !keyframe ? 0 : keyframe->masks.size();
3258 int k = mwindow->edl->session->cwindow_mask;
3259 if( k >= 0 && k < sz )
3260 text = keyframe->masks[k]->name;
3262 k = mwindow->edl->session->cwindow_mask = 0;
3263 mask_name->update(text);
3264 update_buttons(keyframe, k);
3266 x->update(point->x);
3267 y->update(point->y);
3270 double position = mwindow->edl->local_session->get_selectionstart(1);
3271 int64_t position_i = track->to_units(position, 0);
3272 feather->update(autos->get_feather(position_i, k, PLAY_FORWARD));
3273 fade->update(autos->get_fader(position_i, k, PLAY_FORWARD));
3274 int show_mask = track->masks;
3275 for( int i=0; i<SUBMASKS; ++i )
3276 mask_enables[i]->update((show_mask>>i) & 1);
3279 apply_before_plugins->update(keyframe->apply_before_plugins);
3280 disable_opengl_masking->update(keyframe->disable_opengl_masking);
3282 active_point->update((int64_t)mwindow->cwindow->gui->affected_point);
3285 void CWindowMaskGUI::handle_event()
3288 if( event_caller == this->focus_x ||
3289 event_caller == this->focus_y ) {
3292 else if( event_caller == this->x ||
3293 event_caller == this->y ) {
3299 get_keyframe(track, autos, keyframe, mask, point, 0);
3301 mwindow->undo->update_undo_before(_("mask point"), this);
3304 float px = atof(x->get_text());
3305 float py = atof(y->get_text());
3306 float dx = px - point->x, dy = py - point->y;
3307 #ifdef USE_KEYFRAME_SPANNING
3308 // Create temp keyframe
3309 MaskAuto temp_keyframe(mwindow->edl, autos);
3310 temp_keyframe.copy_data(keyframe);
3311 // Get affected point in temp keyframe
3312 mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
3314 MaskPoints &points = mask->points;
3315 int gang = gang_point->get_value();
3316 int k = mwindow->cwindow->gui->affected_point;
3317 int n = gang ? points.size() : k+1;
3318 for( int i=gang? 0 : k; i<n; ++i ) {
3319 if( i < 0 || i >= points.size() ) continue;
3320 MaskPoint *point = points[i];
3321 point->x += dx; point->y += dy;
3323 #ifdef USE_KEYFRAME_SPANNING
3324 // Commit to spanned keyframes
3325 autos->update_parameter(&temp_keyframe);
3328 mwindow->undo->update_undo_after(_("mask point"), LOAD_AUTOMATION);
3336 void CWindowMaskGUI::set_focused(int v, float cx, float cy)
3338 CWindowGUI *cgui = mwindow->cwindow->gui;
3339 cgui->unlock_window();
3340 lock_window("CWindowMaskGUI::set_focused");
3342 focus->update(focused = v);
3343 focus_x->update(cx);
3344 focus_y->update(cy);
3346 cgui->lock_window("CWindowCanvas::set_focused");
3349 void CWindowMaskGUI::update_buttons(MaskAuto *keyframe, int k)
3351 int text_color = get_resources()->default_text_color;
3352 int high_color = get_resources()->button_highlighted;
3353 for( int i=0; i<SUBMASKS; ++i ) {
3354 int color = text_color;
3356 SubMask *submask = keyframe->get_submask(i);
3357 if( submask && submask->points.size() )
3360 mask_blabels[i]->set_color(color);
3361 mask_buttons[i]->update(i==k ? 1 : 0);
3365 // typ=0, this mask, this point
3366 // typ>0, this mask, all points
3367 // typ<0, all masks, all points
3368 // dxy= on? pt[+1]-pt[-1] : dxy=0
3369 int CWindowMaskGUI::smooth_mask(int typ, int on)
3376 #ifdef USE_KEYFRAME_SPANNING
3382 mwindow->undo->update_undo_before(_("mask smooth"), this);
3384 // Get existing keyframe
3385 get_keyframe(track, autos, keyframe,
3386 mask, point, create_it);
3388 #ifdef USE_KEYFRAME_SPANNING
3389 MaskAuto temp_keyframe(mwindow->edl, autos);
3390 temp_keyframe.copy_data(keyframe);
3391 keyframe = &temp_keyframe;
3393 int k = mwindow->edl->session->cwindow_mask;
3394 int n = typ>=0 ? k+1 : keyframe->masks.size();
3395 for( int j=typ<0? 0 : k; j<n; ++j ) {
3396 if( !mask_enables[j]->get_value() ) continue;
3397 SubMask *sub_mask = keyframe->get_submask(j);
3398 MaskPoints &points = sub_mask->points;
3399 int psz = points.size();
3400 if( psz < 3 ) continue;
3401 int l = mwindow->cwindow->gui->affected_point;
3402 if( l > psz ) l = psz;
3403 int m = typ ? psz : l+1;
3404 for( int i=typ ? 0 : l; i<m; ++i ) {
3405 int i0 = i-1, i1 = i+1;
3406 if( i0 < 0 ) i0 = psz-1;
3407 if( i1 >= psz ) i1 = 0;
3408 MaskPoint *p0 = points[i0];
3409 MaskPoint *p = points[i];
3410 MaskPoint *p1 = points[i1];
3411 float dx = !on ? 0 : p1->x - p0->x;
3412 float dy = !on ? 0 : p1->y - p0->y;
3413 p->control_x1 = -dx/4; p->control_y1 = -dy/4;
3414 p->control_x2 = dx/4; p->control_y2 = dy/4;
3417 #ifdef USE_KEYFRAME_SPANNING
3418 autos->update_parameter(keyframe);
3423 mwindow->undo->update_undo_after(_("mask smooth"), LOAD_AUTOMATION);
3427 int CWindowMaskGUI::save_mask(const char *nm)
3429 int k = mwindow->edl->session->cwindow_mask;
3435 get_keyframe(track, autos, keyframe, mask, point, 0);
3436 if( !track ) return 0;
3437 SubMask *sub_mask = keyframe->get_submask(k);
3438 ArrayList<SubMask *> masks;
3440 int i = masks.size();
3442 if( strcmp(masks[i]->name, nm) ) continue;
3443 masks.remove_object_number(i++);
3445 mask = new SubMask(0, -1);
3446 strncpy(mask->name, nm, sizeof(mask->name)-1);
3447 mask->copy_from(*sub_mask, 0);
3450 masks.remove_all_objects();
3454 int CWindowMaskGUI::del_mask(const char *nm)
3456 ArrayList<SubMask *> masks;
3458 int i = masks.size();
3460 if( strcmp(masks[i]->name, nm) ) continue;
3461 masks.remove_object_number(i++);
3464 masks.remove_all_objects();
3468 int CWindowMaskGUI::center_mask()
3470 int k = mwindow->edl->session->cwindow_mask;
3476 #ifdef USE_KEYFRAME_SPANNING
3481 get_keyframe(track, autos, keyframe,
3482 mask, point, create_it);
3483 if( !track ) return 0;
3484 mwindow->undo->update_undo_before(_("mask center"), this);
3486 // Get existing keyframe
3487 #ifdef USE_KEYFRAME_SPANNING
3488 MaskAuto temp_keyframe(mwindow->edl, autos);
3489 temp_keyframe.copy_data(keyframe);
3490 keyframe = &temp_keyframe;
3492 SubMask *sub_mask = keyframe->get_submask(k);
3493 MaskPoints &points = sub_mask->points;
3494 int psz = points.size();
3496 float cx = 0, cy = 0;
3497 for( int i=0; i<psz; ++i ) {
3498 MaskPoint *p = points[i];
3499 cx += p->x; cy += p->y;
3501 cx /= psz; cy /= psz;
3502 cx -= mwindow->edl->session->output_w / 2.f;
3503 cy -= mwindow->edl->session->output_h / 2.f;
3504 for( int i=0; i<psz; ++i ) {
3505 MaskPoint *p = points[i];
3506 p->x -= cx; p->y -= cy;
3509 #ifdef USE_KEYFRAME_SPANNING
3510 autos->update_parameter(keyframe);
3513 mwindow->undo->update_undo_after(_("mask center"), LOAD_AUTOMATION);
3517 int CWindowMaskGUI::normal_mask()
3519 int k = mwindow->edl->session->cwindow_mask;
3525 #ifdef USE_KEYFRAME_SPANNING
3530 // Get existing keyframe
3531 get_keyframe(track, autos, keyframe,
3532 mask, point, create_it);
3533 if( !track ) return 0;
3534 mwindow->undo->update_undo_before(_("mask normal"), this);
3536 #ifdef USE_KEYFRAME_SPANNING
3537 MaskAuto temp_keyframe(mwindow->edl, autos);
3538 temp_keyframe.copy_data(keyframe);
3539 keyframe = &temp_keyframe;
3541 SubMask *sub_mask = keyframe->get_submask(k);
3542 MaskPoints &points = sub_mask->points;
3543 int psz = points.size();
3544 float cx = 0, cy = 0;
3547 for( int i=0; i<psz; ++i ) {
3548 MaskPoint *p = points[i];
3549 cx += p->x; cy += p->y;
3551 cx /= psz; cy /= psz;
3552 for( int i=0; i<psz; ++i ) {
3553 MaskPoint *p = points[i];
3554 float dx = fabsf(p->x-cx), dy = fabsf(p->y-cy);
3555 double d = sqrt(dx*dx + dy*dy);
3556 if( dr < d ) dr = d;
3560 float out_w = mwindow->edl->session->output_w;
3561 float out_h = mwindow->edl->session->output_h;
3562 float r = bmax(out_w, out_h);
3563 float s = r / (4 * dr * sqrt(2.));
3564 for( int i=0; i<psz; ++i ) {
3565 MaskPoint *p = points[i];
3566 float x = p->x, y = p->y;
3567 p->x = (x-cx) * s + cx;
3568 p->y = (y-cy) * s + cy;
3569 p->control_x1 *= s; p->control_y1 *= s;
3570 p->control_x2 *= s; p->control_y2 *= s;
3573 #ifdef USE_KEYFRAME_SPANNING
3574 autos->update_parameter(keyframe);
3578 mwindow->undo->update_undo_after(_("mask normal"), LOAD_AUTOMATION);
3583 CWindowMaskLoadList::CWindowMaskLoadList(MWindow *mwindow, CWindowMaskGUI *gui)
3584 : BC_ListBox(-1, -1, 1, 1, LISTBOX_TEXT, 0, 0, 0, 1, 0, 1)
3586 this->mwindow = mwindow;
3591 CWindowMaskLoadList::~CWindowMaskLoadList()
3596 int CWindowMaskLoadList::handle_event()
3603 #ifdef USE_KEYFRAME_SPANNING
3609 mwindow->undo->update_undo_before(_("mask shape"), this);
3611 // Get existing keyframe
3612 gui->get_keyframe(track, autos, keyframe,
3613 mask, point, create_it);
3614 CWindowMaskItem *item = (CWindowMaskItem *) get_selection(0, 0);
3615 if( track && item ) {
3616 #ifdef USE_KEYFRAME_SPANNING
3617 MaskAuto temp_keyframe(mwindow->edl, autos);
3618 temp_keyframe.copy_data(keyframe);
3619 keyframe = &temp_keyframe;
3620 mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
3622 ArrayList<SubMask *> masks;
3623 gui->load_masks(masks);
3624 mask->copy_from(*masks[item->id], 0);
3625 masks.remove_all_objects();
3626 #ifdef USE_KEYFRAME_SPANNING
3627 autos->update_parameter(keyframe);
3630 gui->update_preview(1);
3632 mwindow->undo->update_undo_after(_("mask shape"), LOAD_AUTOMATION);
3636 void CWindowMaskLoadList::create_objects()
3638 shape_items.remove_all_objects();
3639 ArrayList<SubMask *> masks;
3640 gui->load_masks(masks);
3641 for( int i=0; i<masks.size(); ++i )
3642 shape_items.append(new CWindowMaskItem(masks[i]->name, i));
3643 masks.remove_all_objects();
3644 update(&shape_items, 0, 0, 1);
3647 CWindowMaskLoad::CWindowMaskLoad(MWindow *mwindow,
3648 CWindowMaskGUI *gui, int x, int y, int w)
3649 : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_load_images"))
3651 this->mwindow = mwindow;
3653 set_tooltip(_("Load preset"));
3656 int CWindowMaskLoad::handle_event()
3658 gui->mask_load_list->create_objects();
3660 get_abs_cursor(px, py);
3661 return gui->mask_load_list->activate(px, py, xS(120),yS(160));
3665 CWindowMaskSave::CWindowMaskSave(MWindow *mwindow,
3666 CWindowMaskGUI *gui, int x, int y, int w)
3667 : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_save_images"))
3669 this->mwindow = mwindow;
3671 set_tooltip(_("Save preset"));
3674 CWindowMaskSave::~CWindowMaskSave()
3678 int CWindowMaskSave::handle_event()
3685 gui->get_keyframe(track, autos, keyframe, mask, point, 0);
3688 gui->get_abs_cursor(sx, sy);
3689 if( !gui->preset_dialog )
3690 gui->preset_dialog = new CWindowMaskPresetDialog(mwindow, gui);
3691 gui->preset_dialog->start_dialog(sx, sy, keyframe);
3696 CWindowMaskPresetDialog::CWindowMaskPresetDialog(MWindow *mwindow, CWindowMaskGUI *gui)
3699 this->mwindow = mwindow;
3704 CWindowMaskPresetDialog::~CWindowMaskPresetDialog()
3709 void CWindowMaskPresetDialog::handle_close_event(int result)
3714 void CWindowMaskPresetDialog::handle_done_event(int result)
3716 if( result ) return;
3717 const char *nm = pgui->preset_text->get_text();
3724 BC_Window* CWindowMaskPresetDialog::new_gui()
3726 pgui = new CWindowMaskPresetGUI(this, sx, sy,
3727 keyframe ? _(PROGRAM_NAME ": Save Mask") :
3728 _(PROGRAM_NAME ": Delete Mask"));
3729 pgui->create_objects();
3733 void CWindowMaskPresetDialog::start_dialog(int sx, int sy, MaskAuto *keyframe)
3736 this->sx = sx; this->sy = sy;
3737 this->keyframe = keyframe;
3741 CWindowMaskPresetGUI::CWindowMaskPresetGUI(CWindowMaskPresetDialog *preset_dialog,
3742 int x, int y, const char *title)
3743 : BC_Window(title, x, y, xS(320), yS(100), xS(320), yS(100), 0, 0, 1)
3745 this->preset_dialog = preset_dialog;
3746 // *** CONTEXT_HELP ***
3747 context_help_set_keyword("Masks");
3750 void CWindowMaskPresetGUI::create_objects()
3752 int xs8 = xS(8), xs10 = xS(10);
3754 int x = xs10, y = ys10;
3755 lock_window("CWindowMaskPresetGUI::create_objects");
3757 add_subwindow(title = new BC_Title(x, y,
3758 preset_dialog->keyframe ? _("Save mask:") : _("Delete mask:")));
3759 int x1 = x + title->get_w() + xs8;
3760 int x2 = get_w() - x - xs8 - x1 -
3761 BC_WindowBase::get_resources()->listbox_button[0]->get_w();
3762 CWindowMaskGUI *gui = preset_dialog->gui;
3763 preset_text = new CWindowMaskPresetText(this,
3764 x1, y, x2, yS(120), gui->mask_name->get_text());
3765 preset_text->create_objects();
3766 preset_text->set_tooltip(_("Mask name"));
3767 preset_text->update_items();
3768 add_subwindow(new BC_OKButton(this));
3769 add_subwindow(new BC_CancelButton(this));
3775 CWindowMaskPresetText::CWindowMaskPresetText(CWindowMaskPresetGUI *pgui,
3776 int x, int y, int w, int h, const char *text)
3777 : BC_PopupTextBox(pgui, 0, text, x, y, w, h)
3782 int CWindowMaskPresetText::handle_event()
3784 int k = get_number();
3785 if( k >= 0 && k<mask_items.size() )
3786 update(mask_items[k]->get_text());
3790 void CWindowMaskPresetText::update_items()
3792 mask_items.remove_all_objects();
3793 ArrayList<SubMask *> masks;
3794 pgui->preset_dialog->gui->load_masks(masks);
3795 for( int i=0; i<masks.size(); ++i ) {
3796 char text[BCSTRLEN]; memset(text, 0, sizeof(text));
3797 strncpy(text, masks[i]->name, sizeof(text)-1);
3798 mask_items.append(new CWindowMaskItem(text));
3800 masks.remove_all_objects();
3801 update_list(&mask_items);
3805 CWindowMaskDelete::CWindowMaskDelete(MWindow *mwindow,
3806 CWindowMaskGUI *gui, int x, int y, int w)
3807 : BC_Button(x, y, mwindow->theme->get_image_set("mask_prst_trsh_images"))
3809 this->mwindow = mwindow;
3811 set_tooltip(_("Delete preset"));
3814 int CWindowMaskDelete::handle_event()
3817 gui->get_abs_cursor(sx, sy);
3818 if( !gui->preset_dialog )
3819 gui->preset_dialog = new CWindowMaskPresetDialog(mwindow, gui);
3820 gui->preset_dialog->start_dialog(sx, sy, 0);
3825 CWindowMaskCenter::CWindowMaskCenter(MWindow *mwindow,
3826 CWindowMaskGUI *gui, int x, int y, int w)
3827 : BC_Button(x, y, mwindow->theme->get_image_set("mask_pstn_cen_images"))
3829 this->mwindow = mwindow;
3831 set_tooltip(_("center mask"));
3834 int CWindowMaskCenter::handle_event()
3836 return gui->center_mask();
3840 CWindowMaskNormal::CWindowMaskNormal(MWindow *mwindow,
3841 CWindowMaskGUI *gui, int x, int y, int w)
3842 : BC_Button(x, y, mwindow->theme->get_image_set("mask_pstn_nrm_images"))
3844 this->mwindow = mwindow;
3846 set_tooltip(_("normalize mask"));
3849 int CWindowMaskNormal::handle_event()
3851 return gui->normal_mask();
3855 CWindowMaskShape::CWindowMaskShape(MWindow *mwindow, CWindowMaskGUI *gui,
3856 const char *images, int shape, int x, int y, const char *tip)
3857 : BC_Button(x, y, mwindow->theme->get_image_set(images))
3859 this->mwindow = mwindow;
3861 this->shape = shape;
3865 CWindowMaskShape::~CWindowMaskShape()
3869 void CWindowMaskShape::builtin_shape(int i, SubMask *sub_mask)
3871 int out_w = mwindow->edl->session->output_w;
3872 int out_h = mwindow->edl->session->output_h;
3873 float cx = out_w/2.f, cy = out_h/2.f;
3874 float r = bmax(cx, cy) / 4.f;
3875 double c = 4*(sqrt(2.)-1)/3; // bezier aprox circle
3876 float r2 = r / 2.f, rc = r*c, r4 = r / 4.f;
3878 MaskPoints &points = sub_mask->points;
3879 points.remove_all_objects();
3881 case MASK_SHAPE_SQUARE:
3882 points.append(pt = new MaskPoint());
3883 pt->x = cx - r; pt->y = cy - r;
3884 points.append(pt = new MaskPoint());
3885 pt->x = cx + r; pt->y = cy - r;
3886 points.append(pt = new MaskPoint());
3887 pt->x = cx + r; pt->y = cy + r;
3888 points.append(pt = new MaskPoint());
3889 pt->x = cx - r; pt->y = cy + r;
3891 case MASK_SHAPE_CIRCLE:
3892 points.append(pt = new MaskPoint());
3893 pt->x = cx - r; pt->y = cy - r;
3894 pt->control_x1 = -rc; pt->control_y1 = rc;
3895 pt->control_x2 = rc; pt->control_y2 = -rc;
3896 points.append(pt = new MaskPoint());
3897 pt->x = cx + r; pt->y = cy - r;
3898 pt->control_x1 = -rc; pt->control_y1 = -rc;
3899 pt->control_x2 = rc; pt->control_y2 = rc;
3900 points.append(pt = new MaskPoint());
3901 pt->x = cx + r; pt->y = cy + r;
3902 pt->control_x1 = rc; pt->control_y1 = -rc;
3903 pt->control_x2 = -rc; pt->control_y2 = rc;
3904 points.append(pt = new MaskPoint());
3905 pt->x = cx - r; pt->y = cy + r;
3906 pt->control_x1 = rc; pt->control_y1 = rc;
3907 pt->control_x2 = -rc; pt->control_y2 = -rc;
3909 case MASK_SHAPE_TRIANGLE:
3910 points.append(pt = new MaskPoint());
3911 pt->x = cx + 0; pt->y = cy - r*(sqrt(3.)-1.);
3912 points.append(pt = new MaskPoint());
3913 pt->x = cx + r; pt->y = cy + r;
3914 points.append(pt = new MaskPoint());
3915 pt->x = cx - r; pt->y = cy + r;
3917 case MASK_SHAPE_OVAL:
3918 points.append(pt = new MaskPoint());
3919 pt->x = cx - r; pt->y = cy - r2;
3920 pt->control_x1 = -r2; pt->control_y1 = r4;
3921 pt->control_x2 = r2; pt->control_y2 = -r4;
3922 points.append(pt = new MaskPoint());
3923 pt->x = cx + r; pt->y = cy - r2;
3924 pt->control_x1 = -r2; pt->control_y1 = -r4;
3925 pt->control_x2 = r2; pt->control_y2 = r4;
3926 points.append(pt = new MaskPoint());
3927 pt->x = cx + r; pt->y = cy + r2;
3928 pt->control_x1 = r2; pt->control_y1 = -r4;
3929 pt->control_x2 = -r2; pt->control_y2 = r4;
3930 points.append(pt = new MaskPoint());
3931 pt->x = cx - r; pt->y = cy + r2;
3932 pt->control_x1 = r2; pt->control_y1 = r4;
3933 pt->control_x2 = -r2; pt->control_y2 = -r4;
3938 int CWindowMaskShape::handle_event()
3945 #ifdef USE_KEYFRAME_SPANNING
3951 mwindow->undo->update_undo_before(_("mask shape"), this);
3953 // Get existing keyframe
3954 gui->get_keyframe(track, autos, keyframe,
3955 mask, point, create_it);
3957 #ifdef USE_KEYFRAME_SPANNING
3958 MaskAuto temp_keyframe(mwindow->edl, autos);
3959 temp_keyframe.copy_data(keyframe);
3960 keyframe = &temp_keyframe;
3961 mask = temp_keyframe.get_submask(mwindow->edl->session->cwindow_mask);
3964 builtin_shape(shape, mask);
3965 #ifdef USE_KEYFRAME_SPANNING
3966 autos->update_parameter(keyframe);
3969 gui->update_preview(1);
3972 mwindow->undo->update_undo_after(_("mask shape"), LOAD_AUTOMATION);
3976 void CWindowMaskGUI::load_masks(ArrayList<SubMask *> &masks)
3978 char path[BCTEXTLEN];
3979 sprintf(path, "%s/%s", File::get_config_path(), MASKS_FILE);
3981 fs.complete_path(path);
3983 file.read_from_file(path, 1);
3985 masks.remove_all_objects();
3987 while( !(result = file.read_tag()) ) {
3988 if( file.tag.title_is("MASK") ) {
3989 SubMask *sub_mask = new SubMask(0, -1);
3990 char name[BCTEXTLEN]; name[0] = 0;
3991 file.tag.get_property("NAME", name);
3992 strncpy(sub_mask->name, name, sizeof(sub_mask->name));
3993 sub_mask->load(&file);
3994 masks.append(sub_mask);
3999 void CWindowMaskGUI::save_masks(ArrayList<SubMask *> &masks)
4002 for( int i=0; i<masks.size(); ++i ) {
4003 SubMask *sub_mask = masks[i];
4004 sub_mask->copy(&file);
4006 file.terminate_string();
4008 char path[BCTEXTLEN];
4009 sprintf(path, "%s/%s", File::get_config_path(), MASKS_FILE);
4011 fs.complete_path(path);
4012 file.write_to_file(path);
4016 CWindowRulerGUI::CWindowRulerGUI(MWindow *mwindow, CWindowTool *thread)
4017 : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Ruler"), xS(320), yS(240))
4019 // *** CONTEXT_HELP ***
4020 context_help_set_keyword("Compositor Toolbar");
4023 CWindowRulerGUI::~CWindowRulerGUI()
4027 void CWindowRulerGUI::create_objects()
4029 int xs10 = xS(10), xs200 = xS(200);
4030 int ys5 = yS(5), ys10 = yS(10);
4031 int x = xs10, y = ys10, x1 = xS(100);
4034 lock_window("CWindowRulerGUI::create_objects");
4035 add_subwindow(title = new BC_Title(x, y, _("Current:")));
4036 add_subwindow(current = new BC_TextBox(x1, y, xs200, 1, ""));
4037 y += title->get_h() + ys5;
4038 add_subwindow(title = new BC_Title(x, y, _("Point 1:")));
4039 add_subwindow(point1 = new BC_TextBox(x1, y, xs200, 1, ""));
4040 y += title->get_h() + ys5;
4041 add_subwindow(title = new BC_Title(x, y, _("Point 2:")));
4042 add_subwindow(point2 = new BC_TextBox(x1, y, xs200, 1, ""));
4043 y += title->get_h() + ys5;
4044 add_subwindow(title = new BC_Title(x, y, _("Deltas:")));
4045 add_subwindow(deltas = new BC_TextBox(x1, y, xs200, 1, ""));
4046 y += title->get_h() + ys5;
4047 add_subwindow(title = new BC_Title(x, y, _("Distance:")));
4048 add_subwindow(distance = new BC_TextBox(x1, y, xs200, 1, ""));
4049 y += title->get_h() + ys5;
4050 add_subwindow(title = new BC_Title(x, y, _("Angle:")));
4051 add_subwindow(angle = new BC_TextBox(x1, y, xs200, 1, ""));
4052 y += title->get_h() + ys10;
4053 char string[BCTEXTLEN];
4055 _("Press Ctrl to lock ruler to the\nnearest 45%c%c angle."),
4056 0xc2, 0xb0); // degrees utf
4057 add_subwindow(title = new BC_Title(x,
4060 y += title->get_h() + ys10;
4061 sprintf(string, _("Press Alt to translate the ruler."));
4062 add_subwindow(title = new BC_Title(x,
4069 void CWindowRulerGUI::update()
4071 char string[BCTEXTLEN];
4072 int cx = mwindow->session->cwindow_output_x;
4073 int cy = mwindow->session->cwindow_output_y;
4074 sprintf(string, "%d, %d", cx, cy);
4075 current->update(string);
4076 double x1 = mwindow->edl->session->ruler_x1;
4077 double y1 = mwindow->edl->session->ruler_y1;
4078 sprintf(string, "%.0f, %.0f", x1, y1);
4079 point1->update(string);
4080 double x2 = mwindow->edl->session->ruler_x2;
4081 double y2 = mwindow->edl->session->ruler_y2;
4082 sprintf(string, "%.0f, %.0f", x2, y2);
4083 point2->update(string);
4084 double dx = x2 - x1, dy = y2 - y1;
4085 sprintf(string, "%s%.0f, %s%.0f", (dx>=0? "+":""), dx, (dy>=0? "+":""), dy);
4086 deltas->update(string);
4087 double d = sqrt(dx*dx + dy*dy);
4088 sprintf(string, _("%0.01f pixels"), d);
4089 distance->update(string);
4090 double a = d > 0 ? (atan2(-dy, dx) * 180/M_PI) : 0.;
4091 sprintf(string, "%0.02f %c%c", a, 0xc2, 0xb0);
4092 angle->update(string);
4095 void CWindowRulerGUI::handle_event()