96bb68211c24799d358e044a7edbba2f8d490f0c
[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, 600, 400, 600, 400, 0)
36 {
37         this->plugin = plugin;
38 }
39
40 Motion51Window::~Motion51Window()
41 {
42 }
43
44 void Motion51Window::create_objects()
45 {
46         int x = 10, y = 20;
47         int x0 = x, x1 = get_w()/2;
48         add_subwindow(sample_steps = new Motion51SampleSteps(plugin, x0=x, y, 120));
49         BC_Title *title = new BC_Title(x0+=sample_steps->get_w()+10, y, _("Samples"));
50         add_subwindow(title);
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;
56
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;
71
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;
90
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;
98
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;
102
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));
110
111         show_window(1);
112 }
113
114 void Motion51Window::update_gui()
115 {
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);
122
123         sample_r->update(config.sample_r);
124         char string[BCTEXTLEN];
125         sprintf(string, "%d", config.sample_steps);
126         sample_steps->set_text(string);
127
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);
132
133         draw_vectors->update(config.draw_vectors);
134         tracking_file->update(config.tracking_file);
135         enable_tracking->update(config.tracking);
136 }
137
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)
141 {
142         this->plugin = plugin;
143         this->gui = gui;
144         this->ttext = cstrdup(ttext);
145         this->value = value;
146         title = 0;
147 }
148
149 Motion51Limits::~Motion51Limits()
150 {
151         delete [] ttext;
152 }
153
154 void Motion51Limits::create_objects()
155 {
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));
160 }
161
162 int Motion51Limits::handle_event()
163 {
164         *value = atof(get_text());
165         plugin->send_configure_change();
166         return 1;
167 }
168
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)
172 {
173         this->plugin = plugin;
174         this->gui = gui;
175 };
176
177 int Motion51TrackingFile::handle_event()
178 {
179         strcpy(plugin->config.tracking_file, get_text());
180         plugin->send_configure_change();
181         return 1;
182 }
183
184
185 Motion51SampleSteps::Motion51SampleSteps(Motion51Main *plugin,
186         int x, int y, int w)
187  : BC_PopupMenu(x, y, w, "", 1)
188 {
189         this->plugin = plugin;
190 }
191
192 void Motion51SampleSteps::create_objects()
193 {
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);
208         set_text(string);
209 }
210
211 int Motion51SampleSteps::handle_event()
212 {
213         plugin->config.sample_steps = atoi(get_text());
214         plugin->send_configure_change();
215         return 1;
216 }
217
218
219
220 Motion51DrawVectors::Motion51DrawVectors(Motion51Main *plugin,
221         Motion51Window *gui, int x, int y)
222  : BC_CheckBox(x, y, plugin->config.draw_vectors, _("Draw vectors"))
223 {
224         this->gui = gui;
225         this->plugin = plugin;
226 }
227
228 int Motion51DrawVectors::handle_event()
229 {
230         plugin->config.draw_vectors = get_value();
231         plugin->send_configure_change();
232         return 1;
233 }
234
235
236 Motion51ResetConfig::Motion51ResetConfig(Motion51Main *plugin, Motion51Window *gui, int x, int y)
237  : BC_GenericButton(x, y, _("Reset defaults"))
238 {
239         this->plugin = plugin;
240         this->gui = gui;
241 }
242
243 int Motion51ResetConfig::handle_event()
244 {
245         plugin->config.init();
246         gui->update_gui();
247         plugin->send_configure_change();
248         return 1;
249 }
250
251 Motion51ResetTracking::Motion51ResetTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
252  : BC_GenericButton(x, y, _("Reset Tracking"))
253 {
254         this->plugin = plugin;
255         this->gui = gui;
256 }
257
258 int Motion51ResetTracking::handle_event()
259 {
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);
266         return 1;
267 }
268
269 Motion51EnableTracking::Motion51EnableTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
270  : BC_CheckBox(x, y, plugin->config.tracking,_("Enable Tracking"))
271 {
272         this->plugin = plugin;
273         this->gui = gui;
274 }
275
276 int Motion51EnableTracking::handle_event()
277 {
278         plugin->config.tracking = get_value();
279         plugin->send_configure_change();
280         return 1;
281 }
282