1 #include "bcdisplayinfo.h"
5 #include "motionwindow.h"
12 PLUGIN_THREAD_OBJECT(MotionMain, MotionThread, MotionWindow)
16 MotionWindow::MotionWindow(MotionMain *plugin, int x, int y)
17 : BC_Window(plugin->gui_string,
27 this->plugin = plugin;
30 MotionWindow::~MotionWindow()
34 int MotionWindow::create_objects()
36 int x1 = 10, x = 10, y = 10;
42 add_subwindow(global = new MotionGlobal(plugin,
47 add_subwindow(rotate = new MotionRotate(plugin,
53 add_subwindow(title = new BC_Title(x1,
55 _("Translation search radius:\n(W/H Percent of image)")));
56 add_subwindow(global_range_w = new GlobalRange(plugin,
57 x1 + title->get_w() + 10,
59 &plugin->config.global_range_w));
60 add_subwindow(global_range_h = new GlobalRange(plugin,
61 x1 + title->get_w() + 10 + global_range_w->get_w(),
63 &plugin->config.global_range_h));
65 add_subwindow(title = new BC_Title(x2,
67 _("Rotation search radius:\n(Degrees)")));
68 add_subwindow(rotation_range = new RotationRange(plugin,
69 x2 + title->get_w() + 10,
73 add_subwindow(title = new BC_Title(x1,
75 _("Translation block size:\n(W/H Percent of image)")));
76 add_subwindow(global_block_w = new BlockSize(plugin,
77 x1 + title->get_w() + 10,
79 &plugin->config.global_block_w));
80 add_subwindow(global_block_h = new BlockSize(plugin,
81 x1 + title->get_w() + 10 + global_block_w->get_w(),
83 &plugin->config.global_block_h));
85 add_subwindow(title = new BC_Title(x2,
87 _("Rotation block size:\n(W/H Percent of image)")));
88 add_subwindow(rotation_block_w = new BlockSize(plugin,
89 x2 + title->get_w() + 10,
91 &plugin->config.rotation_block_w));
92 add_subwindow(rotation_block_h = new BlockSize(plugin,
93 x2 + title->get_w() + 10 + rotation_block_w->get_w(),
95 &plugin->config.rotation_block_h));
98 add_subwindow(title = new BC_Title(x1, y, _("Translation search steps:")));
99 add_subwindow(global_search_positions = new GlobalSearchPositions(plugin,
100 x1 + title->get_w() + 10,
103 global_search_positions->create_objects();
105 add_subwindow(title = new BC_Title(x2, y, _("Rotation search steps:")));
106 add_subwindow(rotation_search_positions = new RotationSearchPositions(plugin,
107 x2 + title->get_w() + 10,
110 rotation_search_positions->create_objects();
113 add_subwindow(title = new BC_Title(x, y, _("Translation direction:")));
114 add_subwindow(mode3 = new Mode3(plugin,
116 x + title->get_w() + 10,
118 mode3->create_objects();
121 add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
122 add_subwindow(block_x = new MotionBlockX(plugin,
124 x + title->get_w() + 10,
126 add_subwindow(block_x_text = new MotionBlockXText(plugin,
128 x + title->get_w() + 10 + block_x->get_w() + 10,
132 add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
133 add_subwindow(block_y = new MotionBlockY(plugin,
135 x + title->get_w() + 10,
137 add_subwindow(block_y_text = new MotionBlockYText(plugin,
139 x + title->get_w() + 10 + block_y->get_w() + 10,
143 add_subwindow(title = new BC_Title(x, y + 10, _("Maximum absolute offset:")));
144 add_subwindow(magnitude = new MotionMagnitude(plugin,
145 x + title->get_w() + 10,
149 add_subwindow(title = new BC_Title(x, y + 10, _("Settling speed:")));
150 add_subwindow(return_speed = new MotionReturnSpeed(plugin,
151 x + title->get_w() + 10,
157 add_subwindow(vectors = new MotionDrawVectors(plugin,
164 add_subwindow(track_single = new TrackSingleFrame(plugin,
168 add_subwindow(title = new BC_Title(x + track_single->get_w() + 20,
170 _("Frame number:")));
171 add_subwindow(track_frame_number = new TrackFrameNumber(plugin,
173 x + track_single->get_w() + title->get_w() + 20,
177 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
183 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
190 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
191 add_subwindow(master_layer = new MasterLayer(plugin,
193 x + title->get_w() + 10,
195 master_layer->create_objects();
199 add_subwindow(title = new BC_Title(x, y, _("Action:")));
200 add_subwindow(mode1 = new Mode1(plugin,
202 x + title->get_w() + 10,
204 mode1->create_objects();
210 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
211 add_subwindow(mode2 = new Mode2(plugin,
213 x + title->get_w() + 10,
215 mode2->create_objects();
224 void MotionWindow::update_mode()
226 global_range_w->update(plugin->config.global_range_w,
229 global_range_h->update(plugin->config.global_range_h,
232 rotation_range->update(plugin->config.rotation_range,
235 vectors->update(plugin->config.draw_vectors);
236 global->update(plugin->config.global);
237 rotate->update(plugin->config.rotate);
241 WINDOW_CLOSE_EVENT(MotionWindow)
252 GlobalRange::GlobalRange(MotionMain *plugin,
262 this->plugin = plugin;
267 int GlobalRange::handle_event()
269 *value = (int)get_value();
270 plugin->send_configure_change();
277 RotationRange::RotationRange(MotionMain *plugin,
282 (int64_t)plugin->config.rotation_range,
283 (int64_t)MIN_ROTATION,
284 (int64_t)MAX_ROTATION)
286 this->plugin = plugin;
290 int RotationRange::handle_event()
292 plugin->config.rotation_range = (int)get_value();
293 plugin->send_configure_change();
304 BlockSize::BlockSize(MotionMain *plugin,
314 this->plugin = plugin;
319 int BlockSize::handle_event()
321 *value = (int)get_value();
322 plugin->send_configure_change();
338 GlobalSearchPositions::GlobalSearchPositions(MotionMain *plugin,
348 this->plugin = plugin;
350 void GlobalSearchPositions::create_objects()
352 add_item(new BC_MenuItem("64"));
353 add_item(new BC_MenuItem("128"));
354 add_item(new BC_MenuItem("256"));
355 add_item(new BC_MenuItem("512"));
356 add_item(new BC_MenuItem("1024"));
357 add_item(new BC_MenuItem("2048"));
358 add_item(new BC_MenuItem("4096"));
359 add_item(new BC_MenuItem("8192"));
360 add_item(new BC_MenuItem("16384"));
361 add_item(new BC_MenuItem("32768"));
362 add_item(new BC_MenuItem("65536"));
363 add_item(new BC_MenuItem("131072"));
364 char string[BCTEXTLEN];
365 sprintf(string, "%d", plugin->config.global_positions);
369 int GlobalSearchPositions::handle_event()
371 plugin->config.global_positions = atoi(get_text());
372 plugin->send_configure_change();
382 RotationSearchPositions::RotationSearchPositions(MotionMain *plugin,
392 this->plugin = plugin;
394 void RotationSearchPositions::create_objects()
396 add_item(new BC_MenuItem("4"));
397 add_item(new BC_MenuItem("8"));
398 add_item(new BC_MenuItem("16"));
399 add_item(new BC_MenuItem("32"));
400 char string[BCTEXTLEN];
401 sprintf(string, "%d", plugin->config.rotate_positions);
405 int RotationSearchPositions::handle_event()
407 plugin->config.rotate_positions = atoi(get_text());
408 plugin->send_configure_change();
419 MotionMagnitude::MotionMagnitude(MotionMain *plugin,
424 (int64_t)plugin->config.magnitude,
428 this->plugin = plugin;
431 int MotionMagnitude::handle_event()
433 plugin->config.magnitude = (int)get_value();
434 plugin->send_configure_change();
439 MotionReturnSpeed::MotionReturnSpeed(MotionMain *plugin,
444 (int64_t)plugin->config.return_speed,
448 this->plugin = plugin;
451 int MotionReturnSpeed::handle_event()
453 plugin->config.return_speed = (int)get_value();
454 plugin->send_configure_change();
462 MotionGlobal::MotionGlobal(MotionMain *plugin,
468 plugin->config.global,
469 _("Track translation"))
471 this->plugin = plugin;
475 int MotionGlobal::handle_event()
477 plugin->config.global = get_value();
478 plugin->send_configure_change();
482 MotionRotate::MotionRotate(MotionMain *plugin,
488 plugin->config.rotate,
491 this->plugin = plugin;
495 int MotionRotate::handle_event()
497 plugin->config.rotate = get_value();
498 plugin->send_configure_change();
506 MotionBlockX::MotionBlockX(MotionMain *plugin,
512 plugin->config.block_x,
516 this->plugin = plugin;
520 int MotionBlockX::handle_event()
522 plugin->config.block_x = get_value();
523 gui->block_x_text->update((float)plugin->config.block_x);
524 plugin->send_configure_change();
531 MotionBlockY::MotionBlockY(MotionMain *plugin,
537 (float)plugin->config.block_y,
541 this->plugin = plugin;
545 int MotionBlockY::handle_event()
547 plugin->config.block_y = get_value();
548 gui->block_y_text->update((float)plugin->config.block_y);
549 plugin->send_configure_change();
553 MotionBlockXText::MotionBlockXText(MotionMain *plugin,
561 (float)plugin->config.block_x)
563 this->plugin = plugin;
568 int MotionBlockXText::handle_event()
570 plugin->config.block_x = atof(get_text());
571 gui->block_x->update(plugin->config.block_x);
572 plugin->send_configure_change();
579 MotionBlockYText::MotionBlockYText(MotionMain *plugin,
587 (float)plugin->config.block_y)
589 this->plugin = plugin;
594 int MotionBlockYText::handle_event()
596 plugin->config.block_y = atof(get_text());
597 gui->block_y->update(plugin->config.block_y);
598 plugin->send_configure_change();
617 MotionDrawVectors::MotionDrawVectors(MotionMain *plugin,
623 plugin->config.draw_vectors,
627 this->plugin = plugin;
630 int MotionDrawVectors::handle_event()
632 plugin->config.draw_vectors = get_value();
633 plugin->send_configure_change();
644 TrackSingleFrame::TrackSingleFrame(MotionMain *plugin,
650 plugin->config.mode3 == MotionConfig::TRACK_SINGLE,
651 _("Track single frame"))
653 this->plugin = plugin;
657 int TrackSingleFrame::handle_event()
659 plugin->config.mode3 = MotionConfig::TRACK_SINGLE;
660 gui->track_previous->update(0);
661 gui->previous_same->update(0);
662 gui->track_frame_number->enable();
663 plugin->send_configure_change();
674 TrackFrameNumber::TrackFrameNumber(MotionMain *plugin,
678 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
680 this->plugin = plugin;
682 if(plugin->config.mode3 != MotionConfig::TRACK_SINGLE) disable();
685 int TrackFrameNumber::handle_event()
687 plugin->config.track_frame = atol(get_text());
688 plugin->send_configure_change();
698 TrackPreviousFrame::TrackPreviousFrame(MotionMain *plugin,
704 plugin->config.mode3 == MotionConfig::TRACK_PREVIOUS,
705 _("Track previous frame"))
707 this->plugin = plugin;
710 int TrackPreviousFrame::handle_event()
712 plugin->config.mode3 = MotionConfig::TRACK_PREVIOUS;
713 gui->track_single->update(0);
714 gui->previous_same->update(0);
715 gui->track_frame_number->disable();
716 plugin->send_configure_change();
727 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionMain *plugin,
733 plugin->config.mode3 == MotionConfig::PREVIOUS_SAME_BLOCK,
734 _("Previous frame same block"))
736 this->plugin = plugin;
739 int PreviousFrameSameBlock::handle_event()
741 plugin->config.mode3 = MotionConfig::PREVIOUS_SAME_BLOCK;
742 gui->track_single->update(0);
743 gui->track_previous->update(0);
744 gui->track_frame_number->disable();
745 plugin->send_configure_change();
756 MasterLayer::MasterLayer(MotionMain *plugin, MotionWindow *gui, int x, int y)
760 to_text(plugin->config.bottom_is_master))
762 this->plugin = plugin;
766 int MasterLayer::handle_event()
768 plugin->config.bottom_is_master = from_text(get_text());
769 plugin->send_configure_change();
773 void MasterLayer::create_objects()
775 add_item(new BC_MenuItem(to_text(0)));
776 add_item(new BC_MenuItem(to_text(1)));
779 int MasterLayer::from_text(char *text)
781 if(!strcmp(text, _("Top"))) return 0;
785 char* MasterLayer::to_text(int mode)
787 return mode ? _("Bottom") : _("Top");
790 int MasterLayer::calculate_w(MotionWindow *gui)
793 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
794 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
805 Mode1::Mode1(MotionMain *plugin, MotionWindow *gui, int x, int y)
809 to_text(plugin->config.mode1))
811 this->plugin = plugin;
815 int Mode1::handle_event()
817 plugin->config.mode1 = from_text(get_text());
818 plugin->send_configure_change();
822 void Mode1::create_objects()
824 add_item(new BC_MenuItem(to_text(MotionConfig::TRACK)));
825 add_item(new BC_MenuItem(to_text(MotionConfig::TRACK_PIXEL)));
826 add_item(new BC_MenuItem(to_text(MotionConfig::STABILIZE)));
827 add_item(new BC_MenuItem(to_text(MotionConfig::STABILIZE_PIXEL)));
828 add_item(new BC_MenuItem(to_text(MotionConfig::NOTHING)));
831 int Mode1::from_text(char *text)
833 if(!strcmp(text, _("Track Subpixel"))) return MotionConfig::TRACK;
834 if(!strcmp(text, _("Track Pixel"))) return MotionConfig::TRACK_PIXEL;
835 if(!strcmp(text, _("Stabilize Subpixel"))) return MotionConfig::STABILIZE;
836 if(!strcmp(text, _("Stabilize Pixel"))) return MotionConfig::STABILIZE_PIXEL;
837 if(!strcmp(text, _("Do Nothing"))) return MotionConfig::NOTHING;
840 char* Mode1::to_text(int mode)
844 case MotionConfig::TRACK:
845 return _("Track Subpixel");
847 case MotionConfig::TRACK_PIXEL:
848 return _("Track Pixel");
850 case MotionConfig::STABILIZE:
851 return _("Stabilize Subpixel");
853 case MotionConfig::STABILIZE_PIXEL:
854 return _("Stabilize Pixel");
856 case MotionConfig::NOTHING:
857 return _("Do Nothing");
862 int Mode1::calculate_w(MotionWindow *gui)
865 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::TRACK)));
866 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::TRACK_PIXEL)));
867 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::STABILIZE)));
868 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::STABILIZE_PIXEL)));
869 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::NOTHING)));
877 Mode2::Mode2(MotionMain *plugin, MotionWindow *gui, int x, int y)
881 to_text(plugin->config.mode2))
883 this->plugin = plugin;
887 int Mode2::handle_event()
889 plugin->config.mode2 = from_text(get_text());
890 plugin->send_configure_change();
894 void Mode2::create_objects()
896 add_item(new BC_MenuItem(to_text(MotionConfig::NO_CALCULATE)));
897 add_item(new BC_MenuItem(to_text(MotionConfig::RECALCULATE)));
898 add_item(new BC_MenuItem(to_text(MotionConfig::SAVE)));
899 add_item(new BC_MenuItem(to_text(MotionConfig::LOAD)));
902 int Mode2::from_text(char *text)
904 if(!strcmp(text, _("Don't Calculate"))) return MotionConfig::NO_CALCULATE;
905 if(!strcmp(text, _("Recalculate"))) return MotionConfig::RECALCULATE;
906 if(!strcmp(text, _("Save coords to /tmp"))) return MotionConfig::SAVE;
907 if(!strcmp(text, _("Load coords from /tmp"))) return MotionConfig::LOAD;
910 char* Mode2::to_text(int mode)
914 case MotionConfig::NO_CALCULATE:
915 return _("Don't Calculate");
917 case MotionConfig::RECALCULATE:
918 return _("Recalculate");
920 case MotionConfig::SAVE:
921 return _("Save coords to /tmp");
923 case MotionConfig::LOAD:
924 return _("Load coords from /tmp");
929 int Mode2::calculate_w(MotionWindow *gui)
932 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::NO_CALCULATE)));
933 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::RECALCULATE)));
934 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::SAVE)));
935 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionConfig::LOAD)));
948 Mode3::Mode3(MotionMain *plugin, MotionWindow *gui, int x, int y)
952 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
954 this->plugin = plugin;
958 int Mode3::handle_event()
960 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
961 plugin->send_configure_change();
965 void Mode3::create_objects()
967 add_item(new BC_MenuItem(to_text(1, 0)));
968 add_item(new BC_MenuItem(to_text(0, 1)));
969 add_item(new BC_MenuItem(to_text(0, 0)));
972 void Mode3::from_text(int *horizontal_only, int *vertical_only, char *text)
974 *horizontal_only = 0;
976 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
977 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
980 char* Mode3::to_text(int horizontal_only, int vertical_only)
982 if(horizontal_only) return _("Horizontal only");
983 if(vertical_only) return _("Vertical only");
987 int Mode3::calculate_w(MotionWindow *gui)
990 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
991 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
992 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));