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