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