4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
24 #include "mwindowgui.h"
25 #include "mainsession.h"
26 #include "videowindow.h"
27 #include "videowindowgui.h"
31 #define CROPHANDLE_W xS(10)
32 #define CROPHANDLE_H yS(10)
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)
39 this->thread = thread;
42 VideoWindowGUI::~VideoWindowGUI()
46 void VideoWindowGUI::create_objects()
48 lock_window("VideoWindowGUI::create_objects");
49 add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
54 int VideoWindowGUI::keypress_event()
58 int VideoWindowGUI::resize_event(int w, int h)
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;
66 // thread->get_full_sizes(full_w, full_h);
68 // if(labs(full_w - new_w) < xS(50))
74 // thread->fix_size(new_w, new_h, w, thread->mwindow->get_aspect_ratio());
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;
81 // resize_window(w, h);
82 // canvas->reposition_window(0, 0, w, h);
84 // if(thread->video_cropping) canvas->draw_crop_box();
87 int VideoWindowGUI::update_title()
91 // if(thread->mwindow->get_aspect_ratio() > (float)thread->mwindow->session->output_w / thread->mwindow->session->output_h)
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));
98 // sprintf(string, PROGRAM_NAME ": Video out %d%%",
99 // (int)((float)thread->video_window_w / thread->mwindow->session->output_w * 100 + 0.5));
102 // set_title(string);
105 int VideoWindowGUI::close_event()
107 thread->hide_window();
111 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
112 : BC_SubWindow(0, 0, w, h, BLACK)
119 VideoWindowCanvas::~VideoWindowCanvas()
123 int VideoWindowCanvas::button_press()
125 if(gui->thread->video_cropping)
127 int x = get_cursor_x();
128 int y = get_cursor_y();
131 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
134 gui->x_offset = x - gui->x1;
135 gui->y_offset = y - gui->y1;
137 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
140 gui->x_offset = x - gui->x1;
141 gui->y_offset = y - gui->y2;
143 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
146 gui->x_offset = x - gui->x2;
147 gui->y_offset = y - gui->y2;
149 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
152 gui->x_offset = x - gui->x2;
153 gui->y_offset = y - gui->y1;
158 int VideoWindowCanvas::button_release()
160 if(gui->thread->video_cropping && button_down)
167 int VideoWindowCanvas::cursor_motion()
169 if(button_down && gui->thread->video_cropping && corner_selected)
171 int x = get_cursor_x();
172 int y = get_cursor_y();
175 switch(corner_selected)
178 gui->x1 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
181 gui->x1 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
184 gui->x2 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
187 gui->x2 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
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();
204 int VideoWindowCanvas::draw_crop_box()
206 int w = gui->x2 - gui->x1;
207 int h = gui->y2 - gui->y1;
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);