r802: Remove renderframfsclient and renderfarmfsserver .h and .C from Makefile.am...
[cinelerra_cv/mob.git] / cinelerra / cwindowtool.C
blobe418db8eded4f7c3fd1c298a02e100624f8a1144
1 #include "automation.h"
2 #include "clip.h"
3 #include "condition.h"
4 #include "cpanel.h"
5 #include "cplayback.h"
6 #include "cwindow.h"
7 #include "cwindowgui.h"
8 #include "cwindowtool.h"
9 #include "edl.h"
10 #include "edlsession.h"
11 #include "floatauto.h"
12 #include "floatautos.h"
13 #include "keys.h"
14 #include "language.h"
15 #include "localsession.h"
16 #include "mainsession.h"
17 #include "maskauto.h"
18 #include "maskautos.h"
19 #include "mwindow.h"
20 #include "mwindowgui.h"
21 #include "theme.h"
22 #include "track.h"
23 #include "trackcanvas.h"
24 #include "transportque.h"
27 CWindowTool::CWindowTool(MWindow *mwindow, CWindowGUI *gui)
28  : Thread()
30         this->mwindow = mwindow;
31         this->gui = gui;
32         tool_gui = 0;
33         done = 0;
34         current_tool = CWINDOW_NONE;
35         set_synchronous(1);
36         input_lock = new Condition(0, "CWindowTool::input_lock");
37         output_lock = new Condition(1, "CWindowTool::output_lock");
38         tool_gui_lock = new Mutex("CWindowTool::tool_gui_lock");
41 CWindowTool::~CWindowTool()
43         done = 1;
44         stop_tool();
45         input_lock->unlock();
46         Thread::join();
47         delete input_lock;
48         delete output_lock;
49         delete tool_gui_lock;
52 void CWindowTool::start_tool(int operation)
54         CWindowToolGUI *new_gui = 0;
55         int result = 0;
57 //printf("CWindowTool::start_tool 1\n");
58         if(current_tool != operation)
59         {
60                 current_tool = operation;
61                 switch(operation)
62                 {
63                         case CWINDOW_EYEDROP:
64                                 new_gui = new CWindowEyedropGUI(mwindow, this);
65                                 break;
66                         case CWINDOW_CROP:
67                                 new_gui = new CWindowCropGUI(mwindow, this);
68                                 break;
69                         case CWINDOW_CAMERA:
70                                 new_gui = new CWindowCameraGUI(mwindow, this);
71                                 break;
72                         case CWINDOW_PROJECTOR:
73                                 new_gui = new CWindowProjectorGUI(mwindow, this);
74                                 break;
75                         case CWINDOW_MASK:
76                                 new_gui = new CWindowMaskGUI(mwindow, this);
77                                 break;
78                         default:
79                                 result = 1;
80                                 stop_tool();
81                                 break;
82                 }
84 //printf("CWindowTool::start_tool 1\n");
87                 if(!result)
88                 {
89                         stop_tool();
90 // Wait for previous tool GUI to finish
91                         output_lock->lock("CWindowTool::start_tool");
92                         this->tool_gui = new_gui;
93                         tool_gui->create_objects();
94                         
95                         if(mwindow->edl->session->tool_window &&
96                                 mwindow->session->show_cwindow) tool_gui->show_window();
97                         tool_gui->flush();
98                         
99                         
100 // Signal thread to run next tool GUI
101                         input_lock->unlock();
102                 }
103 //printf("CWindowTool::start_tool 1\n");
104         }
105         else
106         if(tool_gui) 
107         {
108                 tool_gui->lock_window("CWindowTool::start_tool");
109                 tool_gui->update();
110                 tool_gui->unlock_window();
111         }
113 //printf("CWindowTool::start_tool 2\n");
118 void CWindowTool::stop_tool()
120         if(tool_gui)
121         {
122                 tool_gui->lock_window("CWindowTool::stop_tool");
123                 tool_gui->set_done(0);
124                 tool_gui->unlock_window();
125         }
128 void CWindowTool::show_tool()
130         if(tool_gui && mwindow->edl->session->tool_window)
131         {
132                 tool_gui->lock_window("CWindowTool::show_tool");
133                 tool_gui->show_window();
134                 tool_gui->unlock_window();
135         }
138 void CWindowTool::hide_tool()
140         if(tool_gui && mwindow->edl->session->tool_window)
141         {
142                 tool_gui->lock_window("CWindowTool::show_tool");
143                 tool_gui->hide_window();
144                 tool_gui->unlock_window();
145         }
149 void CWindowTool::run()
151         while(!done)
152         {
153                 input_lock->lock("CWindowTool::run");
154                 if(!done)
155                 {
156                         tool_gui->run_window();
157                         tool_gui_lock->lock("CWindowTool::run");
158                         delete tool_gui;
159                         tool_gui = 0;
160                         tool_gui_lock->unlock();
161                 }
162                 output_lock->unlock();
163         }
166 void CWindowTool::update_show_window()
168         if(tool_gui)
169         {
170                 tool_gui->lock_window("CWindowTool::update_show_window");
172                 if(mwindow->edl->session->tool_window) 
173                 {
174                         tool_gui->update();
175                         tool_gui->show_window();
176                 }
177                 else
178                         tool_gui->hide_window();
179                 tool_gui->flush();
181                 tool_gui->unlock_window();
182         }
185 void CWindowTool::update_values()
187         tool_gui_lock->lock("CWindowTool::update_values");
188         if(tool_gui)
189         {
190                 tool_gui->lock_window("CWindowTool::update_values");
191                 tool_gui->update();
192                 tool_gui->flush();
193                 tool_gui->unlock_window();
194         }
195         tool_gui_lock->unlock();
204 CWindowToolGUI::CWindowToolGUI(MWindow *mwindow, 
205         CWindowTool *thread, 
206         char *title,
207         int w, 
208         int h)
209  : BC_Window(title,
210         mwindow->session->ctool_x,
211         mwindow->session->ctool_y,
212         w,
213         h,
214         w,
215         h,
216         0,
217         0,
218         1)
220         this->mwindow = mwindow;
221         this->thread = thread;
222         current_operation = 0;
225 CWindowToolGUI::~CWindowToolGUI()
229 int CWindowToolGUI::close_event()
231         hide_window();
232         flush();
233         mwindow->edl->session->tool_window = 0;
234         unlock_window();
238         thread->gui->lock_window("CWindowToolGUI::close_event");
239         thread->gui->composite_panel->set_operation(mwindow->edl->session->cwindow_operation);
240         thread->gui->flush();
241         thread->gui->unlock_window();
243         lock_window("CWindowToolGUI::close_event");
244         return 1;
247 int CWindowToolGUI::keypress_event()
249         if(get_keypress() == 'w' || get_keypress() == 'W')
250                 return close_event();
251         return 0;
254 int CWindowToolGUI::translation_event()
256         mwindow->session->ctool_x = get_x();
257         mwindow->session->ctool_y = get_y();
258         return 0;
266 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value)
267  : BC_TumbleTextBox(gui, 
268                 (float)value,
269                 (float)-65536,
270                 (float)65536,
271                 x, 
272                 y, 
273                 100)
275         this->gui = gui;
278 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value)
279  : BC_TumbleTextBox(gui, 
280                 (int64_t)value,
281                 (int64_t)-65536,
282                 (int64_t)65536,
283                 x, 
284                 y, 
285                 100)
287         this->gui = gui;
289 int CWindowCoord::handle_event()
291         gui->event_caller = this;
292         gui->handle_event();
293         return 1;
297 CWindowCropOK::CWindowCropOK(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
298  : BC_GenericButton(x, y, _("Do it"))
300         this->mwindow = mwindow;
301         this->gui = gui;
303 int CWindowCropOK::handle_event()
305         mwindow->crop_video();
306         return 1;
310 int CWindowCropOK::keypress_event()
312         if(get_keypress() == 0xd) 
313         {
314                 handle_event();
315                 return 1;
316         }
317         return 0;
326 CWindowCropGUI::CWindowCropGUI(MWindow *mwindow, CWindowTool *thread)
327  : CWindowToolGUI(mwindow, 
328         thread,
329         PROGRAM_NAME ": Crop",
330         330,
331         100)
336 CWindowCropGUI::~CWindowCropGUI()
340 void CWindowCropGUI::create_objects()
342         int x = 10, y = 10;
343         BC_TumbleTextBox *textbox;
344         BC_Title *title;
346         int column1 = 0;
347         int pad = MAX(BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1), 
348                 BC_Title::calculate_h(this, "X")) + 5;
349         add_subwindow(title = new BC_Title(x, y, _("X1:")));
350         column1 = MAX(column1, title->get_w());
351         y += pad;
352         add_subwindow(title = new BC_Title(x, y, _("W:")));
353         column1 = MAX(column1, title->get_w());
354         y += pad;
355         add_subwindow(new CWindowCropOK(mwindow, thread->tool_gui, x, y));
357         x += column1 + 5;
358         y = 10;
359         x1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_x1);
360         x1->create_objects();
361         y += pad;
362         width = new CWindowCoord(thread->tool_gui, 
363                 x, 
364                 y, 
365                 mwindow->edl->session->crop_x2 - 
366                         mwindow->edl->session->crop_x1);
367         width->create_objects();
370         x += x1->get_w() + 10;
371         y = 10;
372         int column2 = 0;
373         add_subwindow(title = new BC_Title(x, y, _("Y1:")));
374         column2 = MAX(column2, title->get_w());
375         y += pad;
376         add_subwindow(title = new BC_Title(x, y, _("H:")));
377         column2 = MAX(column2, title->get_w());
378         y += pad;
380         y = 10;
381         x += column2 + 5;
382         y1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_y1);
383         y1->create_objects();
384         y += pad;
385         height = new CWindowCoord(thread->tool_gui, 
386                 x, 
387                 y, 
388                 mwindow->edl->session->crop_y2 - 
389                         mwindow->edl->session->crop_y1);
390         height->create_objects();
393 void CWindowCropGUI::handle_event()
395         int new_x1, new_y1;
396         new_x1 = atol(x1->get_text());
397         new_y1 = atol(y1->get_text());
398         if(new_x1 != mwindow->edl->session->crop_x1)
399         {
400                 mwindow->edl->session->crop_x2 = new_x1 +
401                         mwindow->edl->session->crop_x2 - 
402                         mwindow->edl->session->crop_x1;
403                 mwindow->edl->session->crop_x1 = new_x1;
404         }
405         if(new_y1 != mwindow->edl->session->crop_y1)
406         {
407                 mwindow->edl->session->crop_y2 = new_y1 +
408                         mwindow->edl->session->crop_y2 -
409                         mwindow->edl->session->crop_y1;
410                 mwindow->edl->session->crop_y1 = atol(y1->get_text());
411         }
412         mwindow->edl->session->crop_x2 = atol(width->get_text()) + 
413                 mwindow->edl->session->crop_x1;
414         mwindow->edl->session->crop_y2 = atol(height->get_text()) + 
415                 mwindow->edl->session->crop_y1;
416         update();
417         mwindow->cwindow->gui->lock_window("CWindowCropGUI::handle_event");
418         mwindow->cwindow->gui->canvas->draw_refresh();
419         mwindow->cwindow->gui->unlock_window();
422 void CWindowCropGUI::update()
424         x1->update((int64_t)mwindow->edl->session->crop_x1);
425         y1->update((int64_t)mwindow->edl->session->crop_y1);
426         width->update((int64_t)mwindow->edl->session->crop_x2 - 
427                 mwindow->edl->session->crop_x1);
428         height->update((int64_t)mwindow->edl->session->crop_y2 - 
429                 mwindow->edl->session->crop_y1);
437 CWindowEyedropGUI::CWindowEyedropGUI(MWindow *mwindow, CWindowTool *thread)
438  : CWindowToolGUI(mwindow, 
439         thread,
440         PROGRAM_NAME ": Color",
441         150,
442         150)
446 CWindowEyedropGUI::~CWindowEyedropGUI()
450 void CWindowEyedropGUI::create_objects()
452         int x = 10;
453         int y = 10;
454         int x2 = 70;
455         BC_Title *title1, *title2, *title3;
456         add_subwindow(title1 = new BC_Title(x, y, "Red:"));
457         y += title1->get_h() + 5;
458         add_subwindow(title2 = new BC_Title(x, y, "Green:"));
459         y += title2->get_h() + 5;
460         add_subwindow(title3 = new BC_Title(x, y, "Blue:"));
463         add_subwindow(red = new BC_Title(x2, title1->get_y(), "0"));
464         add_subwindow(green = new BC_Title(x2, title2->get_y(), "0"));
465         add_subwindow(blue = new BC_Title(x2, title3->get_y(), "0"));
467         y = blue->get_y() + blue->get_h() + 5;
468         add_subwindow(sample = new BC_SubWindow(x, y, 50, 50));
469         update();       
472 void CWindowEyedropGUI::update()
474         red->update(mwindow->edl->local_session->red);
475         green->update(mwindow->edl->local_session->green);
476         blue->update(mwindow->edl->local_session->blue);
478         int red = (int)(CLIP(mwindow->edl->local_session->red, 0, 1) * 0xff);
479         int green = (int)(CLIP(mwindow->edl->local_session->green, 0, 1) * 0xff);
480         int blue = (int)(CLIP(mwindow->edl->local_session->blue, 0, 1) * 0xff);
481         sample->set_color((red << 16) | (green << 8) | blue);
482         sample->draw_box(0, 0, sample->get_w(), sample->get_h());
483         sample->set_color(BLACK);
484         sample->draw_rectangle(0, 0, sample->get_w(), sample->get_h());
485         sample->flash();
496 CWindowCameraGUI::CWindowCameraGUI(MWindow *mwindow, CWindowTool *thread)
497  : CWindowToolGUI(mwindow, 
498         thread,
499         PROGRAM_NAME ": Camera",
500         170,
501         170)
504 CWindowCameraGUI::~CWindowCameraGUI()
508 void CWindowCameraGUI::create_objects()
510         int x = 10, y = 10, x1;
511         Track *track = mwindow->cwindow->calculate_affected_track();
512         FloatAuto *x_auto = 0;
513         FloatAuto *y_auto = 0;
514         FloatAuto *z_auto = 0;
515         BC_Title *title;
516         BC_Button *button;
518         if(track)
519         {
520                 mwindow->cwindow->calculate_affected_autos(&x_auto,
521                         &y_auto,
522                         &z_auto,
523                         track,
524                         1,
525                         0,
526                         0,
527                         0);
528         }
530         add_subwindow(title = new BC_Title(x, y, _("X:")));
531         x += title->get_w();
532         this->x = new CWindowCoord(this, 
533                 x, 
534                 y, 
535                 x_auto ? x_auto->value : (float)0);
536         this->x->create_objects();
537         y += 30;
538         x = 10;
539         add_subwindow(title = new BC_Title(x, y, _("Y:")));
540         x += title->get_w();
541         this->y = new CWindowCoord(this, 
542                 x, 
543                 y, 
544                 y_auto ? y_auto->value : (float)0);
545         this->y->create_objects();
546         y += 30;
547         x = 10;
548         add_subwindow(title = new BC_Title(x, y, _("Z:")));
549         x += title->get_w();
550         this->z = new CWindowCoord(this, 
551                 x, 
552                 y, 
553                 z_auto ? z_auto->value : (float)1);
554         this->z->create_objects();
556         y += 30;
557         x1 = 10;
558         add_subwindow(button = new CWindowCameraLeft(mwindow, this, x1, y));
559         x1 += button->get_w();
560         add_subwindow(button = new CWindowCameraCenter(mwindow, this, x1, y));
561         x1 += button->get_w();
562         add_subwindow(button = new CWindowCameraRight(mwindow, this, x1, y));
564         y += button->get_h();
565         x1 = 10;
566         add_subwindow(button = new CWindowCameraTop(mwindow, this, x1, y));
567         x1 += button->get_w();
568         add_subwindow(button = new CWindowCameraMiddle(mwindow, this, x1, y));
569         x1 += button->get_w();
570         add_subwindow(button = new CWindowCameraBottom(mwindow, this, x1, y));
574 void CWindowCameraGUI::update_preview()
576         mwindow->restart_brender();
577         mwindow->sync_parameters(CHANGE_PARAMS);
579         mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
580                         CHANGE_NONE,
581                         mwindow->edl,
582                         1);
583         mwindow->cwindow->gui->lock_window("CWindowCameraGUI::update_preview");
584         mwindow->cwindow->gui->canvas->draw_refresh();
585         mwindow->cwindow->gui->unlock_window();
589 void CWindowCameraGUI::handle_event()
591         FloatAuto *x_auto = 0;
592         FloatAuto *y_auto = 0;
593         FloatAuto *z_auto = 0;
594         Track *track = mwindow->cwindow->calculate_affected_track();
595         if(track)
596         {
597                 if(event_caller == x)
598                 {
599                         x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
600                                 track->automation->autos[AUTOMATION_CAMERA_X],
601                                 1);
602                         if(x_auto)
603                         {
604                                 x_auto->value = atof(x->get_text());
605                                 update_preview();
606                         }
607                 }
608                 else
609                 if(event_caller == y)
610                 {
611                         y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
612                                 track->automation->autos[AUTOMATION_CAMERA_Y],
613                                 1);
614                         if(y_auto)
615                         {
616                                 y_auto->value = atof(y->get_text());
617                                 update_preview();
618                         }
619                 }
620                 else
621                 if(event_caller == z)
622                 {
623                         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
624                                 track->automation->autos[AUTOMATION_CAMERA_Z],
625                                 1);
626                         if(z_auto)
627                         {
628                                 float zoom = atof(z->get_text());
629                                 if(zoom > 10) zoom = 10; 
630                                 else
631                                 if(zoom < 0) zoom = 0;
632         // Doesn't allow user to enter from scratch
633         //              if(zoom != atof(z->get_text())) 
634         //                      z->update(zoom);
636                                 z_auto->value = zoom;
637                                 mwindow->gui->lock_window("CWindowCameraGUI::handle_event");
638                                 mwindow->gui->canvas->draw_overlays();
639                                 mwindow->gui->canvas->flash();
640                                 mwindow->gui->unlock_window();
641                                 update_preview();
642                         }
643                 }
644         }
647 void CWindowCameraGUI::update()
649         FloatAuto *x_auto = 0;
650         FloatAuto *y_auto = 0;
651         FloatAuto *z_auto = 0;
652         Track *track = mwindow->cwindow->calculate_affected_track();
654         if(track)
655         {
656                 mwindow->cwindow->calculate_affected_autos(&x_auto,
657                         &y_auto,
658                         &z_auto,
659                         track,
660                         1,
661                         0,
662                         0,
663                         0);
664         }
666         if(x_auto)
667                 x->update(x_auto->value);
668         if(y_auto)
669                 y->update(y_auto->value);
670         if(z_auto)
671                 z->update(z_auto->value);
674 // BezierAuto* CWindowCameraGUI::get_keyframe()
675 // {
676 //      BezierAuto *keyframe = 0;
677 //      Track *track = mwindow->cwindow->calculate_affected_track();
678 //      if(track)
679 //              keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
680 //                      track->automation->autos[AUTOMATION_CAMERA]);
681 //      return keyframe;
682 // }
686 CWindowCameraLeft::CWindowCameraLeft(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
687  : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
689         this->gui = gui;
690         this->mwindow = mwindow;
691         set_tooltip(_("Left justify"));
693 int CWindowCameraLeft::handle_event()
695         FloatAuto *x_auto = 0;
696         FloatAuto *z_auto = 0;
697         Track *track = mwindow->cwindow->calculate_affected_track();
698         if(track)
699         {
700                 mwindow->cwindow->calculate_affected_autos(&x_auto,
701                         0,
702                         &z_auto,
703                         track,
704                         1,
705                         1,
706                         0,
707                         0);
708         }
710         if(x_auto && z_auto)
711         {
712                 int w = 0, h = 0;
713                 track->get_source_dimensions(
714                         mwindow->edl->local_session->get_selectionstart(1),
715                         w,
716                         h);
718                 if(w && h)
719                 {
720                         x_auto->value = 
721                                 (double)track->track_w / z_auto->value / 2 - 
722                                 (double)w / 2;
723                         gui->update();
724                         gui->update_preview();
725                 }
726         }
728         return 1;
732 CWindowCameraCenter::CWindowCameraCenter(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
733  : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
735         this->gui = gui;
736         this->mwindow = mwindow;
737         set_tooltip(_("Center horizontal"));
739 int CWindowCameraCenter::handle_event()
741         FloatAuto *x_auto = 0;
742         Track *track = mwindow->cwindow->calculate_affected_track();
743         if(track)
744                 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
745                         track->automation->autos[AUTOMATION_CAMERA_X],
746                         1);
748         if(x_auto)
749         {
750                 x_auto->value = 0;
751                 gui->update();
752                 gui->update_preview();
753         }
755         return 1;
759 CWindowCameraRight::CWindowCameraRight(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
760  : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
762         this->gui = gui;
763         this->mwindow = mwindow;
764         set_tooltip(_("Right justify"));
766 int CWindowCameraRight::handle_event()
768         FloatAuto *x_auto = 0;
769         FloatAuto *z_auto = 0;
770         Track *track = mwindow->cwindow->calculate_affected_track();
771         if(track)
772         {
773                 mwindow->cwindow->calculate_affected_autos(&x_auto,
774                         0,
775                         &z_auto,
776                         track,
777                         1,
778                         1,
779                         0,
780                         0);
781         }
783         if(x_auto && z_auto)
784         {
785                 int w = 0, h = 0;
786                 track->get_source_dimensions(
787                         mwindow->edl->local_session->get_selectionstart(1),
788                         w,
789                         h);
791                 if(w && h)
792                 {
793                         x_auto->value = -((double)track->track_w / z_auto->value / 2 - 
794                                 (double)w / 2);
795                         gui->update();
796                         gui->update_preview();
797                 }
798         }
800         return 1;
804 CWindowCameraTop::CWindowCameraTop(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
805  : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
807         this->gui = gui;
808         this->mwindow = mwindow;
809         set_tooltip(_("Top justify"));
811 int CWindowCameraTop::handle_event()
813         FloatAuto *y_auto = 0;
814         FloatAuto *z_auto = 0;
815         Track *track = mwindow->cwindow->calculate_affected_track();
816         if(track)
817         {
818                 mwindow->cwindow->calculate_affected_autos(0,
819                         &y_auto,
820                         &z_auto,
821                         track,
822                         1,
823                         0,
824                         1,
825                         0);
826         }
828         if(y_auto && z_auto)
829         {
830                 int w = 0, h = 0;
831                 track->get_source_dimensions(
832                         mwindow->edl->local_session->get_selectionstart(1),
833                         w,
834                         h);
836                 if(w && h)
837                 {
838                         y_auto->value = (double)track->track_h / z_auto->value / 2 - 
839                                 (double)h / 2;
840                         gui->update();
841                         gui->update_preview();
842                 }
843         }
845         return 1;
849 CWindowCameraMiddle::CWindowCameraMiddle(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
850  : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
852         this->gui = gui;
853         this->mwindow = mwindow;
854         set_tooltip(_("Center vertical"));
856 int CWindowCameraMiddle::handle_event()
858         FloatAuto *y_auto = 0;
859         Track *track = mwindow->cwindow->calculate_affected_track();
860         if(track)
861                 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
862                         track->automation->autos[AUTOMATION_CAMERA_Y], 1);
864         if(y_auto)
865         {
866                 y_auto->value = 0;
867                 gui->update();
868                 gui->update_preview();
869         }
871         return 1;
875 CWindowCameraBottom::CWindowCameraBottom(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
876  : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
878         this->gui = gui;
879         this->mwindow = mwindow;
880         set_tooltip(_("Bottom justify"));
882 int CWindowCameraBottom::handle_event()
884         FloatAuto *y_auto = 0;
885         FloatAuto *z_auto = 0;
886         Track *track = mwindow->cwindow->calculate_affected_track();
887         if(track)
888         {
889                 mwindow->cwindow->calculate_affected_autos(0,
890                         &y_auto,
891                         &z_auto,
892                         track,
893                         1,
894                         0,
895                         1,
896                         0);
897         }
899         if(y_auto && z_auto)
900         {
901                 int w = 0, h = 0;
902                 track->get_source_dimensions(
903                         mwindow->edl->local_session->get_selectionstart(1),
904                         w,
905                         h);
907                 if(w && h)
908                 {
909                         y_auto->value = -((double)track->track_h / z_auto->value / 2 - 
910                                 (double)h / 2);
911                         gui->update();
912                         gui->update_preview();
913                 }
914         }
916         return 1;
935 CWindowProjectorGUI::CWindowProjectorGUI(MWindow *mwindow, CWindowTool *thread)
936  : CWindowToolGUI(mwindow, 
937         thread,
938         PROGRAM_NAME ": Projector",
939         170,
940         170)
943 CWindowProjectorGUI::~CWindowProjectorGUI()
946 void CWindowProjectorGUI::create_objects()
948         int x = 10, y = 10, x1;
949         Track *track = mwindow->cwindow->calculate_affected_track();
950         FloatAuto *x_auto = 0;
951         FloatAuto *y_auto = 0;
952         FloatAuto *z_auto = 0;
953         BC_Title *title;
954         BC_Button *button;
956         if(track)
957         {
958                 mwindow->cwindow->calculate_affected_autos(&x_auto,
959                         &y_auto,
960                         &z_auto,
961                         track,
962                         0,
963                         0,
964                         0,
965                         0);
966         }
968         add_subwindow(title = new BC_Title(x, y, _("X:")));
969         x += title->get_w();
970         this->x = new CWindowCoord(this, 
971                 x, 
972                 y, 
973                 x_auto ? x_auto->value : (float)0);
974         this->x->create_objects();
975         y += 30;
976         x = 10;
977         add_subwindow(title = new BC_Title(x, y, _("Y:")));
978         x += title->get_w();
979         this->y = new CWindowCoord(this, 
980                 x, 
981                 y, 
982                 y_auto ? y_auto->value : (float)0);
983         this->y->create_objects();
984         y += 30;
985         x = 10;
986         add_subwindow(title = new BC_Title(x, y, _("Z:")));
987         x += title->get_w();
988         this->z = new CWindowCoord(this, 
989                 x, 
990                 y, 
991                 z_auto ? z_auto->value : (float)1);
992         this->z->create_objects();
994         y += 30;
995         x1 = 10;
996         add_subwindow(button = new CWindowProjectorLeft(mwindow, this, x1, y));
997         x1 += button->get_w();
998         add_subwindow(button = new CWindowProjectorCenter(mwindow, this, x1, y));
999         x1 += button->get_w();
1000         add_subwindow(button = new CWindowProjectorRight(mwindow, this, x1, y));
1002         y += button->get_h();
1003         x1 = 10;
1004         add_subwindow(button = new CWindowProjectorTop(mwindow, this, x1, y));
1005         x1 += button->get_w();
1006         add_subwindow(button = new CWindowProjectorMiddle(mwindow, this, x1, y));
1007         x1 += button->get_w();
1008         add_subwindow(button = new CWindowProjectorBottom(mwindow, this, x1, y));
1012 void CWindowProjectorGUI::update_preview()
1014         mwindow->restart_brender();
1015         mwindow->sync_parameters(CHANGE_PARAMS);
1016         mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1017                         CHANGE_NONE,
1018                         mwindow->edl,
1019                         1);
1020         mwindow->cwindow->gui->lock_window("CWindowProjectorGUI::update_preview");
1021         mwindow->cwindow->gui->canvas->draw_refresh();
1022         mwindow->cwindow->gui->unlock_window();
1025 void CWindowProjectorGUI::handle_event()
1027         FloatAuto *x_auto = 0;
1028         FloatAuto *y_auto = 0;
1029         FloatAuto *z_auto = 0;
1030         Track *track = mwindow->cwindow->calculate_affected_track();
1032         if(track)
1033         {
1034                 if(event_caller == x)
1035                 {
1036                         x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1037                                 track->automation->autos[AUTOMATION_PROJECTOR_X],
1038                                 1);
1039                         if(x_auto)
1040                         {
1041                                 x_auto->value = atof(x->get_text());
1042                                 update_preview();
1043                         }
1044                 }
1045                 else
1046                 if(event_caller == y)
1047                 {
1048                         y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1049                                 track->automation->autos[AUTOMATION_PROJECTOR_Y],
1050                                 1);
1051                         if(y_auto)
1052                         {
1053                                 y_auto->value = atof(y->get_text());
1054                                 update_preview();
1055                         }
1056                 }
1057                 else
1058                 if(event_caller == z)
1059                 {
1060                         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1061                                 track->automation->autos[AUTOMATION_PROJECTOR_Z],
1062                                 1);
1063                         if(z_auto)
1064                         {
1065                                 float zoom = atof(z->get_text());
1066                                 if(zoom > 10000) zoom = 10000; 
1067                                 else 
1068                                 if(zoom < 0) zoom = 0;
1069 //                      if (zoom != atof(z->get_text())) 
1070 //                              z->update(zoom);
1071                                 z_auto->value = zoom;
1073                                 mwindow->gui->lock_window("CWindowProjectorGUI::handle_event");
1074                                 mwindow->gui->canvas->draw_overlays();
1075                                 mwindow->gui->canvas->flash();
1076                                 mwindow->gui->unlock_window();
1078                                 update_preview();
1079                         }
1080                 }
1081         }
1084 void CWindowProjectorGUI::update()
1086         FloatAuto *x_auto = 0;
1087         FloatAuto *y_auto = 0;
1088         FloatAuto *z_auto = 0;
1089         Track *track = mwindow->cwindow->calculate_affected_track();
1091         if(track)
1092         {
1093                 mwindow->cwindow->calculate_affected_autos(&x_auto,
1094                         &y_auto,
1095                         &z_auto,
1096                         track,
1097                         0,
1098                         0,
1099                         0,
1100                         0);
1101         }
1103         if(x_auto)
1104                 x->update(x_auto->value);
1105         if(y_auto)
1106                 y->update(y_auto->value);
1107         if(z_auto)
1108                 z->update(z_auto->value);
1111 // BezierAuto* CWindowProjectorGUI::get_keyframe()
1112 // {
1113 //      BezierAuto *keyframe = 0;
1114 //      Track *track = mwindow->cwindow->calculate_affected_track();
1115 //      if(track)
1116 //              keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
1117 //                      track->automation->autos[AUTOMATION_PROJECTOR]);
1118 //      return keyframe;
1119 // }
1158 CWindowProjectorLeft::CWindowProjectorLeft(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1159  : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
1161         this->gui = gui;
1162         this->mwindow = mwindow;
1163         set_tooltip(_("Left justify"));
1165 int CWindowProjectorLeft::handle_event()
1167         FloatAuto *x_auto = 0;
1168         FloatAuto *z_auto = 0;
1169         Track *track = mwindow->cwindow->calculate_affected_track();
1170         if(track)
1171         {
1172                 mwindow->cwindow->calculate_affected_autos(&x_auto,
1173                         0,
1174                         &z_auto,
1175                         track,
1176                         0,
1177                         1,
1178                         0,
1179                         0);
1180         }
1181         if(x_auto && z_auto)
1182         {
1183                 x_auto->value = (double)track->track_w * z_auto->value / 2 - 
1184                         (double)mwindow->edl->session->output_w / 2;
1185                 gui->update();
1186                 gui->update_preview();
1187         }
1189         return 1;
1193 CWindowProjectorCenter::CWindowProjectorCenter(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1194  : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
1196         this->gui = gui;
1197         this->mwindow = mwindow;
1198         set_tooltip(_("Center horizontal"));
1200 int CWindowProjectorCenter::handle_event()
1202         FloatAuto *x_auto = 0;
1203         Track *track = mwindow->cwindow->calculate_affected_track();
1204         if(track)
1205                 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1206                         track->automation->autos[AUTOMATION_PROJECTOR_X],
1207                         1);
1209         if(x_auto)
1210         {
1211                 x_auto->value = 0;
1212                 gui->update();
1213                 gui->update_preview();
1214         }
1216         return 1;
1220 CWindowProjectorRight::CWindowProjectorRight(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1221  : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
1223         this->gui = gui;
1224         this->mwindow = mwindow;
1225         set_tooltip(_("Right justify"));
1227 int CWindowProjectorRight::handle_event()
1229         FloatAuto *x_auto = 0;
1230         FloatAuto *z_auto = 0;
1231         Track *track = mwindow->cwindow->calculate_affected_track();
1232         if(track)
1233         {
1234                 mwindow->cwindow->calculate_affected_autos(&x_auto,
1235                         0,
1236                         &z_auto,
1237                         track,
1238                         0,
1239                         1,
1240                         0,
1241                         0);
1242         }
1244         if(x_auto && z_auto)
1245         {
1246                 x_auto->value = -((double)track->track_w * z_auto->value / 2 - 
1247                         (double)mwindow->edl->session->output_w / 2);
1248                 gui->update();
1249                 gui->update_preview();
1250         }
1252         return 1;
1256 CWindowProjectorTop::CWindowProjectorTop(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1257  : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
1259         this->gui = gui;
1260         this->mwindow = mwindow;
1261         set_tooltip(_("Top justify"));
1263 int CWindowProjectorTop::handle_event()
1265         FloatAuto *y_auto = 0;
1266         FloatAuto *z_auto = 0;
1267         Track *track = mwindow->cwindow->calculate_affected_track();
1268         if(track)
1269         {
1270                 mwindow->cwindow->calculate_affected_autos(0,
1271                         &y_auto,
1272                         &z_auto,
1273                         track,
1274                         0,
1275                         0,
1276                         1,
1277                         0);
1278         }
1280         if(y_auto && z_auto)
1281         {
1282                 y_auto->value = (double)track->track_h * z_auto->value / 2 - 
1283                         (double)mwindow->edl->session->output_h / 2;
1284                 gui->update();
1285                 gui->update_preview();
1286         }
1288         return 1;
1292 CWindowProjectorMiddle::CWindowProjectorMiddle(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1293  : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
1295         this->gui = gui;
1296         this->mwindow = mwindow;
1297         set_tooltip(_("Center vertical"));
1299 int CWindowProjectorMiddle::handle_event()
1301         FloatAuto *y_auto = 0;
1302         Track *track = mwindow->cwindow->calculate_affected_track();
1303         if(track)
1304                 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
1305                         track->automation->autos[AUTOMATION_PROJECTOR_Y], 1);
1307         if(y_auto)
1308         {
1309                 y_auto->value = 0;
1310                 gui->update();
1311                 gui->update_preview();
1312         }
1314         return 1;
1318 CWindowProjectorBottom::CWindowProjectorBottom(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
1319  : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
1321         this->gui = gui;
1322         this->mwindow = mwindow;
1323         set_tooltip(_("Bottom justify"));
1325 int CWindowProjectorBottom::handle_event()
1327         FloatAuto *y_auto = 0;
1328         FloatAuto *z_auto = 0;
1329         Track *track = mwindow->cwindow->calculate_affected_track();
1330         if(track)
1331         {
1332                 mwindow->cwindow->calculate_affected_autos(0,
1333                         &y_auto,
1334                         &z_auto,
1335                         track,
1336                         0,
1337                         0,
1338                         1,
1339                         0);
1340         }
1342         if(y_auto && z_auto)
1343         {
1344                 y_auto->value = -((double)track->track_h * z_auto->value / 2 - 
1345                         (double)mwindow->edl->session->output_h / 2);
1346                 gui->update();
1347                 gui->update_preview();
1348         }
1350         return 1;
1360 CWindowMaskMode::CWindowMaskMode(MWindow *mwindow, 
1361         CWindowToolGUI *gui, 
1362         int x, 
1363         int y,
1364         char *text)
1365  : BC_PopupMenu(x,
1366         y,
1367         200,
1368         text,
1369         1)
1371         this->mwindow = mwindow;
1372         this->gui = gui;
1375 void CWindowMaskMode::create_objects()
1377         add_item(new BC_MenuItem(mode_to_text(MASK_MULTIPLY_ALPHA)));
1378         add_item(new BC_MenuItem(mode_to_text(MASK_SUBTRACT_ALPHA)));
1381 char* CWindowMaskMode::mode_to_text(int mode)
1383         switch(mode)
1384         {
1385                 case MASK_MULTIPLY_ALPHA:
1386                         return _("Multiply alpha");
1387                         break;
1388                 
1389                 case MASK_SUBTRACT_ALPHA:
1390                         return _("Subtract alpha");
1391                         break;
1392         }
1394         return _("Subtract alpha");
1397 int CWindowMaskMode::text_to_mode(char *text)
1399         if(!strcasecmp(text, _("Multiply alpha")))
1400                 return MASK_MULTIPLY_ALPHA;
1401         else
1402         if(!strcasecmp(text, _("Subtract alpha")))
1403                 return MASK_SUBTRACT_ALPHA;
1405         return MASK_SUBTRACT_ALPHA;
1408 int CWindowMaskMode::handle_event()
1410         MaskAuto *keyframe;
1411         Track *track;
1412         MaskPoint *point;
1413         SubMask *mask;
1414         ((CWindowMaskGUI*)gui)->get_keyframe(track, 
1415                 keyframe, 
1416                 mask,
1417                 point,
1418                 0);
1420         if(track)
1421         {
1422                 ((MaskAuto*)track->automation->autos[AUTOMATION_MASK]->default_auto)->mode = 
1423                         text_to_mode(get_text());
1424         }
1426 //printf("CWindowMaskMode::handle_event 1\n");
1427         gui->update_preview();
1428         return 1;
1438 CWindowMaskDelete::CWindowMaskDelete(MWindow *mwindow, 
1439         CWindowToolGUI *gui, 
1440         int x, 
1441         int y)
1442  : BC_GenericButton(x, y, _("Delete"))
1444         this->mwindow = mwindow;
1445         this->gui = gui;
1448 int CWindowMaskDelete::handle_event()
1450         MaskAuto *keyframe;
1451         Track *track = mwindow->cwindow->calculate_affected_track();
1452         MaskPoint *point;
1453         SubMask *mask;
1456         if(track)
1457         {
1458                 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1459                 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1460                         current; )
1461                 {
1462                         SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1465                         
1466                         for(int i = mwindow->cwindow->gui->affected_point;
1467                                 i < submask->points.total - 1;
1468                                 i++)
1469                         {
1470                                 *submask->points.values[i] = *submask->points.values[i + 1];
1471                         }
1473                         if(submask->points.total)
1474                         {
1475                                 submask->points.remove_object(
1476                                         submask->points.values[submask->points.total - 1]);
1477                         }
1480                         if(current == (MaskAuto*)mask_autos->default_auto)
1481                                 current = (MaskAuto*)mask_autos->first;
1482                         else
1483                                 current = (MaskAuto*)NEXT;
1484                 }
1485                 gui->update();
1486                 gui->update_preview();
1487         }
1490 //      ((CWindowMaskGUI*)gui)->get_keyframe(track, 
1491 //              keyframe, 
1492 //              mask, 
1493 //              point,
1494 //              0);
1496 // Need to apply to every keyframe
1497         
1498 //      if(keyframe)
1499 //      {
1500 //              for(int i = mwindow->cwindow->gui->affected_point;
1501 //                      i < mask->points.total - 1;
1502 //                      i++)
1503 //              {
1504 //                      *mask->points.values[i] = *mask->points.values[i + 1];
1505 //              }
1506 //              
1507 //              if(mask->points.total)
1508 //              {
1509 //                      mask->points.remove_object(mask->points.values[mask->points.total - 1]);
1510 //              }
1511 // 
1512 //              gui->update();
1513 //              gui->update_preview();
1514 //      }
1516         return 1;
1519 int CWindowMaskDelete::keypress_event()
1521         if(get_keypress() == BACKSPACE ||
1522                 get_keypress() == DELETE) 
1523                 return handle_event();
1524         return 0;
1528 CWindowMaskCycleNext::CWindowMaskCycleNext(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1529  : BC_GenericButton(x, y, _("Cycle next"))
1531         this->mwindow = mwindow;
1532         this->gui = gui;
1534 int CWindowMaskCycleNext::handle_event()
1536         MaskAuto *keyframe;
1537         Track *track;
1538         MaskPoint *point;
1539         SubMask *mask;
1540         ((CWindowMaskGUI*)gui)->get_keyframe(track, 
1541                 keyframe,
1542                 mask,  
1543                 point,
1544                 0);
1546         MaskPoint *temp;
1548 // Should apply to all keyframes
1549         if(keyframe && mask->points.total)
1550         {
1551                 temp = mask->points.values[0];
1553                 for(int i = 0; i < mask->points.total - 1; i++)
1554                 {
1555                         mask->points.values[i] = mask->points.values[i + 1];
1556                 }
1557                 mask->points.values[mask->points.total - 1] = temp;
1559                 mwindow->cwindow->gui->affected_point--;
1560                 if(mwindow->cwindow->gui->affected_point < 0)
1561                         mwindow->cwindow->gui->affected_point = mask->points.total - 1;
1563                 gui->update();
1564                 gui->update_preview();
1565         }
1566         
1567         return 1;
1570 CWindowMaskCyclePrev::CWindowMaskCyclePrev(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1571  : BC_GenericButton(x, y, _("Cycle prev"))
1573         this->mwindow = mwindow;
1574         this->gui = gui;
1576 int CWindowMaskCyclePrev::handle_event()
1578         MaskAuto *keyframe;
1579         Track *track;
1580         MaskPoint *point;
1581         SubMask *mask;
1582         ((CWindowMaskGUI*)gui)->get_keyframe(track, 
1583                 keyframe,
1584                 mask, 
1585                 point,
1586                 0);
1588 // Should apply to all keyframes
1589         MaskPoint *temp;
1590         if(keyframe && mask->points.total)
1591         {
1592                 temp = mask->points.values[mask->points.total - 1];
1594                 for(int i = mask->points.total - 1; i > 0; i--)
1595                 {
1596                         mask->points.values[i] = mask->points.values[i - 1];
1597                 }
1598                 mask->points.values[0] = temp;
1600                 mwindow->cwindow->gui->affected_point++;
1601                 if(mwindow->cwindow->gui->affected_point >= mask->points.total)
1602                         mwindow->cwindow->gui->affected_point = 0;
1604                 gui->update();
1605                 gui->update_preview();
1606         }
1607         return 1;
1611 CWindowMaskNumber::CWindowMaskNumber(MWindow *mwindow, 
1612         CWindowToolGUI *gui, 
1613         int x, 
1614         int y)
1615  : BC_TumbleTextBox(gui, 
1616                 (int64_t)mwindow->edl->session->cwindow_mask,
1617                 (int64_t)0,
1618                 (int64_t)SUBMASKS - 1,
1619                 x, 
1620                 y, 
1621                 100)
1623         this->mwindow = mwindow;
1624         this->gui = gui;
1627 CWindowMaskNumber::~CWindowMaskNumber()
1631 int CWindowMaskNumber::handle_event()
1633         mwindow->edl->session->cwindow_mask = atol(get_text());
1634         gui->update();
1635         gui->update_preview();
1636         return 1;
1643 CWindowMaskFeather::CWindowMaskFeather(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1644  : BC_TumbleTextBox(gui, 
1645                 (int64_t)0,
1646                 (int64_t)0,
1647                 (int64_t)0xff,
1648                 x, 
1649                 y, 
1650                 100)
1652         this->mwindow = mwindow;
1653         this->gui = gui;
1655 CWindowMaskFeather::~CWindowMaskFeather()
1658 int CWindowMaskFeather::handle_event()
1660         MaskAuto *keyframe;
1661         Track *track;
1662         MaskPoint *point;
1663         SubMask *mask;
1664         ((CWindowMaskGUI*)gui)->get_keyframe(track, 
1665                 keyframe,
1666                 mask, 
1667                 point,
1668                 1);
1670         keyframe->feather = atof(get_text());
1671         gui->update_preview();
1672         return 1;
1675 CWindowMaskValue::CWindowMaskValue(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
1676  : BC_ISlider(x, 
1677                         y,
1678                         0,
1679                         200, 
1680                         200, 
1681                         0, 
1682                         100, 
1683                         0)
1685         this->mwindow = mwindow;
1686         this->gui = gui;
1689 CWindowMaskValue::~CWindowMaskValue()
1693 int CWindowMaskValue::handle_event()
1696         MaskAuto *keyframe;
1697         Track *track;
1698         MaskPoint *point;
1699         SubMask *mask;
1700         ((CWindowMaskGUI*)gui)->get_keyframe(track, 
1701                 keyframe,
1702                 mask, 
1703                 point,
1704                 1);
1706         keyframe->value = get_value();
1707         gui->update_preview();
1708         return 1;
1713 CWindowMaskBeforePlugins::CWindowMaskBeforePlugins(CWindowToolGUI *gui, int x, int y)
1714  : BC_CheckBox(x, 
1715         y, 
1716         1, 
1717         _("Apply mask before plugins"))
1719         this->gui = gui;
1722 int CWindowMaskBeforePlugins::handle_event()
1724         MaskAuto *keyframe;
1725         Track *track;
1726         MaskPoint *point;
1727         SubMask *mask;
1728         ((CWindowMaskGUI*)gui)->get_keyframe(track, 
1729                 keyframe,
1730                 mask, 
1731                 point,
1732                 1);
1734         keyframe->apply_before_plugins = get_value();
1735         gui->update_preview();
1736         return 1;
1746 CWindowMaskGUI::CWindowMaskGUI(MWindow *mwindow, CWindowTool *thread)
1747  : CWindowToolGUI(mwindow, 
1748         thread,
1749         PROGRAM_NAME ": Mask",
1750         330,
1751         280)
1753         this->mwindow = mwindow;
1754         this->thread = thread;
1756 CWindowMaskGUI::~CWindowMaskGUI()
1758         delete number;
1759         delete feather;
1762 void CWindowMaskGUI::create_objects()
1764         int x = 10, y = 10;
1765         MaskAuto *keyframe = 0;
1766         Track *track = mwindow->cwindow->calculate_affected_track();
1767         if(track)
1768                 keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(track->automation->autos[AUTOMATION_MASK], 0);
1770         BC_Title *title;
1771         add_subwindow(title = new BC_Title(x, y, _("Mode:")));
1772         add_subwindow(mode = new CWindowMaskMode(mwindow, 
1773                 this, 
1774                 x + title->get_w(), 
1775                 y,
1776                 ""));
1777         mode->create_objects();
1778         y += 40;
1779         add_subwindow(new BC_Title(x, y, _("Value:")));
1780         add_subwindow(value = new CWindowMaskValue(mwindow, this, x + 50, y));
1781         y += 30;
1782         add_subwindow(delete_point = new CWindowMaskDelete(mwindow, this, x, y));
1783         y += 30;
1784         add_subwindow(new BC_Title(x, y, _("Mask number:")));
1785         number = new CWindowMaskNumber(mwindow, 
1786                 this, 
1787                 x + 110, 
1788                 y);
1789         number->create_objects();
1790         y += 30;
1791         add_subwindow(new BC_Title(x, y, _("Feather:")));
1792         feather = new CWindowMaskFeather(mwindow,
1793                 this,
1794                 x + 110,
1795                 y);
1796         feather->create_objects();
1797         y += 30;
1798         add_subwindow(title = new BC_Title(x, y, _("X:")));
1799         x += title->get_w();
1800         this->x = new CWindowCoord(this, 
1801                 x, 
1802                 y, 
1803                 (float)0.0);
1804         this->x->create_objects();
1805         x += 150;
1806         add_subwindow(title = new BC_Title(x, y, _("Y:")));
1807         x += title->get_w();
1808         this->y = new CWindowCoord(this, 
1809                 x, 
1810                 y, 
1811                 (float)0.0);
1812         this->y->create_objects();
1814         y += 30;
1815 //      add_subwindow(title = new BC_Title(x, y, _("Apply mask before plugins:")));
1816         
1817         add_subwindow(this->apply_before_plugins = new CWindowMaskBeforePlugins(this, 
1818                 10, 
1819                 y));
1820 //      this->apply_before_plugins->create_objects();
1823         update();
1826 void CWindowMaskGUI::get_keyframe(Track* &track, 
1827         MaskAuto* &keyframe, 
1828         SubMask* &mask, 
1829         MaskPoint* &point,
1830         int create_it)
1832         keyframe = 0;
1833         track = mwindow->cwindow->calculate_affected_track();
1834         if(track)
1835                 keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(track->automation->autos[AUTOMATION_MASK], create_it);
1836         else
1837                 keyframe = 0;
1839         if(keyframe)
1840                 mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1841         else
1842                 mask = 0;
1844         point = 0;
1845         if(keyframe)
1846         {
1847                 if(mwindow->cwindow->gui->affected_point < mask->points.total &&
1848                         mwindow->cwindow->gui->affected_point >= 0)
1849                 {
1850                         point =  mask->points.values[mwindow->cwindow->gui->affected_point];
1851                 }
1852         }
1855 void CWindowMaskGUI::update()
1857         MaskAuto *keyframe;
1858         Track *track;
1859         MaskPoint *point;
1860         SubMask *mask;
1861 //printf("CWindowMaskGUI::update 1\n");
1862         get_keyframe(track, 
1863                 keyframe, 
1864                 mask,
1865                 point,
1866                 0);
1868 //printf("CWindowMaskGUI::update 1\n");
1869         if(point)
1870         {
1871                 x->update(point->x);
1872                 y->update(point->y);
1873         }
1874 //printf("CWindowMaskGUI::update 1\n");
1876         if(mask)
1877         {
1878                 feather->update((int64_t)keyframe->feather);
1879                 value->update((int64_t)keyframe->value);
1880                 apply_before_plugins->update((int64_t)keyframe->apply_before_plugins);
1881         }
1882 //printf("CWindowMaskGUI::update 1\n");
1884         number->update((int64_t)mwindow->edl->session->cwindow_mask);
1886 //printf("CWindowMaskGUI::update 1\n");
1887         if(track)
1888         {
1889                 mode->set_text(
1890                         CWindowMaskMode::mode_to_text(((MaskAuto*)track->automation->autos[AUTOMATION_MASK]->default_auto)->mode));
1891         }
1892 //printf("CWindowMaskGUI::update 2\n");
1895 void CWindowMaskGUI::handle_event()
1897         MaskAuto *keyframe;
1898         Track *track;
1899         MaskPoint *point;
1900         SubMask *mask;
1901         get_keyframe(track, 
1902                 keyframe, 
1903                 mask,
1904                 point,
1905                 0);
1907         if(point)
1908         {
1909                 point->x = atof(x->get_text());
1910                 point->y = atof(y->get_text());
1911         }
1913         update_preview();
1916 void CWindowMaskGUI::update_preview()
1918         mwindow->restart_brender();
1919         mwindow->sync_parameters(CHANGE_PARAMS);
1920         mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1921                         CHANGE_NONE,
1922                         mwindow->edl,
1923                         1);
1924         mwindow->cwindow->gui->lock_window("CWindowMaskGUI::update_preview");
1925         mwindow->cwindow->gui->canvas->draw_refresh();
1926         mwindow->cwindow->gui->unlock_window();