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

videowindowgui.C

Go to the documentation of this file.
00001 #include "mbuttons.h"
00002 #include "mwindow.h"
00003 #include "mwindowgui.h"
00004 #include "mainsession.h"
00005 #include "videowindow.h"
00006 #include "videowindowgui.h"
00007 
00008 
00009 
00010 #define CROPHANDLE_W 10
00011 #define CROPHANDLE_H 10
00012 
00013 VideoWindowGUI::VideoWindowGUI(VideoWindow *thread, int w, int h)
00014  : BC_Window(PROGRAM_NAME ": Video out", 
00015         (int)BC_INFINITY,
00016         (int)BC_INFINITY,
00017         w, 
00018         h, 
00019         10, 
00020         10, 
00021         1, 
00022         1,
00023         1)
00024 {
00025         this->thread = thread;
00026 }
00027 
00028 VideoWindowGUI::~VideoWindowGUI()
00029 {
00030 }
00031 
00032 int VideoWindowGUI::create_objects()
00033 {
00034         add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
00035         update_title();
00036 }
00037 
00038 
00039 int VideoWindowGUI::keypress_event()
00040 {
00041 }
00042 
00043 int VideoWindowGUI::resize_event(int w, int h)
00044 {
00045 //      int output_w = thread->mwindow->session->output_w;
00046 //      int output_h = thread->mwindow->session->output_h;
00047 //      int new_w, new_h, full_w, full_h;
00048 // 
00049 //      new_w = w;
00050 //      new_h = h;
00051 //      thread->get_full_sizes(full_w, full_h);
00052 // 
00053 //      if(labs(full_w - new_w) < 50)
00054 //      {
00055 //              new_w = full_w;
00056 //              new_h = full_h;
00057 //      }
00058 //      else
00059 //              thread->fix_size(new_w, new_h, w, thread->mwindow->get_aspect_ratio());
00060 // 
00061 //      if(new_w < 10) new_w = 10;
00062 //      if(new_h < 10) new_h = 10;
00063 //      w = thread->video_window_w = new_w;
00064 //      h = new_h;
00065 // 
00066 //      resize_window(w, h);
00067 //      canvas->reposition_window(0, 0, w, h);
00068 //      update_title();
00069 //      if(thread->video_cropping) canvas->draw_crop_box();
00070 }
00071 
00072 int VideoWindowGUI::update_title()
00073 {
00074 //      char string[1024];
00075 // 
00076 //      if(thread->mwindow->get_aspect_ratio() > (float)thread->mwindow->session->output_w / thread->mwindow->session->output_h)
00077 //      {
00078 //              sprintf(string, PROGRAM_NAME ": Video out %d%%", 
00079 //                      (int)((float)thread->video_window_w / (thread->mwindow->session->output_h * thread->mwindow->get_aspect_ratio()) * 100 + 0.5));
00080 //      }
00081 //      else
00082 //      {
00083 //              sprintf(string, PROGRAM_NAME ": Video out %d%%", 
00084 //                      (int)((float)thread->video_window_w / thread->mwindow->session->output_w * 100 + 0.5));
00085 //      }
00086 // 
00087 //      set_title(string);
00088 }
00089 
00090 int VideoWindowGUI::close_event()
00091 {
00092         thread->hide_window();
00093 }
00094 
00095 
00096 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
00097  : BC_SubWindow(0, 0, w, h, BLACK)
00098 {
00099         this->gui = gui;
00100         corner_selected = 0;
00101         button_down = 0;
00102 }
00103 
00104 VideoWindowCanvas::~VideoWindowCanvas()
00105 {
00106 }
00107 
00108 int VideoWindowCanvas::button_press()
00109 {
00110         if(gui->thread->video_cropping)
00111         {
00112                 int x = get_cursor_x();
00113                 int y = get_cursor_y();
00114                 button_down = 1;
00115 
00116                 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
00117                 {
00118                         corner_selected = 1;
00119                         gui->x_offset = x - gui->x1;
00120                         gui->y_offset = y - gui->y1;
00121                 }
00122                 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
00123                 {
00124                         corner_selected = 2;
00125                         gui->x_offset = x - gui->x1;
00126                         gui->y_offset = y - gui->y2;
00127                 }
00128                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
00129                 {
00130                         corner_selected = 3;
00131                         gui->x_offset = x - gui->x2;
00132                         gui->y_offset = y - gui->y2;
00133                 }
00134                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
00135                 {
00136                         corner_selected = 4;
00137                         gui->x_offset = x - gui->x2;
00138                         gui->y_offset = y - gui->y1;
00139                 }
00140         }
00141 }
00142 
00143 int VideoWindowCanvas::button_release()
00144 {
00145         if(gui->thread->video_cropping && button_down)
00146         {
00147                 button_down = 0;
00148                 corner_selected = 0;
00149         }
00150 }
00151 
00152 int VideoWindowCanvas::cursor_motion()
00153 {
00154         if(button_down && gui->thread->video_cropping && corner_selected)
00155         {
00156                 int x = get_cursor_x();
00157                 int y = get_cursor_y();
00158                 draw_crop_box();
00159 
00160                 switch(corner_selected)
00161                 {
00162                         case 1:
00163                                 gui->x1 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
00164                                 break;
00165                         case 2:
00166                                 gui->x1 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
00167                                 break;
00168                         case 3:
00169                                 gui->x2 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
00170                                 break;
00171                         case 4:
00172                                 gui->x2 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
00173                                 break;
00174                 };
00175 
00176                 if(gui->x1 < 0) gui->x1 = 0;
00177                 if(gui->y1 < 0) gui->y1 = 0;
00178                 if(gui->x1 > get_w()) gui->x1 = get_w();
00179                 if(gui->y1 > get_h()) gui->y1 = get_h();
00180                 if(gui->x2 < 0) gui->x2 = 0;
00181                 if(gui->y2 < 0) gui->y2 = 0;
00182                 if(gui->x2 > get_w()) gui->x2 = get_w();
00183                 if(gui->y2 > get_h()) gui->y2 = get_h();
00184                 draw_crop_box();
00185                 flash();
00186         }
00187 }
00188 
00189 int VideoWindowCanvas::draw_crop_box()
00190 {
00191         int w = gui->x2 - gui->x1;
00192         int h = gui->y2 - gui->y1;
00193 
00194         set_inverse();
00195         set_color(WHITE);
00196         draw_box(gui->x1 + 1, gui->y1 + 1, CROPHANDLE_W - 1, CROPHANDLE_H - 1);
00197         draw_box(gui->x1 + 1, gui->y2 - CROPHANDLE_H, CROPHANDLE_W - 1, CROPHANDLE_H);
00198         draw_box(gui->x2 - CROPHANDLE_W, gui->y2 - CROPHANDLE_H, CROPHANDLE_W, CROPHANDLE_H);
00199         draw_box(gui->x2 - CROPHANDLE_W, gui->y1 + 1, CROPHANDLE_W, CROPHANDLE_H - 1);
00200         draw_rectangle(gui->x1, gui->y1, w, h);
00201         set_opaque();
00202 }
00203 

Generated on Sun Jan 8 13:39:02 2006 for Cinelerra-svn by  doxygen 1.4.4