c84305bf8002881554212415f4b987814e4647fe
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / motion51 / motionwindow51.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2012 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "cstrdup.h"
25 #include "edl.h"
26 #include "fonts.h"
27 #include "edlsession.h"
28 #include "language.h"
29 #include "motion51.h"
30 #include "motionwindow51.h"
31 #include "mwindow.h"
32 #include "pluginserver.h"
33
34 Motion51Window::Motion51Window(Motion51Main *plugin)
35  : PluginClientWindow(plugin, xS(600), yS(400), xS(600), yS(400), 0)
36 {
37         this->plugin = plugin;
38 }
39
40 Motion51Window::~Motion51Window()
41 {
42 }
43
44 void Motion51Window::create_objects()
45 {
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"));
52         add_subwindow(title);
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;
58
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;
73
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;
92
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;
100
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;
104
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));
112
113         show_window(1);
114 }
115
116 void Motion51Window::update_gui()
117 {
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);
124
125         sample_r->update(config.sample_r);
126         char string[BCTEXTLEN];
127         sprintf(string, "%d", config.sample_steps);
128         sample_steps->set_text(string);
129
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);
134
135         draw_vectors->update(config.draw_vectors);
136         tracking_file->update(config.tracking_file);
137         enable_tracking->update(config.tracking);
138 }
139
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)
143 {
144         this->plugin = plugin;
145         this->gui = gui;
146         this->ttext = cstrdup(ttext);
147         this->value = value;
148         title = 0;
149 }
150
151 Motion51Limits::~Motion51Limits()
152 {
153         delete [] ttext;
154 }
155
156 void Motion51Limits::create_objects()
157 {
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));
162 }
163
164 int Motion51Limits::handle_event()
165 {
166         *value = atof(get_text());
167         plugin->send_configure_change();
168         return 1;
169 }
170
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)
174 {
175         this->plugin = plugin;
176         this->gui = gui;
177 };
178
179 int Motion51TrackingFile::handle_event()
180 {
181         strcpy(plugin->config.tracking_file, get_text());
182         plugin->send_configure_change();
183         return 1;
184 }
185
186
187 Motion51SampleSteps::Motion51SampleSteps(Motion51Main *plugin,
188         int x, int y, int w)
189  : BC_PopupMenu(x, y, w, "", 1)
190 {
191         this->plugin = plugin;
192 }
193
194 void Motion51SampleSteps::create_objects()
195 {
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);
210         set_text(string);
211 }
212
213 int Motion51SampleSteps::handle_event()
214 {
215         plugin->config.sample_steps = atoi(get_text());
216         plugin->send_configure_change();
217         return 1;
218 }
219
220
221
222 Motion51DrawVectors::Motion51DrawVectors(Motion51Main *plugin,
223         Motion51Window *gui, int x, int y)
224  : BC_CheckBox(x, y, plugin->config.draw_vectors, _("Draw vectors"))
225 {
226         this->gui = gui;
227         this->plugin = plugin;
228 }
229
230 int Motion51DrawVectors::handle_event()
231 {
232         plugin->config.draw_vectors = get_value();
233         plugin->send_configure_change();
234         return 1;
235 }
236
237
238 Motion51ResetConfig::Motion51ResetConfig(Motion51Main *plugin, Motion51Window *gui, int x, int y)
239  : BC_GenericButton(x, y, _("Reset defaults"))
240 {
241         this->plugin = plugin;
242         this->gui = gui;
243 }
244
245 int Motion51ResetConfig::handle_event()
246 {
247         plugin->config.init();
248         gui->update_gui();
249         plugin->send_configure_change();
250         return 1;
251 }
252
253 Motion51ResetTracking::Motion51ResetTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
254  : BC_GenericButton(x, y, _("Reset Tracking"))
255 {
256         this->plugin = plugin;
257         this->gui = gui;
258 }
259
260 int Motion51ResetTracking::handle_event()
261 {
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);
268         return 1;
269 }
270
271 Motion51EnableTracking::Motion51EnableTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
272  : BC_CheckBox(x, y, plugin->config.tracking,_("Enable Tracking"))
273 {
274         this->plugin = plugin;
275         this->gui = gui;
276 }
277
278 int Motion51EnableTracking::handle_event()
279 {
280         plugin->config.tracking = get_value();
281         plugin->send_configure_change();
282         return 1;
283 }
284