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,
212 add_subwindow(addtrackedframeoffset = new AddTrackedFrameOffset(plugin,
214 x + track_single->get_w() + title->get_w() + 20 + track_frame_number->get_w(),
219 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
225 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
232 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
233 add_subwindow(master_layer = new MasterLayer(plugin,
235 x + title->get_w() + 10,
237 master_layer->create_objects();
241 add_subwindow(title = new BC_Title(x, y, _("Action:")));
242 add_subwindow(action_type = new ActionType(plugin,
244 x + title->get_w() + 10,
246 action_type->create_objects();
252 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
253 add_subwindow(tracking_type = new TrackingType(plugin,
255 x + title->get_w() + 10,
257 tracking_type->create_objects();
264 void MotionWindow::update_mode()
266 global_range_w->update(plugin->config.global_range_w,
269 global_range_h->update(plugin->config.global_range_h,
272 rotation_range->update(plugin->config.rotation_range,
275 vectors->update(plugin->config.draw_vectors);
276 global->update(plugin->config.global);
277 rotate->update(plugin->config.rotate);
278 addtrackedframeoffset->update(plugin->config.addtrackedframeoffset);
293 GlobalRange::GlobalRange(MotionMain *plugin,
303 this->plugin = plugin;
308 int GlobalRange::handle_event()
310 *value = (int)get_value();
311 plugin->send_configure_change();
318 RotationRange::RotationRange(MotionMain *plugin,
323 (int64_t)plugin->config.rotation_range,
324 (int64_t)MIN_ROTATION,
325 (int64_t)MAX_ROTATION)
327 this->plugin = plugin;
331 int RotationRange::handle_event()
333 plugin->config.rotation_range = (int)get_value();
334 plugin->send_configure_change();
341 RotationCenter::RotationCenter(MotionMain *plugin,
346 (int64_t)plugin->config.rotation_center,
347 (int64_t)-MAX_ROTATION,
348 (int64_t)MAX_ROTATION)
350 this->plugin = plugin;
354 int RotationCenter::handle_event()
356 plugin->config.rotation_center = (int)get_value();
357 plugin->send_configure_change();
366 BlockSize::BlockSize(MotionMain *plugin,
376 this->plugin = plugin;
381 int BlockSize::handle_event()
383 *value = (int)get_value();
384 plugin->send_configure_change();
400 GlobalSearchPositions::GlobalSearchPositions(MotionMain *plugin,
410 this->plugin = plugin;
412 void GlobalSearchPositions::create_objects()
414 add_item(new BC_MenuItem("16"));
415 add_item(new BC_MenuItem("32"));
416 add_item(new BC_MenuItem("64"));
417 add_item(new BC_MenuItem("128"));
418 add_item(new BC_MenuItem("256"));
419 add_item(new BC_MenuItem("512"));
420 add_item(new BC_MenuItem("1024"));
421 add_item(new BC_MenuItem("2048"));
422 add_item(new BC_MenuItem("4096"));
423 add_item(new BC_MenuItem("8192"));
424 add_item(new BC_MenuItem("16384"));
425 add_item(new BC_MenuItem("32768"));
426 add_item(new BC_MenuItem("65536"));
427 add_item(new BC_MenuItem("131072"));
428 char string[BCTEXTLEN];
429 sprintf(string, "%d", plugin->config.global_positions);
433 int GlobalSearchPositions::handle_event()
435 plugin->config.global_positions = atoi(get_text());
436 plugin->send_configure_change();
446 RotationSearchPositions::RotationSearchPositions(MotionMain *plugin,
456 this->plugin = plugin;
458 void RotationSearchPositions::create_objects()
460 add_item(new BC_MenuItem("4"));
461 add_item(new BC_MenuItem("8"));
462 add_item(new BC_MenuItem("16"));
463 add_item(new BC_MenuItem("32"));
464 char string[BCTEXTLEN];
465 sprintf(string, "%d", plugin->config.rotate_positions);
469 int RotationSearchPositions::handle_event()
471 plugin->config.rotate_positions = atoi(get_text());
472 plugin->send_configure_change();
483 MotionMagnitude::MotionMagnitude(MotionMain *plugin,
488 (int64_t)plugin->config.magnitude,
492 this->plugin = plugin;
495 int MotionMagnitude::handle_event()
497 plugin->config.magnitude = (int)get_value();
498 plugin->send_configure_change();
503 MotionReturnSpeed::MotionReturnSpeed(MotionMain *plugin,
508 (int64_t)plugin->config.return_speed,
512 this->plugin = plugin;
515 int MotionReturnSpeed::handle_event()
517 plugin->config.return_speed = (int)get_value();
518 plugin->send_configure_change();
524 AddTrackedFrameOffset::AddTrackedFrameOffset(MotionMain *plugin,
530 plugin->config.addtrackedframeoffset,
531 _("Add (loaded) offset from tracked frame"))
533 this->plugin = plugin;
537 int AddTrackedFrameOffset::handle_event()
539 plugin->config.addtrackedframeoffset = get_value();
540 plugin->send_configure_change();
545 MotionRMagnitude::MotionRMagnitude(MotionMain *plugin,
550 (int64_t)plugin->config.rotate_magnitude,
554 this->plugin = plugin;
557 int MotionRMagnitude::handle_event()
559 plugin->config.rotate_magnitude = (int)get_value();
560 plugin->send_configure_change();
566 MotionRReturnSpeed::MotionRReturnSpeed(MotionMain *plugin,
571 (int64_t)plugin->config.rotate_return_speed,
575 this->plugin = plugin;
578 int MotionRReturnSpeed::handle_event()
580 plugin->config.rotate_return_speed = (int)get_value();
581 plugin->send_configure_change();
589 MotionGlobal::MotionGlobal(MotionMain *plugin,
595 plugin->config.global,
596 _("Track translation"))
598 this->plugin = plugin;
602 int MotionGlobal::handle_event()
604 plugin->config.global = get_value();
605 plugin->send_configure_change();
609 MotionRotate::MotionRotate(MotionMain *plugin,
615 plugin->config.rotate,
618 this->plugin = plugin;
622 int MotionRotate::handle_event()
624 plugin->config.rotate = get_value();
625 plugin->send_configure_change();
633 MotionBlockX::MotionBlockX(MotionMain *plugin,
639 plugin->config.block_x,
643 this->plugin = plugin;
647 int MotionBlockX::handle_event()
649 plugin->config.block_x = get_value();
650 gui->block_x_text->update((float)plugin->config.block_x);
651 plugin->send_configure_change();
658 MotionBlockY::MotionBlockY(MotionMain *plugin,
664 (float)plugin->config.block_y,
668 this->plugin = plugin;
672 int MotionBlockY::handle_event()
674 plugin->config.block_y = get_value();
675 gui->block_y_text->update((float)plugin->config.block_y);
676 plugin->send_configure_change();
680 MotionBlockXText::MotionBlockXText(MotionMain *plugin,
688 (float)plugin->config.block_x)
690 this->plugin = plugin;
695 int MotionBlockXText::handle_event()
697 plugin->config.block_x = atof(get_text());
698 gui->block_x->update(plugin->config.block_x);
699 plugin->send_configure_change();
706 MotionBlockYText::MotionBlockYText(MotionMain *plugin,
714 (float)plugin->config.block_y)
716 this->plugin = plugin;
721 int MotionBlockYText::handle_event()
723 plugin->config.block_y = atof(get_text());
724 gui->block_y->update(plugin->config.block_y);
725 plugin->send_configure_change();
744 MotionDrawVectors::MotionDrawVectors(MotionMain *plugin,
750 plugin->config.draw_vectors,
754 this->plugin = plugin;
757 int MotionDrawVectors::handle_event()
759 plugin->config.draw_vectors = get_value();
760 plugin->send_configure_change();
771 TrackSingleFrame::TrackSingleFrame(MotionMain *plugin,
777 plugin->config.tracking_object == MotionScan::TRACK_SINGLE,
778 _("Track single frame"))
780 this->plugin = plugin;
784 int TrackSingleFrame::handle_event()
786 plugin->config.tracking_object = MotionScan::TRACK_SINGLE;
787 gui->track_previous->update(0);
788 gui->previous_same->update(0);
789 gui->track_frame_number->enable();
790 plugin->send_configure_change();
801 TrackFrameNumber::TrackFrameNumber(MotionMain *plugin,
805 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
807 this->plugin = plugin;
809 if(plugin->config.tracking_object != MotionScan::TRACK_SINGLE) disable();
812 int TrackFrameNumber::handle_event()
814 plugin->config.track_frame = atol(get_text());
815 plugin->send_configure_change();
825 TrackPreviousFrame::TrackPreviousFrame(MotionMain *plugin,
831 plugin->config.tracking_object == MotionScan::TRACK_PREVIOUS,
832 _("Track previous frame"))
834 this->plugin = plugin;
837 int TrackPreviousFrame::handle_event()
839 plugin->config.tracking_object = MotionScan::TRACK_PREVIOUS;
840 gui->track_single->update(0);
841 gui->previous_same->update(0);
842 gui->track_frame_number->disable();
843 plugin->send_configure_change();
854 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionMain *plugin,
860 plugin->config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK,
861 _("Previous frame same block"))
863 this->plugin = plugin;
866 int PreviousFrameSameBlock::handle_event()
868 plugin->config.tracking_object = MotionScan::PREVIOUS_SAME_BLOCK;
869 gui->track_single->update(0);
870 gui->track_previous->update(0);
871 gui->track_frame_number->disable();
872 plugin->send_configure_change();
883 MasterLayer::MasterLayer(MotionMain *plugin, MotionWindow *gui, int x, int y)
887 to_text(plugin->config.bottom_is_master))
889 this->plugin = plugin;
893 int MasterLayer::handle_event()
895 plugin->config.bottom_is_master = from_text(get_text());
896 plugin->send_configure_change();
900 void MasterLayer::create_objects()
902 add_item(new BC_MenuItem(to_text(0)));
903 add_item(new BC_MenuItem(to_text(1)));
906 int MasterLayer::from_text(char *text)
908 if(!strcmp(text, _("Top"))) return 0;
912 char* MasterLayer::to_text(int mode)
914 return mode ? _("Bottom") : _("Top");
917 int MasterLayer::calculate_w(MotionWindow *gui)
920 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
921 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
932 ActionType::ActionType(MotionMain *plugin, MotionWindow *gui, int x, int y)
936 to_text(plugin->config.action_type))
938 this->plugin = plugin;
942 int ActionType::handle_event()
944 plugin->config.action_type = from_text(get_text());
945 plugin->send_configure_change();
949 void ActionType::create_objects()
951 add_item(new BC_MenuItem(to_text(MotionScan::TRACK)));
952 add_item(new BC_MenuItem(to_text(MotionScan::TRACK_PIXEL)));
953 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE)));
954 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE_PIXEL)));
955 add_item(new BC_MenuItem(to_text(MotionScan::NOTHING)));
958 int ActionType::from_text(char *text)
960 if(!strcmp(text, _("Track Subpixel"))) return MotionScan::TRACK;
961 if(!strcmp(text, _("Track Pixel"))) return MotionScan::TRACK_PIXEL;
962 if(!strcmp(text, _("Stabilize Subpixel"))) return MotionScan::STABILIZE;
963 if(!strcmp(text, _("Stabilize Pixel"))) return MotionScan::STABILIZE_PIXEL;
964 //if(!strcmp(text, _("Do Nothing"))) return MotionScan::NOTHING;
965 return MotionScan::NOTHING;
968 char* ActionType::to_text(int mode)
972 case MotionScan::TRACK:
973 return _("Track Subpixel");
974 case MotionScan::TRACK_PIXEL:
975 return _("Track Pixel");
976 case MotionScan::STABILIZE:
977 return _("Stabilize Subpixel");
978 case MotionScan::STABILIZE_PIXEL:
979 return _("Stabilize Pixel");
981 case MotionScan::NOTHING:
982 return _("Do Nothing");
986 int ActionType::calculate_w(MotionWindow *gui)
989 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK)));
990 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK_PIXEL)));
991 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE)));
992 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE_PIXEL)));
993 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NOTHING)));
1001 TrackingType::TrackingType(MotionMain *plugin, MotionWindow *gui, int x, int y)
1005 to_text(plugin->config.tracking_type))
1007 this->plugin = plugin;
1011 int TrackingType::handle_event()
1013 plugin->config.tracking_type = from_text(get_text());
1014 plugin->send_configure_change();
1018 void TrackingType::create_objects()
1020 add_item(new BC_MenuItem(to_text(MotionScan::NO_CALCULATE)));
1021 add_item(new BC_MenuItem(to_text(MotionScan::CALCULATE)));
1022 add_item(new BC_MenuItem(to_text(MotionScan::SAVE)));
1023 add_item(new BC_MenuItem(to_text(MotionScan::LOAD)));
1026 int TrackingType::from_text(char *text)
1028 if(!strcmp(text, _("Save coords to /tmp"))) return MotionScan::SAVE;
1029 if(!strcmp(text, _("Load coords from /tmp"))) return MotionScan::LOAD;
1030 if(!strcmp(text, _("Recalculate"))) return MotionScan::CALCULATE;
1031 //if(!strcmp(text, _("Don't Calculate"))) return MotionScan::NO_CALCULATE;
1032 return MotionScan::NO_CALCULATE;
1035 char* TrackingType::to_text(int mode)
1039 case MotionScan::SAVE:
1040 return _("Save coords to /tmp");
1041 case MotionScan::LOAD:
1042 return _("Load coords from /tmp");
1043 case MotionScan::CALCULATE:
1044 return _("Recalculate");
1046 case MotionScan::NO_CALCULATE:
1047 return _("Don't Calculate");
1051 int TrackingType::calculate_w(MotionWindow *gui)
1054 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NO_CALCULATE)));
1055 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::CALCULATE)));
1056 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::SAVE)));
1057 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::LOAD)));
1070 TrackDirection::TrackDirection(MotionMain *plugin, MotionWindow *gui, int x, int y)
1074 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
1076 this->plugin = plugin;
1080 int TrackDirection::handle_event()
1082 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
1083 plugin->send_configure_change();
1087 void TrackDirection::create_objects()
1089 add_item(new BC_MenuItem(to_text(1, 0)));
1090 add_item(new BC_MenuItem(to_text(0, 1)));
1091 add_item(new BC_MenuItem(to_text(0, 0)));
1094 void TrackDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
1096 *horizontal_only = 0;
1098 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1099 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1102 char* TrackDirection::to_text(int horizontal_only, int vertical_only)
1104 if(horizontal_only) return _("Horizontal only");
1105 if(vertical_only) return _("Vertical only");
1109 int TrackDirection::calculate_w(MotionWindow *gui)
1112 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
1113 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
1114 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));