repair selected_to_clipboard bug
[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 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, (int)BC_INFINITY,
37         w, h, 10, 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) < 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 < 10) new_w = 10;
77 //      if(new_h < 10) new_h = 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 }
109
110
111 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
112  : BC_SubWindow(0, 0, w, h, BLACK)
113 {
114         this->gui = gui;
115         corner_selected = 0;
116         button_down = 0;
117 }
118
119 VideoWindowCanvas::~VideoWindowCanvas()
120 {
121 }
122
123 int VideoWindowCanvas::button_press()
124 {
125         if(gui->thread->video_cropping)
126         {
127                 int x = get_cursor_x();
128                 int y = get_cursor_y();
129                 button_down = 1;
130
131                 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
132                 {
133                         corner_selected = 1;
134                         gui->x_offset = x - gui->x1;
135                         gui->y_offset = y - gui->y1;
136                 }
137                 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
138                 {
139                         corner_selected = 2;
140                         gui->x_offset = x - gui->x1;
141                         gui->y_offset = y - gui->y2;
142                 }
143                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
144                 {
145                         corner_selected = 3;
146                         gui->x_offset = x - gui->x2;
147                         gui->y_offset = y - gui->y2;
148                 }
149                 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
150                 {
151                         corner_selected = 4;
152                         gui->x_offset = x - gui->x2;
153                         gui->y_offset = y - gui->y1;
154                 }
155         }
156 }
157
158 int VideoWindowCanvas::button_release()
159 {
160         if(gui->thread->video_cropping && button_down)
161         {
162                 button_down = 0;
163                 corner_selected = 0;
164         }
165 }
166
167 int VideoWindowCanvas::cursor_motion()
168 {
169         if(button_down && gui->thread->video_cropping && corner_selected)
170         {
171                 int x = get_cursor_x();
172                 int y = get_cursor_y();
173                 draw_crop_box();
174
175                 switch(corner_selected)
176                 {
177                         case 1:
178                                 gui->x1 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
179                                 break;
180                         case 2:
181                                 gui->x1 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
182                                 break;
183                         case 3:
184                                 gui->x2 = x - gui->x_offset;  gui->y2 = y - gui->y_offset;
185                                 break;
186                         case 4:
187                                 gui->x2 = x - gui->x_offset;  gui->y1 = y - gui->y_offset;
188                                 break;
189                 };
190
191                 if(gui->x1 < 0) gui->x1 = 0;
192                 if(gui->y1 < 0) gui->y1 = 0;
193                 if(gui->x1 > get_w()) gui->x1 = get_w();
194                 if(gui->y1 > get_h()) gui->y1 = get_h();
195                 if(gui->x2 < 0) gui->x2 = 0;
196                 if(gui->y2 < 0) gui->y2 = 0;
197                 if(gui->x2 > get_w()) gui->x2 = get_w();
198                 if(gui->y2 > get_h()) gui->y2 = get_h();
199                 draw_crop_box();
200                 flash();
201         }
202 }
203
204 int VideoWindowCanvas::draw_crop_box()
205 {
206         int w = gui->x2 - gui->x1;
207         int h = gui->y2 - gui->y1;
208
209         set_inverse();
210         set_color(WHITE);
211         draw_box(gui->x1 + 1, gui->y1 + 1, CROPHANDLE_W - 1, CROPHANDLE_H - 1);
212         draw_box(gui->x1 + 1, gui->y2 - CROPHANDLE_H, CROPHANDLE_W - 1, CROPHANDLE_H);
213         draw_box(gui->x2 - CROPHANDLE_W, gui->y2 - CROPHANDLE_H, CROPHANDLE_W, CROPHANDLE_H);
214         draw_box(gui->x2 - CROPHANDLE_W, gui->y1 + 1, CROPHANDLE_W, CROPHANDLE_H - 1);
215         draw_rectangle(gui->x1, gui->y1, w, h);
216         set_opaque();
217 }
218