4 * Copyright (C) 2008 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"
23 #include "bcsignals.h"
27 #include "motionscan-hv.h"
28 #include "motionwindow.h"
39 MotionWindow::MotionWindow(MotionMain2 *plugin)
40 : PluginClientWindow(plugin, 680, 660, 680, 660, 0)
42 this->plugin = plugin;
45 MotionWindow::~MotionWindow()
49 void MotionWindow::create_objects()
51 int x1[] = { 10, get_w()/2 };
52 int x = 10, y = 10, y1 = 10;
56 for(int i = 0; i < TOTAL_POINTS; i++)
59 char *global_title[] =
64 add_subwindow(global[i] = new MotionGlobal(plugin,
68 &plugin->config.global[i],
72 add_subwindow(title = new BC_Title(x1[i],
74 _("Translation search radius:\n(W/H Percent of image)")));
75 add_subwindow(global_range_w[i] = new MotionPot(plugin,
76 x1[i] + title->get_w() + 10,
78 &plugin->config.global_range_w[i],
81 add_subwindow(global_range_h[i] = new MotionPot(plugin,
82 x1[i] + title->get_w() + 10 + global_range_w[i]->get_w(),
84 &plugin->config.global_range_h[i],
90 add_subwindow(title = new BC_Title(x1[i],
92 _("Translation search offset:\n(X/Y Percent of image)")));
93 add_subwindow(global_origin_x[i] = new MotionPot(plugin,
94 x1[i] + title->get_w() + 10,
96 &plugin->config.global_origin_x[i],
99 add_subwindow(global_origin_y[i] = new MotionPot(plugin,
100 x1[i] + title->get_w() + 10 + global_origin_x[i]->get_w(),
102 &plugin->config.global_origin_y[i],
107 add_subwindow(title = new BC_Title(x1[i],
109 _("Translation block size:\n(W/H Percent of image)")));
110 add_subwindow(global_block_w[i] = new MotionPot(plugin,
111 x1[i] + title->get_w() + 10,
113 &plugin->config.global_block_w[i],
116 add_subwindow(global_block_h[i] = new MotionPot(plugin,
117 x1[i] + title->get_w() + 10 + global_block_w[i]->get_w(),
119 &plugin->config.global_block_h[i],
125 add_subwindow(title = new BC_Title(x1[i], y + 10, _("Block X:")));
126 add_subwindow(block_x[i] = new MotionBlockX(plugin,
128 x1[i] + title->get_w() + 10,
131 add_subwindow(block_x_text[i] = new MotionBlockXText(plugin,
133 x1[i] + title->get_w() + 10 + block_x[i]->get_w() + 10,
138 add_subwindow(title = new BC_Title(x1[i], y + 10, _("Block Y:")));
139 add_subwindow(block_y[i] = new MotionBlockY(plugin,
141 x1[i] + title->get_w() + 10,
144 add_subwindow(block_y_text[i] = new MotionBlockYText(plugin,
146 x1[i] + title->get_w() + 10 + block_y[i]->get_w() + 10,
152 add_subwindow(vectors[i] = new MotionDrawVectors(plugin,
161 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
163 add_subwindow(title = new BC_Title(x, y, _("Search steps:")));
164 add_subwindow(global_search_positions = new GlobalSearchPositions(plugin,
165 x + title->get_w() + 10,
168 global_search_positions->create_objects();
171 add_subwindow(title = new BC_Title(x, y, _("Search directions:")));
172 add_subwindow(tracking_direction = new TrackingDirection(plugin,
174 x + title->get_w() + 10,
176 tracking_direction->create_objects();
179 add_subwindow(title = new BC_Title(x, y + 10, _("Maximum absolute offset:")));
180 add_subwindow(magnitude = new MotionMagnitude(plugin,
181 x + title->get_w() + 10,
185 add_subwindow(title = new BC_Title(x, y + 10, _("Settling speed:")));
186 add_subwindow(return_speed = new MotionReturnSpeed(plugin,
187 x + title->get_w() + 10,
192 add_subwindow(track_single = new TrackSingleFrame(plugin,
196 add_subwindow(title = new BC_Title(x + track_single->get_w() + 20,
198 _("Frame number:")));
199 add_subwindow(track_frame_number = new TrackFrameNumber(plugin,
201 x + track_single->get_w() + title->get_w() + 20,
203 if(plugin->config.tracking_object != MotionScan::TRACK_SINGLE)
204 track_frame_number->disable();
207 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
213 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
220 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
221 add_subwindow(master_layer = new MasterLayer(plugin,
223 x + title->get_w() + 10,
225 master_layer->create_objects();
229 add_subwindow(title = new BC_Title(x, y, _("Action:")));
230 add_subwindow(action = new Action(plugin,
232 x + title->get_w() + 10,
234 action->create_objects();
240 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
241 add_subwindow(calculation = new Calculation(plugin,
243 x + title->get_w() + 10,
245 calculation->create_objects();
253 void MotionWindow::update_mode()
255 for(int i = 0; i < TOTAL_POINTS; i++)
257 global_range_w[i]->update(plugin->config.global_range_w[i],
260 global_range_h[i]->update(plugin->config.global_range_h[i],
263 vectors[i]->update(plugin->config.draw_vectors[i]);
264 global[i]->update(plugin->config.global[i]);
280 MotionGlobal::MotionGlobal(MotionMain2 *plugin,
291 this->plugin = plugin;
296 int MotionGlobal::handle_event()
298 *value = get_value();
299 plugin->send_configure_change();
304 MotionPot::MotionPot(MotionMain2 *plugin,
316 this->plugin = plugin;
321 int MotionPot::handle_event()
323 *value = (int)get_value();
324 plugin->send_configure_change();
339 GlobalSearchPositions::GlobalSearchPositions(MotionMain2 *plugin,
349 this->plugin = plugin;
351 void GlobalSearchPositions::create_objects()
353 add_item(new BC_MenuItem("16"));
354 add_item(new BC_MenuItem("32"));
355 add_item(new BC_MenuItem("64"));
356 add_item(new BC_MenuItem("128"));
357 add_item(new BC_MenuItem("256"));
358 add_item(new BC_MenuItem("512"));
359 add_item(new BC_MenuItem("1024"));
360 add_item(new BC_MenuItem("2048"));
361 add_item(new BC_MenuItem("4096"));
362 add_item(new BC_MenuItem("8192"));
363 add_item(new BC_MenuItem("16384"));
364 add_item(new BC_MenuItem("32768"));
365 add_item(new BC_MenuItem("65536"));
366 add_item(new BC_MenuItem("131072"));
367 char string[BCTEXTLEN];
368 sprintf(string, "%d", plugin->config.global_positions);
372 int GlobalSearchPositions::handle_event()
374 plugin->config.global_positions = atoi(get_text());
375 plugin->send_configure_change();
390 MotionMagnitude::MotionMagnitude(MotionMain2 *plugin,
395 (int64_t)plugin->config.magnitude,
399 this->plugin = plugin;
402 int MotionMagnitude::handle_event()
404 plugin->config.magnitude = (int)get_value();
405 plugin->send_configure_change();
410 MotionReturnSpeed::MotionReturnSpeed(MotionMain2 *plugin,
415 (int64_t)plugin->config.return_speed,
419 this->plugin = plugin;
422 int MotionReturnSpeed::handle_event()
424 plugin->config.return_speed = (int)get_value();
425 plugin->send_configure_change();
433 MotionBlockX::MotionBlockX(MotionMain2 *plugin,
440 (float)plugin->config.block_x[number],
444 this->plugin = plugin;
446 this->number = number;
449 int MotionBlockX::handle_event()
451 plugin->config.block_x[number] = get_value();
452 gui->block_x_text[number]->update((float)plugin->config.block_x[number]);
453 plugin->send_configure_change();
460 MotionBlockY::MotionBlockY(MotionMain2 *plugin,
467 (float)plugin->config.block_y[number],
471 this->plugin = plugin;
473 this->number = number;
476 int MotionBlockY::handle_event()
478 plugin->config.block_y[number] = get_value();
479 gui->block_y_text[number]->update((float)plugin->config.block_y[number]);
480 plugin->send_configure_change();
484 MotionBlockXText::MotionBlockXText(MotionMain2 *plugin,
493 (float)plugin->config.block_x[number])
495 this->plugin = plugin;
497 this->number = number;
501 int MotionBlockXText::handle_event()
503 plugin->config.block_x[number] = atof(get_text());
504 gui->block_x[number]->update(plugin->config.block_x[number]);
505 plugin->send_configure_change();
512 MotionBlockYText::MotionBlockYText(MotionMain2 *plugin,
521 (float)plugin->config.block_y[number])
523 this->plugin = plugin;
525 this->number = number;
529 int MotionBlockYText::handle_event()
531 plugin->config.block_y[number] = atof(get_text());
532 gui->block_y[number]->update(plugin->config.block_y[number]);
533 plugin->send_configure_change();
552 MotionDrawVectors::MotionDrawVectors(MotionMain2 *plugin,
559 plugin->config.draw_vectors[number],
563 this->plugin = plugin;
564 this->number = number;
567 int MotionDrawVectors::handle_event()
569 plugin->config.draw_vectors[number] = get_value();
570 plugin->send_configure_change();
581 TrackSingleFrame::TrackSingleFrame(MotionMain2 *plugin,
587 plugin->config.tracking_object == MotionScan::TRACK_SINGLE,
588 _("Track single frame"))
590 this->plugin = plugin;
594 int TrackSingleFrame::handle_event()
596 plugin->config.tracking_object = MotionScan::TRACK_SINGLE;
597 gui->track_previous->update(0);
598 gui->previous_same->update(0);
599 gui->track_frame_number->enable();
600 plugin->send_configure_change();
611 TrackFrameNumber::TrackFrameNumber(MotionMain2 *plugin,
615 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
617 this->plugin = plugin;
621 int TrackFrameNumber::handle_event()
623 plugin->config.track_frame = atol(get_text());
624 plugin->send_configure_change();
634 TrackPreviousFrame::TrackPreviousFrame(MotionMain2 *plugin,
640 plugin->config.tracking_object == MotionScan::TRACK_PREVIOUS,
641 _("Track previous frame"))
643 this->plugin = plugin;
646 int TrackPreviousFrame::handle_event()
648 plugin->config.tracking_object = MotionScan::TRACK_PREVIOUS;
649 gui->track_single->update(0);
650 gui->previous_same->update(0);
651 gui->track_frame_number->disable();
652 plugin->send_configure_change();
663 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionMain2 *plugin,
669 plugin->config.tracking_object == MotionScan::PREVIOUS_SAME_BLOCK,
670 _("Previous frame same block"))
672 this->plugin = plugin;
675 int PreviousFrameSameBlock::handle_event()
677 plugin->config.tracking_object = MotionScan::PREVIOUS_SAME_BLOCK;
678 gui->track_single->update(0);
679 gui->track_previous->update(0);
680 gui->track_frame_number->disable();
681 plugin->send_configure_change();
692 MasterLayer::MasterLayer(MotionMain2 *plugin, MotionWindow *gui, int x, int y)
696 to_text(plugin->config.bottom_is_master))
698 this->plugin = plugin;
702 int MasterLayer::handle_event()
704 plugin->config.bottom_is_master = from_text(get_text());
705 plugin->send_configure_change();
709 void MasterLayer::create_objects()
711 add_item(new BC_MenuItem(to_text(0)));
712 add_item(new BC_MenuItem(to_text(1)));
715 int MasterLayer::from_text(char *text)
717 if(!strcmp(text, _("Top"))) return 0;
721 char* MasterLayer::to_text(int mode)
723 return mode ? _("Bottom") : _("Top");
726 int MasterLayer::calculate_w(MotionWindow *gui)
729 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
730 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
741 Action::Action(MotionMain2 *plugin, MotionWindow *gui, int x, int y)
745 to_text(plugin->config.action))
747 this->plugin = plugin;
751 int Action::handle_event()
753 plugin->config.action = from_text(get_text());
754 plugin->send_configure_change();
758 void Action::create_objects()
760 add_item(new BC_MenuItem(to_text(MotionScan::TRACK)));
761 add_item(new BC_MenuItem(to_text(MotionScan::TRACK_PIXEL)));
762 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE)));
763 add_item(new BC_MenuItem(to_text(MotionScan::STABILIZE_PIXEL)));
764 add_item(new BC_MenuItem(to_text(MotionScan::NOTHING)));
767 int Action::from_text(char *text)
769 if(!strcmp(text, _("Track"))) return MotionScan::TRACK;
770 if(!strcmp(text, _("Track Pixel"))) return MotionScan::TRACK_PIXEL;
771 if(!strcmp(text, _("Stabilize"))) return MotionScan::STABILIZE;
772 if(!strcmp(text, _("Stabilize Pixel"))) return MotionScan::STABILIZE_PIXEL;
773 if(!strcmp(text, _("Do Nothing"))) return MotionScan::NOTHING;
777 char* Action::to_text(int mode)
781 case MotionScan::TRACK:
784 case MotionScan::TRACK_PIXEL:
785 return _("Track Pixel");
787 case MotionScan::STABILIZE:
788 return _("Stabilize");
790 case MotionScan::STABILIZE_PIXEL:
791 return _("Stabilize Pixel");
793 case MotionScan::NOTHING:
794 return _("Do Nothing");
802 int Action::calculate_w(MotionWindow *gui)
805 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK)));
806 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::TRACK_PIXEL)));
807 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE)));
808 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE_PIXEL)));
809 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NOTHING)));
817 Calculation::Calculation(MotionMain2 *plugin, MotionWindow *gui, int x, int y)
821 to_text(plugin->config.calculation))
823 this->plugin = plugin;
827 int Calculation::handle_event()
829 plugin->config.calculation = from_text(get_text());
830 plugin->send_configure_change();
834 void Calculation::create_objects()
836 add_item(new BC_MenuItem(to_text(MotionScan::NO_CALCULATE)));
837 add_item(new BC_MenuItem(to_text(MotionScan::CALCULATE)));
838 add_item(new BC_MenuItem(to_text(MotionScan::SAVE)));
839 add_item(new BC_MenuItem(to_text(MotionScan::LOAD)));
842 int Calculation::from_text(char *text)
844 if(!strcmp(text, _("Don't Calculate"))) return MotionScan::NO_CALCULATE;
845 if(!strcmp(text, _("Recalculate"))) return MotionScan::CALCULATE;
846 if(!strcmp(text, _("Save coords to /tmp"))) return MotionScan::SAVE;
847 if(!strcmp(text, _("Load coords from /tmp"))) return MotionScan::LOAD;
851 char* Calculation::to_text(int mode)
855 case MotionScan::NO_CALCULATE:
856 return _("Don't Calculate");
858 case MotionScan::CALCULATE:
859 return _("Recalculate");
861 case MotionScan::SAVE:
862 return _("Save coords to /tmp");
864 case MotionScan::LOAD:
865 return _("Load coords from /tmp");
873 int Calculation::calculate_w(MotionWindow *gui)
876 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NO_CALCULATE)));
877 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::CALCULATE)));
878 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::SAVE)));
879 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::LOAD)));
892 TrackingDirection::TrackingDirection(MotionMain2 *plugin, MotionWindow *gui, int x, int y)
896 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
898 this->plugin = plugin;
902 int TrackingDirection::handle_event()
904 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
905 plugin->send_configure_change();
909 void TrackingDirection::create_objects()
911 add_item(new BC_MenuItem(to_text(1, 0)));
912 add_item(new BC_MenuItem(to_text(0, 1)));
913 add_item(new BC_MenuItem(to_text(0, 0)));
916 void TrackingDirection::from_text(int *horizontal_only, int *vertical_only, char *text)
918 *horizontal_only = 0;
920 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
921 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
924 char* TrackingDirection::to_text(int horizontal_only, int vertical_only)
926 if(horizontal_only) return _("Horizontal only");
927 if(vertical_only) return _("Vertical only");
931 int TrackingDirection::calculate_w(MotionWindow *gui)
934 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
935 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
936 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));