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
23 #include "levelwindow.h"
26 #include "mwindowgui.h"
27 #include "mainsession.h"
29 #include "videowindow.h"
30 #include "videowindowgui.h"
33 VideoWindow::VideoWindow(MWindow *mwindow)
36 this->mwindow = mwindow;
44 VideoWindow::~VideoWindow()
46 if(gui && running()) {
53 int VideoWindow::load_defaults(BC_Hash *defaults)
55 video_visible = defaults->get("VIDEOVISIBLE", 1);
56 video_window_w = defaults->get("PLAYVIDEOW", video_window_w);
59 int VideoWindow::update_defaults(BC_Hash *defaults)
61 defaults->update("VIDEOVISIBLE", video_visible);
62 defaults->update("PLAYVIDEOW", video_window_w);
65 void VideoWindow::create_objects()
74 int VideoWindow::init_window()
76 // int w = mwindow->session->output_w;
77 // int h = mwindow->session->output_h;
79 // fix_size(w, h, video_window_w, mwindow->get_aspect_ratio());
80 // gui = new VideoWindowGUI(this, w, h);
81 // gui->create_objects();
84 int VideoWindow::show_window()
90 mwindow->gui->mainmenu->set_show_video(1);
94 int VideoWindow::hide_window()
100 mwindow->gui->mainmenu->set_show_video(0);
104 int VideoWindow::resize_window()
106 int proper_w = mwindow->session->output_w;
107 int proper_h = mwindow->session->output_h;
109 // fix_size(proper_w, proper_h, video_window_w, mwindow->get_aspect_ratio());
113 (gui->get_w() != proper_w ||
114 gui->get_h() != proper_h))
116 gui->resize_window(proper_w, proper_h);
117 gui->canvas->reposition_window(0, 0, proper_w, proper_h);
118 if(video_cropping) gui->canvas->draw_crop_box();
123 int VideoWindow::fix_size(int &w, int &h, int width_given, float aspect_ratio)
126 h = (int)((float)width_given / aspect_ratio);
129 int VideoWindow::original_size()
132 get_full_sizes(w, h);
137 int VideoWindow::get_full_sizes(int &w, int &h)
139 // if(mwindow->get_aspect_ratio() > (float)mwindow->session->output_w / mwindow->session->output_h)
141 // w = (int)((float)mwindow->session->output_h * mwindow->get_aspect_ratio() + 0.5);
142 // h = mwindow->session->output_h;
146 // w = mwindow->session->output_w;
147 // h = (int)((float)mwindow->session->output_w / mwindow->get_aspect_ratio() + 0.5);
152 void VideoWindow::run()
154 if(gui) gui->run_window();
157 int VideoWindow::init_video()
161 gui->canvas->start_video();
165 int VideoWindow::stop_video()
169 gui->canvas->stop_video();
173 int VideoWindow::update(BC_Bitmap *frame)
178 // gui->canvas->draw_bitmap(frame, 1);
179 gui->unlock_window();
183 int VideoWindow::get_w()
185 if(gui) return gui->get_w();
189 int VideoWindow::get_h()
191 if(gui) return gui->get_h();
195 BC_Bitmap* VideoWindow::get_bitmap()
197 return gui->canvas->new_bitmap(gui->get_w(), gui->get_h());
200 int VideoWindow::reset()
204 int VideoWindow::start_cropping()
209 gui->x2 = gui->get_w();
210 gui->y2 = gui->get_h();
211 gui->canvas->draw_crop_box();
212 gui->canvas->flash();
215 int VideoWindow::get_aspect_ratio(float &aspect_w, float &aspect_h)
218 float zoom_factor = (float)video_window_w / mwindow->session->output_w;
220 // For new aspect ratio
221 new_w = (int)((float)(gui->x2 - gui->x1) / zoom_factor);
222 new_h = (int)((float)(gui->y2 - gui->y1) / zoom_factor);
224 mwindow->create_aspect_ratio(aspect_w, aspect_h, new_w, new_h);
227 int VideoWindow::stop_cropping()
229 // float x_zoom, y_zoom;
231 // float zoom_factor;
233 // if(mwindow->get_aspect_ratio() < (float)mwindow->session->output_w / mwindow->session->output_h)
236 // y_zoom = (float)mwindow->session->output_w / mwindow->get_aspect_ratio() / mwindow->session->output_h;
237 // zoom_factor = (float)video_window_w / mwindow->session->output_w;
241 // x_zoom = (float)mwindow->session->output_h * mwindow->get_aspect_ratio() / mwindow->session->output_w;
243 // zoom_factor = (float)video_window_w / (mwindow->session->output_h * mwindow->get_aspect_ratio());
247 // gui->canvas->draw_crop_box();
248 // gui->canvas->flash();
249 // video_window_w = gui->x2 - gui->x1;
251 // gui->x1 = (int)(gui->x1 / zoom_factor / x_zoom);
252 // gui->y1 = (int)(gui->y1 / zoom_factor / y_zoom);
253 // gui->x2 = (int)(gui->x2 / zoom_factor / x_zoom);
254 // gui->y2 = (int)(gui->y2 / zoom_factor / y_zoom);
256 // video_cropping = 0;