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, 600, 650, 600, 650, 0)
41 this->plugin = plugin;
44 MotionWindow::~MotionWindow()
48 void MotionWindow::create_objects()
50 int x1 = 10, x = 10, y = 10;
56 // add_subwindow(global = new MotionGlobal(plugin,
61 add_subwindow(rotate = new MotionRotate(plugin,
67 add_subwindow(title = new BC_Title(x1,
69 _("Translation search radius:\n(W/H Percent of image)")));
70 add_subwindow(global_range_w = new GlobalRange(plugin,
71 x1 + title->get_w() + 10,
73 &plugin->config.global_range_w));
74 add_subwindow(global_range_h = new GlobalRange(plugin,
75 x1 + title->get_w() + 10 + global_range_w->get_w(),
77 &plugin->config.global_range_h));
79 add_subwindow(title = new BC_Title(x2,
81 _("Rotation search radius:\n(Degrees)")));
82 add_subwindow(rotation_range = new RotationRange(plugin,
83 x2 + title->get_w() + 10,
87 add_subwindow(title = new BC_Title(x1,
89 _("Translation block size:\n(W/H Percent of image)")));
90 add_subwindow(global_block_w = new BlockSize(plugin,
91 x1 + title->get_w() + 10,
93 &plugin->config.global_block_w));
94 add_subwindow(global_block_h = new BlockSize(plugin,
95 x1 + title->get_w() + 10 + global_block_w->get_w(),
97 &plugin->config.global_block_h));
99 // add_subwindow(title = new BC_Title(x2,
101 // _("Rotation block size:\n(W/H Percent of image)")));
102 // add_subwindow(rotation_block_w = new BlockSize(plugin,
103 // x2 + title->get_w() + 10,
105 // &plugin->config.rotation_block_w));
106 // add_subwindow(rotation_block_h = new BlockSize(plugin,
107 // x2 + title->get_w() + 10 + rotation_block_w->get_w(),
109 // &plugin->config.rotation_block_h));
112 // add_subwindow(title = new BC_Title(x1, y, _("Translation search steps:")));
113 // add_subwindow(global_search_positions = new GlobalSearchPositions(plugin,
114 // x1 + title->get_w() + 10,
117 // global_search_positions->create_objects();
119 // add_subwindow(title = new BC_Title(x2, y, _("Rotation search steps:")));
120 // add_subwindow(rotation_search_positions = new RotationSearchPositions(plugin,
121 // x2 + title->get_w() + 10,
124 // rotation_search_positions->create_objects();
127 add_subwindow(title = new BC_Title(x, y, _("Translation direction:")));
128 add_subwindow(track_direction = new TrackDirection(plugin,
130 x + title->get_w() + 10,
132 track_direction->create_objects();
135 add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
136 add_subwindow(block_x = new MotionBlockX(plugin,
138 x + title->get_w() + 10,
140 add_subwindow(block_x_text = new MotionBlockXText(plugin,
142 x + title->get_w() + 10 + block_x->get_w() + 10,
145 add_subwindow(title = new BC_Title(x2, y, _("Rotation center:")));
146 add_subwindow(rotation_center = new RotationCenter(plugin,
147 x2 + title->get_w() + 10,
154 add_subwindow(title = new BC_Title(x2, y + 10, _("Maximum angle offset:")));
155 add_subwindow(rotate_magnitude = new MotionRMagnitude(plugin,
156 x2 + title->get_w() + 10,
160 add_subwindow(title = new BC_Title(x2, y + 10, _("Rotation settling speed:")));
161 add_subwindow(rotate_return_speed = new MotionRReturnSpeed(plugin,
162 x2 + title->get_w() + 10,
169 add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
170 add_subwindow(block_y = new MotionBlockY(plugin,
172 x + title->get_w() + 10,
174 add_subwindow(block_y_text = new MotionBlockYText(plugin,
176 x + title->get_w() + 10 + block_y->get_w() + 10,
180 add_subwindow(title = new BC_Title(x, y + 10, _("Maximum absolute offset:")));
181 add_subwindow(magnitude = new MotionMagnitude(plugin,
182 x + title->get_w() + 10,
186 add_subwindow(title = new BC_Title(x, y + 10, _("Motion settling speed:")));
187 add_subwindow(return_speed = new MotionReturnSpeed(plugin,
188 x + title->get_w() + 10,
194 add_subwindow(vectors = new MotionDrawVectors(plugin,
201 add_subwindow(track_single = new TrackSingleFrame(plugin,
205 add_subwindow(title = new BC_Title(x + track_single->get_w() + 20,
207 _("Frame number:")));
208 add_subwindow(track_frame_number = new TrackFrameNumber(plugin,
210 x + track_single->get_w() + title->get_w() + 20,
214 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
220 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
227 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
228 add_subwindow(master_layer = new MasterLayer(plugin,
230 x + title->get_w() + 10,
232 master_layer->create_objects();
236 add_subwindow(title = new BC_Title(x, y, _("Action:")));
237 add_subwindow(action_type = new ActionType(plugin,
239 x + title->get_w() + 10,
241 action_type->create_objects();
247 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
248 add_subwindow(tracking_type = new TrackingType(plugin,
250 x + title->get_w() + 10,
252 tracking_type->create_objects();
259 void MotionWindow::update_mode()
261 global_range_w->update(plugin->config.global_range_w,
264 global_range_h->update(plugin->config.global_range_h,
267 rotation_range->update(plugin->config.rotation_range,
270 vectors->update(plugin->config.draw_vectors);
271 // global->update(plugin->config.global);
272 rotate->update(plugin->config.rotate);
287 GlobalRange::GlobalRange(MotionMain *plugin,
297 this->plugin = plugin;
302 int GlobalRange::handle_event()
304 *value = (int)get_value();
305 plugin->send_configure_change();
312 RotationRange::RotationRange(MotionMain *plugin,
317 (int64_t)plugin->config.rotation_range,
318 (int64_t)MIN_ROTATION,
319 (int64_t)MAX_ROTATION)
321 this->plugin = plugin;
325 int RotationRange::handle_event()
327 plugin->config.rotation_range = (int)get_value();
328 plugin->send_configure_change();
335 RotationCenter::RotationCenter(MotionMain *plugin,
340 (int64_t)plugin->config.rotation_center,
341 (int64_t)-MAX_ROTATION,
342 (int64_t)MAX_ROTATION)
344 this->plugin = plugin;
348 int RotationCenter::handle_event()
350 plugin->config.rotation_center = (int)get_value();
351 plugin->send_configure_change();
360 BlockSize::BlockSize(MotionMain *plugin,
370 this->plugin = plugin;
375 int BlockSize::handle_event()
377 *value = (int)get_value();
378 plugin->send_configure_change();
394 // GlobalSearchPositions::GlobalSearchPositions(MotionMain *plugin,
404 // this->plugin = plugin;
406 // void GlobalSearchPositions::create_objects()
408 // add_item(new BC_MenuItem("16"));
409 // add_item(new BC_MenuItem("32"));
410 // add_item(new BC_MenuItem("64"));
411 // add_item(new BC_MenuItem("128"));
412 // add_item(new BC_MenuItem("256"));
413 // add_item(new BC_MenuItem("512"));
414 // add_item(new BC_MenuItem("1024"));
415 // add_item(new BC_MenuItem("2048"));
416 // add_item(new BC_MenuItem("4096"));
417 // add_item(new BC_MenuItem("8192"));
418 // add_item(new BC_MenuItem("16384"));
419 // add_item(new BC_MenuItem("32768"));
420 // add_item(new BC_MenuItem("65536"));
421 // add_item(new BC_MenuItem("131072"));
422 // char string[BCTEXTLEN];
423 // sprintf(string, "%d", plugin->config.global_positions);
427 // int GlobalSearchPositions::handle_event()
429 // plugin->config.global_positions = atoi(get_text());
430 // plugin->send_configure_change();
440 // RotationSearchPositions::RotationSearchPositions(MotionMain *plugin,
450 // this->plugin = plugin;
452 // void RotationSearchPositions::create_objects()
454 // add_item(new BC_MenuItem("4"));
455 // add_item(new BC_MenuItem("8"));
456 // add_item(new BC_MenuItem("16"));
457 // add_item(new BC_MenuItem("32"));
458 // char string[BCTEXTLEN];
459 // sprintf(string, "%d", plugin->config.rotate_positions);
463 // int RotationSearchPositions::handle_event()
465 // plugin->config.rotate_positions = atoi(get_text());
466 // plugin->send_configure_change();
477 MotionMagnitude::MotionMagnitude(MotionMain *plugin,
482 (int64_t)plugin->config.magnitude,
486 this->plugin = plugin;
489 int MotionMagnitude::handle_event()
491 plugin->config.magnitude = (int)get_value();
492 plugin->send_configure_change();
497 MotionReturnSpeed::MotionReturnSpeed(MotionMain *plugin,
502 (int64_t)plugin->config.return_speed,
506 this->plugin = plugin;
509 int MotionReturnSpeed::handle_event()
511 plugin->config.return_speed = (int)get_value();
512 plugin->send_configure_change();
518 MotionRMagnitude::MotionRMagnitude(MotionMain *plugin,
523 (int64_t)plugin->config.rotate_magnitude,
527 this->plugin = plugin;
530 int MotionRMagnitude::handle_event()
532 plugin->config.rotate_magnitude = (int)get_value();
533 plugin->send_configure_change();
539 MotionRReturnSpeed::MotionRReturnSpeed(MotionMain *plugin,
544 (int64_t)plugin->config.rotate_return_speed,
548 this->plugin = plugin;
551 int MotionRReturnSpeed::handle_event()
553 plugin->config.rotate_return_speed = (int)get_value();
554 plugin->send_configure_change();
562 // MotionGlobal::MotionGlobal(MotionMain *plugin,
563 // MotionWindow *gui,
568 // plugin->config.global,
569 // _("Track translation"))
571 // this->plugin = plugin;
575 // int MotionGlobal::handle_event()
577 // plugin->config.global = get_value();
578 // plugin->send_configure_change();
582 MotionRotate::MotionRotate(MotionMain *plugin,
588 plugin->config.rotate,
591 this->plugin = plugin;
595 int MotionRotate::handle_event()
597 plugin->config.rotate = get_value();
598 plugin->send_configure_change();
606 MotionBlockX::MotionBlockX(MotionMain *plugin,
612 plugin->config.block_x,
616 this->plugin = plugin;
620 int MotionBlockX::handle_event()
622 plugin->config.block_x = get_value();
623 gui->block_x_text->update((float)plugin->config.block_x);
624 plugin->send_configure_change();
631 MotionBlockY::MotionBlockY(MotionMain *plugin,
637 (float)plugin->config.block_y,
641 this->plugin = plugin;
645 int MotionBlockY::handle_event()
647 plugin->config.block_y = get_value();
648 gui->block_y_text->update((float)plugin->config.block_y);
649 plugin->send_configure_change();
653 MotionBlockXText::MotionBlockXText(MotionMain *plugin,
661 (float)plugin->config.block_x)
663 this->plugin = plugin;
668 int MotionBlockXText::handle_event()
670 plugin->config.block_x = atof(get_text());
671 gui->block_x->update(plugin->config.block_x);
672 plugin->send_configure_change();
679 MotionBlockYText::MotionBlockYText(MotionMain *plugin,
687 (float)plugin->config.block_y)
689 this->plugin = plugin;
694 int MotionBlockYText::handle_event()
696 plugin->config.block_y = atof(get_text());
697 gui->block_y->update(plugin->config.block_y);
698 plugin->send_configure_change();
717 MotionDrawVectors::MotionDrawVectors(MotionMain *plugin,
723 plugin->config.draw_vectors,
727 this->plugin = plugin;
730 int MotionDrawVectors::handle_event()
732 plugin->config.draw_vectors = get_value();
733 plugin->send_configure_change();
744 TrackSingleFrame::TrackSingleFrame(MotionMain *plugin,
750 plugin->config.tracking_object == MotionScan::TRACK_SINGLE,
751 _("Track single frame"))
753 this->plugin = plugin;
757 int TrackSingleFrame::handle_event()
759 plugin->config.tracking_object = MotionScan::TRACK_SINGLE;
760 gui->track_previous->update(0);
761 gui->previous_same->update(0);
762 gui->track_frame_number->enable();
763 plugin->send_configure_change();
774 TrackFrameNumber::TrackFrameNumber(MotionMain *plugin,
778 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
780 this->plugin = plugin;
782 if(plugin->config.tracking_object != MotionScan::TRACK_SINGLE) disable();
785 int TrackFrameNumber::handle_event()
787 plugin->config.track_frame = atol(get_text());
788 plugin->send_configure_change();
798 TrackPreviousFrame::TrackPreviousFrame(MotionMain *plugin,
804 plugin->config.tracking_object == MotionScan::TRACK_PREVIOUS,
805 _("Track previous frame"))
807 this->plugin = plugin;
810 int TrackPreviousFrame::handle_event()
812 plugin->config.tracking_object = MotionScan::TRACK_PREVIOUS;
813 gui->track_single->update(0);
814 gui->previous_same->update(0);
815 gui->track_frame_number->disable();
816 plugin->send_configure_change();
827 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionMain *plugin,
833 plugin->config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK,
834 _("Previous frame same block"))
836 this->plugin = plugin;
839 int PreviousFrameSameBlock::handle_event()
841 plugin->config.tracking_object = MotionScan::PREVIOUS_SAME_BLOCK;
842 gui->track_single->update(0);
843 gui->track_previous->update(0);
844 gui->track_frame_number->disable();
845 plugin->send_configure_change();
856 MasterLayer::MasterLayer(MotionMain *plugin, MotionWindow *gui, int x, int y)
860 to_text(plugin->config.bottom_is_master))
862 this->plugin = plugin;
866 int MasterLayer::handle_event()
868 plugin->config.bottom_is_master = from_text(get_text());
869 plugin->send_configure_change();
873 void MasterLayer::create_objects()
875 add_item(new BC_MenuItem(to_text(0)));
876 add_item(new BC_MenuItem(to_text(1)));
879 int MasterLayer::from_text(char *text)
881 if(!strcmp(text, _("Top"))) return 0;
885 char* MasterLayer::to_text(int mode)
887 return mode ? _("Bottom") : _("Top");
890 int MasterLayer::calculate_w(MotionWindow *gui)
893 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
894 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
905 ActionType::ActionType(MotionMain *plugin, MotionWindow *gui, int x, int y)
909 to_text(plugin->config.action_type))
911 this->plugin = plugin;
915 int ActionType::handle_event()
917 plugin->config.action_type = from_text(get_text());
918 plugin->send_configure_change();
922 void ActionType::create_objects()
924 add_item(new BC_MenuItem(to_text(MotionScan::TRACK)));
925 add_item(new BC_MenuItem(to_text(MotionScan::TRACK_PIXEL)));
926 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE)));
927 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE_PIXEL)));
928 add_item(new BC_MenuItem(to_text(MotionScan::NOTHING)));
931 int ActionType::from_text(char *text)
933 if(!strcmp(text, _("Track Subpixel"))) return MotionScan::TRACK;
934 if(!strcmp(text, _("Track Pixel"))) return MotionScan::TRACK_PIXEL;
935 if(!strcmp(text, _("Stabilize Subpixel"))) return MotionScan::STABILIZE;
936 if(!strcmp(text, _("Stabilize Pixel"))) return MotionScan::STABILIZE_PIXEL;
937 //if(!strcmp(text, _("Do Nothing"))) return MotionScan::NOTHING;
938 return MotionScan::NOTHING;
941 char* ActionType::to_text(int mode)
945 case MotionScan::TRACK:
946 return _("Track Subpixel");
947 case MotionScan::TRACK_PIXEL:
948 return _("Track Pixel");
949 case MotionScan::STABILIZE:
950 return _("Stabilize Subpixel");
951 case MotionScan::STABILIZE_PIXEL:
952 return _("Stabilize Pixel");
954 case MotionScan::NOTHING:
955 return _("Do Nothing");
959 int ActionType::calculate_w(MotionWindow *gui)
962 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK)));
963 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK_PIXEL)));
964 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE)));
965 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE_PIXEL)));
966 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NOTHING)));
974 TrackingType::TrackingType(MotionMain *plugin, MotionWindow *gui, int x, int y)
978 to_text(plugin->config.tracking_type))
980 this->plugin = plugin;
984 int TrackingType::handle_event()
986 plugin->config.tracking_type = from_text(get_text());
987 plugin->send_configure_change();
991 void TrackingType::create_objects()
993 add_item(new BC_MenuItem(to_text(MotionScan::NO_CALCULATE)));
994 add_item(new BC_MenuItem(to_text(MotionScan::CALCULATE)));
995 add_item(new BC_MenuItem(to_text(MotionScan::SAVE)));
996 add_item(new BC_MenuItem(to_text(MotionScan::LOAD)));
999 int TrackingType::from_text(char *text)
1001 if(!strcmp(text, _("Save coords to /tmp"))) return MotionScan::SAVE;
1002 if(!strcmp(text, _("Load coords from /tmp"))) return MotionScan::LOAD;
1003 if(!strcmp(text, _("Recalculate"))) return MotionScan::CALCULATE;
1004 //if(!strcmp(text, _("Don't Calculate"))) return MotionScan::NO_CALCULATE;
1005 return MotionScan::NO_CALCULATE;
1008 char* TrackingType::to_text(int mode)
1012 case MotionScan::SAVE:
1013 return _("Save coords to /tmp");
1014 case MotionScan::LOAD:
1015 return _("Load coords from /tmp");
1016 case MotionScan::CALCULATE:
1017 return _("Recalculate");
1019 case MotionScan::NO_CALCULATE:
1020 return _("Don't Calculate");
1024 int TrackingType::calculate_w(MotionWindow *gui)
1027 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NO_CALCULATE)));
1028 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::CALCULATE)));
1029 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::SAVE)));
1030 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::LOAD)));
1043 TrackDirection::TrackDirection(MotionMain *plugin, MotionWindow *gui, int x, int y)
1047 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
1049 this->plugin = plugin;
1053 int TrackDirection::handle_event()
1055 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
1056 plugin->send_configure_change();
1060 void TrackDirection::create_objects()
1062 add_item(new BC_MenuItem(to_text(1, 0)));
1063 add_item(new BC_MenuItem(to_text(0, 1)));
1064 add_item(new BC_MenuItem(to_text(0, 0)));
1067 void TrackDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
1069 *horizontal_only = 0;
1071 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1072 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1075 char* TrackDirection::to_text(int horizontal_only, int vertical_only)
1077 if(horizontal_only) return _("Horizontal only");
1078 if(vertical_only) return _("Vertical only");
1082 int TrackDirection::calculate_w(MotionWindow *gui)
1085 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
1086 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
1087 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));