4 * Copyright (C) 2012 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcdisplayinfo.h"
25 #include "motion-hv.h"
26 #include "motionscan-hv.h"
27 #include "motionwindow-hv.h"
38 MotionHVWindow::MotionHVWindow(MotionHVMain *plugin)
39 : PluginClientWindow(plugin, xS(600), yS(650), xS(600), yS(650), 0)
41 this->plugin = plugin;
44 MotionHVWindow::~MotionHVWindow()
48 void MotionHVWindow::create_objects()
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;
58 // add_subwindow(global = new MotionHVGlobal(plugin,
63 add_subwindow(rotate = new MotionHVRotate(plugin,
69 add_subwindow(title = new BC_Title(x1,
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,
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(),
79 &plugin->config.global_range_h));
81 add_subwindow(title = new BC_Title(x2,
83 _("Rotation search radius:\n(Degrees)")));
84 add_subwindow(rotation_range = new RotationRange(plugin,
85 x2 + title->get_w() + xs10,
89 add_subwindow(title = new BC_Title(x1,
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,
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(),
99 &plugin->config.global_block_h));
101 // add_subwindow(title = new BC_Title(x2,
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,
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(),
111 // &plugin->config.rotation_block_h));
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,
119 // global_search_positions->create_objects();
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,
126 // rotation_search_positions->create_objects();
129 add_subwindow(title = new BC_Title(x, y, _("Translation direction:")));
130 add_subwindow(track_direction = new TrackDirection(plugin,
132 x + title->get_w() + xs10,
134 track_direction->create_objects();
137 add_subwindow(title = new BC_Title(x, y + ys10, _("Block X:")));
138 add_subwindow(block_x = new MotionHVBlockX(plugin,
140 x + title->get_w() + xs10,
142 add_subwindow(block_x_text = new MotionHVBlockXText(plugin,
144 x + title->get_w() + xs10 + block_x->get_w() + xs10,
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,
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,
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,
171 add_subwindow(title = new BC_Title(x, y + ys10, _("Block Y:")));
172 add_subwindow(block_y = new MotionHVBlockY(plugin,
174 x + title->get_w() + xs10,
176 add_subwindow(block_y_text = new MotionHVBlockYText(plugin,
178 x + title->get_w() + xs10 + block_y->get_w() + xs10,
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,
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,
196 add_subwindow(vectors = new MotionHVDrawVectors(plugin,
203 add_subwindow(track_single = new TrackSingleFrame(plugin,
207 add_subwindow(title = new BC_Title(x + track_single->get_w() + xs20,
209 _("Frame number:")));
210 add_subwindow(track_frame_number = new TrackFrameNumber(plugin,
212 x + track_single->get_w() + title->get_w() + xs20,
214 if(plugin->config.tracking_object != MotionHVScan::TRACK_SINGLE)
215 track_frame_number->disable();
218 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
224 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
231 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
232 add_subwindow(master_layer = new MasterLayer(plugin,
234 x + title->get_w() + xs10,
236 master_layer->create_objects();
240 add_subwindow(title = new BC_Title(x, y, _("Action:")));
241 add_subwindow(action_type = new ActionType(plugin,
243 x + title->get_w() + xs10,
245 action_type->create_objects();
251 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
252 add_subwindow(tracking_type = new TrackingType(plugin,
254 x + title->get_w() + xs10,
256 tracking_type->create_objects();
263 void MotionHVWindow::update_mode()
265 global_range_w->update(plugin->config.global_range_w,
268 global_range_h->update(plugin->config.global_range_h,
271 rotation_range->update(plugin->config.rotation_range,
274 vectors->update(plugin->config.draw_vectors);
275 // global->update(plugin->config.global);
276 rotate->update(plugin->config.rotate);
291 GlobalRange::GlobalRange(MotionHVMain *plugin,
301 this->plugin = plugin;
306 int GlobalRange::handle_event()
308 *value = (int)get_value();
309 plugin->send_configure_change();
316 RotationRange::RotationRange(MotionHVMain *plugin,
321 (int64_t)plugin->config.rotation_range,
322 (int64_t)MIN_ROTATION,
323 (int64_t)MAX_ROTATION)
325 this->plugin = plugin;
329 int RotationRange::handle_event()
331 plugin->config.rotation_range = (int)get_value();
332 plugin->send_configure_change();
339 RotationCenter::RotationCenter(MotionHVMain *plugin,
344 (int64_t)plugin->config.rotation_center,
345 (int64_t)-MAX_ROTATION,
346 (int64_t)MAX_ROTATION)
348 this->plugin = plugin;
352 int RotationCenter::handle_event()
354 plugin->config.rotation_center = (int)get_value();
355 plugin->send_configure_change();
364 BlockSize::BlockSize(MotionHVMain *plugin,
374 this->plugin = plugin;
379 int BlockSize::handle_event()
381 *value = (int)get_value();
382 plugin->send_configure_change();
398 // GlobalSearchPositions::GlobalSearchPositions(MotionHVMain *plugin,
408 // this->plugin = plugin;
410 // void GlobalSearchPositions::create_objects()
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);
431 // int GlobalSearchPositions::handle_event()
433 // plugin->config.global_positions = atoi(get_text());
434 // plugin->send_configure_change();
444 // RotationSearchPositions::RotationSearchPositions(MotionHVMain *plugin,
454 // this->plugin = plugin;
456 // void RotationSearchPositions::create_objects()
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);
467 // int RotationSearchPositions::handle_event()
469 // plugin->config.rotate_positions = atoi(get_text());
470 // plugin->send_configure_change();
481 MotionHVMagnitude::MotionHVMagnitude(MotionHVMain *plugin,
486 (int64_t)plugin->config.magnitude,
490 this->plugin = plugin;
493 int MotionHVMagnitude::handle_event()
495 plugin->config.magnitude = (int)get_value();
496 plugin->send_configure_change();
501 MotionHVReturnSpeed::MotionHVReturnSpeed(MotionHVMain *plugin,
506 (int64_t)plugin->config.return_speed,
510 this->plugin = plugin;
513 int MotionHVReturnSpeed::handle_event()
515 plugin->config.return_speed = (int)get_value();
516 plugin->send_configure_change();
522 MotionHVRMagnitude::MotionHVRMagnitude(MotionHVMain *plugin,
527 (int64_t)plugin->config.rotate_magnitude,
531 this->plugin = plugin;
534 int MotionHVRMagnitude::handle_event()
536 plugin->config.rotate_magnitude = (int)get_value();
537 plugin->send_configure_change();
543 MotionHVRReturnSpeed::MotionHVRReturnSpeed(MotionHVMain *plugin,
548 (int64_t)plugin->config.rotate_return_speed,
552 this->plugin = plugin;
555 int MotionHVRReturnSpeed::handle_event()
557 plugin->config.rotate_return_speed = (int)get_value();
558 plugin->send_configure_change();
566 // MotionHVGlobal::MotionHVGlobal(MotionHVMain *plugin,
567 // MotionHVWindow *gui,
572 // plugin->config.global,
573 // _("Track translation"))
575 // this->plugin = plugin;
579 // int MotionHVGlobal::handle_event()
581 // plugin->config.global = get_value();
582 // plugin->send_configure_change();
586 MotionHVRotate::MotionHVRotate(MotionHVMain *plugin,
592 plugin->config.rotate,
595 this->plugin = plugin;
599 int MotionHVRotate::handle_event()
601 plugin->config.rotate = get_value();
602 plugin->send_configure_change();
610 MotionHVBlockX::MotionHVBlockX(MotionHVMain *plugin,
616 plugin->config.block_x,
620 this->plugin = plugin;
624 int MotionHVBlockX::handle_event()
626 plugin->config.block_x = get_value();
627 gui->block_x_text->update((float)plugin->config.block_x);
628 plugin->send_configure_change();
635 MotionHVBlockY::MotionHVBlockY(MotionHVMain *plugin,
641 (float)plugin->config.block_y,
645 this->plugin = plugin;
649 int MotionHVBlockY::handle_event()
651 plugin->config.block_y = get_value();
652 gui->block_y_text->update((float)plugin->config.block_y);
653 plugin->send_configure_change();
657 MotionHVBlockXText::MotionHVBlockXText(MotionHVMain *plugin,
661 : BC_TextBox(x, y, xS(75), 1,
662 (float)plugin->config.block_x)
664 this->plugin = plugin;
669 int MotionHVBlockXText::handle_event()
671 plugin->config.block_x = atof(get_text());
672 gui->block_x->update(plugin->config.block_x);
673 plugin->send_configure_change();
680 MotionHVBlockYText::MotionHVBlockYText(MotionHVMain *plugin,
684 : BC_TextBox(x, y, xS(75), 1,
685 (float)plugin->config.block_y)
687 this->plugin = plugin;
692 int MotionHVBlockYText::handle_event()
694 plugin->config.block_y = atof(get_text());
695 gui->block_y->update(plugin->config.block_y);
696 plugin->send_configure_change();
715 MotionHVDrawVectors::MotionHVDrawVectors(MotionHVMain *plugin,
721 plugin->config.draw_vectors,
725 this->plugin = plugin;
728 int MotionHVDrawVectors::handle_event()
730 plugin->config.draw_vectors = get_value();
731 plugin->send_configure_change();
742 TrackSingleFrame::TrackSingleFrame(MotionHVMain *plugin,
748 plugin->config.tracking_object == MotionHVScan::TRACK_SINGLE,
749 _("Track single frame"))
751 this->plugin = plugin;
755 int TrackSingleFrame::handle_event()
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();
772 TrackFrameNumber::TrackFrameNumber(MotionHVMain *plugin,
776 : BC_TextBox(x, y, xS(100), 1, plugin->config.track_frame)
778 this->plugin = plugin;
782 int TrackFrameNumber::handle_event()
784 plugin->config.track_frame = atol(get_text());
785 plugin->send_configure_change();
795 TrackPreviousFrame::TrackPreviousFrame(MotionHVMain *plugin,
801 plugin->config.tracking_object == MotionHVScan::TRACK_PREVIOUS,
802 _("Track previous frame"))
804 this->plugin = plugin;
807 int TrackPreviousFrame::handle_event()
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();
824 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionHVMain *plugin,
830 plugin->config.tracking_object == MotionHVScan::PREVIOUS_SAME_BLOCK,
831 _("Previous frame same block"))
833 this->plugin = plugin;
836 int PreviousFrameSameBlock::handle_event()
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();
853 MasterLayer::MasterLayer(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
857 to_text(plugin->config.bottom_is_master))
859 this->plugin = plugin;
863 int MasterLayer::handle_event()
865 plugin->config.bottom_is_master = from_text(get_text());
866 plugin->send_configure_change();
870 void MasterLayer::create_objects()
872 add_item(new BC_MenuItem(to_text(0)));
873 add_item(new BC_MenuItem(to_text(1)));
876 int MasterLayer::from_text(char *text)
878 if(!strcmp(text, _("Top"))) return 0;
882 char* MasterLayer::to_text(int mode)
884 return mode ? _("Bottom") : _("Top");
887 int MasterLayer::calculate_w(MotionHVWindow *gui)
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);
902 ActionType::ActionType(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
906 to_text(plugin->config.action_type))
908 this->plugin = plugin;
912 int ActionType::handle_event()
914 plugin->config.action_type = from_text(get_text());
915 plugin->send_configure_change();
919 void ActionType::create_objects()
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)));
928 int ActionType::from_text(char *text)
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;
938 char* ActionType::to_text(int mode)
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");
951 case MotionHVScan::NOTHING:
952 return _("Do Nothing");
956 int ActionType::calculate_w(MotionHVWindow *gui)
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);
971 TrackingType::TrackingType(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
975 to_text(plugin->config.tracking_type))
977 this->plugin = plugin;
981 int TrackingType::handle_event()
983 plugin->config.tracking_type = from_text(get_text());
984 plugin->send_configure_change();
988 void TrackingType::create_objects()
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)));
996 int TrackingType::from_text(char *text)
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;
1005 char* TrackingType::to_text(int mode)
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");
1016 case MotionHVScan::NO_CALCULATE:
1017 return _("Don't Calculate");
1021 int TrackingType::calculate_w(MotionHVWindow *gui)
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);
1040 TrackDirection::TrackDirection(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
1044 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
1046 this->plugin = plugin;
1050 int TrackDirection::handle_event()
1052 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
1053 plugin->send_configure_change();
1057 void TrackDirection::create_objects()
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)));
1064 void TrackDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
1066 *horizontal_only = 0;
1068 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1069 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1072 char* TrackDirection::to_text(int horizontal_only, int vertical_only)
1074 if(horizontal_only) return _("Horizontal only");
1075 if(vertical_only) return _("Vertical only");
1079 int TrackDirection::calculate_w(MotionHVWindow *gui)
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);