Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / videowindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "mbuttons.h"
23 #include "mwindow.h"
24 #include "mwindowgui.h"
25 #include "mainsession.h"
26 #include "videowindow.h"
27 #include "videowindowgui.h"
28
29
30
31 #define CROPHANDLE_W xS(10)
32 #define CROPHANDLE_H yS(10)
33
34 VideoWindowGUI::VideoWindowGUI(VideoWindow *thread, int w, int h)
35  : BC_Window(_(PROGRAM_NAME ": Video out"),
36         (int)BC_INFINITY, (int)BC_INFINITY,
37         w, h, xS(10), yS(10), 1, 1, 1)
38 {
39         this->thread = thread;
40 }
41
42 VideoWindowGUI::~VideoWindowGUI()
43 {
44 }
45
46 void VideoWindowGUI::create_objects()
47 {
48         lock_window("VideoWindowGUI::create_objects");
49         add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
50         update_title();
51         unlock_window();
52 }
53
54 int VideoWindowGUI::keypress_event()
55 {
56 }
57
58 int VideoWindowGUI::resize_event(int w, int h)
59 {
60 //      int output_w = thread->mwindow->session->output_w;
61 //      int output_h = thread->mwindow->session->output_h;
62 //      int new_w, new_h, full_w, full_h;
63 //
64 //      new_w = w;
65 //      new_h = h;
66 //      thread->get_full_sizes(full_w, full_h);
67 //
68 //      if(labs(full_w - new_w) < xS(50))
69 //      {
70 //              new_w = full_w;
71 //              new_h = full_h;
72 //      }
73 //      else
74 //              thread->fix_size(new_w, new_h, w, thread->mwindow->get_aspect_ratio());
75 //
76 //      if(new_w < xS(10)) new_w = xS(10);
77 //      if(new_h < yS(10)) new_h = yS(10);
78 //      w = thread->video_window_w = new_w;
79 //      h = new_h;
80 //
81 //      resize_window(w, h);
82 //      canvas->reposition_window(0, 0, w, h);
83 //      update_title();
84 //      if(thread->video_cropping) canvas->draw_crop_box();
85 }
86
87 int VideoWindowGUI::update_title()
88 {
89 //      char string[1024];
90 //
91 //      if(thread->mwindow->get_aspect_ratio() > (float)thread->mwindow->session->output_w / thread->mwindow->session->output_h)
92 //      {
93 //              sprintf(string, PROGRAM_NAME ": Video out %d%%",
94 //                      (int)((float)thread->video_window_w / (thread->mwindow->session->output_h * thread->mwindow->get_aspect_ratio()) * 100 + 0.5));
95 //      }
96 //      else
97 //      {
98 //              sprintf(string, PROGRAM_NAME ": Video out %d%%",
99 //                      (int)((float)thread->video_window_w / thread->mwindow->session->output_w * 100 + 0.5));
100 //      }
101 //
102 //      set_title(string);
103 }
104
105 int VideoWindowGUI::close_event()
106 {
107         thread->hide_window();
108         return 0;
109 }
110
111
112 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
113  : BC_SubWindow(0, 0, w, h, BLACK)
114 {
115         this->gui = gui;
116         corner_selected = 0;
117         button_down = 0;
118 }
119
120 VideoWindowCanvas::~VideoWindowCanvas()
121 {
122 }
123
124 int VideoWindowCanvas::button_press()
125 {
126         if(gui->thread->video_cropping)
127         {
128                 int x = get_cursor_x();
129                 int y = get_cursor_y();
130                 button_down = 1;
131
132                 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
133                 {
134                         corner_selected = 1;
135                         gui->x_offset = x - gui->x1;
136                         gui->y_offset = y - gui->y1;
137                 }
138                 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
139                 {
140                         corner_selected = 2;
141                         gui->x_offset = x - gui->x1;
142                         gui->y_offset = y - gui->y2;
143                 }
144                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
145                 {
146                         corner_selected = 3;
147                         gui->x_offset = x - gui->x2;
148                         gui->y_offset = y - gui->y2;
149                 }
150                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
151                 {
152                         corner_selected = 4;
153                         gui->x_offset = x - gui->x2;
154                         gui->y_offset = y - gui->y1;
155                 }
156         }
157         return 0;
158 }
159
160 int VideoWindowCanvas::button_release()
161 {
162         if(gui->thread->video_cropping && button_down)
163         {
164                 button_down = 0;
165                 corner_selected = 0;
166         }
167         return 0;
168 }
169
170 int VideoWindowCanvas::cursor_motion()
171 {
172         if(button_down && gui->thread->video_cropping && corner_selected)
173         {
174                 int x = get_cursor_x();
175                 int y = get_cursor_y();
176                 draw_crop_box();
177
178                 switch(corner_selected)
179                 {
180                         case 1:
181                                 gui->x1 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
182                                 break;
183                         case 2:
184                                 gui->x1 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
185                                 break;
186                         case 3:
187                                 gui->x2 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
188                                 break;
189                         case 4:
190                                 gui->x2 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
191                                 break;
192                 };
193
194                 if(gui->x1 < 0) gui->x1 = 0;
195                 if(gui->y1 < 0) gui->y1 = 0;
196                 if(gui->x1 > get_w()) gui->x1 = get_w();
197                 if(gui->y1 > get_h()) gui->y1 = get_h();
198                 if(gui->x2 < 0) gui->x2 = 0;
199                 if(gui->y2 < 0) gui->y2 = 0;
200                 if(gui->x2 > get_w()) gui->x2 = get_w();
201                 if(gui->y2 > get_h()) gui->y2 = get_h();
202                 draw_crop_box();
203                 flash();
204         }
205         return 0;
206 }
207
208 int VideoWindowCanvas::draw_crop_box()
209 {
210         int w = gui->x2 - gui->x1;
211         int h = gui->y2 - gui->y1;
212
213         set_inverse();
214         set_color(WHITE);
215         draw_box(gui->x1 + 1, gui->y1 + 1, CROPHANDLE_W - 1, CROPHANDLE_H - 1);
216         draw_box(gui->x1 + 1, gui->y2 - CROPHANDLE_H, CROPHANDLE_W - 1, CROPHANDLE_H);
217         draw_box(gui->x2 - CROPHANDLE_W, gui->y2 - CROPHANDLE_H, CROPHANDLE_W, CROPHANDLE_H);
218         draw_box(gui->x2 - CROPHANDLE_W, gui->y1 + 1, CROPHANDLE_W, CROPHANDLE_H - 1);
219         draw_rectangle(gui->x1, gui->y1, w, h);
220         set_opaque();
221         return 0;
222 }
223