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