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