3 * Copyright (C) 2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "bcdisplayinfo.h"
26 #include "edlsession.h"
29 #include "motionwindow51.h"
31 #include "pluginserver.h"
33 Motion51Window::Motion51Window(Motion51Main *plugin)
34 : PluginClientWindow(plugin, xS(600), yS(400), xS(600), yS(400), 0)
36 this->plugin = plugin;
39 Motion51Window::~Motion51Window()
43 void Motion51Window::create_objects()
45 int xs10 = xS(10), xs30 = xS(30), xs120 = xS(120);
46 int ys5 = yS(5), ys10 = yS(10), ys20 = yS(20);
47 int x = xs10, y = ys20, xs72 = xS(72);
48 int x0 = x, x1 = get_w()/2;
49 add_subwindow(sample_steps = new Motion51SampleSteps(plugin, x0=x, y, xs120));
50 BC_Title *title = new BC_Title(x0+=sample_steps->get_w()+xs10, y, _("Samples"));
52 sample_steps->create_objects();
53 sample_r = new Motion51Limits(plugin, this, x1,y, _("Sample Radius%"),
54 &plugin->config.sample_r, 0.f,100.f, xs72);
55 sample_r->create_objects();
56 y += sample_r->get_h() + ys20;
58 block_x = new Motion51Limits(plugin, this, x0=x,y, _("Center X%"),
59 &plugin->config.block_x, 0.f, 100.f, xs72);
60 block_x->create_objects();
61 block_y = new Motion51Limits(plugin, this, x1,y, _("Center Y%"),
62 &plugin->config.block_y, 0.f, 100.f, xs72);
63 block_y->create_objects();
64 y += block_x->get_h() + ys10;
65 block_w = new Motion51Limits(plugin, this, x0,y, _("Search W%"),
66 &plugin->config.block_w, 0.f,100.f, xs72);
67 block_w->create_objects();
68 block_h = new Motion51Limits(plugin, this, x1,y, _("Search H%"),
69 &plugin->config.block_h, 0.f,100.f, xs72);
70 block_h->create_objects();
71 y += block_w->get_h() + ys10;
73 horiz_limit = new Motion51Limits(plugin, this, x0=x,y, _("Horiz shake limit%"),
74 &plugin->config.horiz_limit, 0.f, 75.f, xs72);
75 horiz_limit->create_objects();
76 shake_fade = new Motion51Limits(plugin, this, x1,y, _("Shake fade%"),
77 &plugin->config.shake_fade, 0.f, 75.f, xs72);
78 shake_fade->create_objects();
79 y += horiz_limit->get_h() + ys10;
80 vert_limit = new Motion51Limits(plugin, this, x0,y, _("Vert shake limit%"),
81 &plugin->config.vert_limit, 0.f, 75.f, xs72);
82 vert_limit->create_objects();
83 y += vert_limit->get_h() + ys10;
84 twist_limit = new Motion51Limits(plugin, this, x0,y, _("Twist limit%"),
85 &plugin->config.twist_limit, 0.f, 75.f, xs72);
86 twist_limit->create_objects();
87 twist_fade = new Motion51Limits(plugin, this, x1,y, _("Twist fade%"),
88 &plugin->config.twist_fade, 0.f, 75.f, xs72);
89 twist_fade->create_objects();
90 y += twist_fade->get_h() + ys20;
92 add_subwindow(draw_vectors = new Motion51DrawVectors(plugin, this, x, y));
93 add_subwindow(title = new BC_Title(x1, y, _("Tracking file:")));
94 y += draw_vectors->get_h() + ys5;
95 add_subwindow(enable_tracking = new Motion51EnableTracking(plugin, this, x, y));
96 add_subwindow(tracking_file = new Motion51TrackingFile(plugin,
97 plugin->config.tracking_file, this, x1, y, get_w()-xs30-x1));
98 y += enable_tracking->get_h() + ys20;
100 add_subwindow(reset_config = new Motion51ResetConfig(plugin, this, x0=x, y));
101 add_subwindow(reset_tracking = new Motion51ResetTracking(plugin, this, x1, y));
102 y += reset_config->get_h()+ys20;
104 int pef = client->server->mwindow->edl->session->video_every_frame;
105 add_subwindow(pef_title = new BC_Title(x, y,
106 !pef ? _("For best results\n"
107 " Set: Play every frame\n"
108 " Preferences-> Playback-> Video Out") :
109 _("Currently using: Play every frame"), MEDIUMFONT,
110 !pef ? RED : GREEN));
115 void Motion51Window::update_gui()
117 Motion51Config &config = plugin->config;
118 horiz_limit->update(config.horiz_limit);
119 vert_limit->update(config.vert_limit);
120 twist_limit->update(config.twist_limit);
121 shake_fade->update(config.shake_fade);
122 twist_fade->update(config.twist_fade);
124 sample_r->update(config.sample_r);
125 char string[BCTEXTLEN];
126 sprintf(string, "%d", config.sample_steps);
127 sample_steps->set_text(string);
129 block_w->update(config.block_w);
130 block_h->update(config.block_h);
131 block_x->update(config.block_x);
132 block_y->update(config.block_y);
134 draw_vectors->update(config.draw_vectors);
135 tracking_file->update(config.tracking_file);
136 enable_tracking->update(config.tracking);
139 Motion51Limits::Motion51Limits(Motion51Main *plugin, Motion51Window *gui, int x, int y,
140 const char *ttext, float *value, float min, float max, int ttbox_w)
141 : BC_TumbleTextBox(gui, *value, min, max, x, y, ttbox_w)
143 this->plugin = plugin;
145 this->ttext = cstrdup(ttext);
150 Motion51Limits::~Motion51Limits()
155 void Motion51Limits::create_objects()
157 BC_TumbleTextBox::create_objects();
158 int tx = BC_TumbleTextBox::get_x() + BC_TumbleTextBox::get_w() + xS(5);
159 int ty = BC_TumbleTextBox::get_y();
160 gui->add_subwindow(title = new BC_Title(tx,ty,ttext));
163 int Motion51Limits::handle_event()
165 *value = atof(get_text());
166 plugin->send_configure_change();
170 Motion51TrackingFile::Motion51TrackingFile(Motion51Main *plugin,
171 const char *filename, Motion51Window *gui, int x, int y, int w)
172 : BC_TextBox(x, y, w, 1, filename)
174 this->plugin = plugin;
178 int Motion51TrackingFile::handle_event()
180 strcpy(plugin->config.tracking_file, get_text());
181 plugin->send_configure_change();
186 Motion51SampleSteps::Motion51SampleSteps(Motion51Main *plugin,
188 : BC_PopupMenu(x, y, w, "", 1)
190 this->plugin = plugin;
193 void Motion51SampleSteps::create_objects()
195 add_item(new BC_MenuItem("16"));
196 add_item(new BC_MenuItem("32"));
197 add_item(new BC_MenuItem("64"));
198 add_item(new BC_MenuItem("128"));
199 add_item(new BC_MenuItem("256"));
200 add_item(new BC_MenuItem("512"));
201 add_item(new BC_MenuItem("1024"));
202 add_item(new BC_MenuItem("2048"));
203 add_item(new BC_MenuItem("4096"));
204 add_item(new BC_MenuItem("8192"));
205 add_item(new BC_MenuItem("16384"));
206 add_item(new BC_MenuItem("32768"));
207 char string[BCTEXTLEN];
208 sprintf(string, "%d", plugin->config.sample_steps);
212 int Motion51SampleSteps::handle_event()
214 plugin->config.sample_steps = atoi(get_text());
215 plugin->send_configure_change();
221 Motion51DrawVectors::Motion51DrawVectors(Motion51Main *plugin,
222 Motion51Window *gui, int x, int y)
223 : BC_CheckBox(x, y, plugin->config.draw_vectors, _("Draw vectors"))
226 this->plugin = plugin;
229 int Motion51DrawVectors::handle_event()
231 plugin->config.draw_vectors = get_value();
232 plugin->send_configure_change();
237 Motion51ResetConfig::Motion51ResetConfig(Motion51Main *plugin, Motion51Window *gui, int x, int y)
238 : BC_GenericButton(x, y, _("Reset defaults"))
240 this->plugin = plugin;
244 int Motion51ResetConfig::handle_event()
246 plugin->config.init();
248 plugin->send_configure_change();
252 Motion51ResetTracking::Motion51ResetTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
253 : BC_GenericButton(x, y, _("Reset Tracking"))
255 this->plugin = plugin;
259 int Motion51ResetTracking::handle_event()
261 plugin->set_tracking_path();
262 gui->tracking_file->update(plugin->config.tracking_file);
263 plugin->config.tracking = 0;
264 plugin->send_configure_change();
265 gui->enable_tracking->update(0);
266 ::remove(plugin->config.tracking_file);
270 Motion51EnableTracking::Motion51EnableTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
271 : BC_CheckBox(x, y, plugin->config.tracking,_("Enable Tracking"))
273 this->plugin = plugin;
277 int Motion51EnableTracking::handle_event()
279 plugin->config.tracking = get_value();
280 plugin->send_configure_change();