5 #include "mainsession.h"
7 #include "videowindow.h"
10 #define _(String) gettext(String)
11 #define gettext_noop(String) String
12 #define N_(String) gettext_noop (String)
14 Scale::Scale(MWindow *mwindow)
15 : BC_MenuItem(_("Resize..."))
17 this->mwindow = mwindow;
18 thread = new ScaleThread(mwindow);
26 int Scale::handle_event()
31 ScaleThread::ScaleThread(MWindow *mwindow)
34 this->mwindow = mwindow;
38 ScaleThread::~ScaleThread() {}
40 void ScaleThread::run()
42 if(already_running) return;
44 constrain_ratio = mwindow->defaults->get("SCALECONSTRAIN", 0);
45 scale_data = mwindow->defaults->get("SCALEDATA", 0);
46 auto_aspect = mwindow->defaults->get("AUDIOASPECT", 0);
47 offsets[0] = offsets[1] = offsets[2] = offsets[3] = 0;
49 orig_dimension[0] = dimension[0] = mwindow->session->track_w;
50 orig_dimension[1] = dimension[1] = mwindow->session->track_h;
51 orig_dimension[2] = dimension[2] = mwindow->session->output_w;
52 orig_dimension[3] = dimension[3] = mwindow->session->output_h;
53 ratio[0] = ratio[1] = ratio[2] = ratio[3] = 1;
54 aspect_w = mwindow->session->aspect_w;
55 aspect_h = mwindow->session->aspect_h;
57 window = new ScaleWindow(this);
58 window->create_objects();
59 int result = window->run_window();
63 dummy_offsets[0] = dummy_offsets[1] = dummy_offsets[2] = dummy_offsets[3] = 0;
64 // Fake the offsets if data is scaled.
67 //mwindow->stop_playback(1);
68 // save the before undo
69 mwindow->undo->update_undo_edits("Resize", 0);
70 mwindow->tracks->scale_video(dimension, scale_data ? dummy_offsets : offsets, scale_data);
71 mwindow->session->track_w = dimension[0];
72 mwindow->session->track_h = dimension[1];
73 mwindow->session->output_w = dimension[2];
74 mwindow->session->output_h = dimension[3];
75 mwindow->session->aspect_w = aspect_w;
76 mwindow->session->aspect_h = aspect_h;
77 mwindow->video_window->resize_window();
79 mwindow->undo->update_undo_edits();
80 mwindow->session->changes_made = 1;
81 mwindow->defaults->update("ASPECTW", aspect_w);
82 mwindow->defaults->update("ASPECTH", aspect_h);
83 mwindow->defaults->update("AUTOASPECT", auto_aspect);
87 mwindow->defaults->update("SCALECONSTRAIN", constrain_ratio);
88 mwindow->defaults->update("SCALEDATA", scale_data);
92 int ScaleThread::update_window(int offset_updated)
95 int i, result, modified_item, dimension_modified = 0, ratio_modified = 0;
97 for(i = 0, result = 0; i < 4 && !result; i++)
99 if(i == 2) pair_start = 2;
105 dimension_modified = 1;
118 if(dimension_modified)
119 ratio[modified_item] = (float)dimension[modified_item] / orig_dimension[modified_item];
121 if(ratio_modified && !constrain_ratio)
123 dimension[modified_item] = (int)(orig_dimension[modified_item] * ratio[modified_item]);
124 window->dimension[modified_item]->update((long)dimension[modified_item]);
127 for(i = pair_start; i < pair_start + 2 && constrain_ratio; i++)
129 if(dimension_modified ||
130 (i != modified_item && ratio_modified))
132 ratio[i] = ratio[modified_item];
133 window->ratio[i]->update(ratio[i]);
137 (i != modified_item && dimension_modified))
139 dimension[i] = (int)(orig_dimension[i] * ratio[modified_item]);
140 window->dimension[i]->update((long)dimension[i]);
145 // window->position1->draw();
146 // window->position2->draw();
147 //printf("%d\n", offsets[0]);
148 // if(!offset_updated)
150 // window->offsets[0]->update(offsets[0]);
151 // window->offsets[1]->update(offsets[1]);
152 // window->offsets[2]->update(offsets[2]);
153 // window->offsets[3]->update(offsets[3]);
156 update_aspect(window);
160 int ScaleThread::update_aspect(ScaleWindow *window)
165 mwindow->create_aspect_ratio(aspect_w, aspect_h, dimension[2], dimension[3]);
166 sprintf(string, "%.0f", aspect_w);
167 window->aspect_w->update(string);
168 sprintf(string, "%.0f", aspect_h);
169 window->aspect_h->update(string);
175 ScaleWindow::ScaleWindow(ScaleThread *thread)
176 : BC_Window(PROGRAM_NAME ": Scale", 370, 260, 0, 0)
177 { this->thread = thread; }
179 ScaleWindow::~ScaleWindow()
183 int ScaleWindow::create_objects()
186 add_subwindow(new BC_Title(x, y, _("New camera size:")));
187 add_subwindow(new BC_Title(x + 200, y, _("New projector size:")));
189 add_subwindow(new BC_Title(x, y, _("Width:")));
191 add_subwindow(dimension[0] = new ScaleSizeText(x, y, thread, &(thread->dimension[0])));
193 add_subwindow(new BC_Title(x, y, _("Width:")));
195 add_subwindow(dimension[2] = new ScaleSizeText(x, y, thread, &(thread->dimension[2])));
199 add_subwindow(new BC_Title(x, y, _("Height:")));
201 add_subwindow(dimension[1] = new ScaleSizeText(x, y, thread, &(thread->dimension[1])));
203 add_subwindow(new BC_Title(x, y, _("Height:")));
205 add_subwindow(dimension[3] = new ScaleSizeText(x, y, thread, &(thread->dimension[3])));
209 add_subwindow(new BC_Title(x, y, _("W Ratio:")));
211 add_subwindow(ratio[0] = new ScaleRatioText(x, y, thread, &(thread->ratio[0])));
213 add_subwindow(new BC_Title(x, y, _("W Ratio:")));
215 add_subwindow(ratio[2] = new ScaleRatioText(x, y, thread, &(thread->ratio[2])));
219 add_subwindow(new BC_Title(x, y, _("H Ratio:")));
221 add_subwindow(ratio[1] = new ScaleRatioText(x, y, thread, &(thread->ratio[1])));
223 add_subwindow(new BC_Title(x, y, _("H Ratio:")));
225 add_subwindow(ratio[3] = new ScaleRatioText(x, y, thread, &(thread->ratio[3])));
229 // add_subwindow(new BC_Title(x, y, "X Offset:"));
231 // add_subwindow(offsets[0] = new ScaleOffsetText(x, y, thread, &(thread->offsets[0])));
233 // add_subwindow(new BC_Title(x, y, "X Offset:"));
235 // add_subwindow(offsets[2] = new ScaleOffsetText(x, y, thread, &(thread->offsets[2])));
239 // add_subwindow(new BC_Title(x, y, "Y Offset:"));
241 // add_subwindow(offsets[1] = new ScaleOffsetText(x, y, thread, &(thread->offsets[1])));
243 // add_subwindow(new BC_Title(x, y, "Y Offset:"));
245 // add_subwindow(offsets[3] = new ScaleOffsetText(x, y, thread, &(thread->offsets[3])));
249 add_subwindow(new BC_Title(x, y, _("Aspect ratio:")));
252 sprintf(string, "%.0f", thread->aspect_w);
253 add_subwindow(aspect_w = new ScaleAspectW(x, y, thread, &(thread->aspect_w), string));
255 add_subwindow(new BC_Title(x, y, _(":")));
257 sprintf(string, "%.0f", thread->aspect_h);
258 add_subwindow(aspect_h = new ScaleAspectH(x, y, thread, &(thread->aspect_h), string));
260 add_subwindow(new ScaleAspectAuto(x, y + 5, thread));
264 // add_subwindow(new BC_Title(x, y, _("Camera position:")));
266 // add_subwindow(new BC_Title(x, y, _("Projector position:")));
268 // ScalePosition *position;
271 // add_subwindow(position1 = new ScalePosition(x, y, thread, this,
272 // &(thread->orig_dimension[0]), &(thread->dimension[0]), &(thread->offsets[0])));
273 // position1->draw();
276 // add_subwindow(position2 = new ScalePosition(x, y, thread, this,
277 // &(thread->orig_dimension[2]), &(thread->dimension[2]), &(thread->offsets[2])));
278 // position2->draw();
282 add_subwindow(new ScaleConstrain(x, y, thread));
284 add_subwindow(new ScaleData(x, y, thread));
288 add_subwindow(new BC_OKButton(x, y));
290 add_subwindow(new BC_CancelButton(x, y));
293 ScaleSizeText::ScaleSizeText(int x, int y, ScaleThread *thread, int *output)
294 : BC_TextBox(x, y, 100, 1, *output)
296 this->thread = thread;
297 this->output = output;
299 ScaleSizeText::~ScaleSizeText() {}
300 int ScaleSizeText::handle_event()
302 *output = atol(get_text());
305 if(*output <= 0) *output = 2;
306 if(*output > 10000) *output = 10000;
308 thread->update_window();
311 ScaleOffsetText::ScaleOffsetText(int x, int y, ScaleThread *thread, int *output)
312 : BC_TextBox(x, y, 100, 1, *output)
313 { this->thread = thread; this->output = output; }
314 ScaleOffsetText::~ScaleOffsetText() {}
315 int ScaleOffsetText::handle_event()
317 *output = atol(get_text());
318 //if(*output <= 0) *output = 0;
319 if(*output > 10000) *output = 10000;
320 if(*output < -10000) *output = -10000;
321 thread->update_window(1);
324 ScaleRatioText::ScaleRatioText(int x, int y, ScaleThread *thread, float *output)
325 : BC_TextBox(x, y, 100, 1, *output)
326 { this->thread = thread; this->output = output; }
327 ScaleRatioText::~ScaleRatioText() {}
328 int ScaleRatioText::handle_event()
330 *output = atof(get_text());
331 //if(*output <= 0) *output = 1;
332 if(*output > 10000) *output = 10000;
333 if(*output < -10000) *output = -10000;
335 thread->update_window();
341 ScaleConstrain::ScaleConstrain(int x, int y, ScaleThread *thread)
342 : BC_CheckBox(x, y, thread->constrain_ratio, _("Constrain ratio"))
343 { this->thread = thread; }
344 ScaleConstrain::~ScaleConstrain() {}
345 int ScaleConstrain::handle_event()
347 thread->constrain_ratio = get_value();
350 ScaleData::ScaleData(int x, int y, ScaleThread *thread)
351 : BC_CheckBox(x, y, thread->scale_data, _("Scale data"))
352 { this->thread = thread; }
353 ScaleData::~ScaleData() {}
354 int ScaleData::handle_event()
356 thread->scale_data = get_value();
357 thread->update_window();
361 ScaleAspectAuto::ScaleAspectAuto(int x, int y, ScaleThread *thread)
362 : BC_CheckBox(x, y, thread->auto_aspect, _("Auto"))
363 { this->thread = thread; }
365 ScaleAspectAuto::~ScaleAspectAuto()
369 int ScaleAspectAuto::handle_event()
371 thread->auto_aspect = get_value();
372 thread->update_aspect(thread->window);
378 ScaleAspectW::ScaleAspectW(int x, int y, ScaleThread *thread, float *output, char *string)
379 : BC_TextBox(x, y, 50, 1, string)
381 this->output = output;
382 this->thread = thread;
384 ScaleAspectW::~ScaleAspectW()
388 int ScaleAspectW::handle_event()
390 *output = atof(get_text());
394 ScaleAspectH::ScaleAspectH(int x, int y, ScaleThread *thread, float *output, char *string)
395 : BC_TextBox(x, y, 50, 1, string)
397 this->output = output;
398 this->thread = thread;
400 ScaleAspectH::~ScaleAspectH()
404 int ScaleAspectH::handle_event()
406 *output = atof(get_text());