r999: maintainers added to README_en.
[cinelerra_cv/mob.git] / cinelerra / videowindowgui.C
blob26e7f64045ffe1d1bfc5d2ef187948110966a8a9
1 #include "mbuttons.h"
2 #include "mwindow.h"
3 #include "mwindowgui.h"
4 #include "mainsession.h"
5 #include "videowindow.h"
6 #include "videowindowgui.h"
10 #define CROPHANDLE_W 10
11 #define CROPHANDLE_H 10
13 VideoWindowGUI::VideoWindowGUI(VideoWindow *thread, int w, int h)
14  : BC_Window(PROGRAM_NAME ": Video out", 
15         (int)BC_INFINITY,
16         (int)BC_INFINITY,
17         w, 
18         h, 
19         10, 
20         10, 
21         1, 
22         1,
23         1)
25         this->thread = thread;
28 VideoWindowGUI::~VideoWindowGUI()
32 int VideoWindowGUI::create_objects()
34         add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
35         update_title();
39 int VideoWindowGUI::keypress_event()
43 int VideoWindowGUI::resize_event(int w, int h)
45 //      int output_w = thread->mwindow->session->output_w;
46 //      int output_h = thread->mwindow->session->output_h;
47 //      int new_w, new_h, full_w, full_h;
48 // 
49 //      new_w = w;
50 //      new_h = h;
51 //      thread->get_full_sizes(full_w, full_h);
52 // 
53 //      if(labs(full_w - new_w) < 50)
54 //      {
55 //              new_w = full_w;
56 //              new_h = full_h;
57 //      }
58 //      else
59 //              thread->fix_size(new_w, new_h, w, thread->mwindow->get_aspect_ratio());
60 // 
61 //      if(new_w < 10) new_w = 10;
62 //      if(new_h < 10) new_h = 10;
63 //      w = thread->video_window_w = new_w;
64 //      h = new_h;
65 // 
66 //      resize_window(w, h);
67 //      canvas->reposition_window(0, 0, w, h);
68 //      update_title();
69 //      if(thread->video_cropping) canvas->draw_crop_box();
72 int VideoWindowGUI::update_title()
74 //      char string[1024];
75 // 
76 //      if(thread->mwindow->get_aspect_ratio() > (float)thread->mwindow->session->output_w / thread->mwindow->session->output_h)
77 //      {
78 //              sprintf(string, PROGRAM_NAME ": Video out %d%%", 
79 //                      (int)((float)thread->video_window_w / (thread->mwindow->session->output_h * thread->mwindow->get_aspect_ratio()) * 100 + 0.5));
80 //      }
81 //      else
82 //      {
83 //              sprintf(string, PROGRAM_NAME ": Video out %d%%", 
84 //                      (int)((float)thread->video_window_w / thread->mwindow->session->output_w * 100 + 0.5));
85 //      }
86 // 
87 //      set_title(string);
90 int VideoWindowGUI::close_event()
92         thread->hide_window();
96 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
97  : BC_SubWindow(0, 0, w, h, BLACK)
99         this->gui = gui;
100         corner_selected = 0;
101         button_down = 0;
104 VideoWindowCanvas::~VideoWindowCanvas()
108 int VideoWindowCanvas::button_press()
110         if(gui->thread->video_cropping)
111         {
112                 int x = get_cursor_x();
113                 int y = get_cursor_y();
114                 button_down = 1;
116                 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
117                 {
118                         corner_selected = 1;
119                         gui->x_offset = x - gui->x1;
120                         gui->y_offset = y - gui->y1;
121                 }
122                 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
123                 {
124                         corner_selected = 2;
125                         gui->x_offset = x - gui->x1;
126                         gui->y_offset = y - gui->y2;
127                 }
128                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
129                 {
130                         corner_selected = 3;
131                         gui->x_offset = x - gui->x2;
132                         gui->y_offset = y - gui->y2;
133                 }
134                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
135                 {
136                         corner_selected = 4;
137                         gui->x_offset = x - gui->x2;
138                         gui->y_offset = y - gui->y1;
139                 }
140         }
143 int VideoWindowCanvas::button_release()
145         if(gui->thread->video_cropping && button_down)
146         {
147                 button_down = 0;
148                 corner_selected = 0;
149         }
152 int VideoWindowCanvas::cursor_motion()
154         if(button_down && gui->thread->video_cropping && corner_selected)
155         {
156                 int x = get_cursor_x();
157                 int y = get_cursor_y();
158                 draw_crop_box();
160                 switch(corner_selected)
161                 {
162                         case 1:
163                                 gui->x1 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
164                                 break;
165                         case 2:
166                                 gui->x1 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
167                                 break;
168                         case 3:
169                                 gui->x2 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
170                                 break;
171                         case 4:
172                                 gui->x2 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
173                                 break;
174                 };
176                 if(gui->x1 < 0) gui->x1 = 0;
177                 if(gui->y1 < 0) gui->y1 = 0;
178                 if(gui->x1 > get_w()) gui->x1 = get_w();
179                 if(gui->y1 > get_h()) gui->y1 = get_h();
180                 if(gui->x2 < 0) gui->x2 = 0;
181                 if(gui->y2 < 0) gui->y2 = 0;
182                 if(gui->x2 > get_w()) gui->x2 = get_w();
183                 if(gui->y2 > get_h()) gui->y2 = get_h();
184                 draw_crop_box();
185                 flash();
186         }
189 int VideoWindowCanvas::draw_crop_box()
191         int w = gui->x2 - gui->x1;
192         int h = gui->y2 - gui->y1;
194         set_inverse();
195         set_color(WHITE);
196         draw_box(gui->x1 + 1, gui->y1 + 1, CROPHANDLE_W - 1, CROPHANDLE_H - 1);
197         draw_box(gui->x1 + 1, gui->y2 - CROPHANDLE_H, CROPHANDLE_W - 1, CROPHANDLE_H);
198         draw_box(gui->x2 - CROPHANDLE_W, gui->y2 - CROPHANDLE_H, CROPHANDLE_W, CROPHANDLE_H);
199         draw_box(gui->x2 - CROPHANDLE_W, gui->y1 + 1, CROPHANDLE_W, CROPHANDLE_H - 1);
200         draw_rectangle(gui->x1, gui->y1, w, h);
201         set_opaque();