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();
270 void MotionWindow::update_mode()
272 global_range_w->update(plugin->config.global_range_w,
275 global_range_h->update(plugin->config.global_range_h,
278 rotation_range->update(plugin->config.rotation_range,
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);
299 GlobalRange::GlobalRange(MotionMain *plugin,
309 this->plugin = plugin;
314 int GlobalRange::handle_event()
316 *value = (int)get_value();
317 plugin->send_configure_change();
324 RotationRange::RotationRange(MotionMain *plugin,
329 (int64_t)plugin->config.rotation_range,
330 (int64_t)MIN_ROTATION,
331 (int64_t)MAX_ROTATION)
333 this->plugin = plugin;
337 int RotationRange::handle_event()
339 plugin->config.rotation_range = (int)get_value();
340 plugin->send_configure_change();
347 RotationCenter::RotationCenter(MotionMain *plugin,
352 (int64_t)plugin->config.rotation_center,
353 (int64_t)-MAX_ROTATION,
354 (int64_t)MAX_ROTATION)
356 this->plugin = plugin;
360 int RotationCenter::handle_event()
362 plugin->config.rotation_center = (int)get_value();
363 plugin->send_configure_change();
372 BlockSize::BlockSize(MotionMain *plugin,
382 this->plugin = plugin;
387 int BlockSize::handle_event()
389 *value = (int)get_value();
390 plugin->send_configure_change();
406 GlobalSearchPositions::GlobalSearchPositions(MotionMain *plugin,
416 this->plugin = plugin;
418 void GlobalSearchPositions::create_objects()
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);
439 int GlobalSearchPositions::handle_event()
441 plugin->config.global_positions = atoi(get_text());
442 plugin->send_configure_change();
452 RotationSearchPositions::RotationSearchPositions(MotionMain *plugin,
462 this->plugin = plugin;
464 void RotationSearchPositions::create_objects()
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);
475 int RotationSearchPositions::handle_event()
477 plugin->config.rotate_positions = atoi(get_text());
478 plugin->send_configure_change();
489 MotionMagnitude::MotionMagnitude(MotionMain *plugin,
494 (int64_t)plugin->config.magnitude,
498 this->plugin = plugin;
501 int MotionMagnitude::handle_event()
503 plugin->config.magnitude = (int)get_value();
504 plugin->send_configure_change();
509 MotionReturnSpeed::MotionReturnSpeed(MotionMain *plugin,
514 (int64_t)plugin->config.return_speed,
518 this->plugin = plugin;
521 int MotionReturnSpeed::handle_event()
523 plugin->config.return_speed = (int)get_value();
524 plugin->send_configure_change();
530 AddTrackedFrameOffset::AddTrackedFrameOffset(MotionMain *plugin,
536 plugin->config.addtrackedframeoffset,
537 _("Add (loaded) offset from tracked frame"))
539 this->plugin = plugin;
543 int AddTrackedFrameOffset::handle_event()
545 plugin->config.addtrackedframeoffset = get_value();
546 plugin->send_configure_change();
551 MotionRMagnitude::MotionRMagnitude(MotionMain *plugin,
556 (int64_t)plugin->config.rotate_magnitude,
560 this->plugin = plugin;
563 int MotionRMagnitude::handle_event()
565 plugin->config.rotate_magnitude = (int)get_value();
566 plugin->send_configure_change();
572 MotionRReturnSpeed::MotionRReturnSpeed(MotionMain *plugin,
577 (int64_t)plugin->config.rotate_return_speed,
581 this->plugin = plugin;
584 int MotionRReturnSpeed::handle_event()
586 plugin->config.rotate_return_speed = (int)get_value();
587 plugin->send_configure_change();
595 MotionGlobal::MotionGlobal(MotionMain *plugin,
601 plugin->config.global,
602 _("Track translation"))
604 this->plugin = plugin;
608 int MotionGlobal::handle_event()
610 plugin->config.global = get_value();
611 plugin->send_configure_change();
615 MotionRotate::MotionRotate(MotionMain *plugin,
621 plugin->config.rotate,
624 this->plugin = plugin;
628 int MotionRotate::handle_event()
630 plugin->config.rotate = get_value();
631 plugin->send_configure_change();
639 MotionBlockX::MotionBlockX(MotionMain *plugin,
645 plugin->config.block_x,
649 this->plugin = plugin;
653 int MotionBlockX::handle_event()
655 plugin->config.block_x = get_value();
656 gui->block_x_text->update((float)plugin->config.block_x);
657 plugin->send_configure_change();
664 MotionBlockY::MotionBlockY(MotionMain *plugin,
670 (float)plugin->config.block_y,
674 this->plugin = plugin;
678 int MotionBlockY::handle_event()
680 plugin->config.block_y = get_value();
681 gui->block_y_text->update((float)plugin->config.block_y);
682 plugin->send_configure_change();
686 MotionBlockXText::MotionBlockXText(MotionMain *plugin,
694 (float)plugin->config.block_x)
696 this->plugin = plugin;
701 int MotionBlockXText::handle_event()
703 plugin->config.block_x = atof(get_text());
704 gui->block_x->update(plugin->config.block_x);
705 plugin->send_configure_change();
712 MotionBlockYText::MotionBlockYText(MotionMain *plugin,
720 (float)plugin->config.block_y)
722 this->plugin = plugin;
727 int MotionBlockYText::handle_event()
729 plugin->config.block_y = atof(get_text());
730 gui->block_y->update(plugin->config.block_y);
731 plugin->send_configure_change();
750 MotionDrawVectors::MotionDrawVectors(MotionMain *plugin,
756 plugin->config.draw_vectors,
760 this->plugin = plugin;
763 int MotionDrawVectors::handle_event()
765 plugin->config.draw_vectors = get_value();
766 plugin->send_configure_change();
777 TrackSingleFrame::TrackSingleFrame(MotionMain *plugin,
783 plugin->config.tracking_object == MotionScan::TRACK_SINGLE,
784 _("Track single frame"))
786 this->plugin = plugin;
790 int TrackSingleFrame::handle_event()
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();
807 TrackFrameNumber::TrackFrameNumber(MotionMain *plugin,
811 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
813 this->plugin = plugin;
815 if(plugin->config.tracking_object != MotionScan::TRACK_SINGLE) disable();
818 int TrackFrameNumber::handle_event()
820 plugin->config.track_frame = atol(get_text());
821 plugin->send_configure_change();
831 TrackPreviousFrame::TrackPreviousFrame(MotionMain *plugin,
837 plugin->config.tracking_object == MotionScan::TRACK_PREVIOUS,
838 _("Track previous frame"))
840 this->plugin = plugin;
843 int TrackPreviousFrame::handle_event()
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();
860 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionMain *plugin,
866 plugin->config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK,
867 _("Previous frame same block"))
869 this->plugin = plugin;
872 int PreviousFrameSameBlock::handle_event()
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();
889 MasterLayer::MasterLayer(MotionMain *plugin, MotionWindow *gui, int x, int y)
893 to_text(plugin->config.bottom_is_master))
895 this->plugin = plugin;
899 int MasterLayer::handle_event()
901 plugin->config.bottom_is_master = from_text(get_text());
902 plugin->send_configure_change();
906 void MasterLayer::create_objects()
908 add_item(new BC_MenuItem(to_text(0)));
909 add_item(new BC_MenuItem(to_text(1)));
912 int MasterLayer::from_text(char *text)
914 if(!strcmp(text, _("Top"))) return 0;
918 char* MasterLayer::to_text(int mode)
920 return mode ? _("Bottom") : _("Top");
923 int MasterLayer::calculate_w(MotionWindow *gui)
926 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
927 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
938 ActionType::ActionType(MotionMain *plugin, MotionWindow *gui, int x, int y)
942 to_text(plugin->config.action_type))
944 this->plugin = plugin;
948 int ActionType::handle_event()
950 plugin->config.action_type = from_text(get_text());
951 plugin->send_configure_change();
955 void ActionType::create_objects()
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)));
964 int ActionType::from_text(char *text)
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;
974 char* ActionType::to_text(int mode)
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");
987 case MotionScan::NOTHING:
988 return _("Do Nothing");
992 int ActionType::calculate_w(MotionWindow *gui)
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)));
1007 TrackingType::TrackingType(MotionMain *plugin, MotionWindow *gui, int x, int y)
1011 to_text(plugin->config.tracking_type))
1013 this->plugin = plugin;
1017 int TrackingType::handle_event()
1019 plugin->config.tracking_type = from_text(get_text());
1020 plugin->send_configure_change();
1024 void TrackingType::create_objects()
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)));
1032 int TrackingType::from_text(char *text)
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;
1041 char* TrackingType::to_text(int mode)
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");
1052 case MotionScan::NO_CALCULATE:
1053 return _("Don't Calculate");
1057 int TrackingType::calculate_w(MotionWindow *gui)
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)));
1076 TrackDirection::TrackDirection(MotionMain *plugin, MotionWindow *gui, int x, int y)
1080 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
1082 this->plugin = plugin;
1086 int TrackDirection::handle_event()
1088 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
1089 plugin->send_configure_change();
1093 void TrackDirection::create_objects()
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)));
1100 void TrackDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
1102 *horizontal_only = 0;
1104 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1105 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1108 char* TrackDirection::to_text(int horizontal_only, int vertical_only)
1110 if(horizontal_only) return _("Horizontal only");
1111 if(vertical_only) return _("Vertical only");
1115 int TrackDirection::calculate_w(MotionWindow *gui)
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)));