prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / setformat.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
5  * 
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.
10  * 
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.
15  * 
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
19  * 
20  */
21
22 #include "clip.h"
23 #include "cwindow.h"
24 #include "cwindowgui.h"
25 #include "datatype.h"
26 #include "bchash.h"
27 #include "edl.h"
28 #include "edlsession.h"
29 #include "formatpresets.h"
30 #include "language.h"
31 #include "levelwindow.h"
32 #include "levelwindowgui.h"
33 #include "mainerror.h"
34 #include "mainundo.h"
35 #include "mutex.h"
36 #include "mwindow.h"
37 #include "mwindowgui.h"
38 #include "new.h"
39 #include "preferences.h"
40 #include "rotateframe.h"
41 #include "setformat.h"
42 #include "theme.h"
43 #include "vframe.h"
44 #include "vwindow.h"
45 #include "vwindowgui.h"
46
47
48
49 SetFormat::SetFormat(MWindow *mwindow)
50  : BC_MenuItem(_("Format..."), _("Shift-F"), 'F')
51 {
52         set_shift(1); 
53         this->mwindow = mwindow;
54         thread = new SetFormatThread(mwindow);
55 }
56
57 SetFormat::~SetFormat()
58 {
59         delete thread;
60 }
61
62
63 int SetFormat::handle_event()
64 {
65         if(!thread->running())
66         {
67                 thread->start();
68         }
69         else
70         {
71 // window_lock has to be locked but window can't be locked until after
72 // it is known to exist, so we neglect window_lock for now
73                 if(thread->window)
74                 {
75                         thread->window_lock->lock("SetFormat::handle_event");
76                         thread->window->lock_window("SetFormat::handle_event");
77                         thread->window->raise_window();
78                         thread->window->unlock_window();
79                         thread->window_lock->unlock();
80                 }
81         }
82         return 1;
83 }
84
85 SetFormatThread::SetFormatThread(MWindow *mwindow)
86  : Thread(1, 0, 0)
87 {
88         this->mwindow = mwindow;
89         window_lock = new Mutex("SetFormatThread::window_lock");
90         window = 0;
91 }
92
93 SetFormatThread::~SetFormatThread()
94 {
95         if( running() ) {
96                 window->set_done(1);
97                 cancel();
98                 join();
99         }
100         delete window_lock;
101 }
102
103 void SetFormatThread::run()
104 {
105         orig_dimension[0] = dimension[0] = mwindow->edl->session->output_w;
106         orig_dimension[1] = dimension[1] = mwindow->edl->session->output_h;
107         auto_aspect = mwindow->defaults->get("AUTOASPECT", 0);
108         constrain_ratio = 0;
109         ratio[0] = ratio[1] = 1;
110
111         new_settings = new EDL;
112         new_settings->create_objects();
113         new_settings->copy_session(mwindow->edl);
114
115 // This locks mwindow, so it must be done outside window_lock
116         int x = mwindow->gui->get_abs_cursor_x(1) - mwindow->theme->setformat_w / 2;
117         int y = mwindow->gui->get_abs_cursor_y(1) - mwindow->theme->setformat_h / 2;
118
119         window_lock->lock("SetFormatThread::run 1");
120         window = new SetFormatWindow(mwindow, this, x, y);
121         window->create_objects();
122         window_lock->unlock();
123
124         int result = window->run_window();
125
126
127         window_lock->lock("SetFormatThread::run 2");
128         delete window;
129         window = 0;
130         window_lock->unlock();
131
132
133         if(!result)
134         {
135                 apply_changes();
136         }
137
138         mwindow->defaults->update("AUTOASPECT", auto_aspect);
139         new_settings->Garbage::remove_user();
140 }
141
142 void SetFormatThread::apply_changes()
143 {
144         double new_samplerate = new_settings->session->sample_rate;
145         double old_samplerate = mwindow->edl->session->sample_rate;
146         double new_framerate = new_settings->session->frame_rate;
147         double old_framerate = mwindow->edl->session->frame_rate;
148         int new_channels = new_settings->session->audio_channels;
149         CLAMP(new_channels, 1, MAXCHANNELS);
150
151
152
153         mwindow->undo->update_undo_before();
154
155         memcpy(&mwindow->preferences->channel_positions[MAXCHANNELS * (new_channels - 1)],
156                 new_settings->session->achannel_positions,
157                 sizeof(int) * MAXCHANNELS);
158
159
160         mwindow->edl->copy_session(new_settings, 1);
161         mwindow->edl->session->output_w = dimension[0];
162         mwindow->edl->session->output_h = dimension[1];
163         mwindow->edl->rechannel();
164         mwindow->edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
165         mwindow->edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
166         mwindow->save_backup();
167         mwindow->undo->update_undo_after(_("set format"), LOAD_ALL);
168
169         mwindow->resync_guis();
170 }
171
172 void SetFormatThread::update()
173 {
174         window->sample_rate->update(new_settings->session->sample_rate);
175         window->channels->update((int64_t)new_settings->session->audio_channels);
176         window->frame_rate->update((float)new_settings->session->frame_rate);
177
178         auto_aspect = 0;
179         window->auto_aspect->update(0);
180
181         constrain_ratio = 0;
182         dimension[0] = new_settings->session->output_w;
183         window->dimension[0]->update((int64_t)dimension[0]);
184         dimension[1] = new_settings->session->output_h;
185         window->dimension[1]->update((int64_t)dimension[1]);
186
187         ratio[0] = (float)dimension[0] / orig_dimension[0];
188         window->ratio[0]->update(ratio[0]);
189         ratio[1] = (float)dimension[1] / orig_dimension[1];
190         window->ratio[1]->update(ratio[1]);
191
192         window->aspect_w->update(new_settings->session->aspect_w);
193         window->aspect_h->update(new_settings->session->aspect_h);
194
195         window->canvas->draw();
196 }
197
198 void SetFormatThread::update_window()
199 {
200         int i, result, modified_item = 0, dimension_modified = 0, ratio_modified = 0;
201
202         for(i = 0, result = 0; i < 2 && !result; i++)
203         {
204                 if(dimension[i] < 0)
205                 {
206                         dimension[i] *= -1;
207                         result = 1;
208                         modified_item = i;
209                         dimension_modified = 1;
210                 }
211                 if(ratio[i] < 0)
212                 {
213                         ratio[i] *= -1;
214                         result = 1;
215                         modified_item = i;
216                         ratio_modified = 1;
217                 }
218         }
219
220         if(result)
221         {
222                 if(dimension_modified)
223                         ratio[modified_item] = (float)dimension[modified_item] / orig_dimension[modified_item];
224
225                 if(ratio_modified && !constrain_ratio)
226                 {
227                         dimension[modified_item] = (int)(orig_dimension[modified_item] * ratio[modified_item]);
228                         window->dimension[modified_item]->update((int64_t)dimension[modified_item]);
229                 }
230
231                 for(i = 0; i < 2; i++)
232                 {
233                         if(dimension_modified ||
234                                 (i != modified_item && ratio_modified))
235                         {
236                                 if(constrain_ratio) ratio[i] = ratio[modified_item];
237                                 window->ratio[i]->update(ratio[i]);
238                         }
239
240                         if(ratio_modified ||
241                                 (i != modified_item && dimension_modified))
242                         {
243                                 if(constrain_ratio) 
244                                 {
245                                         dimension[i] = (int)(orig_dimension[i] * ratio[modified_item]);
246                                         window->dimension[i]->update((int64_t)dimension[i]);
247                                 }
248                         }
249                 }
250         }
251
252         update_aspect();
253 }
254
255 void SetFormatThread::update_aspect()
256 {
257         if(auto_aspect)
258         {
259                 char string[BCTEXTLEN];
260                 MWindow::create_aspect_ratio(new_settings->session->aspect_w, 
261                         new_settings->session->aspect_h, 
262                         dimension[0], 
263                         dimension[1]);
264                 sprintf(string, "%.02f", new_settings->session->aspect_w);
265                 window->aspect_w->update(string);
266                 sprintf(string, "%.02f", new_settings->session->aspect_h);
267                 window->aspect_h->update(string);
268         }
269 }
270
271
272
273
274
275
276
277
278
279 SetFormatWindow::SetFormatWindow(MWindow *mwindow, 
280         SetFormatThread *thread,
281         int x,
282         int y)
283  : BC_Window(_(PROGRAM_NAME ": Set Format"),
284         x,
285         y,
286         mwindow->theme->setformat_w,
287         mwindow->theme->setformat_h,
288         -1,
289         -1,
290         0,
291         0,
292         1)
293 {
294         this->mwindow = mwindow;
295         this->thread = thread;
296 }
297
298 void SetFormatWindow::create_objects()
299 {
300         int x = 10, y = mwindow->theme->setformat_y1;
301         BC_Title *title;
302
303         lock_window("SetFormatWindow::create_objects");
304         mwindow->theme->draw_setformat_bg(this);
305
306
307
308         presets = new SetFormatPresets(mwindow, 
309                 this, 
310                 x, 
311                 y);
312         presets->create_objects();
313         x = presets->x;
314         y = presets->y;
315
316         y = mwindow->theme->setformat_y2;
317
318         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
319                 y, 
320                 _("Audio"), 
321                 LARGEFONT));
322         y = mwindow->theme->setformat_y3;
323         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
324                 y,
325                 _("Samplerate:")));
326
327         y += mwindow->theme->setformat_margin;
328         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
329                 y,
330                 _("Samplerate:")));
331         add_subwindow(sample_rate = new SetSampleRateTextBox(thread, 
332                 mwindow->theme->setformat_x2, 
333                 y));
334         add_subwindow(new SampleRatePulldown(mwindow, 
335                 sample_rate, 
336                 mwindow->theme->setformat_x2 + sample_rate->get_w(), 
337                 y));
338
339         y += mwindow->theme->setformat_margin;
340         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
341                 y, 
342                 _("Channels:")));
343         add_subwindow(channels = new SetChannelsTextBox(thread, 
344                 mwindow->theme->setformat_x2, 
345                 y));
346         add_subwindow(new BC_ITumbler(channels, 
347                 1, 
348                 MAXCHANNELS, 
349                 mwindow->theme->setformat_x2 + channels->get_w(), 
350                 y));
351
352         y += mwindow->theme->setformat_margin;
353         add_subwindow(new BC_Title(mwindow->theme->setformat_x1, 
354                 y, 
355                 _("Channel positions:")));
356         y += mwindow->theme->setformat_margin;
357         add_subwindow(canvas = new SetChannelsCanvas(mwindow, 
358                 thread, 
359                 mwindow->theme->setformat_channels_x, 
360                 mwindow->theme->setformat_channels_y, 
361                 mwindow->theme->setformat_channels_w, 
362                 mwindow->theme->setformat_channels_h));
363         canvas->draw();
364
365
366
367
368
369
370
371
372
373         y = mwindow->theme->setformat_y2;
374         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
375                 y, 
376                 _("Video"), 
377                 LARGEFONT));
378
379         y = mwindow->theme->setformat_y3;
380         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
381                 y, 
382                 _("Frame rate:")));
383         add_subwindow(frame_rate = new SetFrameRateTextBox(thread, 
384                 mwindow->theme->setformat_x4, 
385                 y));
386         add_subwindow(new FrameRatePulldown(mwindow, 
387                 frame_rate, 
388                 mwindow->theme->setformat_x4 + frame_rate->get_w(), 
389                 y));
390
391         y += mwindow->theme->setformat_margin;
392         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
393                 y, 
394                 _("Canvas size:")));
395
396         y += mwindow->theme->setformat_margin;
397         add_subwindow(title = new BC_Title(mwindow->theme->setformat_x3, y, _("Width:")));
398         add_subwindow(dimension[0] = new ScaleSizeText(mwindow->theme->setformat_x4, 
399                 y, 
400                 thread, 
401                 &(thread->dimension[0])));
402
403         y += mwindow->theme->setformat_margin;
404         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, y, _("Height:")));
405         add_subwindow(dimension[1] = new ScaleSizeText(mwindow->theme->setformat_x4, 
406                 y, 
407                 thread, 
408                 &(thread->dimension[1])));
409
410         x = mwindow->theme->setformat_x4 + dimension[0]->get_w();
411         FrameSizePulldown *pulldown;
412         add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme, 
413                 dimension[0], 
414                 dimension[1], 
415                 x, 
416                 y - mwindow->theme->setformat_margin));
417
418         add_subwindow(new FormatSwapExtents(mwindow, 
419                 thread, 
420                 this, 
421                 x + pulldown->get_w() + 5,
422                 y - mwindow->theme->setformat_margin));
423                 
424         y += mwindow->theme->setformat_margin;
425         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
426                 y, 
427                 _("W Ratio:")));
428         add_subwindow(ratio[0] = new ScaleRatioText(mwindow->theme->setformat_x4, 
429                 y, 
430                 thread, 
431                 &(thread->ratio[0])));
432
433         y += mwindow->theme->setformat_margin;
434         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
435                 y, 
436                 _("H Ratio:")));
437         add_subwindow(ratio[1] = new ScaleRatioText(mwindow->theme->setformat_x4, 
438                 y, 
439                 thread, 
440                 &(thread->ratio[1])));
441
442         y += mwindow->theme->setformat_margin;
443         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
444                 y, 
445                 _("Color model:")));
446         x = mwindow->theme->setformat_x4;
447         add_subwindow(color_model = new BC_TextBox(x, 
448                 y, 
449                 100, 
450                 1, 
451                 ""));
452         x += color_model->get_w();
453         add_subwindow(new ColormodelPulldown(mwindow, 
454                 color_model, 
455                 &thread->new_settings->session->color_model,
456                 x, 
457                 y));
458
459         y += mwindow->theme->setformat_margin;
460         add_subwindow(new BC_Title(mwindow->theme->setformat_x3, 
461                 y, 
462                 _("Aspect ratio:")));
463         y += mwindow->theme->setformat_margin;
464         x = mwindow->theme->setformat_x3;
465         add_subwindow(aspect_w = new ScaleAspectText(x, 
466                 y, 
467                 thread, 
468                 &(thread->new_settings->session->aspect_w)));
469         x += aspect_w->get_w() + 5;
470         add_subwindow(new BC_Title(x, y, _(":")));
471         x += 10;
472         add_subwindow(aspect_h = new ScaleAspectText(x, 
473                 y, 
474                 thread, 
475                 &(thread->new_settings->session->aspect_h)));
476         x += aspect_h->get_w();
477         add_subwindow(new AspectPulldown(mwindow, 
478                 aspect_w, 
479                 aspect_h, 
480                 x, 
481                 y));
482         x += 30;
483         add_subwindow(auto_aspect = new ScaleAspectAuto(x, y, thread));
484
485
486
487         BC_OKTextButton *ok;
488         BC_CancelTextButton *cancel;
489         add_subwindow(ok = new BC_OKTextButton(this));
490         add_subwindow(cancel = new BC_CancelTextButton(this));
491         add_subwindow(new SetFormatApply((ok->get_x() + cancel->get_x()) / 2, 
492                 ok->get_y(), 
493                 thread));
494         flash();
495         show_window();
496         unlock_window();
497 }
498
499 const char* SetFormatWindow::get_preset_text()
500 {
501         return "";
502 }
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518 SetFormatPresets::SetFormatPresets(MWindow *mwindow, 
519         SetFormatWindow *gui, 
520         int x, 
521         int y)
522  : FormatPresets(mwindow, 0, gui, x, y)
523 {
524         
525 }
526
527 SetFormatPresets::~SetFormatPresets()
528 {
529 }
530
531 int SetFormatPresets::handle_event()
532 {
533         format_gui->thread->update();
534         return 1;
535 }
536
537 EDL* SetFormatPresets::get_edl()
538 {
539         return format_gui->thread->new_settings;
540 }
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556 SetSampleRateTextBox::SetSampleRateTextBox(SetFormatThread *thread, int x, int y)
557  : BC_TextBox(x, y, 100, 1, (int64_t)thread->new_settings->session->sample_rate)
558 {
559         this->thread = thread;
560 }
561 int SetSampleRateTextBox::handle_event()
562 {
563         thread->new_settings->session->sample_rate = CLIP(atol(get_text()), 1, 1000000);
564         return 1;
565 }
566
567 SetChannelsTextBox::SetChannelsTextBox(SetFormatThread *thread, int x, int y)
568  : BC_TextBox(x, y, 100, 1, thread->new_settings->session->audio_channels)
569 {
570         this->thread = thread;
571 }
572 int SetChannelsTextBox::handle_event()
573 {
574         int new_channels = CLIP(atoi(get_text()), 1, MAXCHANNELS);
575         
576         thread->new_settings->session->audio_channels = new_channels;
577
578
579         if(new_channels > 0)
580         {
581                 memcpy(thread->new_settings->session->achannel_positions,
582                         &thread->mwindow->preferences->channel_positions[MAXCHANNELS * (new_channels - 1)],
583                         sizeof(int) * MAXCHANNELS);
584         }
585
586
587         thread->window->canvas->draw();
588         return 1;
589 }
590
591
592 SetChannelsCanvas::SetChannelsCanvas(MWindow *mwindow, 
593         SetFormatThread *thread, 
594         int x, 
595         int y,
596         int w,
597         int h)
598  : BC_SubWindow(x, 
599         y, 
600         w,
601         h)
602 {
603         this->thread = thread;
604         this->mwindow = mwindow;
605         active_channel = -1;
606         box_r = mwindow->theme->channel_position_data->get_w() / 2;
607         temp_picon = new VFrame(0, 
608                 -1,
609                 mwindow->theme->channel_position_data->get_w(),
610                 mwindow->theme->channel_position_data->get_h(),
611                 mwindow->theme->channel_position_data->get_color_model(),
612                 -1);
613         rotater = new RotateFrame(mwindow->preferences->processors,
614                 mwindow->theme->channel_position_data->get_w(),
615                 mwindow->theme->channel_position_data->get_h());
616 }
617 SetChannelsCanvas::~SetChannelsCanvas()
618 {
619         delete temp_picon;
620         delete rotater;
621 }
622
623 int SetChannelsCanvas::draw(int angle)
624 {
625         set_color(RED);
626         //int real_w = get_w() - box_r * 2;
627         //int real_h = get_h() - box_r * 2;
628         //int real_x = box_r;
629         //int real_y = box_r;
630
631         draw_top_background(get_top_level(), 0, 0, get_w(), get_h());
632 //      draw_vframe(mwindow->theme->channel_bg_data, 0, 0);
633
634
635
636
637         int x, y, w, h;
638         char string[32];
639         set_color(mwindow->theme->channel_position_color);
640         for(int i = 0; i < thread->new_settings->session->audio_channels; i++)
641         {
642                 get_dimensions(thread->new_settings->session->achannel_positions[i], 
643                         x, 
644                         y, 
645                         w, 
646                         h);
647                 double rotate_angle = thread->new_settings->session->achannel_positions[i];
648                 rotate_angle = -rotate_angle;
649                 while(rotate_angle < 0) rotate_angle += 360;
650                 rotater->rotate(temp_picon, 
651                         mwindow->theme->channel_position_data, 
652                         rotate_angle, 
653                         0);
654
655                 BC_Pixmap temp_pixmap(this, 
656                         temp_picon, 
657                         PIXMAP_ALPHA,
658                         0);
659                 draw_pixmap(&temp_pixmap, x, y);
660                 sprintf(string, "%d", i + 1);
661                 draw_text(x + 2, y + box_r * 2 - 2, string);
662         }
663
664         if(angle > -1)
665         {
666                 sprintf(string, _("%d degrees"), angle);
667                 draw_text(this->get_w() / 2 - 40, this->get_h() / 2, string);
668         }
669
670         flash();
671         return 0;
672 }
673
674 int SetChannelsCanvas::get_dimensions(int channel_position, 
675         int &x, 
676         int &y, 
677         int &w, 
678         int &h)
679 {
680 #define MARGIN 10
681         int real_w = this->get_w() - box_r * 2 - MARGIN;
682         int real_h = this->get_h() - box_r * 2 - MARGIN;
683         float corrected_position = channel_position;
684         if(corrected_position < 0) corrected_position += 360;
685         Units::polar_to_xy((float)corrected_position, real_w / 2, x, y);
686         x += real_w / 2 + MARGIN / 2;
687         y += real_h / 2 + MARGIN / 2;
688         w = box_r * 2;
689         h = box_r * 2;
690         return 0;
691 }
692
693 int SetChannelsCanvas::button_press_event()
694 {
695         if(!cursor_inside()) return 0;
696 // get active channel
697         for(int i = 0; 
698                 i < thread->new_settings->session->audio_channels; 
699                 i++)
700         {
701                 int x, y, w, h;
702                 get_dimensions(thread->new_settings->session->achannel_positions[i], 
703                         x, 
704                         y, 
705                         w, 
706                         h);
707                 if(get_cursor_x() > x && get_cursor_y() > y && 
708                         get_cursor_x() < x + w && get_cursor_y() < y + h)
709                 {
710                         active_channel = i;
711                         degree_offset = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
712                         degree_offset += 90;
713                         if(degree_offset >= 360) degree_offset -= 360;
714                         degree_offset -= thread->new_settings->session->achannel_positions[i];
715                         draw(thread->new_settings->session->achannel_positions[i]);
716                         return 1;
717                 }
718         }
719         return 0;
720 }
721
722 int SetChannelsCanvas::button_release_event()
723 {
724         if(active_channel >= 0)
725         {
726                 active_channel = -1;
727                 draw(-1);
728                 return 1;
729         }
730         return 0;
731 }
732
733 int SetChannelsCanvas::cursor_motion_event()
734 {
735         if(active_channel >= 0)
736         {
737 // get degrees of new channel
738                 int new_d;
739                 new_d = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
740                 new_d += 90;
741                 new_d -= degree_offset;
742
743                 while(new_d >= 360) new_d -= 360;
744                 while(new_d < 0) new_d += 360;
745
746                 if(thread->new_settings->session->achannel_positions[active_channel] != new_d)
747                 {
748                         thread->new_settings->session->achannel_positions[active_channel] = new_d;
749                         int new_channels = thread->new_settings->session->audio_channels;
750                         memcpy(&thread->mwindow->preferences->channel_positions[MAXCHANNELS * (new_channels - 1)],
751                                 thread->new_settings->session->achannel_positions,
752                                 sizeof(int) * MAXCHANNELS);
753                         draw(thread->new_settings->session->achannel_positions[active_channel]);
754                 }
755                 return 1;
756         }
757         return 0;
758 }
759
760
761
762
763
764
765
766
767
768 SetFrameRateTextBox::SetFrameRateTextBox(SetFormatThread *thread, int x, int y)
769  : BC_TextBox(x, y, 100, 1, (float)thread->new_settings->session->frame_rate)
770 {
771         this->thread = thread;
772 }
773
774 int SetFrameRateTextBox::handle_event()
775 {
776         thread->new_settings->session->frame_rate = Units::atoframerate(get_text());
777         return 1;
778 }
779
780
781 // 
782 // SetVChannels::SetVChannels(SetFormatThread *thread, int x, int y)
783 //  : BC_TextBox(x, y, 100, 1, thread->channels)
784 // {
785 //      this->thread = thread;
786 // }
787 // int SetVChannels::handle_event()
788 // {
789 //      thread->channels = atol(get_text());
790 //      return 1;
791 // }
792
793
794
795
796 ScaleSizeText::ScaleSizeText(int x, int y, SetFormatThread *thread, int *output)
797  : BC_TextBox(x, y, 100, 1, *output)
798
799         this->thread = thread; 
800         this->output = output; 
801 }
802 ScaleSizeText::~ScaleSizeText()
803 {
804 }
805 int ScaleSizeText::handle_event()
806 {
807         *output = atol(get_text());
808         *output /= 2;
809         *output *= 2;
810         if(*output <= 0) *output = 2;
811         if(*output > 10000) *output = 10000;
812         *output *= -1;
813         thread->update_window();
814         return 1;
815 }
816
817
818
819 ScaleRatioText::ScaleRatioText(int x, 
820         int y, 
821         SetFormatThread *thread, 
822         float *output)
823  : BC_TextBox(x, y, 100, 1, *output)
824
825         this->thread = thread; 
826         this->output = output; 
827 }
828 ScaleRatioText::~ScaleRatioText()
829 {
830 }
831 int ScaleRatioText::handle_event()
832 {
833         *output = atof(get_text());
834         //if(*output <= 0) *output = 1;
835         if(*output > 10000) *output = 10000;
836         if(*output < -10000) *output = -10000;
837         *output *= -1;
838         thread->update_window();
839         return 1;
840 }
841
842
843
844 ScaleAspectAuto::ScaleAspectAuto(int x, int y, SetFormatThread *thread)
845  : BC_CheckBox(x, y, thread->auto_aspect, _("Auto"))
846 {
847         this->thread = thread; 
848 }
849
850 ScaleAspectAuto::~ScaleAspectAuto()
851 {
852 }
853
854 int ScaleAspectAuto::handle_event()
855 {
856         thread->auto_aspect = get_value();
857         thread->update_aspect();
858         return 0;
859 }
860
861 ScaleAspectText::ScaleAspectText(int x, int y, SetFormatThread *thread, float *output)
862  : BC_TextBox(x, y, 70, 1, *output)
863 {
864         this->output = output;
865         this->thread = thread;
866 }
867 ScaleAspectText::~ScaleAspectText()
868 {
869 }
870
871 int ScaleAspectText::handle_event()
872 {
873         *output = atof(get_text());
874         return 1;
875 }
876
877
878
879
880
881
882 SetFormatApply::SetFormatApply(int x, int y, SetFormatThread *thread)
883  : BC_GenericButton(x, y, _("Apply"))
884 {
885         this->thread = thread;
886 }
887
888 int SetFormatApply::handle_event()
889 {
890         thread->apply_changes();
891         return 1;
892 }
893
894
895
896
897
898
899
900
901
902
903
904
905
906 FormatSwapExtents::FormatSwapExtents(MWindow *mwindow, 
907         SetFormatThread *thread,
908         SetFormatWindow *gui, 
909         int x, 
910         int y)
911  : BC_Button(x, y, mwindow->theme->get_image_set("swap_extents"))
912 {
913         this->mwindow = mwindow;
914         this->thread = thread;
915         this->gui = gui;
916         set_tooltip(_("Swap dimensions"));
917 }
918
919 int FormatSwapExtents::handle_event()
920 {
921         int w = thread->dimension[0];
922         int h = thread->dimension[1];
923         thread->dimension[0] = -h;
924         gui->dimension[0]->update((int64_t)h);
925         gui->dimension[1]->update((int64_t)w);
926         thread->update_window();
927         thread->dimension[1] = -w;
928         thread->update_window();
929         return 1;
930 }
931
932
933
934