00001 #include "mbuttons.h"
00002 #include "mwindow.h"
00003 #include "mwindowgui.h"
00004 #include "mainsession.h"
00005 #include "videowindow.h"
00006 #include "videowindowgui.h"
00007
00008
00009
00010 #define CROPHANDLE_W 10
00011 #define CROPHANDLE_H 10
00012
00013 VideoWindowGUI::VideoWindowGUI(VideoWindow *thread, int w, int h)
00014 : BC_Window(PROGRAM_NAME ": Video out",
00015 (int)BC_INFINITY,
00016 (int)BC_INFINITY,
00017 w,
00018 h,
00019 10,
00020 10,
00021 1,
00022 1,
00023 1)
00024 {
00025 this->thread = thread;
00026 }
00027
00028 VideoWindowGUI::~VideoWindowGUI()
00029 {
00030 }
00031
00032 int VideoWindowGUI::create_objects()
00033 {
00034 add_subwindow(canvas = new VideoWindowCanvas(this, get_w(), get_h()));
00035 update_title();
00036 }
00037
00038
00039 int VideoWindowGUI::keypress_event()
00040 {
00041 }
00042
00043 int VideoWindowGUI::resize_event(int w, int h)
00044 {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 }
00071
00072 int VideoWindowGUI::update_title()
00073 {
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 }
00089
00090 int VideoWindowGUI::close_event()
00091 {
00092 thread->hide_window();
00093 }
00094
00095
00096 VideoWindowCanvas::VideoWindowCanvas(VideoWindowGUI *gui, int w, int h)
00097 : BC_SubWindow(0, 0, w, h, BLACK)
00098 {
00099 this->gui = gui;
00100 corner_selected = 0;
00101 button_down = 0;
00102 }
00103
00104 VideoWindowCanvas::~VideoWindowCanvas()
00105 {
00106 }
00107
00108 int VideoWindowCanvas::button_press()
00109 {
00110 if(gui->thread->video_cropping)
00111 {
00112 int x = get_cursor_x();
00113 int y = get_cursor_y();
00114 button_down = 1;
00115
00116 if(x > gui->x1 && y > gui->y1 && x < gui->x1 + CROPHANDLE_W && y < gui->y1 + CROPHANDLE_H)
00117 {
00118 corner_selected = 1;
00119 gui->x_offset = x - gui->x1;
00120 gui->y_offset = y - gui->y1;
00121 }
00122 if(x > gui->x1 && y > gui->y2 - CROPHANDLE_H && x < gui->x1 + CROPHANDLE_W && y < gui->y2)
00123 {
00124 corner_selected = 2;
00125 gui->x_offset = x - gui->x1;
00126 gui->y_offset = y - gui->y2;
00127 }
00128 if(x > gui->x2 - CROPHANDLE_W && y > gui->y2 - CROPHANDLE_H && x < gui->x2 && y < gui->y2)
00129 {
00130 corner_selected = 3;
00131 gui->x_offset = x - gui->x2;
00132 gui->y_offset = y - gui->y2;
00133 }
00134 if(x > gui->x2 - CROPHANDLE_W && y > gui->y1 && x < gui->x2 && y < gui->y1 + CROPHANDLE_H)
00135 {
00136 corner_selected = 4;
00137 gui->x_offset = x - gui->x2;
00138 gui->y_offset = y - gui->y1;
00139 }
00140 }
00141 }
00142
00143 int VideoWindowCanvas::button_release()
00144 {
00145 if(gui->thread->video_cropping && button_down)
00146 {
00147 button_down = 0;
00148 corner_selected = 0;
00149 }
00150 }
00151
00152 int VideoWindowCanvas::cursor_motion()
00153 {
00154 if(button_down && gui->thread->video_cropping && corner_selected)
00155 {
00156 int x = get_cursor_x();
00157 int y = get_cursor_y();
00158 draw_crop_box();
00159
00160 switch(corner_selected)
00161 {
00162 case 1:
00163 gui->x1 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
00164 break;
00165 case 2:
00166 gui->x1 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
00167 break;
00168 case 3:
00169 gui->x2 = x - gui->x_offset; gui->y2 = y - gui->y_offset;
00170 break;
00171 case 4:
00172 gui->x2 = x - gui->x_offset; gui->y1 = y - gui->y_offset;
00173 break;
00174 };
00175
00176 if(gui->x1 < 0) gui->x1 = 0;
00177 if(gui->y1 < 0) gui->y1 = 0;
00178 if(gui->x1 > get_w()) gui->x1 = get_w();
00179 if(gui->y1 > get_h()) gui->y1 = get_h();
00180 if(gui->x2 < 0) gui->x2 = 0;
00181 if(gui->y2 < 0) gui->y2 = 0;
00182 if(gui->x2 > get_w()) gui->x2 = get_w();
00183 if(gui->y2 > get_h()) gui->y2 = get_h();
00184 draw_crop_box();
00185 flash();
00186 }
00187 }
00188
00189 int VideoWindowCanvas::draw_crop_box()
00190 {
00191 int w = gui->x2 - gui->x1;
00192 int h = gui->y2 - gui->y1;
00193
00194 set_inverse();
00195 set_color(WHITE);
00196 draw_box(gui->x1 + 1, gui->y1 + 1, CROPHANDLE_W - 1, CROPHANDLE_H - 1);
00197 draw_box(gui->x1 + 1, gui->y2 - CROPHANDLE_H, CROPHANDLE_W - 1, CROPHANDLE_H);
00198 draw_box(gui->x2 - CROPHANDLE_W, gui->y2 - CROPHANDLE_H, CROPHANDLE_W, CROPHANDLE_H);
00199 draw_box(gui->x2 - CROPHANDLE_W, gui->y1 + 1, CROPHANDLE_W, CROPHANDLE_H - 1);
00200 draw_rectangle(gui->x1, gui->y1, w, h);
00201 set_opaque();
00202 }
00203