bsd lang segv fix, enable bsd lv2, lv2 gui enable fix, proxy/ffmpeg toggle resize...
[goodguy/history.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 10
32 #define CROPHANDLE_H 10
33
34 VideoWindowGUI::VideoWindowGUI(VideoWindow *thread, int w, int h)
35  : BC_Window(_(PROGRAM_NAME ": Video out"),
36         (int)BC_INFINITY,
37         (int)BC_INFINITY,
38         w,
39         h,
40         10,
41         10,
42         1,
43         1,
44         1)
45 {
46         this->thread = thread;
47 }
48
49 VideoWindowGUI::~VideoWindowGUI()
50 {
51 }
52
53 void VideoWindowGUI::create_objects()
54 {
55         add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
56         update_title();
57 }
58
59
60 int VideoWindowGUI::keypress_event()
61 {
62 }
63
64 int VideoWindowGUI::resize_event(int w, int h)
65 {
66 //      int output_w = thread->mwindow->session->output_w;
67 //      int output_h = thread->mwindow->session->output_h;
68 //      int new_w, new_h, full_w, full_h;
69 //
70 //      new_w = w;
71 //      new_h = h;
72 //      thread->get_full_sizes(full_w, full_h);
73 //
74 //      if(labs(full_w - new_w) < 50)
75 //      {
76 //              new_w = full_w;
77 //              new_h = full_h;
78 //      }
79 //      else
80 //              thread->fix_size(new_w, new_h, w, thread->mwindow->get_aspect_ratio());
81 //
82 //      if(new_w < 10) new_w = 10;
83 //      if(new_h < 10) new_h = 10;
84 //      w = thread->video_window_w = new_w;
85 //      h = new_h;
86 //
87 //      resize_window(w, h);
88 //      canvas->reposition_window(0, 0, w, h);
89 //      update_title();
90 //      if(thread->video_cropping) canvas->draw_crop_box();
91 }
92
93 int VideoWindowGUI::update_title()
94 {
95 //      char string[1024];
96 //
97 //      if(thread->mwindow->get_aspect_ratio() > (float)thread->mwindow->session->output_w / thread->mwindow->session->output_h)
98 //      {
99 //              sprintf(string, PROGRAM_NAME ": Video out %d%%",
100 //                      (int)((float)thread->video_window_w / (thread->mwindow->session->output_h * thread->mwindow->get_aspect_ratio()) * 100 + 0.5));
101 //      }
102 //      else
103 //      {
104 //              sprintf(string, PROGRAM_NAME ": Video out %d%%",
105 //                      (int)((float)thread->video_window_w / thread->mwindow->session->output_w * 100 + 0.5));
106 //      }
107 //
108 //      set_title(string);
109 }
110
111 int VideoWindowGUI::close_event()
112 {
113         thread->hide_window();
114 }
115
116
117 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
118  : BC_SubWindow(0, 0, w, h, BLACK)
119 {
120         this->gui = gui;
121         corner_selected = 0;
122         button_down = 0;
123 }
124
125 VideoWindowCanvas::~VideoWindowCanvas()
126 {
127 }
128
129 int VideoWindowCanvas::button_press()
130 {
131         if(gui->thread->video_cropping)
132         {
133                 int x = get_cursor_x();
134                 int y = get_cursor_y();
135                 button_down = 1;
136
137                 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
138                 {
139                         corner_selected = 1;
140                         gui->x_offset = x - gui->x1;
141                         gui->y_offset = y - gui->y1;
142                 }
143                 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
144                 {
145                         corner_selected = 2;
146                         gui->x_offset = x - gui->x1;
147                         gui->y_offset = y - gui->y2;
148                 }
149                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
150                 {
151                         corner_selected = 3;
152                         gui->x_offset = x - gui->x2;
153                         gui->y_offset = y - gui->y2;
154                 }
155                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
156                 {
157                         corner_selected = 4;
158                         gui->x_offset = x - gui->x2;
159                         gui->y_offset = y - gui->y1;
160                 }
161         }
162 }
163
164 int VideoWindowCanvas::button_release()
165 {
166         if(gui->thread->video_cropping && button_down)
167         {
168                 button_down = 0;
169                 corner_selected = 0;
170         }
171 }
172
173 int VideoWindowCanvas::cursor_motion()
174 {
175         if(button_down && gui->thread->video_cropping && corner_selected)
176         {
177                 int x = get_cursor_x();
178                 int y = get_cursor_y();
179                 draw_crop_box();
180
181                 switch(corner_selected)
182                 {
183                         case 1:
184                                 gui->x1 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
185                                 break;
186                         case 2:
187                                 gui->x1 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
188                                 break;
189                         case 3:
190                                 gui->x2 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
191                                 break;
192                         case 4:
193                                 gui->x2 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
194                                 break;
195                 };
196
197                 if(gui->x1 < 0) gui->x1 = 0;
198                 if(gui->y1 < 0) gui->y1 = 0;
199                 if(gui->x1 > get_w()) gui->x1 = get_w();
200                 if(gui->y1 > get_h()) gui->y1 = get_h();
201                 if(gui->x2 < 0) gui->x2 = 0;
202                 if(gui->y2 < 0) gui->y2 = 0;
203                 if(gui->x2 > get_w()) gui->x2 = get_w();
204                 if(gui->y2 > get_h()) gui->y2 = get_h();
205                 draw_crop_box();
206                 flash();
207         }
208 }
209
210 int VideoWindowCanvas::draw_crop_box()
211 {
212         int w = gui->x2 - gui->x1;
213         int h = gui->y2 - gui->y1;
214
215         set_inverse();
216         set_color(WHITE);
217         draw_box(gui->x1 + 1, gui->y1 + 1, CROPHANDLE_W - 1, CROPHANDLE_H - 1);
218         draw_box(gui->x1 + 1, gui->y2 - CROPHANDLE_H, CROPHANDLE_W - 1, CROPHANDLE_H);
219         draw_box(gui->x2 - CROPHANDLE_W, gui->y2 - CROPHANDLE_H, CROPHANDLE_W, CROPHANDLE_H);
220         draw_box(gui->x2 - CROPHANDLE_W, gui->y1 + 1, CROPHANDLE_W, CROPHANDLE_H - 1);
221         draw_rectangle(gui->x1, gui->y1, w, h);
222         set_opaque();
223 }
224