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"
27 #include "edlsession.h"
30 #include "motionwindow51.h"
32 #include "pluginserver.h"
34 Motion51Window::Motion51Window(Motion51Main *plugin)
35 : PluginClientWindow(plugin, xS(600), yS(400), xS(600), yS(400), 0)
37 this->plugin = plugin;
40 Motion51Window::~Motion51Window()
44 void Motion51Window::create_objects()
46 int xs10 = xS(10), xs30 = xS(30), xs120 = xS(120);
47 int ys5 = yS(5), ys10 = yS(10), ys20 = yS(20);
48 int x = xs10, y = ys20, xs72 = xS(72);
49 int x0 = x, x1 = get_w()/2;
50 add_subwindow(sample_steps = new Motion51SampleSteps(plugin, x0=x, y, xs120));
51 BC_Title *title = new BC_Title(x0+=sample_steps->get_w()+xs10, y, _("Samples"));
53 sample_steps->create_objects();
54 sample_r = new Motion51Limits(plugin, this, x1,y, _("Sample Radius%"),
55 &plugin->config.sample_r, 0.f,100.f, xs72);
56 sample_r->create_objects();
57 y += sample_r->get_h() + ys20;
59 block_x = new Motion51Limits(plugin, this, x0=x,y, _("Center X%"),
60 &plugin->config.block_x, 0.f, 100.f, xs72);
61 block_x->create_objects();
62 block_y = new Motion51Limits(plugin, this, x1,y, _("Center Y%"),
63 &plugin->config.block_y, 0.f, 100.f, xs72);
64 block_y->create_objects();
65 y += block_x->get_h() + ys10;
66 block_w = new Motion51Limits(plugin, this, x0,y, _("Search W%"),
67 &plugin->config.block_w, 0.f,100.f, xs72);
68 block_w->create_objects();
69 block_h = new Motion51Limits(plugin, this, x1,y, _("Search H%"),
70 &plugin->config.block_h, 0.f,100.f, xs72);
71 block_h->create_objects();
72 y += block_w->get_h() + ys10;
74 horiz_limit = new Motion51Limits(plugin, this, x0=x,y, _("Horiz shake limit%"),
75 &plugin->config.horiz_limit, 0.f, 75.f, xs72);
76 horiz_limit->create_objects();
77 shake_fade = new Motion51Limits(plugin, this, x1,y, _("Shake fade%"),
78 &plugin->config.shake_fade, 0.f, 75.f, xs72);
79 shake_fade->create_objects();
80 y += horiz_limit->get_h() + ys10;
81 vert_limit = new Motion51Limits(plugin, this, x0,y, _("Vert shake limit%"),
82 &plugin->config.vert_limit, 0.f, 75.f, xs72);
83 vert_limit->create_objects();
84 y += vert_limit->get_h() + ys10;
85 twist_limit = new Motion51Limits(plugin, this, x0,y, _("Twist limit%"),
86 &plugin->config.twist_limit, 0.f, 75.f, xs72);
87 twist_limit->create_objects();
88 twist_fade = new Motion51Limits(plugin, this, x1,y, _("Twist fade%"),
89 &plugin->config.twist_fade, 0.f, 75.f, xs72);
90 twist_fade->create_objects();
91 y += twist_fade->get_h() + ys20;
93 add_subwindow(draw_vectors = new Motion51DrawVectors(plugin, this, x, y));
94 add_subwindow(title = new BC_Title(x1, y, _("Tracking file:")));
95 y += draw_vectors->get_h() + ys5;
96 add_subwindow(enable_tracking = new Motion51EnableTracking(plugin, this, x, y));
97 add_subwindow(tracking_file = new Motion51TrackingFile(plugin,
98 plugin->config.tracking_file, this, x1, y, get_w()-xs30-x1));
99 y += enable_tracking->get_h() + ys20;
101 add_subwindow(reset_config = new Motion51ResetConfig(plugin, this, x0=x, y));
102 add_subwindow(reset_tracking = new Motion51ResetTracking(plugin, this, x1, y));
103 y += reset_config->get_h()+ys20;
105 int pef = client->server->mwindow->edl->session->video_every_frame;
106 add_subwindow(pef_title = new BC_Title(x, y,
107 !pef ? _("For best results\n"
108 " Set: Play every frame\n"
109 " Preferences-> Playback-> Video Out") :
110 _("Currently using: Play every frame"), MEDIUMFONT,
111 !pef ? RED : GREEN));
116 void Motion51Window::update_gui()
118 Motion51Config &config = plugin->config;
119 horiz_limit->update(config.horiz_limit);
120 vert_limit->update(config.vert_limit);
121 twist_limit->update(config.twist_limit);
122 shake_fade->update(config.shake_fade);
123 twist_fade->update(config.twist_fade);
125 sample_r->update(config.sample_r);
126 char string[BCTEXTLEN];
127 sprintf(string, "%d", config.sample_steps);
128 sample_steps->set_text(string);
130 block_w->update(config.block_w);
131 block_h->update(config.block_h);
132 block_x->update(config.block_x);
133 block_y->update(config.block_y);
135 draw_vectors->update(config.draw_vectors);
136 tracking_file->update(config.tracking_file);
137 enable_tracking->update(config.tracking);
140 Motion51Limits::Motion51Limits(Motion51Main *plugin, Motion51Window *gui, int x, int y,
141 const char *ttext, float *value, float min, float max, int ttbox_w)
142 : BC_TumbleTextBox(gui, *value, min, max, x, y, ttbox_w)
144 this->plugin = plugin;
146 this->ttext = cstrdup(ttext);
151 Motion51Limits::~Motion51Limits()
156 void Motion51Limits::create_objects()
158 BC_TumbleTextBox::create_objects();
159 int tx = BC_TumbleTextBox::get_x() + BC_TumbleTextBox::get_w() + xS(5);
160 int ty = BC_TumbleTextBox::get_y();
161 gui->add_subwindow(title = new BC_Title(tx,ty,ttext));
164 int Motion51Limits::handle_event()
166 *value = atof(get_text());
167 plugin->send_configure_change();
171 Motion51TrackingFile::Motion51TrackingFile(Motion51Main *plugin,
172 const char *filename, Motion51Window *gui, int x, int y, int w)
173 : BC_TextBox(x, y, w, 1, filename)
175 this->plugin = plugin;
179 int Motion51TrackingFile::handle_event()
181 strcpy(plugin->config.tracking_file, get_text());
182 plugin->send_configure_change();
187 Motion51SampleSteps::Motion51SampleSteps(Motion51Main *plugin,
189 : BC_PopupMenu(x, y, w, "", 1)
191 this->plugin = plugin;
194 void Motion51SampleSteps::create_objects()
196 add_item(new BC_MenuItem("16"));
197 add_item(new BC_MenuItem("32"));
198 add_item(new BC_MenuItem("64"));
199 add_item(new BC_MenuItem("128"));
200 add_item(new BC_MenuItem("256"));
201 add_item(new BC_MenuItem("512"));
202 add_item(new BC_MenuItem("1024"));
203 add_item(new BC_MenuItem("2048"));
204 add_item(new BC_MenuItem("4096"));
205 add_item(new BC_MenuItem("8192"));
206 add_item(new BC_MenuItem("16384"));
207 add_item(new BC_MenuItem("32768"));
208 char string[BCTEXTLEN];
209 sprintf(string, "%d", plugin->config.sample_steps);
213 int Motion51SampleSteps::handle_event()
215 plugin->config.sample_steps = atoi(get_text());
216 plugin->send_configure_change();
222 Motion51DrawVectors::Motion51DrawVectors(Motion51Main *plugin,
223 Motion51Window *gui, int x, int y)
224 : BC_CheckBox(x, y, plugin->config.draw_vectors, _("Draw vectors"))
227 this->plugin = plugin;
230 int Motion51DrawVectors::handle_event()
232 plugin->config.draw_vectors = get_value();
233 plugin->send_configure_change();
238 Motion51ResetConfig::Motion51ResetConfig(Motion51Main *plugin, Motion51Window *gui, int x, int y)
239 : BC_GenericButton(x, y, _("Reset defaults"))
241 this->plugin = plugin;
245 int Motion51ResetConfig::handle_event()
247 plugin->config.init();
249 plugin->send_configure_change();
253 Motion51ResetTracking::Motion51ResetTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
254 : BC_GenericButton(x, y, _("Reset Tracking"))
256 this->plugin = plugin;
260 int Motion51ResetTracking::handle_event()
262 plugin->set_tracking_path();
263 gui->tracking_file->update(plugin->config.tracking_file);
264 plugin->config.tracking = 0;
265 plugin->send_configure_change();
266 gui->enable_tracking->update(0);
267 ::remove(plugin->config.tracking_file);
271 Motion51EnableTracking::Motion51EnableTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
272 : BC_CheckBox(x, y, plugin->config.tracking,_("Enable Tracking"))
274 this->plugin = plugin;
278 int Motion51EnableTracking::handle_event()
280 plugin->config.tracking = get_value();
281 plugin->send_configure_change();