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