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, 600, 650, 600, 650, 0)
41 this->plugin = plugin;
44 MotionHVWindow::~MotionHVWindow()
48 void MotionHVWindow::create_objects()
50 int x1 = 10, x = 10, y = 10;
56 // add_subwindow(global = new MotionHVGlobal(plugin,
61 add_subwindow(rotate = new MotionHVRotate(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 MotionHVBlockX(plugin,
138 x + title->get_w() + 10,
140 add_subwindow(block_x_text = new MotionHVBlockXText(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 MotionHVRMagnitude(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 MotionHVRReturnSpeed(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 MotionHVBlockY(plugin,
172 x + title->get_w() + 10,
174 add_subwindow(block_y_text = new MotionHVBlockYText(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 MotionHVMagnitude(plugin,
182 x + title->get_w() + 10,
186 add_subwindow(title = new BC_Title(x, y + 10, _("MotionHV settling speed:")));
187 add_subwindow(return_speed = new MotionHVReturnSpeed(plugin,
188 x + title->get_w() + 10,
194 add_subwindow(vectors = new MotionHVDrawVectors(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 if(plugin->config.tracking_object != MotionHVScan::TRACK_SINGLE)
213 track_frame_number->disable();
216 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
222 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
229 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
230 add_subwindow(master_layer = new MasterLayer(plugin,
232 x + title->get_w() + 10,
234 master_layer->create_objects();
238 add_subwindow(title = new BC_Title(x, y, _("Action:")));
239 add_subwindow(action_type = new ActionType(plugin,
241 x + title->get_w() + 10,
243 action_type->create_objects();
249 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
250 add_subwindow(tracking_type = new TrackingType(plugin,
252 x + title->get_w() + 10,
254 tracking_type->create_objects();
261 void MotionHVWindow::update_mode()
263 global_range_w->update(plugin->config.global_range_w,
266 global_range_h->update(plugin->config.global_range_h,
269 rotation_range->update(plugin->config.rotation_range,
272 vectors->update(plugin->config.draw_vectors);
273 // global->update(plugin->config.global);
274 rotate->update(plugin->config.rotate);
289 GlobalRange::GlobalRange(MotionHVMain *plugin,
299 this->plugin = plugin;
304 int GlobalRange::handle_event()
306 *value = (int)get_value();
307 plugin->send_configure_change();
314 RotationRange::RotationRange(MotionHVMain *plugin,
319 (int64_t)plugin->config.rotation_range,
320 (int64_t)MIN_ROTATION,
321 (int64_t)MAX_ROTATION)
323 this->plugin = plugin;
327 int RotationRange::handle_event()
329 plugin->config.rotation_range = (int)get_value();
330 plugin->send_configure_change();
337 RotationCenter::RotationCenter(MotionHVMain *plugin,
342 (int64_t)plugin->config.rotation_center,
343 (int64_t)-MAX_ROTATION,
344 (int64_t)MAX_ROTATION)
346 this->plugin = plugin;
350 int RotationCenter::handle_event()
352 plugin->config.rotation_center = (int)get_value();
353 plugin->send_configure_change();
362 BlockSize::BlockSize(MotionHVMain *plugin,
372 this->plugin = plugin;
377 int BlockSize::handle_event()
379 *value = (int)get_value();
380 plugin->send_configure_change();
396 // GlobalSearchPositions::GlobalSearchPositions(MotionHVMain *plugin,
406 // this->plugin = plugin;
408 // void GlobalSearchPositions::create_objects()
410 // add_item(new BC_MenuItem("16"));
411 // add_item(new BC_MenuItem("32"));
412 // add_item(new BC_MenuItem("64"));
413 // add_item(new BC_MenuItem("128"));
414 // add_item(new BC_MenuItem("256"));
415 // add_item(new BC_MenuItem("512"));
416 // add_item(new BC_MenuItem("1024"));
417 // add_item(new BC_MenuItem("2048"));
418 // add_item(new BC_MenuItem("4096"));
419 // add_item(new BC_MenuItem("8192"));
420 // add_item(new BC_MenuItem("16384"));
421 // add_item(new BC_MenuItem("32768"));
422 // add_item(new BC_MenuItem("65536"));
423 // add_item(new BC_MenuItem("131072"));
424 // char string[BCTEXTLEN];
425 // sprintf(string, "%d", plugin->config.global_positions);
429 // int GlobalSearchPositions::handle_event()
431 // plugin->config.global_positions = atoi(get_text());
432 // plugin->send_configure_change();
442 // RotationSearchPositions::RotationSearchPositions(MotionHVMain *plugin,
452 // this->plugin = plugin;
454 // void RotationSearchPositions::create_objects()
456 // add_item(new BC_MenuItem("4"));
457 // add_item(new BC_MenuItem("8"));
458 // add_item(new BC_MenuItem("16"));
459 // add_item(new BC_MenuItem("32"));
460 // char string[BCTEXTLEN];
461 // sprintf(string, "%d", plugin->config.rotate_positions);
465 // int RotationSearchPositions::handle_event()
467 // plugin->config.rotate_positions = atoi(get_text());
468 // plugin->send_configure_change();
479 MotionHVMagnitude::MotionHVMagnitude(MotionHVMain *plugin,
484 (int64_t)plugin->config.magnitude,
488 this->plugin = plugin;
491 int MotionHVMagnitude::handle_event()
493 plugin->config.magnitude = (int)get_value();
494 plugin->send_configure_change();
499 MotionHVReturnSpeed::MotionHVReturnSpeed(MotionHVMain *plugin,
504 (int64_t)plugin->config.return_speed,
508 this->plugin = plugin;
511 int MotionHVReturnSpeed::handle_event()
513 plugin->config.return_speed = (int)get_value();
514 plugin->send_configure_change();
520 MotionHVRMagnitude::MotionHVRMagnitude(MotionHVMain *plugin,
525 (int64_t)plugin->config.rotate_magnitude,
529 this->plugin = plugin;
532 int MotionHVRMagnitude::handle_event()
534 plugin->config.rotate_magnitude = (int)get_value();
535 plugin->send_configure_change();
541 MotionHVRReturnSpeed::MotionHVRReturnSpeed(MotionHVMain *plugin,
546 (int64_t)plugin->config.rotate_return_speed,
550 this->plugin = plugin;
553 int MotionHVRReturnSpeed::handle_event()
555 plugin->config.rotate_return_speed = (int)get_value();
556 plugin->send_configure_change();
564 // MotionHVGlobal::MotionHVGlobal(MotionHVMain *plugin,
565 // MotionHVWindow *gui,
570 // plugin->config.global,
571 // _("Track translation"))
573 // this->plugin = plugin;
577 // int MotionHVGlobal::handle_event()
579 // plugin->config.global = get_value();
580 // plugin->send_configure_change();
584 MotionHVRotate::MotionHVRotate(MotionHVMain *plugin,
590 plugin->config.rotate,
593 this->plugin = plugin;
597 int MotionHVRotate::handle_event()
599 plugin->config.rotate = get_value();
600 plugin->send_configure_change();
608 MotionHVBlockX::MotionHVBlockX(MotionHVMain *plugin,
614 plugin->config.block_x,
618 this->plugin = plugin;
622 int MotionHVBlockX::handle_event()
624 plugin->config.block_x = get_value();
625 gui->block_x_text->update((float)plugin->config.block_x);
626 plugin->send_configure_change();
633 MotionHVBlockY::MotionHVBlockY(MotionHVMain *plugin,
639 (float)plugin->config.block_y,
643 this->plugin = plugin;
647 int MotionHVBlockY::handle_event()
649 plugin->config.block_y = get_value();
650 gui->block_y_text->update((float)plugin->config.block_y);
651 plugin->send_configure_change();
655 MotionHVBlockXText::MotionHVBlockXText(MotionHVMain *plugin,
663 (float)plugin->config.block_x)
665 this->plugin = plugin;
670 int MotionHVBlockXText::handle_event()
672 plugin->config.block_x = atof(get_text());
673 gui->block_x->update(plugin->config.block_x);
674 plugin->send_configure_change();
681 MotionHVBlockYText::MotionHVBlockYText(MotionHVMain *plugin,
689 (float)plugin->config.block_y)
691 this->plugin = plugin;
696 int MotionHVBlockYText::handle_event()
698 plugin->config.block_y = atof(get_text());
699 gui->block_y->update(plugin->config.block_y);
700 plugin->send_configure_change();
719 MotionHVDrawVectors::MotionHVDrawVectors(MotionHVMain *plugin,
725 plugin->config.draw_vectors,
729 this->plugin = plugin;
732 int MotionHVDrawVectors::handle_event()
734 plugin->config.draw_vectors = get_value();
735 plugin->send_configure_change();
746 TrackSingleFrame::TrackSingleFrame(MotionHVMain *plugin,
752 plugin->config.tracking_object == MotionHVScan::TRACK_SINGLE,
753 _("Track single frame"))
755 this->plugin = plugin;
759 int TrackSingleFrame::handle_event()
761 plugin->config.tracking_object = MotionHVScan::TRACK_SINGLE;
762 gui->track_previous->update(0);
763 gui->previous_same->update(0);
764 gui->track_frame_number->enable();
765 plugin->send_configure_change();
776 TrackFrameNumber::TrackFrameNumber(MotionHVMain *plugin,
780 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
782 this->plugin = plugin;
786 int TrackFrameNumber::handle_event()
788 plugin->config.track_frame = atol(get_text());
789 plugin->send_configure_change();
799 TrackPreviousFrame::TrackPreviousFrame(MotionHVMain *plugin,
805 plugin->config.tracking_object == MotionHVScan::TRACK_PREVIOUS,
806 _("Track previous frame"))
808 this->plugin = plugin;
811 int TrackPreviousFrame::handle_event()
813 plugin->config.tracking_object = MotionHVScan::TRACK_PREVIOUS;
814 gui->track_single->update(0);
815 gui->previous_same->update(0);
816 gui->track_frame_number->disable();
817 plugin->send_configure_change();
828 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionHVMain *plugin,
834 plugin->config.tracking_object == MotionHVScan::PREVIOUS_SAME_BLOCK,
835 _("Previous frame same block"))
837 this->plugin = plugin;
840 int PreviousFrameSameBlock::handle_event()
842 plugin->config.tracking_object = MotionHVScan::PREVIOUS_SAME_BLOCK;
843 gui->track_single->update(0);
844 gui->track_previous->update(0);
845 gui->track_frame_number->disable();
846 plugin->send_configure_change();
857 MasterLayer::MasterLayer(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
861 to_text(plugin->config.bottom_is_master))
863 this->plugin = plugin;
867 int MasterLayer::handle_event()
869 plugin->config.bottom_is_master = from_text(get_text());
870 plugin->send_configure_change();
874 void MasterLayer::create_objects()
876 add_item(new BC_MenuItem(to_text(0)));
877 add_item(new BC_MenuItem(to_text(1)));
880 int MasterLayer::from_text(char *text)
882 if(!strcmp(text, _("Top"))) return 0;
886 char* MasterLayer::to_text(int mode)
888 return mode ? _("Bottom") : _("Top");
891 int MasterLayer::calculate_w(MotionHVWindow *gui)
894 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
895 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
906 ActionType::ActionType(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
910 to_text(plugin->config.action_type))
912 this->plugin = plugin;
916 int ActionType::handle_event()
918 plugin->config.action_type = from_text(get_text());
919 plugin->send_configure_change();
923 void ActionType::create_objects()
925 add_item(new BC_MenuItem(to_text(MotionHVScan::TRACK)));
926 add_item(new BC_MenuItem(to_text(MotionHVScan::TRACK_PIXEL)));
927 add_item(new BC_MenuItem(to_text(MotionHVScan::STABILIZE)));
928 add_item(new BC_MenuItem(to_text(MotionHVScan::STABILIZE_PIXEL)));
929 add_item(new BC_MenuItem(to_text(MotionHVScan::NOTHING)));
932 int ActionType::from_text(char *text)
934 if(!strcmp(text, _("Track Subpixel"))) return MotionHVScan::TRACK;
935 if(!strcmp(text, _("Track Pixel"))) return MotionHVScan::TRACK_PIXEL;
936 if(!strcmp(text, _("Stabilize Subpixel"))) return MotionHVScan::STABILIZE;
937 if(!strcmp(text, _("Stabilize Pixel"))) return MotionHVScan::STABILIZE_PIXEL;
938 //if(!strcmp(text, _("Do Nothing"))) return MotionHVScan::NOTHING;
939 return MotionHVScan::NOTHING;
942 char* ActionType::to_text(int mode)
946 case MotionHVScan::TRACK:
947 return _("Track Subpixel");
948 case MotionHVScan::TRACK_PIXEL:
949 return _("Track Pixel");
950 case MotionHVScan::STABILIZE:
951 return _("Stabilize Subpixel");
952 case MotionHVScan::STABILIZE_PIXEL:
953 return _("Stabilize Pixel");
955 case MotionHVScan::NOTHING:
956 return _("Do Nothing");
960 int ActionType::calculate_w(MotionHVWindow *gui)
963 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::TRACK)));
964 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::TRACK_PIXEL)));
965 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::STABILIZE)));
966 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::STABILIZE_PIXEL)));
967 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::NOTHING)));
975 TrackingType::TrackingType(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
979 to_text(plugin->config.tracking_type))
981 this->plugin = plugin;
985 int TrackingType::handle_event()
987 plugin->config.tracking_type = from_text(get_text());
988 plugin->send_configure_change();
992 void TrackingType::create_objects()
994 add_item(new BC_MenuItem(to_text(MotionHVScan::NO_CALCULATE)));
995 add_item(new BC_MenuItem(to_text(MotionHVScan::CALCULATE)));
996 add_item(new BC_MenuItem(to_text(MotionHVScan::SAVE)));
997 add_item(new BC_MenuItem(to_text(MotionHVScan::LOAD)));
1000 int TrackingType::from_text(char *text)
1002 if(!strcmp(text, _("Save coords to /tmp"))) return MotionHVScan::SAVE;
1003 if(!strcmp(text, _("Load coords from /tmp"))) return MotionHVScan::LOAD;
1004 if(!strcmp(text, _("Recalculate"))) return MotionHVScan::CALCULATE;
1005 //if(!strcmp(text, _("Don't Calculate"))) return MotionHVScan::NO_CALCULATE;
1006 return MotionHVScan::NO_CALCULATE;
1009 char* TrackingType::to_text(int mode)
1013 case MotionHVScan::SAVE:
1014 return _("Save coords to /tmp");
1015 case MotionHVScan::LOAD:
1016 return _("Load coords from /tmp");
1017 case MotionHVScan::CALCULATE:
1018 return _("Recalculate");
1020 case MotionHVScan::NO_CALCULATE:
1021 return _("Don't Calculate");
1025 int TrackingType::calculate_w(MotionHVWindow *gui)
1028 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::NO_CALCULATE)));
1029 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::CALCULATE)));
1030 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::SAVE)));
1031 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionHVScan::LOAD)));
1044 TrackDirection::TrackDirection(MotionHVMain *plugin, MotionHVWindow *gui, int x, int y)
1048 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
1050 this->plugin = plugin;
1054 int TrackDirection::handle_event()
1056 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
1057 plugin->send_configure_change();
1061 void TrackDirection::create_objects()
1063 add_item(new BC_MenuItem(to_text(1, 0)));
1064 add_item(new BC_MenuItem(to_text(0, 1)));
1065 add_item(new BC_MenuItem(to_text(0, 0)));
1068 void TrackDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
1070 *horizontal_only = 0;
1072 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1073 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1076 char* TrackDirection::to_text(int horizontal_only, int vertical_only)
1078 if(horizontal_only) return _("Horizontal only");
1079 if(vertical_only) return _("Vertical only");
1083 int TrackDirection::calculate_w(MotionHVWindow *gui)
1086 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
1087 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
1088 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));