r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / videowindow.C
blobcf42a5c1626fec0cad5898049d6331f6806e5264
1 #include "bchash.h"
2 #include "levelwindow.h"
3 #include "mainmenu.h"
4 #include "mwindow.h"
5 #include "mwindowgui.h"
6 #include "mainsession.h"
7 #include "vframe.h"
8 #include "videowindow.h"
9 #include "videowindowgui.h"
12 VideoWindow::VideoWindow(MWindow *mwindow)
13  : Thread()
15         this->mwindow = mwindow;
16         vbuffer = 0;
17         gui = 0;
18         video_window_w = 320;
19         video_visible = 0;
20         video_cropping = 0;
23 VideoWindow::~VideoWindow()
25         if(gui)
26         {
27                 gui->set_done(0);
28                 Thread::join();
29                 delete gui;
30         }
33 int VideoWindow::load_defaults(BC_Hash *defaults)
35         video_visible = defaults->get("VIDEOVISIBLE", 1);
36         video_window_w = defaults->get("PLAYVIDEOW", video_window_w);
39 int VideoWindow::update_defaults(BC_Hash *defaults)
41         defaults->update("VIDEOVISIBLE", video_visible);
42         defaults->update("PLAYVIDEOW", video_window_w);
45 int VideoWindow::create_objects()
47         set_synchronous(1);
48         if(mwindow->gui)
49         {
50                 init_window();
51         }
54 int VideoWindow::init_window()
56 //      int w = mwindow->session->output_w;
57 //      int h = mwindow->session->output_h;
58 // 
59 //      fix_size(w, h, video_window_w, mwindow->get_aspect_ratio());
60 //      gui = new VideoWindowGUI(this, w, h);
61 //      gui->create_objects();
64 int VideoWindow::show_window()
66         if(gui)
67         {
68                 video_visible = 1;
69                 gui->show_window();
70                 mwindow->gui->mainmenu->set_show_video(1);
71         }
74 int VideoWindow::hide_window()
76         if(gui)
77         {
78                 video_visible = 0;
79                 gui->hide_window();
80                 mwindow->gui->mainmenu->set_show_video(0);
81         }
84 int VideoWindow::resize_window()
86         int proper_w = mwindow->session->output_w;
87         int proper_h = mwindow->session->output_h;
89 //      fix_size(proper_w, proper_h, video_window_w, mwindow->get_aspect_ratio());
91         gui->update_title();
92         if(gui && 
93                 (gui->get_w() != proper_w ||
94                         gui->get_h() != proper_h))
95         {
96                 gui->resize_window(proper_w, proper_h);
97                 gui->canvas->reposition_window(0, 0, proper_w, proper_h);
98                 if(video_cropping) gui->canvas->draw_crop_box();
99                 gui->flash();
100         }
103 int VideoWindow::fix_size(int &w, int &h, int width_given, float aspect_ratio)
105         w = width_given;
106         h = (int)((float)width_given / aspect_ratio);
109 int VideoWindow::original_size()
111         int w, h;
112         get_full_sizes(w, h);
113         video_window_w = w;
114         resize_window();
117 int VideoWindow::get_full_sizes(int &w, int &h)
119 //      if(mwindow->get_aspect_ratio() > (float)mwindow->session->output_w / mwindow->session->output_h)
120 //      {
121 //              w = (int)((float)mwindow->session->output_h * mwindow->get_aspect_ratio() + 0.5);
122 //              h = mwindow->session->output_h;
123 //      }
124 //      else
125 //      {
126 //              w = mwindow->session->output_w;
127 //              h = (int)((float)mwindow->session->output_w / mwindow->get_aspect_ratio() + 0.5);
128 //      }
132 void VideoWindow::run()
134         if(gui) gui->run_window();
137 int VideoWindow::init_video()
139         if(gui)
140         {
141                 gui->canvas->start_video();
142         }
145 int VideoWindow::stop_video()
147         if(gui)
148         {
149                 gui->canvas->stop_video();
150         }
153 int VideoWindow::update(BC_Bitmap *frame)
155         if(gui)
156         {
157                 gui->lock_window();
158 //              gui->canvas->draw_bitmap(frame, 1);
159                 gui->unlock_window();
160         }
163 int VideoWindow::get_w()
165         if(gui) return gui->get_w();
166         else return 0;
169 int VideoWindow::get_h()
171         if(gui) return gui->get_h();
172         else return 0;
175 BC_Bitmap* VideoWindow::get_bitmap()
177         return gui->canvas->new_bitmap(gui->get_w(), gui->get_h());
180 int VideoWindow::reset()
184 int VideoWindow::start_cropping()
186         video_cropping = 1;
187         gui->x1 = 0;
188         gui->y1 = 0;
189         gui->x2 = gui->get_w();
190         gui->y2 = gui->get_h();
191         gui->canvas->draw_crop_box();
192         gui->canvas->flash();
195 int VideoWindow::get_aspect_ratio(float &aspect_w, float &aspect_h)
197         int new_w, new_h;
198         float zoom_factor = (float)video_window_w / mwindow->session->output_w;
200 // For new aspect ratio
201         new_w = (int)((float)(gui->x2 - gui->x1) / zoom_factor);
202         new_h = (int)((float)(gui->y2 - gui->y1) / zoom_factor);
204         mwindow->create_aspect_ratio(aspect_w, aspect_h, new_w, new_h);
207 int VideoWindow::stop_cropping()
209 //      float x_zoom, y_zoom;
210 //      int new_w, new_h;
211 //      float zoom_factor;
212 // 
213 //      if(mwindow->get_aspect_ratio() < (float)mwindow->session->output_w / mwindow->session->output_h)
214 //      {
215 //              x_zoom = 1;
216 //              y_zoom = (float)mwindow->session->output_w / mwindow->get_aspect_ratio() / mwindow->session->output_h;
217 //              zoom_factor = (float)video_window_w / mwindow->session->output_w;
218 //      }
219 //      else
220 //      {
221 //              x_zoom = (float)mwindow->session->output_h * mwindow->get_aspect_ratio() / mwindow->session->output_w;
222 //              y_zoom = 1;
223 //              zoom_factor = (float)video_window_w / (mwindow->session->output_h * mwindow->get_aspect_ratio());
224 //      }
225 // 
226 // 
227 //      gui->canvas->draw_crop_box();
228 //      gui->canvas->flash();
229 //      video_window_w = gui->x2 - gui->x1;
230 // 
231 //      gui->x1 = (int)(gui->x1 / zoom_factor / x_zoom);
232 //      gui->y1 = (int)(gui->y1 / zoom_factor / y_zoom);
233 //      gui->x2 = (int)(gui->x2 / zoom_factor / x_zoom);
234 //      gui->y2 = (int)(gui->y2 / zoom_factor / y_zoom);
235 // 
236 //      video_cropping = 0;