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"
26 #include "motionscan.h"
27 #include "motionwindow.h"
38 MotionWindow::MotionWindow(MotionMain *plugin)
39 : PluginClientWindow(plugin,
46 this->plugin = plugin;
49 MotionWindow::~MotionWindow()
53 void MotionWindow::create_objects()
55 int x1 = 10, x = 10, y = 10;
61 add_subwindow(global = new MotionGlobal(plugin,
66 add_subwindow(rotate = new MotionRotate(plugin,
72 add_subwindow(title = new BC_Title(x1,
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,
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(),
82 &plugin->config.global_range_h));
84 add_subwindow(title = new BC_Title(x2,
86 _("Rotation search radius:\n(Degrees)")));
87 add_subwindow(rotation_range = new RotationRange(plugin,
88 x2 + title->get_w() + 10,
92 add_subwindow(title = new BC_Title(x1,
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,
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(),
102 &plugin->config.global_block_h));
104 // add_subwindow(title = new BC_Title(x2,
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,
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(),
114 // &plugin->config.rotation_block_h));
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,
122 global_search_positions->create_objects();
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,
129 rotation_search_positions->create_objects();
132 add_subwindow(title = new BC_Title(x, y, _("Translation direction:")));
133 add_subwindow(track_direction = new TrackDirection(plugin,
135 x + title->get_w() + 10,
137 track_direction->create_objects();
140 add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
141 add_subwindow(block_x = new MotionBlockX(plugin,
143 x + title->get_w() + 10,
145 add_subwindow(block_x_text = new MotionBlockXText(plugin,
147 x + title->get_w() + 10 + block_x->get_w() + 10,
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,
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,
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,
174 add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
175 add_subwindow(block_y = new MotionBlockY(plugin,
177 x + title->get_w() + 10,
179 add_subwindow(block_y_text = new MotionBlockYText(plugin,
181 x + title->get_w() + 10 + block_y->get_w() + 10,
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,
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,
199 add_subwindow(vectors = new MotionDrawVectors(plugin,
206 add_subwindow(track_single = new TrackSingleFrame(plugin,
210 add_subwindow(title = new BC_Title(x + track_single->get_w() + 20,
212 _("Frame number:")));
213 add_subwindow(track_frame_number = new TrackFrameNumber(plugin,
215 x + track_single->get_w() + title->get_w() + 20,
217 add_subwindow(addtrackedframeoffset = new AddTrackedFrameOffset(plugin,
219 x + track_single->get_w() + title->get_w() + 20 + track_frame_number->get_w(),
224 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
230 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
237 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
238 add_subwindow(master_layer = new MasterLayer(plugin,
240 x + title->get_w() + 10,
242 master_layer->create_objects();
246 add_subwindow(title = new BC_Title(x, y, _("Action:")));
247 add_subwindow(action_type = new ActionType(plugin,
249 x + title->get_w() + 10,
251 action_type->create_objects();
257 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
258 add_subwindow(tracking_type = new TrackingType(plugin,
260 x + title->get_w() + 10,
262 tracking_type->create_objects();
269 void MotionWindow::update_mode()
271 global_range_w->update(plugin->config.global_range_w,
274 global_range_h->update(plugin->config.global_range_h,
277 rotation_range->update(plugin->config.rotation_range,
280 vectors->update(plugin->config.draw_vectors);
281 global->update(plugin->config.global);
282 rotate->update(plugin->config.rotate);
283 addtrackedframeoffset->update(plugin->config.addtrackedframeoffset);
298 GlobalRange::GlobalRange(MotionMain *plugin,
308 this->plugin = plugin;
313 int GlobalRange::handle_event()
315 *value = (int)get_value();
316 plugin->send_configure_change();
323 RotationRange::RotationRange(MotionMain *plugin,
328 (int64_t)plugin->config.rotation_range,
329 (int64_t)MIN_ROTATION,
330 (int64_t)MAX_ROTATION)
332 this->plugin = plugin;
336 int RotationRange::handle_event()
338 plugin->config.rotation_range = (int)get_value();
339 plugin->send_configure_change();
346 RotationCenter::RotationCenter(MotionMain *plugin,
351 (int64_t)plugin->config.rotation_center,
352 (int64_t)-MAX_ROTATION,
353 (int64_t)MAX_ROTATION)
355 this->plugin = plugin;
359 int RotationCenter::handle_event()
361 plugin->config.rotation_center = (int)get_value();
362 plugin->send_configure_change();
371 BlockSize::BlockSize(MotionMain *plugin,
381 this->plugin = plugin;
386 int BlockSize::handle_event()
388 *value = (int)get_value();
389 plugin->send_configure_change();
405 GlobalSearchPositions::GlobalSearchPositions(MotionMain *plugin,
415 this->plugin = plugin;
417 void GlobalSearchPositions::create_objects()
419 add_item(new BC_MenuItem("16"));
420 add_item(new BC_MenuItem("32"));
421 add_item(new BC_MenuItem("64"));
422 add_item(new BC_MenuItem("128"));
423 add_item(new BC_MenuItem("256"));
424 add_item(new BC_MenuItem("512"));
425 add_item(new BC_MenuItem("1024"));
426 add_item(new BC_MenuItem("2048"));
427 add_item(new BC_MenuItem("4096"));
428 add_item(new BC_MenuItem("8192"));
429 add_item(new BC_MenuItem("16384"));
430 add_item(new BC_MenuItem("32768"));
431 add_item(new BC_MenuItem("65536"));
432 add_item(new BC_MenuItem("131072"));
433 char string[BCTEXTLEN];
434 sprintf(string, "%d", plugin->config.global_positions);
438 int GlobalSearchPositions::handle_event()
440 plugin->config.global_positions = atoi(get_text());
441 plugin->send_configure_change();
451 RotationSearchPositions::RotationSearchPositions(MotionMain *plugin,
461 this->plugin = plugin;
463 void RotationSearchPositions::create_objects()
465 add_item(new BC_MenuItem("4"));
466 add_item(new BC_MenuItem("8"));
467 add_item(new BC_MenuItem("16"));
468 add_item(new BC_MenuItem("32"));
469 char string[BCTEXTLEN];
470 sprintf(string, "%d", plugin->config.rotate_positions);
474 int RotationSearchPositions::handle_event()
476 plugin->config.rotate_positions = atoi(get_text());
477 plugin->send_configure_change();
488 MotionMagnitude::MotionMagnitude(MotionMain *plugin,
493 (int64_t)plugin->config.magnitude,
497 this->plugin = plugin;
500 int MotionMagnitude::handle_event()
502 plugin->config.magnitude = (int)get_value();
503 plugin->send_configure_change();
508 MotionReturnSpeed::MotionReturnSpeed(MotionMain *plugin,
513 (int64_t)plugin->config.return_speed,
517 this->plugin = plugin;
520 int MotionReturnSpeed::handle_event()
522 plugin->config.return_speed = (int)get_value();
523 plugin->send_configure_change();
529 AddTrackedFrameOffset::AddTrackedFrameOffset(MotionMain *plugin,
535 plugin->config.addtrackedframeoffset,
536 _("Add (loaded) offset from tracked frame"))
538 this->plugin = plugin;
542 int AddTrackedFrameOffset::handle_event()
544 plugin->config.addtrackedframeoffset = get_value();
545 plugin->send_configure_change();
550 MotionRMagnitude::MotionRMagnitude(MotionMain *plugin,
555 (int64_t)plugin->config.rotate_magnitude,
559 this->plugin = plugin;
562 int MotionRMagnitude::handle_event()
564 plugin->config.rotate_magnitude = (int)get_value();
565 plugin->send_configure_change();
571 MotionRReturnSpeed::MotionRReturnSpeed(MotionMain *plugin,
576 (int64_t)plugin->config.rotate_return_speed,
580 this->plugin = plugin;
583 int MotionRReturnSpeed::handle_event()
585 plugin->config.rotate_return_speed = (int)get_value();
586 plugin->send_configure_change();
594 MotionGlobal::MotionGlobal(MotionMain *plugin,
600 plugin->config.global,
601 _("Track translation"))
603 this->plugin = plugin;
607 int MotionGlobal::handle_event()
609 plugin->config.global = get_value();
610 plugin->send_configure_change();
614 MotionRotate::MotionRotate(MotionMain *plugin,
620 plugin->config.rotate,
623 this->plugin = plugin;
627 int MotionRotate::handle_event()
629 plugin->config.rotate = get_value();
630 plugin->send_configure_change();
638 MotionBlockX::MotionBlockX(MotionMain *plugin,
644 plugin->config.block_x,
648 this->plugin = plugin;
652 int MotionBlockX::handle_event()
654 plugin->config.block_x = get_value();
655 gui->block_x_text->update((float)plugin->config.block_x);
656 plugin->send_configure_change();
663 MotionBlockY::MotionBlockY(MotionMain *plugin,
669 (float)plugin->config.block_y,
673 this->plugin = plugin;
677 int MotionBlockY::handle_event()
679 plugin->config.block_y = get_value();
680 gui->block_y_text->update((float)plugin->config.block_y);
681 plugin->send_configure_change();
685 MotionBlockXText::MotionBlockXText(MotionMain *plugin,
693 (float)plugin->config.block_x)
695 this->plugin = plugin;
700 int MotionBlockXText::handle_event()
702 plugin->config.block_x = atof(get_text());
703 gui->block_x->update(plugin->config.block_x);
704 plugin->send_configure_change();
711 MotionBlockYText::MotionBlockYText(MotionMain *plugin,
719 (float)plugin->config.block_y)
721 this->plugin = plugin;
726 int MotionBlockYText::handle_event()
728 plugin->config.block_y = atof(get_text());
729 gui->block_y->update(plugin->config.block_y);
730 plugin->send_configure_change();
749 MotionDrawVectors::MotionDrawVectors(MotionMain *plugin,
755 plugin->config.draw_vectors,
759 this->plugin = plugin;
762 int MotionDrawVectors::handle_event()
764 plugin->config.draw_vectors = get_value();
765 plugin->send_configure_change();
776 TrackSingleFrame::TrackSingleFrame(MotionMain *plugin,
782 plugin->config.tracking_object == MotionScan::TRACK_SINGLE,
783 _("Track single frame"))
785 this->plugin = plugin;
789 int TrackSingleFrame::handle_event()
791 plugin->config.tracking_object = MotionScan::TRACK_SINGLE;
792 gui->track_previous->update(0);
793 gui->previous_same->update(0);
794 gui->track_frame_number->enable();
795 plugin->send_configure_change();
806 TrackFrameNumber::TrackFrameNumber(MotionMain *plugin,
810 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
812 this->plugin = plugin;
814 if(plugin->config.tracking_object != MotionScan::TRACK_SINGLE) disable();
817 int TrackFrameNumber::handle_event()
819 plugin->config.track_frame = atol(get_text());
820 plugin->send_configure_change();
830 TrackPreviousFrame::TrackPreviousFrame(MotionMain *plugin,
836 plugin->config.tracking_object == MotionScan::TRACK_PREVIOUS,
837 _("Track previous frame"))
839 this->plugin = plugin;
842 int TrackPreviousFrame::handle_event()
844 plugin->config.tracking_object = MotionScan::TRACK_PREVIOUS;
845 gui->track_single->update(0);
846 gui->previous_same->update(0);
847 gui->track_frame_number->disable();
848 plugin->send_configure_change();
859 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionMain *plugin,
865 plugin->config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK,
866 _("Previous frame same block"))
868 this->plugin = plugin;
871 int PreviousFrameSameBlock::handle_event()
873 plugin->config.tracking_object = MotionScan::PREVIOUS_SAME_BLOCK;
874 gui->track_single->update(0);
875 gui->track_previous->update(0);
876 gui->track_frame_number->disable();
877 plugin->send_configure_change();
888 MasterLayer::MasterLayer(MotionMain *plugin, MotionWindow *gui, int x, int y)
892 to_text(plugin->config.bottom_is_master))
894 this->plugin = plugin;
898 int MasterLayer::handle_event()
900 plugin->config.bottom_is_master = from_text(get_text());
901 plugin->send_configure_change();
905 void MasterLayer::create_objects()
907 add_item(new BC_MenuItem(to_text(0)));
908 add_item(new BC_MenuItem(to_text(1)));
911 int MasterLayer::from_text(char *text)
913 if(!strcmp(text, _("Top"))) return 0;
917 char* MasterLayer::to_text(int mode)
919 return mode ? _("Bottom") : _("Top");
922 int MasterLayer::calculate_w(MotionWindow *gui)
925 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
926 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
937 ActionType::ActionType(MotionMain *plugin, MotionWindow *gui, int x, int y)
941 to_text(plugin->config.action_type))
943 this->plugin = plugin;
947 int ActionType::handle_event()
949 plugin->config.action_type = from_text(get_text());
950 plugin->send_configure_change();
954 void ActionType::create_objects()
956 add_item(new BC_MenuItem(to_text(MotionScan::TRACK)));
957 add_item(new BC_MenuItem(to_text(MotionScan::TRACK_PIXEL)));
958 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE)));
959 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE_PIXEL)));
960 add_item(new BC_MenuItem(to_text(MotionScan::NOTHING)));
963 int ActionType::from_text(char *text)
965 if(!strcmp(text, _("Track Subpixel"))) return MotionScan::TRACK;
966 if(!strcmp(text, _("Track Pixel"))) return MotionScan::TRACK_PIXEL;
967 if(!strcmp(text, _("Stabilize Subpixel"))) return MotionScan::STABILIZE;
968 if(!strcmp(text, _("Stabilize Pixel"))) return MotionScan::STABILIZE_PIXEL;
969 //if(!strcmp(text, _("Do Nothing"))) return MotionScan::NOTHING;
970 return MotionScan::NOTHING;
973 char* ActionType::to_text(int mode)
977 case MotionScan::TRACK:
978 return _("Track Subpixel");
979 case MotionScan::TRACK_PIXEL:
980 return _("Track Pixel");
981 case MotionScan::STABILIZE:
982 return _("Stabilize Subpixel");
983 case MotionScan::STABILIZE_PIXEL:
984 return _("Stabilize Pixel");
986 case MotionScan::NOTHING:
987 return _("Do Nothing");
991 int ActionType::calculate_w(MotionWindow *gui)
994 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK)));
995 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK_PIXEL)));
996 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE)));
997 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE_PIXEL)));
998 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NOTHING)));
1006 TrackingType::TrackingType(MotionMain *plugin, MotionWindow *gui, int x, int y)
1010 to_text(plugin->config.tracking_type))
1012 this->plugin = plugin;
1016 int TrackingType::handle_event()
1018 plugin->config.tracking_type = from_text(get_text());
1019 plugin->send_configure_change();
1023 void TrackingType::create_objects()
1025 add_item(new BC_MenuItem(to_text(MotionScan::NO_CALCULATE)));
1026 add_item(new BC_MenuItem(to_text(MotionScan::CALCULATE)));
1027 add_item(new BC_MenuItem(to_text(MotionScan::SAVE)));
1028 add_item(new BC_MenuItem(to_text(MotionScan::LOAD)));
1031 int TrackingType::from_text(char *text)
1033 if(!strcmp(text, _("Save coords to /tmp"))) return MotionScan::SAVE;
1034 if(!strcmp(text, _("Load coords from /tmp"))) return MotionScan::LOAD;
1035 if(!strcmp(text, _("Recalculate"))) return MotionScan::CALCULATE;
1036 //if(!strcmp(text, _("Don't Calculate"))) return MotionScan::NO_CALCULATE;
1037 return MotionScan::NO_CALCULATE;
1040 char* TrackingType::to_text(int mode)
1044 case MotionScan::SAVE:
1045 return _("Save coords to /tmp");
1046 case MotionScan::LOAD:
1047 return _("Load coords from /tmp");
1048 case MotionScan::CALCULATE:
1049 return _("Recalculate");
1051 case MotionScan::NO_CALCULATE:
1052 return _("Don't Calculate");
1056 int TrackingType::calculate_w(MotionWindow *gui)
1059 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NO_CALCULATE)));
1060 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::CALCULATE)));
1061 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::SAVE)));
1062 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::LOAD)));
1075 TrackDirection::TrackDirection(MotionMain *plugin, MotionWindow *gui, int x, int y)
1079 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
1081 this->plugin = plugin;
1085 int TrackDirection::handle_event()
1087 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
1088 plugin->send_configure_change();
1092 void TrackDirection::create_objects()
1094 add_item(new BC_MenuItem(to_text(1, 0)));
1095 add_item(new BC_MenuItem(to_text(0, 1)));
1096 add_item(new BC_MenuItem(to_text(0, 0)));
1099 void TrackDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
1101 *horizontal_only = 0;
1103 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1104 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1107 char* TrackDirection::to_text(int horizontal_only, int vertical_only)
1109 if(horizontal_only) return _("Horizontal only");
1110 if(vertical_only) return _("Vertical only");
1114 int TrackDirection::calculate_w(MotionWindow *gui)
1117 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
1118 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
1119 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));