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);
60 int VideoWindow::update_defaults(BC_Hash *defaults)
62 defaults->update("VIDEOVISIBLE", video_visible);
63 defaults->update("PLAYVIDEOW", video_window_w);
67 void VideoWindow::create_objects()
76 int VideoWindow::init_window()
78 // int w = mwindow->session->output_w;
79 // int h = mwindow->session->output_h;
81 // fix_size(w, h, video_window_w, mwindow->get_aspect_ratio());
82 // gui = new VideoWindowGUI(this, w, h);
83 // gui->create_objects();
86 int VideoWindow::show_window()
92 mwindow->gui->mainmenu->set_show_video(1);
97 int VideoWindow::hide_window()
103 mwindow->gui->mainmenu->set_show_video(0);
108 int VideoWindow::resize_window()
110 int proper_w = mwindow->session->output_w;
111 int proper_h = mwindow->session->output_h;
113 // fix_size(proper_w, proper_h, video_window_w, mwindow->get_aspect_ratio());
117 (gui->get_w() != proper_w ||
118 gui->get_h() != proper_h))
120 gui->resize_window(proper_w, proper_h);
121 gui->canvas->reposition_window(0, 0, proper_w, proper_h);
122 if(video_cropping) gui->canvas->draw_crop_box();
128 int VideoWindow::fix_size(int &w, int &h, int width_given, float aspect_ratio)
131 h = (int)((float)width_given / aspect_ratio);
135 int VideoWindow::original_size()
138 get_full_sizes(w, h);
144 int VideoWindow::get_full_sizes(int &w, int &h)
146 // if(mwindow->get_aspect_ratio() > (float)mwindow->session->output_w / mwindow->session->output_h)
148 // w = (int)((float)mwindow->session->output_h * mwindow->get_aspect_ratio() + 0.5);
149 // h = mwindow->session->output_h;
153 // w = mwindow->session->output_w;
154 // h = (int)((float)mwindow->session->output_w / mwindow->get_aspect_ratio() + 0.5);
159 void VideoWindow::run()
161 if(gui) gui->run_window();
164 int VideoWindow::init_video()
168 gui->canvas->start_video();
173 int VideoWindow::stop_video()
177 gui->canvas->stop_video();
182 int VideoWindow::update(BC_Bitmap *frame)
187 // gui->canvas->draw_bitmap(frame, 1);
188 gui->unlock_window();
193 int VideoWindow::get_w()
195 if(gui) return gui->get_w();
199 int VideoWindow::get_h()
201 if(gui) return gui->get_h();
205 BC_Bitmap* VideoWindow::get_bitmap()
207 return gui->canvas->new_bitmap(gui->get_w(), gui->get_h());
210 int VideoWindow::reset()
215 int VideoWindow::start_cropping()
220 gui->x2 = gui->get_w();
221 gui->y2 = gui->get_h();
222 gui->canvas->draw_crop_box();
223 gui->canvas->flash();
227 int VideoWindow::get_aspect_ratio(float &aspect_w, float &aspect_h)
230 float zoom_factor = (float)video_window_w / mwindow->session->output_w;
232 // For new aspect ratio
233 new_w = (int)((float)(gui->x2 - gui->x1) / zoom_factor);
234 new_h = (int)((float)(gui->y2 - gui->y1) / zoom_factor);
236 mwindow->create_aspect_ratio(aspect_w, aspect_h, new_w, new_h);
240 int VideoWindow::stop_cropping()
242 // float x_zoom, y_zoom;
244 // float zoom_factor;
246 // if(mwindow->get_aspect_ratio() < (float)mwindow->session->output_w / mwindow->session->output_h)
249 // y_zoom = (float)mwindow->session->output_w / mwindow->get_aspect_ratio() / mwindow->session->output_h;
250 // zoom_factor = (float)video_window_w / mwindow->session->output_w;
254 // x_zoom = (float)mwindow->session->output_h * mwindow->get_aspect_ratio() / mwindow->session->output_w;
256 // zoom_factor = (float)video_window_w / (mwindow->session->output_h * mwindow->get_aspect_ratio());
260 // gui->canvas->draw_crop_box();
261 // gui->canvas->flash();
262 // video_window_w = gui->x2 - gui->x1;
264 // gui->x1 = (int)(gui->x1 / zoom_factor / x_zoom);
265 // gui->y1 = (int)(gui->y1 / zoom_factor / y_zoom);
266 // gui->x2 = (int)(gui->x2 / zoom_factor / x_zoom);
267 // gui->y2 = (int)(gui->y2 / zoom_factor / y_zoom);
269 // video_cropping = 0;