Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

cwindowtool.C

Go to the documentation of this file.
00001 #include "automation.h"
00002 #include "clip.h"
00003 #include "condition.h"
00004 #include "cpanel.h"
00005 #include "cplayback.h"
00006 #include "cwindow.h"
00007 #include "cwindowgui.h"
00008 #include "cwindowtool.h"
00009 #include "edl.h"
00010 #include "edlsession.h"
00011 #include "floatauto.h"
00012 #include "floatautos.h"
00013 #include "keys.h"
00014 #include "language.h"
00015 #include "localsession.h"
00016 #include "mainsession.h"
00017 #include "maskauto.h"
00018 #include "maskautos.h"
00019 #include "mwindow.h"
00020 #include "mwindowgui.h"
00021 #include "theme.h"
00022 #include "track.h"
00023 #include "trackcanvas.h"
00024 #include "transportque.h"
00025 
00026 
00027 CWindowTool::CWindowTool(MWindow *mwindow, CWindowGUI *gui)
00028  : Thread()
00029 {
00030         this->mwindow = mwindow;
00031         this->gui = gui;
00032         tool_gui = 0;
00033         done = 0;
00034         current_tool = CWINDOW_NONE;
00035         set_synchronous(1);
00036         input_lock = new Condition(0, "CWindowTool::input_lock");
00037         output_lock = new Condition(1, "CWindowTool::output_lock");
00038         tool_gui_lock = new Mutex("CWindowTool::tool_gui_lock");
00039 }
00040 
00041 CWindowTool::~CWindowTool()
00042 {
00043         done = 1;
00044         stop_tool();
00045         input_lock->unlock();
00046         Thread::join();
00047         delete input_lock;
00048         delete output_lock;
00049         delete tool_gui_lock;
00050 }
00051 
00052 void CWindowTool::start_tool(int operation)
00053 {
00054         CWindowToolGUI *new_gui = 0;
00055         int result = 0;
00056 
00057 //printf("CWindowTool::start_tool 1\n");
00058         if(current_tool != operation)
00059         {
00060                 current_tool = operation;
00061                 switch(operation)
00062                 {
00063                         case CWINDOW_EYEDROP:
00064                                 new_gui = new CWindowEyedropGUI(mwindow, this);
00065                                 break;
00066                         case CWINDOW_CROP:
00067                                 new_gui = new CWindowCropGUI(mwindow, this);
00068                                 break;
00069                         case CWINDOW_CAMERA:
00070                                 new_gui = new CWindowCameraGUI(mwindow, this);
00071                                 break;
00072                         case CWINDOW_PROJECTOR:
00073                                 new_gui = new CWindowProjectorGUI(mwindow, this);
00074                                 break;
00075                         case CWINDOW_MASK:
00076                                 new_gui = new CWindowMaskGUI(mwindow, this);
00077                                 break;
00078                         default:
00079                                 result = 1;
00080                                 stop_tool();
00081                                 break;
00082                 }
00083 
00084 //printf("CWindowTool::start_tool 1\n");
00085 
00086 
00087                 if(!result)
00088                 {
00089                         stop_tool();
00090 // Wait for previous tool GUI to finish
00091                         output_lock->lock("CWindowTool::start_tool");
00092                         this->tool_gui = new_gui;
00093                         tool_gui->create_objects();
00094                         
00095                         if(mwindow->edl->session->tool_window &&
00096                                 mwindow->session->show_cwindow) tool_gui->show_window();
00097                         tool_gui->flush();
00098                         
00099                         
00100 // Signal thread to run next tool GUI
00101                         input_lock->unlock();
00102                 }
00103 //printf("CWindowTool::start_tool 1\n");
00104         }
00105         else
00106         if(tool_gui) 
00107         {
00108                 tool_gui->lock_window("CWindowTool::start_tool");
00109                 tool_gui->update();
00110                 tool_gui->unlock_window();
00111         }
00112 
00113 //printf("CWindowTool::start_tool 2\n");
00114 
00115 }
00116 
00117 
00118 void CWindowTool::stop_tool()
00119 {
00120         if(tool_gui)
00121         {
00122                 tool_gui->lock_window("CWindowTool::stop_tool");
00123                 tool_gui->set_done(0);
00124                 tool_gui->unlock_window();
00125         }
00126 }
00127 
00128 void CWindowTool::show_tool()
00129 {
00130         if(tool_gui && mwindow->edl->session->tool_window)
00131         {
00132                 tool_gui->lock_window("CWindowTool::show_tool");
00133                 tool_gui->show_window();
00134                 tool_gui->unlock_window();
00135         }
00136 }
00137 
00138 void CWindowTool::hide_tool()
00139 {
00140         if(tool_gui && mwindow->edl->session->tool_window)
00141         {
00142                 tool_gui->lock_window("CWindowTool::show_tool");
00143                 tool_gui->hide_window();
00144                 tool_gui->unlock_window();
00145         }
00146 }
00147 
00148 
00149 void CWindowTool::run()
00150 {
00151         while(!done)
00152         {
00153                 input_lock->lock("CWindowTool::run");
00154                 if(!done)
00155                 {
00156                         tool_gui->run_window();
00157                         tool_gui_lock->lock("CWindowTool::run");
00158                         delete tool_gui;
00159                         tool_gui = 0;
00160                         tool_gui_lock->unlock();
00161                 }
00162                 output_lock->unlock();
00163         }
00164 }
00165 
00166 void CWindowTool::update_show_window()
00167 {
00168         if(tool_gui)
00169         {
00170                 tool_gui->lock_window("CWindowTool::update_show_window");
00171 
00172                 if(mwindow->edl->session->tool_window) 
00173                 {
00174                         tool_gui->update();
00175                         tool_gui->show_window();
00176                 }
00177                 else
00178                         tool_gui->hide_window();
00179                 tool_gui->flush();
00180 
00181                 tool_gui->unlock_window();
00182         }
00183 }
00184 
00185 void CWindowTool::update_values()
00186 {
00187         tool_gui_lock->lock("CWindowTool::update_values");
00188         if(tool_gui)
00189         {
00190                 tool_gui->lock_window("CWindowTool::update_values");
00191                 tool_gui->update();
00192                 tool_gui->flush();
00193                 tool_gui->unlock_window();
00194         }
00195         tool_gui_lock->unlock();
00196 }
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 CWindowToolGUI::CWindowToolGUI(MWindow *mwindow, 
00205         CWindowTool *thread, 
00206         char *title,
00207         int w, 
00208         int h)
00209  : BC_Window(title,
00210         mwindow->session->ctool_x,
00211         mwindow->session->ctool_y,
00212         w,
00213         h,
00214         w,
00215         h,
00216         0,
00217         0,
00218         1)
00219 {
00220         this->mwindow = mwindow;
00221         this->thread = thread;
00222         current_operation = 0;
00223 }
00224 
00225 CWindowToolGUI::~CWindowToolGUI()
00226 {
00227 }
00228 
00229 int CWindowToolGUI::close_event()
00230 {
00231         hide_window();
00232         flush();
00233         mwindow->edl->session->tool_window = 0;
00234         unlock_window();
00235 
00236 
00237 
00238         thread->gui->lock_window("CWindowToolGUI::close_event");
00239         thread->gui->composite_panel->set_operation(mwindow->edl->session->cwindow_operation);
00240         thread->gui->flush();
00241         thread->gui->unlock_window();
00242 
00243         lock_window("CWindowToolGUI::close_event");
00244         return 1;
00245 }
00246 
00247 int CWindowToolGUI::keypress_event()
00248 {
00249         if(get_keypress() == 'w' || get_keypress() == 'W')
00250                 return close_event();
00251         return 0;
00252 }
00253 
00254 int CWindowToolGUI::translation_event()
00255 {
00256         mwindow->session->ctool_x = get_x();
00257         mwindow->session->ctool_y = get_y();
00258         return 0;
00259 }
00260 
00261 
00262 
00263 
00264 
00265 
00266 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value)
00267  : BC_TumbleTextBox(gui, 
00268                 (float)value,
00269                 (float)-65536,
00270                 (float)65536,
00271                 x, 
00272                 y, 
00273                 100)
00274 {
00275         this->gui = gui;
00276 }
00277 
00278 CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value)
00279  : BC_TumbleTextBox(gui, 
00280                 (int64_t)value,
00281                 (int64_t)-65536,
00282                 (int64_t)65536,
00283                 x, 
00284                 y, 
00285                 100)
00286 {
00287         this->gui = gui;
00288 }
00289 int CWindowCoord::handle_event()
00290 {
00291         gui->event_caller = this;
00292         gui->handle_event();
00293         return 1;
00294 }
00295 
00296 
00297 CWindowCropOK::CWindowCropOK(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
00298  : BC_GenericButton(x, y, _("Do it"))
00299 {
00300         this->mwindow = mwindow;
00301         this->gui = gui;
00302 }
00303 int CWindowCropOK::handle_event()
00304 {
00305         mwindow->crop_video();
00306         return 1;
00307 }
00308 
00309 
00310 int CWindowCropOK::keypress_event()
00311 {
00312         if(get_keypress() == 0xd) 
00313         {
00314                 handle_event();
00315                 return 1;
00316         }
00317         return 0;
00318 }
00319 
00320 
00321 
00322 
00323 
00324 
00325 
00326 CWindowCropGUI::CWindowCropGUI(MWindow *mwindow, CWindowTool *thread)
00327  : CWindowToolGUI(mwindow, 
00328         thread,
00329         PROGRAM_NAME ": Crop",
00330         330,
00331         100)
00332 {
00333 }
00334 
00335 
00336 CWindowCropGUI::~CWindowCropGUI()
00337 {
00338 }
00339 
00340 void CWindowCropGUI::create_objects()
00341 {
00342         int x = 10, y = 10;
00343         BC_TumbleTextBox *textbox;
00344         BC_Title *title;
00345 
00346         int column1 = 0;
00347         int pad = MAX(BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1), 
00348                 BC_Title::calculate_h(this, "X")) + 5;
00349         add_subwindow(title = new BC_Title(x, y, _("X1:")));
00350         column1 = MAX(column1, title->get_w());
00351         y += pad;
00352         add_subwindow(title = new BC_Title(x, y, _("W:")));
00353         column1 = MAX(column1, title->get_w());
00354         y += pad;
00355         add_subwindow(new CWindowCropOK(mwindow, thread->tool_gui, x, y));
00356 
00357         x += column1 + 5;
00358         y = 10;
00359         x1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_x1);
00360         x1->create_objects();
00361         y += pad;
00362         width = new CWindowCoord(thread->tool_gui, 
00363                 x, 
00364                 y, 
00365                 mwindow->edl->session->crop_x2 - 
00366                         mwindow->edl->session->crop_x1);
00367         width->create_objects();
00368 
00369 
00370         x += x1->get_w() + 10;
00371         y = 10;
00372         int column2 = 0;
00373         add_subwindow(title = new BC_Title(x, y, _("Y1:")));
00374         column2 = MAX(column2, title->get_w());
00375         y += pad;
00376         add_subwindow(title = new BC_Title(x, y, _("H:")));
00377         column2 = MAX(column2, title->get_w());
00378         y += pad;
00379 
00380         y = 10;
00381         x += column2 + 5;
00382         y1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_y1);
00383         y1->create_objects();
00384         y += pad;
00385         height = new CWindowCoord(thread->tool_gui, 
00386                 x, 
00387                 y, 
00388                 mwindow->edl->session->crop_y2 - 
00389                         mwindow->edl->session->crop_y1);
00390         height->create_objects();
00391 }
00392 
00393 void CWindowCropGUI::handle_event()
00394 {
00395         int new_x1, new_y1;
00396         new_x1 = atol(x1->get_text());
00397         new_y1 = atol(y1->get_text());
00398         if(new_x1 != mwindow->edl->session->crop_x1)
00399         {
00400                 mwindow->edl->session->crop_x2 = new_x1 +
00401                         mwindow->edl->session->crop_x2 - 
00402                         mwindow->edl->session->crop_x1;
00403                 mwindow->edl->session->crop_x1 = new_x1;
00404         }
00405         if(new_y1 != mwindow->edl->session->crop_y1)
00406         {
00407                 mwindow->edl->session->crop_y2 = new_y1 +
00408                         mwindow->edl->session->crop_y2 -
00409                         mwindow->edl->session->crop_y1;
00410                 mwindow->edl->session->crop_y1 = atol(y1->get_text());
00411         }
00412         mwindow->edl->session->crop_x2 = atol(width->get_text()) + 
00413                 mwindow->edl->session->crop_x1;
00414         mwindow->edl->session->crop_y2 = atol(height->get_text()) + 
00415                 mwindow->edl->session->crop_y1;
00416         update();
00417         mwindow->cwindow->gui->lock_window("CWindowCropGUI::handle_event");
00418         mwindow->cwindow->gui->canvas->draw_refresh();
00419         mwindow->cwindow->gui->unlock_window();
00420 }
00421 
00422 void CWindowCropGUI::update()
00423 {
00424         x1->update((int64_t)mwindow->edl->session->crop_x1);
00425         y1->update((int64_t)mwindow->edl->session->crop_y1);
00426         width->update((int64_t)mwindow->edl->session->crop_x2 - 
00427                 mwindow->edl->session->crop_x1);
00428         height->update((int64_t)mwindow->edl->session->crop_y2 - 
00429                 mwindow->edl->session->crop_y1);
00430 }
00431 
00432 
00433 
00434 
00435 
00436 
00437 CWindowEyedropGUI::CWindowEyedropGUI(MWindow *mwindow, CWindowTool *thread)
00438  : CWindowToolGUI(mwindow, 
00439         thread,
00440         PROGRAM_NAME ": Color",
00441         150,
00442         150)
00443 {
00444 }
00445 
00446 CWindowEyedropGUI::~CWindowEyedropGUI()
00447 {
00448 }
00449 
00450 void CWindowEyedropGUI::create_objects()
00451 {
00452         int x = 10;
00453         int y = 10;
00454         int x2 = 70;
00455         BC_Title *title1, *title2, *title3;
00456         add_subwindow(title1 = new BC_Title(x, y, "Red:"));
00457         y += title1->get_h() + 5;
00458         add_subwindow(title2 = new BC_Title(x, y, "Green:"));
00459         y += title2->get_h() + 5;
00460         add_subwindow(title3 = new BC_Title(x, y, "Blue:"));
00461 
00462 
00463         add_subwindow(red = new BC_Title(x2, title1->get_y(), "0"));
00464         add_subwindow(green = new BC_Title(x2, title2->get_y(), "0"));
00465         add_subwindow(blue = new BC_Title(x2, title3->get_y(), "0"));
00466 
00467         y = blue->get_y() + blue->get_h() + 5;
00468         add_subwindow(sample = new BC_SubWindow(x, y, 50, 50));
00469         update();       
00470 }
00471 
00472 void CWindowEyedropGUI::update()
00473 {
00474         red->update(mwindow->edl->local_session->red);
00475         green->update(mwindow->edl->local_session->green);
00476         blue->update(mwindow->edl->local_session->blue);
00477 
00478         int red = (int)(CLIP(mwindow->edl->local_session->red, 0, 1) * 0xff);
00479         int green = (int)(CLIP(mwindow->edl->local_session->green, 0, 1) * 0xff);
00480         int blue = (int)(CLIP(mwindow->edl->local_session->blue, 0, 1) * 0xff);
00481         sample->set_color((red << 16) | (green << 8) | blue);
00482         sample->draw_box(0, 0, sample->get_w(), sample->get_h());
00483         sample->set_color(BLACK);
00484         sample->draw_rectangle(0, 0, sample->get_w(), sample->get_h());
00485         sample->flash();
00486 }
00487 
00488 
00489 
00490 
00491 
00492 
00493 
00494 
00495 
00496 CWindowCameraGUI::CWindowCameraGUI(MWindow *mwindow, CWindowTool *thread)
00497  : CWindowToolGUI(mwindow, 
00498         thread,
00499         PROGRAM_NAME ": Camera",
00500         170,
00501         170)
00502 {
00503 }
00504 CWindowCameraGUI::~CWindowCameraGUI()
00505 {
00506 }
00507 
00508 void CWindowCameraGUI::create_objects()
00509 {
00510         int x = 10, y = 10, x1;
00511         Track *track = mwindow->cwindow->calculate_affected_track();
00512         FloatAuto *x_auto = 0;
00513         FloatAuto *y_auto = 0;
00514         FloatAuto *z_auto = 0;
00515         BC_Title *title;
00516         BC_Button *button;
00517 
00518         if(track)
00519         {
00520                 mwindow->cwindow->calculate_affected_autos(&x_auto,
00521                         &y_auto,
00522                         &z_auto,
00523                         track,
00524                         1,
00525                         0,
00526                         0,
00527                         0);
00528         }
00529 
00530         add_subwindow(title = new BC_Title(x, y, _("X:")));
00531         x += title->get_w();
00532         this->x = new CWindowCoord(this, 
00533                 x, 
00534                 y, 
00535                 x_auto ? x_auto->value : (float)0);
00536         this->x->create_objects();
00537         y += 30;
00538         x = 10;
00539         add_subwindow(title = new BC_Title(x, y, _("Y:")));
00540         x += title->get_w();
00541         this->y = new CWindowCoord(this, 
00542                 x, 
00543                 y, 
00544                 y_auto ? y_auto->value : (float)0);
00545         this->y->create_objects();
00546         y += 30;
00547         x = 10;
00548         add_subwindow(title = new BC_Title(x, y, _("Z:")));
00549         x += title->get_w();
00550         this->z = new CWindowCoord(this, 
00551                 x, 
00552                 y, 
00553                 z_auto ? z_auto->value : (float)1);
00554         this->z->create_objects();
00555 
00556         y += 30;
00557         x1 = 10;
00558         add_subwindow(button = new CWindowCameraLeft(mwindow, this, x1, y));
00559         x1 += button->get_w();
00560         add_subwindow(button = new CWindowCameraCenter(mwindow, this, x1, y));
00561         x1 += button->get_w();
00562         add_subwindow(button = new CWindowCameraRight(mwindow, this, x1, y));
00563 
00564         y += button->get_h();
00565         x1 = 10;
00566         add_subwindow(button = new CWindowCameraTop(mwindow, this, x1, y));
00567         x1 += button->get_w();
00568         add_subwindow(button = new CWindowCameraMiddle(mwindow, this, x1, y));
00569         x1 += button->get_w();
00570         add_subwindow(button = new CWindowCameraBottom(mwindow, this, x1, y));
00571 
00572 }
00573 
00574 void CWindowCameraGUI::update_preview()
00575 {
00576         mwindow->restart_brender();
00577         mwindow->sync_parameters(CHANGE_PARAMS);
00578 
00579         mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
00580                         CHANGE_NONE,
00581                         mwindow->edl,
00582                         1);
00583         mwindow->cwindow->gui->lock_window("CWindowCameraGUI::update_preview");
00584         mwindow->cwindow->gui->canvas->draw_refresh();
00585         mwindow->cwindow->gui->unlock_window();
00586 }
00587 
00588 
00589 void CWindowCameraGUI::handle_event()
00590 {
00591         FloatAuto *x_auto = 0;
00592         FloatAuto *y_auto = 0;
00593         FloatAuto *z_auto = 0;
00594         Track *track = mwindow->cwindow->calculate_affected_track();
00595         if(track)
00596         {
00597                 if(event_caller == x)
00598                 {
00599                         x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
00600                                 track->automation->autos[AUTOMATION_CAMERA_X],
00601                                 1);
00602                         if(x_auto)
00603                         {
00604                                 x_auto->value = atof(x->get_text());
00605                                 update_preview();
00606                         }
00607                 }
00608                 else
00609                 if(event_caller == y)
00610                 {
00611                         y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
00612                                 track->automation->autos[AUTOMATION_CAMERA_Y],
00613                                 1);
00614                         if(y_auto)
00615                         {
00616                                 y_auto->value = atof(y->get_text());
00617                                 update_preview();
00618                         }
00619                 }
00620                 else
00621                 if(event_caller == z)
00622                 {
00623                         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
00624                                 track->automation->autos[AUTOMATION_CAMERA_Z],
00625                                 1);
00626                         if(z_auto)
00627                         {
00628                                 float zoom = atof(z->get_text());
00629                                 if(zoom > 10) zoom = 10; 
00630                                 else
00631                                 if(zoom < 0) zoom = 0;
00632         // Doesn't allow user to enter from scratch
00633         //              if(zoom != atof(z->get_text())) 
00634         //                      z->update(zoom);
00635 
00636                                 z_auto->value = zoom;
00637                                 mwindow->gui->lock_window("CWindowCameraGUI::handle_event");
00638                                 mwindow->gui->canvas->draw_overlays();
00639                                 mwindow->gui->canvas->flash();
00640                                 mwindow->gui->unlock_window();
00641                                 update_preview();
00642                         }
00643                 }
00644         }
00645 }
00646 
00647 void CWindowCameraGUI::update()
00648 {
00649         FloatAuto *x_auto = 0;
00650         FloatAuto *y_auto = 0;
00651         FloatAuto *z_auto = 0;
00652         Track *track = mwindow->cwindow->calculate_affected_track();
00653 
00654         if(track)
00655         {
00656                 mwindow->cwindow->calculate_affected_autos(&x_auto,
00657                         &y_auto,
00658                         &z_auto,
00659                         track,
00660                         1,
00661                         0,
00662                         0,
00663                         0);
00664         }
00665 
00666         if(x_auto)
00667                 x->update(x_auto->value);
00668         if(y_auto)
00669                 y->update(y_auto->value);
00670         if(z_auto)
00671                 z->update(z_auto->value);
00672 }
00673 
00674 // BezierAuto* CWindowCameraGUI::get_keyframe()
00675 // {
00676 //      BezierAuto *keyframe = 0;
00677 //      Track *track = mwindow->cwindow->calculate_affected_track();
00678 //      if(track)
00679 //              keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
00680 //                      track->automation->autos[AUTOMATION_CAMERA]);
00681 //      return keyframe;
00682 // }
00683 
00684 
00685 
00686 CWindowCameraLeft::CWindowCameraLeft(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
00687  : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
00688 {
00689         this->gui = gui;
00690         this->mwindow = mwindow;
00691         set_tooltip(_("Left justify"));
00692 }
00693 int CWindowCameraLeft::handle_event()
00694 {
00695         FloatAuto *x_auto = 0;
00696         FloatAuto *z_auto = 0;
00697         Track *track = mwindow->cwindow->calculate_affected_track();
00698         if(track)
00699         {
00700                 mwindow->cwindow->calculate_affected_autos(&x_auto,
00701                         0,
00702                         &z_auto,
00703                         track,
00704                         1,
00705                         1,
00706                         0,
00707                         0);
00708         }
00709 
00710         if(x_auto && z_auto)
00711         {
00712                 int w = 0, h = 0;
00713                 track->get_source_dimensions(
00714                         mwindow->edl->local_session->get_selectionstart(1),
00715                         w,
00716                         h);
00717 
00718                 if(w && h)
00719                 {
00720                         x_auto->value = 
00721                                 (double)track->track_w / z_auto->value / 2 - 
00722                                 (double)w / 2;
00723                         gui->update();
00724                         gui->update_preview();
00725                 }
00726         }
00727 
00728         return 1;
00729 }
00730 
00731 
00732 CWindowCameraCenter::CWindowCameraCenter(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
00733  : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
00734 {
00735         this->gui = gui;
00736         this->mwindow = mwindow;
00737         set_tooltip(_("Center horizontal"));
00738 }
00739 int CWindowCameraCenter::handle_event()
00740 {
00741         FloatAuto *x_auto = 0;
00742         Track *track = mwindow->cwindow->calculate_affected_track();
00743         if(track)
00744                 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
00745                         track->automation->autos[AUTOMATION_CAMERA_X],
00746                         1);
00747 
00748         if(x_auto)
00749         {
00750                 x_auto->value = 0;
00751                 gui->update();
00752                 gui->update_preview();
00753         }
00754 
00755         return 1;
00756 }
00757 
00758 
00759 CWindowCameraRight::CWindowCameraRight(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
00760  : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
00761 {
00762         this->gui = gui;
00763         this->mwindow = mwindow;
00764         set_tooltip(_("Right justify"));
00765 }
00766 int CWindowCameraRight::handle_event()
00767 {
00768         FloatAuto *x_auto = 0;
00769         FloatAuto *z_auto = 0;
00770         Track *track = mwindow->cwindow->calculate_affected_track();
00771         if(track)
00772         {
00773                 mwindow->cwindow->calculate_affected_autos(&x_auto,
00774                         0,
00775                         &z_auto,
00776                         track,
00777                         1,
00778                         1,
00779                         0,
00780                         0);
00781         }
00782 
00783         if(x_auto && z_auto)
00784         {
00785                 int w = 0, h = 0;
00786                 track->get_source_dimensions(
00787                         mwindow->edl->local_session->get_selectionstart(1),
00788                         w,
00789                         h);
00790 
00791                 if(w && h)
00792                 {
00793                         x_auto->value = -((double)track->track_w / z_auto->value / 2 - 
00794                                 (double)w / 2);
00795                         gui->update();
00796                         gui->update_preview();
00797                 }
00798         }
00799 
00800         return 1;
00801 }
00802 
00803 
00804 CWindowCameraTop::CWindowCameraTop(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
00805  : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
00806 {
00807         this->gui = gui;
00808         this->mwindow = mwindow;
00809         set_tooltip(_("Top justify"));
00810 }
00811 int CWindowCameraTop::handle_event()
00812 {
00813         FloatAuto *y_auto = 0;
00814         FloatAuto *z_auto = 0;
00815         Track *track = mwindow->cwindow->calculate_affected_track();
00816         if(track)
00817         {
00818                 mwindow->cwindow->calculate_affected_autos(0,
00819                         &y_auto,
00820                         &z_auto,
00821                         track,
00822                         1,
00823                         0,
00824                         1,
00825                         0);
00826         }
00827 
00828         if(y_auto && z_auto)
00829         {
00830                 int w = 0, h = 0;
00831                 track->get_source_dimensions(
00832                         mwindow->edl->local_session->get_selectionstart(1),
00833                         w,
00834                         h);
00835 
00836                 if(w && h)
00837                 {
00838                         y_auto->value = (double)track->track_h / z_auto->value / 2 - 
00839                                 (double)h / 2;
00840                         gui->update();
00841                         gui->update_preview();
00842                 }
00843         }
00844 
00845         return 1;
00846 }
00847 
00848 
00849 CWindowCameraMiddle::CWindowCameraMiddle(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
00850  : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
00851 {
00852         this->gui = gui;
00853         this->mwindow = mwindow;
00854         set_tooltip(_("Center vertical"));
00855 }
00856 int CWindowCameraMiddle::handle_event()
00857 {
00858         FloatAuto *y_auto = 0;
00859         Track *track = mwindow->cwindow->calculate_affected_track();
00860         if(track)
00861                 y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
00862                         track->automation->autos[AUTOMATION_CAMERA_Y], 1);
00863 
00864         if(y_auto)
00865         {
00866                 y_auto->value = 0;
00867                 gui->update();
00868                 gui->update_preview();
00869         }
00870 
00871         return 1;
00872 }
00873 
00874 
00875 CWindowCameraBottom::CWindowCameraBottom(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
00876  : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
00877 {
00878         this->gui = gui;
00879         this->mwindow = mwindow;
00880         set_tooltip(_("Bottom justify"));
00881 }
00882 int CWindowCameraBottom::handle_event()
00883 {
00884         FloatAuto *y_auto = 0;
00885         FloatAuto *z_auto = 0;
00886         Track *track = mwindow->cwindow->calculate_affected_track();
00887         if(track)
00888         {
00889                 mwindow->cwindow->calculate_affected_autos(0,
00890                         &y_auto,
00891                         &z_auto,
00892                         track,
00893                         1,
00894                         0,
00895                         1,
00896                         0);
00897         }
00898 
00899         if(y_auto && z_auto)
00900         {
00901                 int w = 0, h = 0;
00902                 track->get_source_dimensions(
00903                         mwindow->edl->local_session->get_selectionstart(1),
00904                         w,
00905                         h);
00906 
00907                 if(w && h)
00908                 {
00909                         y_auto->value = -((double)track->track_h / z_auto->value / 2 - 
00910                                 (double)h / 2);
00911                         gui->update();
00912                         gui->update_preview();
00913                 }
00914         }
00915 
00916         return 1;
00917 }
00918 
00919 
00920 
00921 
00922 
00923 
00924 
00925 
00926 
00927 
00928 
00929 
00930 
00931 
00932 
00933 
00934 
00935 CWindowProjectorGUI::CWindowProjectorGUI(MWindow *mwindow, CWindowTool *thread)
00936  : CWindowToolGUI(mwindow, 
00937         thread,
00938         PROGRAM_NAME ": Projector",
00939         170,
00940         170)
00941 {
00942 }
00943 CWindowProjectorGUI::~CWindowProjectorGUI()
00944 {
00945 }
00946 void CWindowProjectorGUI::create_objects()
00947 {
00948         int x = 10, y = 10, x1;
00949         Track *track = mwindow->cwindow->calculate_affected_track();
00950         FloatAuto *x_auto = 0;
00951         FloatAuto *y_auto = 0;
00952         FloatAuto *z_auto = 0;
00953         BC_Title *title;
00954         BC_Button *button;
00955 
00956         if(track)
00957         {
00958                 mwindow->cwindow->calculate_affected_autos(&x_auto,
00959                         &y_auto,
00960                         &z_auto,
00961                         track,
00962                         0,
00963                         0,
00964                         0,
00965                         0);
00966         }
00967 
00968         add_subwindow(title = new BC_Title(x, y, _("X:")));
00969         x += title->get_w();
00970         this->x = new CWindowCoord(this, 
00971                 x, 
00972                 y, 
00973                 x_auto ? x_auto->value : (float)0);
00974         this->x->create_objects();
00975         y += 30;
00976         x = 10;
00977         add_subwindow(title = new BC_Title(x, y, _("Y:")));
00978         x += title->get_w();
00979         this->y = new CWindowCoord(this, 
00980                 x, 
00981                 y, 
00982                 y_auto ? y_auto->value : (float)0);
00983         this->y->create_objects();
00984         y += 30;
00985         x = 10;
00986         add_subwindow(title = new BC_Title(x, y, _("Z:")));
00987         x += title->get_w();
00988         this->z = new CWindowCoord(this, 
00989                 x, 
00990                 y, 
00991                 z_auto ? z_auto->value : (float)1);
00992         this->z->create_objects();
00993 
00994         y += 30;
00995         x1 = 10;
00996         add_subwindow(button = new CWindowProjectorLeft(mwindow, this, x1, y));
00997         x1 += button->get_w();
00998         add_subwindow(button = new CWindowProjectorCenter(mwindow, this, x1, y));
00999         x1 += button->get_w();
01000         add_subwindow(button = new CWindowProjectorRight(mwindow, this, x1, y));
01001 
01002         y += button->get_h();
01003         x1 = 10;
01004         add_subwindow(button = new CWindowProjectorTop(mwindow, this, x1, y));
01005         x1 += button->get_w();
01006         add_subwindow(button = new CWindowProjectorMiddle(mwindow, this, x1, y));
01007         x1 += button->get_w();
01008         add_subwindow(button = new CWindowProjectorBottom(mwindow, this, x1, y));
01009 
01010 }
01011 
01012 void CWindowProjectorGUI::update_preview()
01013 {
01014         mwindow->restart_brender();
01015         mwindow->sync_parameters(CHANGE_PARAMS);
01016         mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
01017                         CHANGE_NONE,
01018                         mwindow->edl,
01019                         1);
01020         mwindow->cwindow->gui->lock_window("CWindowProjectorGUI::update_preview");
01021         mwindow->cwindow->gui->canvas->draw_refresh();
01022         mwindow->cwindow->gui->unlock_window();
01023 }
01024 
01025 void CWindowProjectorGUI::handle_event()
01026 {
01027         FloatAuto *x_auto = 0;
01028         FloatAuto *y_auto = 0;
01029         FloatAuto *z_auto = 0;
01030         Track *track = mwindow->cwindow->calculate_affected_track();
01031 
01032         if(track)
01033         {
01034                 if(event_caller == x)
01035                 {
01036                         x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
01037                                 track->automation->autos[AUTOMATION_PROJECTOR_X],
01038                                 1);
01039                         if(x_auto)
01040                         {
01041                                 x_auto->value = atof(x->get_text());
01042                                 update_preview();
01043                         }
01044                 }
01045                 else
01046                 if(event_caller == y)
01047                 {
01048                         y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
01049                                 track->automation->autos[AUTOMATION_PROJECTOR_Y],
01050                                 1);
01051                         if(y_auto)
01052                         {
01053                                 y_auto->value = atof(y->get_text());
01054                                 update_preview();
01055                         }
01056                 }
01057                 else
01058                 if(event_caller == z)
01059                 {
01060                         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
01061                                 track->automation->autos[AUTOMATION_PROJECTOR_Z],
01062                                 1);
01063                         if(z_auto)
01064                         {
01065                                 float zoom = atof(z->get_text());
01066                                 if(zoom > 10000) zoom = 10000; 
01067                                 else 
01068                                 if(zoom < 0) zoom = 0;
01069 //                      if (zoom != atof(z->get_text())) 
01070 //                              z->update(zoom);
01071                                 z_auto->value = zoom;
01072 
01073                                 mwindow->gui->lock_window("CWindowProjectorGUI::handle_event");
01074                                 mwindow->gui->canvas->draw_overlays();
01075                                 mwindow->gui->canvas->flash();
01076                                 mwindow->gui->unlock_window();
01077 
01078                                 update_preview();
01079                         }
01080                 }
01081         }
01082 }
01083 
01084 void CWindowProjectorGUI::update()
01085 {
01086         FloatAuto *x_auto = 0;
01087         FloatAuto *y_auto = 0;
01088         FloatAuto *z_auto = 0;
01089         Track *track = mwindow->cwindow->calculate_affected_track();
01090 
01091         if(track)
01092         {
01093                 mwindow->cwindow->calculate_affected_autos(&x_auto,
01094                         &y_auto,
01095                         &z_auto,
01096                         track,
01097                         0,
01098                         0,
01099                         0,
01100                         0);
01101         }
01102 
01103         if(x_auto)
01104                 x->update(x_auto->value);
01105         if(y_auto)
01106                 y->update(y_auto->value);
01107         if(z_auto)
01108                 z->update(z_auto->value);
01109 }
01110 
01111 // BezierAuto* CWindowProjectorGUI::get_keyframe()
01112 // {
01113 //      BezierAuto *keyframe = 0;
01114 //      Track *track = mwindow->cwindow->calculate_affected_track();
01115 //      if(track)
01116 //              keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
01117 //                      track->automation->autos[AUTOMATION_PROJECTOR]);
01118 //      return keyframe;
01119 // }
01120 
01121 
01122 
01123 
01124 
01125 
01126 
01127 
01128 
01129 
01130 
01131 
01132 
01133 
01134 
01135 
01136 
01137 
01138 
01139 
01140 
01141 
01142 
01143 
01144 
01145 
01146 
01147 
01148 
01149 
01150 
01151 
01152 
01153 
01154 
01155 
01156 
01157 
01158 CWindowProjectorLeft::CWindowProjectorLeft(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
01159  : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
01160 {
01161         this->gui = gui;
01162         this->mwindow = mwindow;
01163         set_tooltip(_("Left justify"));
01164 }
01165 int CWindowProjectorLeft::handle_event()
01166 {
01167         FloatAuto *x_auto = 0;
01168         FloatAuto *z_auto = 0;
01169         Track *track = mwindow->cwindow->calculate_affected_track();
01170         if(track)
01171         {
01172                 mwindow->cwindow->calculate_affected_autos(&x_auto,
01173                         0,
01174                         &z_auto,
01175                         track,
01176                         0,
01177                         1,
01178                         0,
01179                         0);
01180         }
01181         if(x_auto && z_auto)
01182         {
01183                 x_auto->value = (double)track->track_w * z_auto->value / 2 - 
01184                         (double)mwindow->edl->session->output_w / 2;
01185                 gui->update();
01186                 gui->update_preview();
01187         }
01188 
01189         return 1;
01190 }
01191 
01192 
01193 CWindowProjectorCenter::CWindowProjectorCenter(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
01194  : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
01195 {
01196         this->gui = gui;
01197         this->mwindow = mwindow;
01198         set_tooltip(_("Center horizontal"));
01199 }
01200 int CWindowProjectorCenter::handle_event()
01201 {
01202         FloatAuto *x_auto = 0;
01203         Track *track = mwindow->cwindow->calculate_affected_track();
01204         if(track)
01205                 x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
01206                         track->automation->autos[AUTOMATION_PROJECTOR_X],
01207                         1);
01208 
01209         if(x_auto)
01210         {
01211                 x_auto->value = 0;
01212                 gui->update();
01213                 gui->update_preview();
01214         }
01215 
01216         return 1;
01217 }