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 10
32 #define CROPHANDLE_H 10
34 VideoWindowGUI::VideoWindowGUI(VideoWindow *thread, int w, int h)
35 : BC_Window(_(PROGRAM_NAME ": Video out"),
46 this->thread = thread;
49 VideoWindowGUI::~VideoWindowGUI()
53 void VideoWindowGUI::create_objects()
55 add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
60 int VideoWindowGUI::keypress_event()
64 int VideoWindowGUI::resize_event(int w, int h)
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;
72 // thread->get_full_sizes(full_w, full_h);
74 // if(labs(full_w - new_w) < 50)
80 // thread->fix_size(new_w, new_h, w, thread->mwindow->get_aspect_ratio());
82 // if(new_w < 10) new_w = 10;
83 // if(new_h < 10) new_h = 10;
84 // w = thread->video_window_w = new_w;
87 // resize_window(w, h);
88 // canvas->reposition_window(0, 0, w, h);
90 // if(thread->video_cropping) canvas->draw_crop_box();
93 int VideoWindowGUI::update_title()
97 // if(thread->mwindow->get_aspect_ratio() > (float)thread->mwindow->session->output_w / thread->mwindow->session->output_h)
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));
104 // sprintf(string, PROGRAM_NAME ": Video out %d%%",
105 // (int)((float)thread->video_window_w / thread->mwindow->session->output_w * 100 + 0.5));
108 // set_title(string);
111 int VideoWindowGUI::close_event()
113 thread->hide_window();
117 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
118 : BC_SubWindow(0, 0, w, h, BLACK)
125 VideoWindowCanvas::~VideoWindowCanvas()
129 int VideoWindowCanvas::button_press()
131 if(gui->thread->video_cropping)
133 int x = get_cursor_x();
134 int y = get_cursor_y();
137 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
140 gui->x_offset = x - gui->x1;
141 gui->y_offset = y - gui->y1;
143 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
146 gui->x_offset = x - gui->x1;
147 gui->y_offset = y - gui->y2;
149 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
152 gui->x_offset = x - gui->x2;
153 gui->y_offset = y - gui->y2;
155 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
158 gui->x_offset = x - gui->x2;
159 gui->y_offset = y - gui->y1;
164 int VideoWindowCanvas::button_release()
166 if(gui->thread->video_cropping && button_down)
173 int VideoWindowCanvas::cursor_motion()
175 if(button_down && gui->thread->video_cropping && corner_selected)
177 int x = get_cursor_x();
178 int y = get_cursor_y();
181 switch(corner_selected)
184 gui->x1 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
187 gui->x1 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
190 gui->x2 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
193 gui->x2 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
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();
210 int VideoWindowCanvas::draw_crop_box()
212 int w = gui->x2 - gui->x1;
213 int h = gui->y2 - gui->y1;
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);