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, 600, 400, 600, 400, 0)
37 this->plugin = plugin;
40 Motion51Window::~Motion51Window()
44 void Motion51Window::create_objects()
47 int x0 = x, x1 = get_w()/2;
48 add_subwindow(sample_steps = new Motion51SampleSteps(plugin, x0=x, y, 72));
49 BC_Title *title = new BC_Title(x0+=sample_steps->get_w()+10, y, _("Samples"));
51 sample_steps->create_objects();
52 sample_r = new Motion51Limits(plugin, this, x1,y, _("Sample Radius%"),
53 &plugin->config.sample_r, 0.f,100.f, 72);
54 sample_r->create_objects();
55 y += sample_r->get_h() + 20;
57 block_x = new Motion51Limits(plugin, this, x0=x,y, _("Center X%"),
58 &plugin->config.block_x, 0.f, 100.f, 72);
59 block_x->create_objects();
60 block_y = new Motion51Limits(plugin, this, x1,y, _("Center Y%"),
61 &plugin->config.block_y, 0.f, 100.f, 72);
62 block_y->create_objects();
63 y += block_x->get_h() + 10;
64 block_w = new Motion51Limits(plugin, this, x0,y, _("Search W%"),
65 &plugin->config.block_w, 0.f,100.f, 72);
66 block_w->create_objects();
67 block_h = new Motion51Limits(plugin, this, x1,y, _("Search H%"),
68 &plugin->config.block_h, 0.f,100.f, 72);
69 block_h->create_objects();
70 y += block_w->get_h() + 10;
72 horiz_limit = new Motion51Limits(plugin, this, x0=x,y, _("Horiz shake limit%"),
73 &plugin->config.horiz_limit, 0.f, 75.f, 72);
74 horiz_limit->create_objects();
75 shake_fade = new Motion51Limits(plugin, this, x1,y, _("Shake fade%"),
76 &plugin->config.shake_fade, 0.f, 75.f, 72);
77 shake_fade->create_objects();
78 y += horiz_limit->get_h() + 10;
79 vert_limit = new Motion51Limits(plugin, this, x0,y, _("Vert shake limit%"),
80 &plugin->config.vert_limit, 0.f, 75.f, 72);
81 vert_limit->create_objects();
82 y += vert_limit->get_h() + 10;
83 twist_limit = new Motion51Limits(plugin, this, x0,y, _("Twist limit%"),
84 &plugin->config.twist_limit, 0.f, 75.f, 72);
85 twist_limit->create_objects();
86 twist_fade = new Motion51Limits(plugin, this, x1,y, _("Twist fade%"),
87 &plugin->config.twist_fade, 0.f, 75.f, 72);
88 twist_fade->create_objects();
89 y += twist_fade->get_h() + 20;
91 add_subwindow(draw_vectors = new Motion51DrawVectors(plugin, this, x, y));
92 add_subwindow(title = new BC_Title(x1, y, _("Tracking file:")));
93 y += draw_vectors->get_h() + 5;
94 add_subwindow(enable_tracking = new Motion51EnableTracking(plugin, this, x, y));
95 add_subwindow(tracking_file = new Motion51TrackingFile(plugin,
96 plugin->config.tracking_file, this, x1, y, get_w()-30-x1));
97 y += enable_tracking->get_h() + 20;
99 add_subwindow(reset_config = new Motion51ResetConfig(plugin, this, x0=x, y));
100 add_subwindow(reset_tracking = new Motion51ResetTracking(plugin, this, x1, y));
101 y += reset_config->get_h()+20;
103 int pef = client->server->mwindow->edl->session->video_every_frame;
104 add_subwindow(pef_title = new BC_Title(x, y,
105 !pef ? _("For best results\n"
106 " Set: Play every frame\n"
107 " Preferences-> Playback-> Video Out") :
108 _("Currently using: Play every frame"), MEDIUMFONT,
109 !pef ? RED : GREEN));
114 void Motion51Window::update_gui()
116 Motion51Config &config = plugin->config;
117 horiz_limit->update(config.horiz_limit);
118 vert_limit->update(config.vert_limit);
119 twist_limit->update(config.twist_limit);
120 shake_fade->update(config.shake_fade);
121 twist_fade->update(config.twist_fade);
123 sample_r->update(config.sample_r);
124 char string[BCTEXTLEN];
125 sprintf(string, "%d", config.sample_steps);
126 sample_steps->set_text(string);
128 block_w->update(config.block_w);
129 block_h->update(config.block_h);
130 block_x->update(config.block_x);
131 block_y->update(config.block_y);
133 draw_vectors->update(config.draw_vectors);
134 tracking_file->update(config.tracking_file);
135 enable_tracking->update(config.tracking);
138 Motion51Limits::Motion51Limits(Motion51Main *plugin, Motion51Window *gui, int x, int y,
139 const char *ttext, float *value, float min, float max, int ttbox_w)
140 : BC_TumbleTextBox(gui, *value, min, max, x, y, ttbox_w)
142 this->plugin = plugin;
144 this->ttext = cstrdup(ttext);
149 Motion51Limits::~Motion51Limits()
154 void Motion51Limits::create_objects()
156 BC_TumbleTextBox::create_objects();
157 int tx = BC_TumbleTextBox::get_x() + BC_TumbleTextBox::get_w() + 5;
158 int ty = BC_TumbleTextBox::get_y();
159 gui->add_subwindow(title = new BC_Title(tx,ty,ttext));
162 int Motion51Limits::handle_event()
164 *value = atof(get_text());
165 plugin->send_configure_change();
169 Motion51TrackingFile::Motion51TrackingFile(Motion51Main *plugin,
170 const char *filename, Motion51Window *gui, int x, int y, int w)
171 : BC_TextBox(x, y, w, 1, filename)
173 this->plugin = plugin;
177 int Motion51TrackingFile::handle_event()
179 strcpy(plugin->config.tracking_file, get_text());
180 plugin->send_configure_change();
185 Motion51SampleSteps::Motion51SampleSteps(Motion51Main *plugin,
187 : BC_PopupMenu(x, y, w, "", 1)
189 this->plugin = plugin;
192 void Motion51SampleSteps::create_objects()
194 add_item(new BC_MenuItem("16"));
195 add_item(new BC_MenuItem("32"));
196 add_item(new BC_MenuItem("64"));
197 add_item(new BC_MenuItem("128"));
198 add_item(new BC_MenuItem("256"));
199 add_item(new BC_MenuItem("512"));
200 add_item(new BC_MenuItem("1024"));
201 add_item(new BC_MenuItem("2048"));
202 add_item(new BC_MenuItem("4096"));
203 add_item(new BC_MenuItem("8192"));
204 add_item(new BC_MenuItem("16384"));
205 add_item(new BC_MenuItem("32768"));
206 char string[BCTEXTLEN];
207 sprintf(string, "%d", plugin->config.sample_steps);
211 int Motion51SampleSteps::handle_event()
213 plugin->config.sample_steps = atoi(get_text());
214 plugin->send_configure_change();
220 Motion51DrawVectors::Motion51DrawVectors(Motion51Main *plugin,
221 Motion51Window *gui, int x, int y)
222 : BC_CheckBox(x, y, plugin->config.draw_vectors, _("Draw vectors"))
225 this->plugin = plugin;
228 int Motion51DrawVectors::handle_event()
230 plugin->config.draw_vectors = get_value();
231 plugin->send_configure_change();
236 Motion51ResetConfig::Motion51ResetConfig(Motion51Main *plugin, Motion51Window *gui, int x, int y)
237 : BC_GenericButton(x, y, _("Reset defaults"))
239 this->plugin = plugin;
243 int Motion51ResetConfig::handle_event()
245 plugin->config.init();
247 plugin->send_configure_change();
251 Motion51ResetTracking::Motion51ResetTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
252 : BC_GenericButton(x, y, _("Reset Tracking"))
254 this->plugin = plugin;
258 int Motion51ResetTracking::handle_event()
260 plugin->set_tracking_path();
261 gui->tracking_file->update(plugin->config.tracking_file);
262 plugin->config.tracking = 0;
263 plugin->send_configure_change();
264 gui->enable_tracking->update(0);
265 ::remove(plugin->config.tracking_file);
269 Motion51EnableTracking::Motion51EnableTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
270 : BC_CheckBox(x, y, plugin->config.tracking,_("Enable Tracking"))
272 this->plugin = plugin;
276 int Motion51EnableTracking::handle_event()
278 plugin->config.tracking = get_value();
279 plugin->send_configure_change();