rework index builder, add pro ffmpeg format
[goodguy/history.git] / cinelerra-5.1 / plugins / motion / motionwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 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 "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "language.h"
25 #include "motion.h"
26 #include "motionscan.h"
27 #include "motionwindow.h"
28
29
30
31
32
33
34
35
36
37
38 MotionWindow::MotionWindow(MotionMain *plugin)
39  : PluginClientWindow(plugin,
40         600,
41         650,
42         600,
43         650,
44         0)
45 {
46         this->plugin = plugin;
47 }
48
49 MotionWindow::~MotionWindow()
50 {
51 }
52
53 void MotionWindow::create_objects()
54 {
55         int x1 = 10, x = 10, y = 10;
56         int x2 = 310;
57         BC_Title *title;
58
59
60
61         add_subwindow(global = new MotionGlobal(plugin,
62                 this,
63                 x1,
64                 y));
65
66         add_subwindow(rotate = new MotionRotate(plugin,
67                 this,
68                 x2,
69                 y));
70         y += 50;
71
72         add_subwindow(title = new BC_Title(x1,
73                 y,
74                 _("Translation search radius:\n(W/H Percent of image)")));
75         add_subwindow(global_range_w = new GlobalRange(plugin,
76                 x1 + title->get_w() + 10,
77                 y,
78                 &plugin->config.global_range_w));
79         add_subwindow(global_range_h = new GlobalRange(plugin,
80                 x1 + title->get_w() + 10 + global_range_w->get_w(),
81                 y,
82                 &plugin->config.global_range_h));
83
84         add_subwindow(title = new BC_Title(x2,
85                 y,
86                 _("Rotation search radius:\n(Degrees)")));
87         add_subwindow(rotation_range = new RotationRange(plugin,
88                 x2 + title->get_w() + 10,
89                 y));
90
91         y += 50;
92         add_subwindow(title = new BC_Title(x1,
93                 y,
94                 _("Translation block size:\n(W/H Percent of image)")));
95         add_subwindow(global_block_w = new BlockSize(plugin,
96                 x1 + title->get_w() + 10,
97                 y,
98                 &plugin->config.global_block_w));
99         add_subwindow(global_block_h = new BlockSize(plugin,
100                 x1 + title->get_w() + 10 + global_block_w->get_w(),
101                 y,
102                 &plugin->config.global_block_h));
103
104 //      add_subwindow(title = new BC_Title(x2,
105 //              y,
106 //              _("Rotation block size:\n(W/H Percent of image)")));
107 //      add_subwindow(rotation_block_w = new BlockSize(plugin,
108 //              x2 + title->get_w() + 10,
109 //              y,
110 //              &plugin->config.rotation_block_w));
111 //      add_subwindow(rotation_block_h = new BlockSize(plugin,
112 //              x2 + title->get_w() + 10 + rotation_block_w->get_w(),
113 //              y,
114 //              &plugin->config.rotation_block_h));
115
116         y += 50;
117         add_subwindow(title = new BC_Title(x1, y, _("Translation search steps:")));
118         add_subwindow(global_search_positions = new GlobalSearchPositions(plugin,
119                 x1 + title->get_w() + 10,
120                 y,
121                 80));
122         global_search_positions->create_objects();
123
124         add_subwindow(title = new BC_Title(x2, y, _("Rotation search steps:")));
125         add_subwindow(rotation_search_positions = new RotationSearchPositions(plugin,
126                 x2 + title->get_w() + 10,
127                 y,
128                 80));
129         rotation_search_positions->create_objects();
130
131         y += 50;
132         add_subwindow(title = new BC_Title(x, y, _("Translation direction:")));
133         add_subwindow(track_direction = new TrackDirection(plugin,
134                 this,
135                 x + title->get_w() + 10,
136                 y));
137         track_direction->create_objects();
138
139         y += 40;
140         add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
141         add_subwindow(block_x = new MotionBlockX(plugin,
142                 this,
143                 x + title->get_w() + 10,
144                 y));
145         add_subwindow(block_x_text = new MotionBlockXText(plugin,
146                 this,
147                 x + title->get_w() + 10 + block_x->get_w() + 10,
148                 y + 10));
149
150         add_subwindow(title = new BC_Title(x2, y, _("Rotation center:")));
151         add_subwindow(rotation_center = new RotationCenter(plugin,
152                 x2 + title->get_w() + 10,
153                 y));
154
155
156
157         int y1 = y;
158         y += 50;
159         add_subwindow(title = new BC_Title(x2, y + 10, _("Maximum angle offset:")));
160         add_subwindow(rotate_magnitude = new MotionRMagnitude(plugin,
161                 x2 + title->get_w() + 10,
162                 y));
163
164         y += 40;
165         add_subwindow(title = new BC_Title(x2, y + 10, _("Rotation settling speed:")));
166         add_subwindow(rotate_return_speed = new MotionRReturnSpeed(plugin,
167                 x2 + title->get_w() + 10,
168                 y));
169
170
171
172         y = y1;
173         y += 40;
174         add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
175         add_subwindow(block_y = new MotionBlockY(plugin,
176                 this,
177                 x + title->get_w() + 10,
178                 y));
179         add_subwindow(block_y_text = new MotionBlockYText(plugin,
180                 this,
181                 x + title->get_w() + 10 + block_y->get_w() + 10,
182                 y + 10));
183
184         y += 50;
185         add_subwindow(title = new BC_Title(x, y + 10, _("Maximum absolute offset:")));
186         add_subwindow(magnitude = new MotionMagnitude(plugin,
187                 x + title->get_w() + 10,
188                 y));
189
190         y += 40;
191         add_subwindow(title = new BC_Title(x, y + 10, _("Motion settling speed:")));
192         add_subwindow(return_speed = new MotionReturnSpeed(plugin,
193                 x + title->get_w() + 10,
194                 y));
195
196
197
198         y += 40;
199         add_subwindow(vectors = new MotionDrawVectors(plugin,
200                 this,
201                 x,
202                 y));
203
204
205         y += 40;
206         add_subwindow(track_single = new TrackSingleFrame(plugin,
207                 this,
208                 x,
209                 y));
210         add_subwindow(title = new BC_Title(x + track_single->get_w() + 20,
211                 y,
212                 _("Frame number:")));
213         add_subwindow(track_frame_number = new TrackFrameNumber(plugin,
214                 this,
215                 x + track_single->get_w() + title->get_w() + 20,
216                 y));
217         add_subwindow(addtrackedframeoffset = new AddTrackedFrameOffset(plugin,
218                 this,
219                 x + track_single->get_w() + title->get_w() + 20 + track_frame_number->get_w(),
220                 y));
221
222
223         y += 20;
224         add_subwindow(track_previous = new TrackPreviousFrame(plugin,
225                 this,
226                 x,
227                 y));
228
229         y += 20;
230         add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
231                 this,
232                 x,
233                 y));
234
235         y += 40;
236         y1 = y;
237         add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
238         add_subwindow(master_layer = new MasterLayer(plugin,
239                 this,
240                 x + title->get_w() + 10,
241                 y));
242         master_layer->create_objects();
243         y += 30;
244
245
246         add_subwindow(title = new BC_Title(x, y, _("Action:")));
247         add_subwindow(action_type = new ActionType(plugin,
248                 this,
249                 x + title->get_w() + 10,
250                 y));
251         action_type->create_objects();
252         y += 30;
253
254
255
256
257         add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
258         add_subwindow(tracking_type = new TrackingType(plugin,
259                 this,
260                 x + title->get_w() + 10,
261                 y));
262         tracking_type->create_objects();
263
264
265
266         show_window(1);
267 }
268
269 void MotionWindow::update_mode()
270 {
271         global_range_w->update(plugin->config.global_range_w,
272                 MIN_RADIUS,
273                 MAX_RADIUS);
274         global_range_h->update(plugin->config.global_range_h,
275                 MIN_RADIUS,
276                 MAX_RADIUS);
277         rotation_range->update(plugin->config.rotation_range,
278                 MIN_ROTATION,
279                 MAX_ROTATION);
280         vectors->update(plugin->config.draw_vectors);
281         global->update(plugin->config.global);
282         rotate->update(plugin->config.rotate);
283         addtrackedframeoffset->update(plugin->config.addtrackedframeoffset);
284 }
285
286
287
288
289
290
291
292
293
294
295
296
297
298 GlobalRange::GlobalRange(MotionMain *plugin,
299         int x,
300         int y,
301         int *value)
302  : BC_IPot(x,
303                 y,
304                 (int64_t)*value,
305                 (int64_t)MIN_RADIUS,
306                 (int64_t)MAX_RADIUS)
307 {
308         this->plugin = plugin;
309         this->value = value;
310 }
311
312
313 int GlobalRange::handle_event()
314 {
315         *value = (int)get_value();
316         plugin->send_configure_change();
317         return 1;
318 }
319
320
321
322
323 RotationRange::RotationRange(MotionMain *plugin,
324         int x,
325         int y)
326  : BC_IPot(x,
327                 y,
328                 (int64_t)plugin->config.rotation_range,
329                 (int64_t)MIN_ROTATION,
330                 (int64_t)MAX_ROTATION)
331 {
332         this->plugin = plugin;
333 }
334
335
336 int RotationRange::handle_event()
337 {
338         plugin->config.rotation_range = (int)get_value();
339         plugin->send_configure_change();
340         return 1;
341 }
342
343
344
345
346 RotationCenter::RotationCenter(MotionMain *plugin,
347         int x,
348         int y)
349  : BC_IPot(x,
350                 y,
351                 (int64_t)plugin->config.rotation_center,
352                 (int64_t)-MAX_ROTATION,
353                 (int64_t)MAX_ROTATION)
354 {
355         this->plugin = plugin;
356 }
357
358
359 int RotationCenter::handle_event()
360 {
361         plugin->config.rotation_center = (int)get_value();
362         plugin->send_configure_change();
363         return 1;
364 }
365
366
367
368
369
370
371 BlockSize::BlockSize(MotionMain *plugin,
372         int x,
373         int y,
374         int *value)
375  : BC_IPot(x,
376                 y,
377                 (int64_t)*value,
378                 (int64_t)MIN_BLOCK,
379                 (int64_t)MAX_BLOCK)
380 {
381         this->plugin = plugin;
382         this->value = value;
383 }
384
385
386 int BlockSize::handle_event()
387 {
388         *value = (int)get_value();
389         plugin->send_configure_change();
390         return 1;
391 }
392
393
394
395
396
397
398
399
400
401
402
403
404
405 GlobalSearchPositions::GlobalSearchPositions(MotionMain *plugin,
406         int x,
407         int y,
408         int w)
409  : BC_PopupMenu(x,
410         y,
411         w,
412         "",
413         1)
414 {
415         this->plugin = plugin;
416 }
417 void GlobalSearchPositions::create_objects()
418 {
419         add_item(new BC_MenuItem("16"));
420         add_item(new BC_MenuItem("32"));
421         add_item(new BC_MenuItem("64"));
422         add_item(new BC_MenuItem("128"));
423         add_item(new BC_MenuItem("256"));
424         add_item(new BC_MenuItem("512"));
425         add_item(new BC_MenuItem("1024"));
426         add_item(new BC_MenuItem("2048"));
427         add_item(new BC_MenuItem("4096"));
428         add_item(new BC_MenuItem("8192"));
429         add_item(new BC_MenuItem("16384"));
430         add_item(new BC_MenuItem("32768"));
431         add_item(new BC_MenuItem("65536"));
432         add_item(new BC_MenuItem("131072"));
433         char string[BCTEXTLEN];
434         sprintf(string, "%d", plugin->config.global_positions);
435         set_text(string);
436 }
437
438 int GlobalSearchPositions::handle_event()
439 {
440         plugin->config.global_positions = atoi(get_text());
441         plugin->send_configure_change();
442         return 1;
443 }
444
445
446
447
448
449
450
451 RotationSearchPositions::RotationSearchPositions(MotionMain *plugin,
452         int x,
453         int y,
454         int w)
455  : BC_PopupMenu(x,
456         y,
457         w,
458         "",
459         1)
460 {
461         this->plugin = plugin;
462 }
463 void RotationSearchPositions::create_objects()
464 {
465         add_item(new BC_MenuItem("4"));
466         add_item(new BC_MenuItem("8"));
467         add_item(new BC_MenuItem("16"));
468         add_item(new BC_MenuItem("32"));
469         char string[BCTEXTLEN];
470         sprintf(string, "%d", plugin->config.rotate_positions);
471         set_text(string);
472 }
473
474 int RotationSearchPositions::handle_event()
475 {
476         plugin->config.rotate_positions = atoi(get_text());
477         plugin->send_configure_change();
478         return 1;
479 }
480
481
482
483
484
485
486
487
488 MotionMagnitude::MotionMagnitude(MotionMain *plugin,
489         int x,
490         int y)
491  : BC_IPot(x,
492                 y,
493                 (int64_t)plugin->config.magnitude,
494                 (int64_t)0,
495                 (int64_t)100)
496 {
497         this->plugin = plugin;
498 }
499
500 int MotionMagnitude::handle_event()
501 {
502         plugin->config.magnitude = (int)get_value();
503         plugin->send_configure_change();
504         return 1;
505 }
506
507
508 MotionReturnSpeed::MotionReturnSpeed(MotionMain *plugin,
509         int x,
510         int y)
511  : BC_IPot(x,
512                 y,
513                 (int64_t)plugin->config.return_speed,
514                 (int64_t)0,
515                 (int64_t)100)
516 {
517         this->plugin = plugin;
518 }
519
520 int MotionReturnSpeed::handle_event()
521 {
522         plugin->config.return_speed = (int)get_value();
523         plugin->send_configure_change();
524         return 1;
525 }
526
527
528
529 AddTrackedFrameOffset::AddTrackedFrameOffset(MotionMain *plugin,
530         MotionWindow *gui,
531         int x,
532         int y)
533  : BC_CheckBox(x,
534         y,
535         plugin->config.addtrackedframeoffset,
536         _("Add (loaded) offset from tracked frame"))
537 {
538         this->plugin = plugin;
539         this->gui = gui;
540 }
541
542 int AddTrackedFrameOffset::handle_event()
543 {
544         plugin->config.addtrackedframeoffset = get_value();
545         plugin->send_configure_change();
546         return 1;
547 }
548
549
550 MotionRMagnitude::MotionRMagnitude(MotionMain *plugin,
551         int x,
552         int y)
553  : BC_IPot(x,
554                 y,
555                 (int64_t)plugin->config.rotate_magnitude,
556                 (int64_t)0,
557                 (int64_t)90)
558 {
559         this->plugin = plugin;
560 }
561
562 int MotionRMagnitude::handle_event()
563 {
564         plugin->config.rotate_magnitude = (int)get_value();
565         plugin->send_configure_change();
566         return 1;
567 }
568
569
570
571 MotionRReturnSpeed::MotionRReturnSpeed(MotionMain *plugin,
572         int x,
573         int y)
574  : BC_IPot(x,
575                 y,
576                 (int64_t)plugin->config.rotate_return_speed,
577                 (int64_t)0,
578                 (int64_t)100)
579 {
580         this->plugin = plugin;
581 }
582
583 int MotionRReturnSpeed::handle_event()
584 {
585         plugin->config.rotate_return_speed = (int)get_value();
586         plugin->send_configure_change();
587         return 1;
588 }
589
590
591
592
593
594 MotionGlobal::MotionGlobal(MotionMain *plugin,
595         MotionWindow *gui,
596         int x,
597         int y)
598  : BC_CheckBox(x,
599         y,
600         plugin->config.global,
601         _("Track translation"))
602 {
603         this->plugin = plugin;
604         this->gui = gui;
605 }
606
607 int MotionGlobal::handle_event()
608 {
609         plugin->config.global = get_value();
610         plugin->send_configure_change();
611         return 1;
612 }
613
614 MotionRotate::MotionRotate(MotionMain *plugin,
615         MotionWindow *gui,
616         int x,
617         int y)
618  : BC_CheckBox(x,
619         y,
620         plugin->config.rotate,
621         _("Track rotation"))
622 {
623         this->plugin = plugin;
624         this->gui = gui;
625 }
626
627 int MotionRotate::handle_event()
628 {
629         plugin->config.rotate = get_value();
630         plugin->send_configure_change();
631         return 1;
632 }
633
634
635
636
637
638 MotionBlockX::MotionBlockX(MotionMain *plugin,
639         MotionWindow *gui,
640         int x,
641         int y)
642  : BC_FPot(x,
643         y,
644         plugin->config.block_x,
645         (float)0,
646         (float)100)
647 {
648         this->plugin = plugin;
649         this->gui = gui;
650 }
651
652 int MotionBlockX::handle_event()
653 {
654         plugin->config.block_x = get_value();
655         gui->block_x_text->update((float)plugin->config.block_x);
656         plugin->send_configure_change();
657         return 1;
658 }
659
660
661
662
663 MotionBlockY::MotionBlockY(MotionMain *plugin,
664         MotionWindow *gui,
665         int x,
666         int y)
667  : BC_FPot(x,
668         y,
669         (float)plugin->config.block_y,
670         (float)0,
671         (float)100)
672 {
673         this->plugin = plugin;
674         this->gui = gui;
675 }
676
677 int MotionBlockY::handle_event()
678 {
679         plugin->config.block_y = get_value();
680         gui->block_y_text->update((float)plugin->config.block_y);
681         plugin->send_configure_change();
682         return 1;
683 }
684
685 MotionBlockXText::MotionBlockXText(MotionMain *plugin,
686         MotionWindow *gui,
687         int x,
688         int y)
689  : BC_TextBox(x,
690         y,
691         75,
692         1,
693         (float)plugin->config.block_x)
694 {
695         this->plugin = plugin;
696         this->gui = gui;
697         set_precision(4);
698 }
699
700 int MotionBlockXText::handle_event()
701 {
702         plugin->config.block_x = atof(get_text());
703         gui->block_x->update(plugin->config.block_x);
704         plugin->send_configure_change();
705         return 1;
706 }
707
708
709
710
711 MotionBlockYText::MotionBlockYText(MotionMain *plugin,
712         MotionWindow *gui,
713         int x,
714         int y)
715  : BC_TextBox(x,
716         y,
717         75,
718         1,
719         (float)plugin->config.block_y)
720 {
721         this->plugin = plugin;
722         this->gui = gui;
723         set_precision(4);
724 }
725
726 int MotionBlockYText::handle_event()
727 {
728         plugin->config.block_y = atof(get_text());
729         gui->block_y->update(plugin->config.block_y);
730         plugin->send_configure_change();
731         return 1;
732 }
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749 MotionDrawVectors::MotionDrawVectors(MotionMain *plugin,
750         MotionWindow *gui,
751         int x,
752         int y)
753  : BC_CheckBox(x,
754         y,
755         plugin->config.draw_vectors,
756         _("Draw vectors"))
757 {
758         this->gui = gui;
759         this->plugin = plugin;
760 }
761
762 int MotionDrawVectors::handle_event()
763 {
764         plugin->config.draw_vectors = get_value();
765         plugin->send_configure_change();
766         return 1;
767 }
768
769
770
771
772
773
774
775
776 TrackSingleFrame::TrackSingleFrame(MotionMain *plugin,
777         MotionWindow *gui,
778         int x,
779         int y)
780  : BC_Radial(x,
781         y,
782         plugin->config.tracking_object == MotionScan::TRACK_SINGLE,
783         _("Track single frame"))
784 {
785         this->plugin = plugin;
786         this->gui = gui;
787 }
788
789 int TrackSingleFrame::handle_event()
790 {
791         plugin->config.tracking_object = MotionScan::TRACK_SINGLE;
792         gui->track_previous->update(0);
793         gui->previous_same->update(0);
794         gui->track_frame_number->enable();
795         plugin->send_configure_change();
796         return 1;
797 }
798
799
800
801
802
803
804
805
806 TrackFrameNumber::TrackFrameNumber(MotionMain *plugin,
807         MotionWindow *gui,
808         int x,
809         int y)
810  : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
811 {
812         this->plugin = plugin;
813         this->gui = gui;
814         if(plugin->config.tracking_object != MotionScan::TRACK_SINGLE) disable();
815 }
816
817 int TrackFrameNumber::handle_event()
818 {
819         plugin->config.track_frame = atol(get_text());
820         plugin->send_configure_change();
821         return 1;
822 }
823
824
825
826
827
828
829
830 TrackPreviousFrame::TrackPreviousFrame(MotionMain *plugin,
831         MotionWindow *gui,
832         int x,
833         int y)
834  : BC_Radial(x,
835         y,
836         plugin->config.tracking_object == MotionScan::TRACK_PREVIOUS,
837         _("Track previous frame"))
838 {
839         this->plugin = plugin;
840         this->gui = gui;
841 }
842 int TrackPreviousFrame::handle_event()
843 {
844         plugin->config.tracking_object = MotionScan::TRACK_PREVIOUS;
845         gui->track_single->update(0);
846         gui->previous_same->update(0);
847         gui->track_frame_number->disable();
848         plugin->send_configure_change();
849         return 1;
850 }
851
852
853
854
855
856
857
858
859 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionMain *plugin,
860         MotionWindow *gui,
861         int x,
862         int y)
863  : BC_Radial(x,
864         y,
865         plugin->config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK,
866         _("Previous frame same block"))
867 {
868         this->plugin = plugin;
869         this->gui = gui;
870 }
871 int PreviousFrameSameBlock::handle_event()
872 {
873         plugin->config.tracking_object = MotionScan::PREVIOUS_SAME_BLOCK;
874         gui->track_single->update(0);
875         gui->track_previous->update(0);
876         gui->track_frame_number->disable();
877         plugin->send_configure_change();
878         return 1;
879 }
880
881
882
883
884
885
886
887
888 MasterLayer::MasterLayer(MotionMain *plugin, MotionWindow *gui, int x, int y)
889  : BC_PopupMenu(x,
890         y,
891         calculate_w(gui),
892         to_text(plugin->config.bottom_is_master))
893 {
894         this->plugin = plugin;
895         this->gui = gui;
896 }
897
898 int MasterLayer::handle_event()
899 {
900         plugin->config.bottom_is_master = from_text(get_text());
901         plugin->send_configure_change();
902         return 1;
903 }
904
905 void MasterLayer::create_objects()
906 {
907         add_item(new BC_MenuItem(to_text(0)));
908         add_item(new BC_MenuItem(to_text(1)));
909 }
910
911 int MasterLayer::from_text(char *text)
912 {
913         if(!strcmp(text, _("Top"))) return 0;
914         return 1;
915 }
916
917 char* MasterLayer::to_text(int mode)
918 {
919         return mode ? _("Bottom") : _("Top");
920 }
921
922 int MasterLayer::calculate_w(MotionWindow *gui)
923 {
924         int result = 0;
925         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
926         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
927         return result + 50;
928 }
929
930
931
932
933
934
935
936
937 ActionType::ActionType(MotionMain *plugin, MotionWindow *gui, int x, int y)
938  : BC_PopupMenu(x,
939         y,
940         calculate_w(gui),
941         to_text(plugin->config.action_type))
942 {
943         this->plugin = plugin;
944         this->gui = gui;
945 }
946
947 int ActionType::handle_event()
948 {
949         plugin->config.action_type = from_text(get_text());
950         plugin->send_configure_change();
951         return 1;
952 }
953
954 void ActionType::create_objects()
955 {
956         add_item(new BC_MenuItem(to_text(MotionScan::TRACK)));
957         add_item(new BC_MenuItem(to_text(MotionScan::TRACK_PIXEL)));
958         add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE)));
959         add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE_PIXEL)));
960         add_item(new BC_MenuItem(to_text(MotionScan::NOTHING)));
961 }
962
963 int ActionType::from_text(char *text)
964 {
965         if(!strcmp(text, _("Track Subpixel"))) return MotionScan::TRACK;
966         if(!strcmp(text, _("Track Pixel"))) return MotionScan::TRACK_PIXEL;
967         if(!strcmp(text, _("Stabilize Subpixel"))) return MotionScan::STABILIZE;
968         if(!strcmp(text, _("Stabilize Pixel"))) return MotionScan::STABILIZE_PIXEL;
969         //if(!strcmp(text, _("Do Nothing"))) return MotionScan::NOTHING;
970         return MotionScan::NOTHING;
971 }
972
973 char* ActionType::to_text(int mode)
974 {
975         switch(mode)
976         {
977                 case MotionScan::TRACK:
978                         return _("Track Subpixel");
979                 case MotionScan::TRACK_PIXEL:
980                         return _("Track Pixel");
981                 case MotionScan::STABILIZE:
982                         return _("Stabilize Subpixel");
983                 case MotionScan::STABILIZE_PIXEL:
984                         return _("Stabilize Pixel");
985                 default:
986                 case MotionScan::NOTHING:
987                         return _("Do Nothing");
988         }
989 }
990
991 int ActionType::calculate_w(MotionWindow *gui)
992 {
993         int result = 0;
994         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK)));
995         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK_PIXEL)));
996         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE)));
997         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE_PIXEL)));
998         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NOTHING)));
999         return result + 50;
1000 }
1001
1002
1003
1004
1005
1006 TrackingType::TrackingType(MotionMain *plugin, MotionWindow *gui, int x, int y)
1007  : BC_PopupMenu(x,
1008         y,
1009         calculate_w(gui),
1010         to_text(plugin->config.tracking_type))
1011 {
1012         this->plugin = plugin;
1013         this->gui = gui;
1014 }
1015
1016 int TrackingType::handle_event()
1017 {
1018         plugin->config.tracking_type = from_text(get_text());
1019         plugin->send_configure_change();
1020         return 1;
1021 }
1022
1023 void TrackingType::create_objects()
1024 {
1025         add_item(new BC_MenuItem(to_text(MotionScan::NO_CALCULATE)));
1026         add_item(new BC_MenuItem(to_text(MotionScan::CALCULATE)));
1027         add_item(new BC_MenuItem(to_text(MotionScan::SAVE)));
1028         add_item(new BC_MenuItem(to_text(MotionScan::LOAD)));
1029 }
1030
1031 int TrackingType::from_text(char *text)
1032 {
1033         if(!strcmp(text, _("Save coords to /tmp"))) return MotionScan::SAVE;
1034         if(!strcmp(text, _("Load coords from /tmp"))) return MotionScan::LOAD;
1035         if(!strcmp(text, _("Recalculate"))) return MotionScan::CALCULATE;
1036         //if(!strcmp(text, _("Don't Calculate"))) return MotionScan::NO_CALCULATE;
1037         return MotionScan::NO_CALCULATE;
1038 }
1039
1040 char* TrackingType::to_text(int mode)
1041 {
1042         switch(mode)
1043         {
1044                 case MotionScan::SAVE:
1045                         return _("Save coords to /tmp");
1046                 case MotionScan::LOAD:
1047                         return _("Load coords from /tmp");
1048                 case MotionScan::CALCULATE:
1049                         return _("Recalculate");
1050                 default:
1051                 case MotionScan::NO_CALCULATE:
1052                         return _("Don't Calculate");
1053         }
1054 }
1055
1056 int TrackingType::calculate_w(MotionWindow *gui)
1057 {
1058         int result = 0;
1059         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NO_CALCULATE)));
1060         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::CALCULATE)));
1061         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::SAVE)));
1062         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::LOAD)));
1063         return result + 50;
1064 }
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075 TrackDirection::TrackDirection(MotionMain *plugin, MotionWindow *gui, int x, int y)
1076  : BC_PopupMenu(x,
1077         y,
1078         calculate_w(gui),
1079         to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
1080 {
1081         this->plugin = plugin;
1082         this->gui = gui;
1083 }
1084
1085 int TrackDirection::handle_event()
1086 {
1087         from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
1088         plugin->send_configure_change();
1089         return 1;
1090 }
1091
1092 void TrackDirection::create_objects()
1093 {
1094         add_item(new BC_MenuItem(to_text(1, 0)));
1095         add_item(new BC_MenuItem(to_text(0, 1)));
1096         add_item(new BC_MenuItem(to_text(0, 0)));
1097 }
1098
1099 void TrackDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
1100 {
1101         *horizontal_only = 0;
1102         *vertical_only = 0;
1103         if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1104         if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1105 }
1106
1107 char* TrackDirection::to_text(int horizontal_only, int vertical_only)
1108 {
1109         if(horizontal_only) return _("Horizontal only");
1110         if(vertical_only) return _("Vertical only");
1111         return _("Both");
1112 }
1113
1114 int TrackDirection::calculate_w(MotionWindow *gui)
1115 {
1116         int result = 0;
1117         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
1118         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
1119         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));
1120         return result + 50;
1121 }
1122