3 #include "mwindowgui.h"
4 #include "mainsession.h"
5 #include "videowindow.h"
6 #include "videowindowgui.h"
10 #define CROPHANDLE_W 10
11 #define CROPHANDLE_H 10
13 VideoWindowGUI::VideoWindowGUI(VideoWindow *thread, int w, int h)
14 : BC_Window(PROGRAM_NAME ": Video out",
25 this->thread = thread;
28 VideoWindowGUI::~VideoWindowGUI()
32 int VideoWindowGUI::create_objects()
34 add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
39 int VideoWindowGUI::keypress_event()
43 int VideoWindowGUI::resize_event(int w, int h)
45 // int output_w = thread->mwindow->session->output_w;
46 // int output_h = thread->mwindow->session->output_h;
47 // int new_w, new_h, full_w, full_h;
51 // thread->get_full_sizes(full_w, full_h);
53 // if(labs(full_w - new_w) < 50)
59 // thread->fix_size(new_w, new_h, w, thread->mwindow->get_aspect_ratio());
61 // if(new_w < 10) new_w = 10;
62 // if(new_h < 10) new_h = 10;
63 // w = thread->video_window_w = new_w;
66 // resize_window(w, h);
67 // canvas->reposition_window(0, 0, w, h);
69 // if(thread->video_cropping) canvas->draw_crop_box();
72 int VideoWindowGUI::update_title()
76 // if(thread->mwindow->get_aspect_ratio() > (float)thread->mwindow->session->output_w / thread->mwindow->session->output_h)
78 // sprintf(string, PROGRAM_NAME ": Video out %d%%",
79 // (int)((float)thread->video_window_w / (thread->mwindow->session->output_h * thread->mwindow->get_aspect_ratio()) * 100 + 0.5));
83 // sprintf(string, PROGRAM_NAME ": Video out %d%%",
84 // (int)((float)thread->video_window_w / thread->mwindow->session->output_w * 100 + 0.5));
90 int VideoWindowGUI::close_event()
92 thread->hide_window();
96 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
97 : BC_SubWindow(0, 0, w, h, BLACK)
104 VideoWindowCanvas::~VideoWindowCanvas()
108 int VideoWindowCanvas::button_press()
110 if(gui->thread->video_cropping)
112 int x = get_cursor_x();
113 int y = get_cursor_y();
116 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
119 gui->x_offset = x - gui->x1;
120 gui->y_offset = y - gui->y1;
122 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
125 gui->x_offset = x - gui->x1;
126 gui->y_offset = y - gui->y2;
128 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
131 gui->x_offset = x - gui->x2;
132 gui->y_offset = y - gui->y2;
134 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
137 gui->x_offset = x - gui->x2;
138 gui->y_offset = y - gui->y1;
143 int VideoWindowCanvas::button_release()
145 if(gui->thread->video_cropping && button_down)
152 int VideoWindowCanvas::cursor_motion()
154 if(button_down && gui->thread->video_cropping && corner_selected)
156 int x = get_cursor_x();
157 int y = get_cursor_y();
160 switch(corner_selected)
163 gui->x1 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
166 gui->x1 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
169 gui->x2 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
172 gui->x2 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
176 if(gui->x1 < 0) gui->x1 = 0;
177 if(gui->y1 < 0) gui->y1 = 0;
178 if(gui->x1 > get_w()) gui->x1 = get_w();
179 if(gui->y1 > get_h()) gui->y1 = get_h();
180 if(gui->x2 < 0) gui->x2 = 0;
181 if(gui->y2 < 0) gui->y2 = 0;
182 if(gui->x2 > get_w()) gui->x2 = get_w();
183 if(gui->y2 > get_h()) gui->y2 = get_h();
189 int VideoWindowCanvas::draw_crop_box()
191 int w = gui->x2 - gui->x1;
192 int h = gui->y2 - gui->y1;
196 draw_box(gui->x1 + 1, gui->y1 + 1, CROPHANDLE_W - 1, CROPHANDLE_H - 1);
197 draw_box(gui->x1 + 1, gui->y2 - CROPHANDLE_H, CROPHANDLE_W - 1, CROPHANDLE_H);
198 draw_box(gui->x2 - CROPHANDLE_W, gui->y2 - CROPHANDLE_H, CROPHANDLE_W, CROPHANDLE_H);
199 draw_box(gui->x2 - CROPHANDLE_W, gui->y1 + 1, CROPHANDLE_W, CROPHANDLE_H - 1);
200 draw_rectangle(gui->x1, gui->y1, w, h);