change to id based refs for plugins, save plugin on/off in edit drag/drop, fix transi...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / findobj / findobjwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-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 "dragcheckbox.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "language.h"
28 #include "findobj.h"
29 #include "findobjwindow.h"
30 #include "plugin.h"
31 #include "pluginserver.h"
32 #include "theme.h"
33 #include "track.h"
34
35
36 FindObjWindow::FindObjWindow(FindObjMain *plugin)
37  : PluginClientWindow(plugin, xS(500), yS(700), xS(500), yS(700), 0)
38 {
39         this->plugin = plugin;
40 }
41
42 FindObjWindow::~FindObjWindow()
43 {
44 }
45
46 void FindObjWindow::create_objects()
47 {
48         int xs10 = xS(10), xs15 = xS(15), xs100 = xS(100), xs200 = xS(200);
49         int ys5 = yS(5), ys10 = yS(10), ys15 = yS(15), ys40 = yS(40);
50         int x = xs10, y = ys10, x1 = x, x2 = get_w()*1/3, x3 = get_w()*2/3;
51         plugin->load_configuration();
52
53         BC_Title *title;
54         add_subwindow(title = new BC_Title(x1, y, _("Mode:")));
55         add_subwindow(mode = new FindObjMode(plugin, this,
56                 x1 + xs100, y));
57         add_subwindow(reset = new FindObjReset(plugin, this, get_w()-xs15, y));
58         mode->create_objects();
59         y += mode->get_h() + ys10;
60         int y0 = y;
61         add_subwindow(title = new BC_Title(x1, y, _("Algorithm:")));
62         add_subwindow(algorithm = new FindObjAlgorithm(plugin, this,
63                 x1 + xs100, y));
64         algorithm->create_objects();
65         y += algorithm->get_h() + plugin->get_theme()->widget_border;
66         add_subwindow(use_flann = new FindObjUseFlann(plugin, this, x, y));
67         y += use_flann->get_h() + ys10;
68
69         int y1 = y;  y = y0;
70         add_subwindow(replace_object = new FindObjReplace(plugin, this,x3, y));
71         y += replace_object->get_h() + ys10;
72         add_subwindow(draw_match = new FindObjDrawMatch(plugin, this, x3, y));
73         y += draw_match->get_h() + ys10;
74         add_subwindow(aspect = new FindObjAspect(plugin, this, x3, y));
75         y += aspect->get_h() + ys10;
76         add_subwindow(scale = new FindObjScale(plugin, this, x3, y));
77         y += scale->get_h() + ys10;
78         add_subwindow(rotate = new FindObjRotate(plugin, this, x3, y));
79         y += rotate->get_h() + ys10;
80         add_subwindow(translate = new FindObjTranslate(plugin, this, x3, y));
81
82         int x0 = x + xs200;  y = y1 + ys10;
83         add_subwindow(title = new BC_Title(x, y, _("Output/scene layer:")));
84         scene_layer = new FindObjLayer(plugin, this, x0, y,
85                 &plugin->config.scene_layer);
86         scene_layer->create_objects();
87         y += scene_layer->get_h() + plugin->get_theme()->widget_border;
88
89         add_subwindow(title = new BC_Title(x, y, _("Object layer:")));
90         object_layer = new FindObjLayer(plugin, this, x0, y,
91                 &plugin->config.object_layer);
92         object_layer->create_objects();
93         y += object_layer->get_h() + plugin->get_theme()->widget_border;
94
95         add_subwindow(title = new BC_Title(x, y, _("Replacement object layer:")));
96         replace_layer = new FindObjLayer(plugin, this, x0, y,
97                 &plugin->config.replace_layer);
98         replace_layer->create_objects();
99         y += replace_layer->get_h() + plugin->get_theme()->widget_border + ys10;
100
101         y += ys10;
102         add_subwindow(title = new BC_Title(x+xs15, y, _("Units: 0 to 100 percent")));
103         y += title->get_h();
104
105         y1 = y;
106         add_subwindow(title = new BC_Title(x1, y + ys10, _("Scene X:")));
107         Track *track = plugin->get_plugin_track();
108         int trk_w = track ? track->track_w : plugin->get_edl()->session->output_w;
109         int trk_h = track ? track->track_h : plugin->get_edl()->session->output_h;
110         float drag_w = trk_w * plugin->config.scene_w / 100.;
111         float drag_h = trk_h * plugin->config.scene_h / 100.;
112         float ctr_x  = trk_w * plugin->config.scene_x / 100.;
113         float ctr_y  = trk_h * plugin->config.scene_y / 100.;
114         float drag_x = ctr_x - drag_w/2, drag_y = ctr_y - drag_h/2;
115         drag_scene = new FindObjDragScene(plugin, this, x1+title->get_w()+xs10, y+ys5,
116                 drag_x, drag_y, drag_w, drag_h);
117         add_subwindow(drag_scene);
118         drag_scene->create_objects();
119         y += title->get_h() + ys15;
120
121         add_subwindow(scene_x = new FindObjScanFloat(plugin, this,
122                 x1, y, &plugin->config.scene_x));
123         add_subwindow(scene_x_text = new FindObjScanFloatText(plugin, this,
124                 x1 + scene_x->get_w() + xs10, y + ys10, &plugin->config.scene_x));
125         scene_x->center_text = scene_x_text;
126         scene_x_text->center = scene_x;
127
128         y += ys40;
129         add_subwindow(title = new BC_Title(x1, y + ys10, _("Scene Y:")));
130         y += title->get_h() + ys15;
131         add_subwindow(scene_y = new FindObjScanFloat(plugin, this,
132                 x1, y, &plugin->config.scene_y));
133         add_subwindow(scene_y_text = new FindObjScanFloatText(plugin, this,
134                 x1 + scene_y->get_w() + xs10, y + ys10, &plugin->config.scene_y));
135         scene_y->center_text = scene_y_text;
136         scene_y_text->center = scene_y;
137
138         y += ys40;
139         add_subwindow(new BC_Title(x1, y + ys10, _("Scene W:")));
140         y += title->get_h() + ys15;
141         add_subwindow(scene_w = new FindObjScanFloat(plugin, this,
142                 x1, y, &plugin->config.scene_w));
143         add_subwindow(scene_w_text = new FindObjScanFloatText(plugin, this,
144                 x1 + scene_w->get_w() + xs10, y + ys10, &plugin->config.scene_w));
145         scene_w->center_text = scene_w_text;
146         scene_w_text->center = scene_w;
147
148         y += ys40;
149         add_subwindow(title = new BC_Title(x1, y + ys10, _("Scene H:")));
150         y += title->get_h() + ys15;
151         add_subwindow(scene_h = new FindObjScanFloat(plugin, this,
152                 x1, y, &plugin->config.scene_h));
153         add_subwindow(scene_h_text = new FindObjScanFloatText(plugin, this,
154                 x1 + scene_h->get_w() + xs10, y + ys10,
155                 &plugin->config.scene_h));
156         scene_h->center_text = scene_h_text;
157         scene_h_text->center = scene_h;
158
159         y = y1;
160         add_subwindow(title = new BC_Title(x2, y + ys10, _("Object X:")));
161         drag_w = trk_w * plugin->config.object_w / 100.;
162         drag_h = trk_h * plugin->config.object_h / 100.;
163         ctr_x  = trk_w * plugin->config.object_x / 100.,
164         ctr_y  = trk_h * plugin->config.object_y / 100.;
165         drag_x = ctr_x - drag_w/2;  drag_y = ctr_y - drag_h/2;
166         drag_object = new FindObjDragObject(plugin, this, x2+title->get_w()+xs10, y+ys5,
167                 drag_x, drag_y, drag_w, drag_h);
168         add_subwindow(drag_object);
169         drag_object->create_objects();
170         y += title->get_h() + ys15;
171
172         add_subwindow(object_x = new FindObjScanFloat(plugin, this,
173                 x2, y, &plugin->config.object_x));
174         add_subwindow(object_x_text = new FindObjScanFloatText(plugin, this,
175                 x2 + object_x->get_w() + xs10, y + ys10, &plugin->config.object_x));
176         object_x->center_text = object_x_text;
177         object_x_text->center = object_x;
178
179         y += ys40;
180         add_subwindow(title = new BC_Title(x2, y + ys10, _("Object Y:")));
181         y += title->get_h() + ys15;
182         add_subwindow(object_y = new FindObjScanFloat(plugin, this,
183                 x2, y, &plugin->config.object_y));
184         add_subwindow(object_y_text = new FindObjScanFloatText(plugin, this,
185                 x2 + object_y->get_w() + xs10, y + ys10, &plugin->config.object_y));
186         object_y->center_text = object_y_text;
187         object_y_text->center = object_y;
188
189         y += ys40;
190         add_subwindow(new BC_Title(x2, y + ys10, _("Object W:")));
191         y += title->get_h() + ys15;
192         add_subwindow(object_w = new FindObjScanFloat(plugin, this,
193                 x2, y, &plugin->config.object_w));
194         add_subwindow(object_w_text = new FindObjScanFloatText(plugin, this,
195                 x2 + object_w->get_w() + xs10, y + ys10, &plugin->config.object_w));
196         object_w->center_text = object_w_text;
197         object_w_text->center = object_w;
198
199         y += ys40;
200         add_subwindow(title = new BC_Title(x2, y + ys10, _("Object H:")));
201         y += title->get_h() + ys15;
202         add_subwindow(object_h = new FindObjScanFloat(plugin, this,
203                 x2, y, &plugin->config.object_h));
204         add_subwindow(object_h_text = new FindObjScanFloatText(plugin, this,
205                 x2 + object_h->get_w() + xs10, y + ys10,
206                 &plugin->config.object_h));
207         object_h->center_text = object_h_text;
208         object_h_text->center = object_h;
209
210         y = y1;
211         add_subwindow(title = new BC_Title(x3, y + ys10, _("Replace X:")));
212         drag_w = trk_w * plugin->config.replace_w / 100.;
213         drag_h = trk_h * plugin->config.replace_h / 100.;
214         ctr_x  = trk_w * plugin->config.replace_x / 100.,
215         ctr_y  = trk_h * plugin->config.replace_y / 100.;
216         drag_x = ctr_x - drag_w/2;  drag_y = ctr_y - drag_h/2;
217         drag_replace = new FindObjDragReplace(plugin, this, x3+title->get_w()+xs10, y+ys5,
218                 drag_x, drag_y, drag_w, drag_h);
219         add_subwindow(drag_replace);
220         drag_replace->create_objects();
221         y += title->get_h() + ys15;
222
223         add_subwindow(replace_x = new FindObjScanFloat(plugin, this,
224                 x3, y, &plugin->config.replace_x));
225         add_subwindow(replace_x_text = new FindObjScanFloatText(plugin, this,
226                 x3 + replace_x->get_w() + xs10, y + ys10, &plugin->config.replace_x));
227         replace_x->center_text = replace_x_text;
228         replace_x_text->center = replace_x;
229
230         y += ys40;
231         add_subwindow(title = new BC_Title(x3, y + ys10, _("Replace Y:")));
232         y += title->get_h() + ys15;
233         add_subwindow(replace_y = new FindObjScanFloat(plugin, this,
234                 x3, y, &plugin->config.replace_y));
235         add_subwindow(replace_y_text = new FindObjScanFloatText(plugin, this,
236                 x3 + replace_y->get_w() + xs10, y + ys10, &plugin->config.replace_y));
237         replace_y->center_text = replace_y_text;
238         replace_y_text->center = replace_y;
239
240         y += ys40;
241         add_subwindow(new BC_Title(x3, y + ys10, _("Replace W:")));
242         y += title->get_h() + ys15;
243         add_subwindow(replace_w = new FindObjScanFloat(plugin, this,
244                 x3, y, &plugin->config.replace_w));
245         add_subwindow(replace_w_text = new FindObjScanFloatText(plugin, this,
246                 x3 + replace_w->get_w() + xs10, y + ys10, &plugin->config.replace_w));
247         replace_w->center_text = replace_w_text;
248         replace_w_text->center = replace_w;
249
250         y += ys40;
251         add_subwindow(title = new BC_Title(x3, y + ys10, _("Replace H:")));
252         y += title->get_h() + ys15;
253         add_subwindow(replace_h = new FindObjScanFloat(plugin, this,
254                 x3, y, &plugin->config.replace_h));
255         add_subwindow(replace_h_text = new FindObjScanFloatText(plugin, this,
256                 x3 + replace_h->get_w() + xs10, y + ys10,
257                 &plugin->config.replace_h));
258         replace_h->center_text = replace_h_text;
259         replace_h_text->center = replace_h;
260
261         y += ys40;  int y2 = y;
262         add_subwindow(title = new BC_Title(x3, y + ys10, _("Replace DX:")));
263         y += title->get_h() + ys15;
264         add_subwindow(replace_dx = new FindObjScanFloat(plugin, this,
265                 x3, y, &plugin->config.replace_dx, -100.f, 100.f));
266         add_subwindow(replace_dx_text = new FindObjScanFloatText(plugin, this,
267                 x3 + replace_dx->get_w() + xs10, y + ys10, &plugin->config.replace_dx));
268         replace_dx->center_text = replace_dx_text;
269         replace_dx_text->center = replace_dx;
270
271         y += ys40;
272         add_subwindow(title = new BC_Title(x3, y + ys10, _("Replace DY:")));
273         y += title->get_h() + ys15;
274         add_subwindow(replace_dy = new FindObjScanFloat(plugin, this,
275                 x3, y, &plugin->config.replace_dy, -100.f, 100.f));
276         add_subwindow(replace_dy_text = new FindObjScanFloatText(plugin, this,
277                 x3 + replace_dy->get_w() + xs10, y + ys10, &plugin->config.replace_dy));
278         replace_dy->center_text = replace_dy_text;
279         replace_dy_text->center = replace_dy;
280
281         y = y2 + ys15;
282         add_subwindow(draw_keypoints = new FindObjDrawKeypoints(plugin, this, x, y));
283         y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
284         add_subwindow(draw_scene_border = new FindObjDrawSceneBorder(plugin, this, x, y));
285         y += draw_scene_border->get_h() + plugin->get_theme()->widget_border;
286         add_subwindow(draw_object_border = new FindObjDrawObjectBorder(plugin, this, x, y));
287         y += draw_object_border->get_h() + plugin->get_theme()->widget_border;
288         add_subwindow(draw_replace_border = new FindObjDrawReplaceBorder(plugin, this, x, y));
289         y += draw_object_border->get_h() + plugin->get_theme()->widget_border;
290
291         add_subwindow(title = new BC_Title(x, y + xs10, _("Object blend amount:")));
292         add_subwindow(blend = new FindObjBlend(plugin,
293                 x + title->get_w() + plugin->get_theme()->widget_border, y,
294                 &plugin->config.blend));
295         y += blend->get_h();
296
297         show_window(1);
298 }
299
300 FindObjReset::FindObjReset(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
301  : BC_GenericButton(x - BC_GenericButton::calculate_w(gui, _("Reset")), y, _("Reset"))
302 {
303         this->plugin = plugin;
304         this->gui = gui;
305 }
306
307 int FindObjReset::handle_event()
308 {
309         plugin->config.reset();
310         gui->drag_scene->drag_deactivate();
311         gui->drag_object->drag_deactivate();
312         gui->drag_replace->drag_deactivate();
313         gui->update_gui();
314         plugin->send_configure_change();
315         return 1;
316 }
317
318 void FindObjWindow::update_drag()
319 {
320         Track *track = drag_scene->get_drag_track();
321         int trk_w = track->track_w, trk_h = track->track_h;
322         drag_scene->drag_w = trk_w * plugin->config.scene_w/100.;
323         drag_scene->drag_h = trk_h * plugin->config.scene_h/100.;
324         drag_scene->drag_x = trk_w * plugin->config.scene_x/100. - drag_scene->drag_w/2;
325         drag_scene->drag_y = trk_h * plugin->config.scene_y/100. - drag_scene->drag_h/2;
326         track = drag_object->get_drag_track();
327         trk_w = track->track_w, trk_h = track->track_h;
328         drag_object->drag_w = trk_w * plugin->config.object_w/100.;
329         drag_object->drag_h = trk_h * plugin->config.object_h/100.;
330         drag_object->drag_x = trk_w * plugin->config.object_x/100. - drag_object->drag_w/2;
331         drag_object->drag_y = trk_h * plugin->config.object_y/100. - drag_object->drag_h/2;
332         track = drag_replace->get_drag_track();
333         trk_w = track->track_w, trk_h = track->track_h;
334         drag_replace->drag_w = trk_w * plugin->config.replace_w/100.;
335         drag_replace->drag_h = trk_h * plugin->config.replace_h/100.;
336         drag_replace->drag_x = trk_w * plugin->config.replace_x/100. - drag_replace->drag_w/2;
337         drag_replace->drag_y = trk_h * plugin->config.replace_y/100. - drag_replace->drag_h/2;
338 }
339
340 void FindObjWindow::update_gui()
341 {
342         update_drag();
343         FindObjConfig &conf = plugin->config;
344         algorithm->update(conf.algorithm);
345         use_flann->update(conf.use_flann);
346         draw_match->update(conf.draw_match);
347         aspect->update(conf.aspect);
348         scale->update(conf.scale);
349         rotate->update(conf.rotate);
350         translate->update(conf.translate);
351         drag_object->update(conf.drag_object);
352         object_x->update(conf.object_x);
353         object_x_text->update((float)conf.object_x);
354         object_y->update(conf.object_y);
355         object_y_text->update((float)conf.object_y);
356         object_w->update(conf.object_w);
357         object_w_text->update((float)conf.object_w);
358         object_h->update(conf.object_h);
359         object_h_text->update((float)conf.object_h);
360         drag_scene->update(conf.drag_scene);
361         scene_x->update(conf.scene_x);
362         scene_x_text->update((float)conf.scene_x);
363         scene_y->update(conf.scene_y);
364         scene_y_text->update((float)conf.scene_y);
365         scene_w->update(conf.scene_w);
366         scene_w_text->update((float)conf.scene_w);
367         scene_h->update(conf.scene_h);
368         scene_h_text->update((float)conf.scene_h);
369         drag_replace->update(conf.drag_replace);
370         replace_x->update(conf.replace_x);
371         replace_x_text->update((float)conf.replace_x);
372         replace_y->update(conf.replace_y);
373         replace_y_text->update((float)conf.replace_y);
374         replace_w->update(conf.replace_w);
375         replace_w_text->update((float)conf.replace_w);
376         replace_h->update(conf.replace_h);
377         replace_h_text->update((float)conf.replace_h);
378         replace_dx->update(conf.replace_dx);
379         replace_dx_text->update((float)conf.replace_dx);
380         replace_dx->update(conf.replace_dx);
381         replace_dx_text->update((float)conf.replace_dx);
382         draw_keypoints->update(conf.draw_keypoints);
383         draw_scene_border->update(conf.draw_scene_border);
384         replace_object->update(conf.replace_object);
385         draw_object_border->update(conf.draw_object_border);
386         draw_replace_border->update(conf.draw_replace_border);
387         object_layer->update( (int64_t)conf.object_layer);
388         replace_layer->update( (int64_t)conf.replace_layer);
389         scene_layer->update( (int64_t)conf.scene_layer);
390         blend->update( (int64_t)conf.blend);
391 }
392
393 FindObjScanFloat::FindObjScanFloat(FindObjMain *plugin, FindObjWindow *gui,
394         int x, int y, float *value, float min, float max)
395  : BC_FPot(x, y, *value, min, max)
396 {
397         this->plugin = plugin;
398         this->gui = gui;
399         this->value = value;
400         this->center_text = 0;
401         set_precision(0.1);
402 }
403
404 int FindObjScanFloat::handle_event()
405 {
406         *value = get_value();
407         center_text->update(*value);
408         gui->update_drag();
409         plugin->send_configure_change();
410         return 1;
411 }
412
413 void FindObjScanFloat::update(float v)
414 {
415         BC_FPot::update(*value = v);
416         center_text->update(v);
417         plugin->send_configure_change();
418 }
419
420
421 FindObjScanFloatText::FindObjScanFloatText(FindObjMain *plugin, FindObjWindow *gui,
422         int x, int y, float *value)
423  : BC_TextBox(x, y, xS(75), 1, *value)
424 {
425         this->plugin = plugin;
426         this->gui = gui;
427         this->value = value;
428         this->center = 0;
429         set_precision(1);
430 }
431
432 int FindObjScanFloatText::handle_event()
433 {
434         *value = atof(get_text());
435         center->update(*value);
436         gui->update_drag();
437         plugin->send_configure_change();
438         return 1;
439 }
440
441
442 FindObjDrawSceneBorder::FindObjDrawSceneBorder(FindObjMain *plugin, FindObjWindow *gui,
443         int x, int y)
444  : BC_CheckBox(x, y, plugin->config.draw_scene_border, _("Draw scene border"))
445 {
446         this->gui = gui;
447         this->plugin = plugin;
448 }
449
450 int FindObjDrawSceneBorder::handle_event()
451 {
452         plugin->config.draw_scene_border = get_value();
453         plugin->send_configure_change();
454         return 1;
455 }
456
457 FindObjDrawObjectBorder::FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui,
458         int x, int y)
459  : BC_CheckBox(x, y, plugin->config.draw_object_border, _("Draw object border"))
460 {
461         this->gui = gui;
462         this->plugin = plugin;
463 }
464
465 int FindObjDrawObjectBorder::handle_event()
466 {
467         plugin->config.draw_object_border = get_value();
468         plugin->send_configure_change();
469         return 1;
470 }
471
472 FindObjDrawReplaceBorder::FindObjDrawReplaceBorder(FindObjMain *plugin, FindObjWindow *gui,
473         int x, int y)
474  : BC_CheckBox(x, y, plugin->config.draw_replace_border, _("Draw replace border"))
475 {
476         this->gui = gui;
477         this->plugin = plugin;
478 }
479
480 int FindObjDrawReplaceBorder::handle_event()
481 {
482         plugin->config.draw_replace_border = get_value();
483         plugin->send_configure_change();
484         return 1;
485 }
486
487
488 FindObjDrawKeypoints::FindObjDrawKeypoints(FindObjMain *plugin, FindObjWindow *gui,
489         int x, int y)
490  : BC_CheckBox(x, y, plugin->config.draw_keypoints, _("Draw keypoints"))
491 {
492         this->gui = gui;
493         this->plugin = plugin;
494 }
495
496 int FindObjDrawKeypoints::handle_event()
497 {
498         plugin->config.draw_keypoints = get_value();
499         plugin->send_configure_change();
500         return 1;
501 }
502
503
504 FindObjReplace::FindObjReplace(FindObjMain *plugin, FindObjWindow *gui,
505         int x, int y)
506  : BC_CheckBox(x, y, plugin->config.replace_object, _("Replace object"))
507 {
508         this->gui = gui;
509         this->plugin = plugin;
510 }
511
512 int FindObjReplace::handle_event()
513 {
514         plugin->config.replace_object = get_value();
515         plugin->send_configure_change();
516         return 1;
517 }
518
519
520 FindObjDragScene::FindObjDragScene(FindObjMain *plugin, FindObjWindow *gui, int x, int y,
521                 float drag_x, float drag_y, float drag_w, float drag_h)
522  : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag_scene,
523                 drag_x, drag_y, drag_w, drag_h)
524 {
525         this->plugin = plugin;
526         this->gui = gui;
527 }
528
529 FindObjDragScene::~FindObjDragScene()
530 {
531 }
532
533 int FindObjDragScene::handle_event()
534 {
535         int ret = DragCheckBox::handle_event();
536         plugin->send_configure_change();
537         return ret;
538 }
539
540 Track *FindObjDragScene::get_drag_track()
541 {
542         return plugin->get_plugin_track();
543 }
544
545 int64_t FindObjDragScene::get_drag_position()
546 {
547         return plugin->get_source_position();
548 }
549
550 void FindObjDragScene::update_gui()
551 {
552         bound();
553         Track *track = get_drag_track();
554         int trk_w = track ? track->track_w : plugin->get_edl()->session->output_w;
555         int trk_h = track ? track->track_h : plugin->get_edl()->session->output_h;
556         float ctr_x = drag_x + drag_w/2, ctr_y = drag_y + drag_h/2;
557         gui->scene_x->update( plugin->config.scene_x = 100. * ctr_x / trk_w );
558         gui->scene_y->update( plugin->config.scene_y = 100. * ctr_y / trk_h );
559         gui->scene_w->update( plugin->config.scene_w = 100. * drag_w / trk_w );
560         gui->scene_h->update( plugin->config.scene_h = 100. * drag_h / trk_h );
561         plugin->send_configure_change();
562 }
563
564 FindObjDragObject::FindObjDragObject(FindObjMain *plugin, FindObjWindow *gui, int x, int y,
565                 float drag_x, float drag_y, float drag_w, float drag_h)
566  : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag_object,
567                 drag_x, drag_y, drag_w, drag_h)
568 {
569         this->plugin = plugin;
570         this->gui = gui;
571 }
572
573 FindObjDragObject::~FindObjDragObject()
574 {
575 }
576
577 int FindObjDragObject::handle_event()
578 {
579         int ret = DragCheckBox::handle_event();
580         plugin->send_configure_change();
581         return ret;
582 }
583
584 Track *FindObjDragObject::get_drag_track()
585 {
586         return plugin->get_plugin_track();
587 }
588
589 int64_t FindObjDragObject::get_drag_position()
590 {
591         return plugin->get_source_position();
592 }
593
594 void FindObjDragObject::update_gui()
595 {
596         bound();
597         Track *track = get_drag_track();
598         int trk_w = track ? track->track_w : plugin->get_edl()->session->output_w;
599         int trk_h = track ? track->track_h : plugin->get_edl()->session->output_h;
600         float ctr_x = drag_x + drag_w/2, ctr_y = drag_y + drag_h/2;
601         gui->object_x->update( plugin->config.object_x = 100. * ctr_x / trk_w );
602         gui->object_y->update( plugin->config.object_y = 100. * ctr_y / trk_h );
603         gui->object_w->update( plugin->config.object_w = 100. * drag_w / trk_w );
604         gui->object_h->update( plugin->config.object_h = 100. * drag_h / trk_h );
605         plugin->send_configure_change();
606 }
607
608 FindObjDragReplace::FindObjDragReplace(FindObjMain *plugin, FindObjWindow *gui, int x, int y,
609                 float drag_x, float drag_y, float drag_w, float drag_h)
610  : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag_replace,
611                 drag_x, drag_y, drag_w, drag_h)
612 {
613         this->plugin = plugin;
614         this->gui = gui;
615 }
616
617 FindObjDragReplace::~FindObjDragReplace()
618 {
619 }
620
621 int FindObjDragReplace::handle_event()
622 {
623         int ret = DragCheckBox::handle_event();
624         plugin->send_configure_change();
625         return ret;
626 }
627 Track *FindObjDragReplace::get_drag_track()
628 {
629         return plugin->get_plugin_track();
630 }
631
632 int64_t FindObjDragReplace::get_drag_position()
633 {
634         return plugin->get_source_position();
635 }
636
637 void FindObjDragReplace::update_gui()
638 {
639         bound();
640         Track *track = get_drag_track();
641         int trk_w = track ? track->track_w : plugin->get_edl()->session->output_w;
642         int trk_h = track ? track->track_h : plugin->get_edl()->session->output_h;
643         float ctr_x = drag_x + drag_w/2, ctr_y = drag_y + drag_h/2;
644         gui->replace_x->update( plugin->config.replace_x = 100. * ctr_x / trk_w );
645         gui->replace_y->update( plugin->config.replace_y = 100. * ctr_y / trk_h );
646         gui->replace_w->update( plugin->config.replace_w = 100. * drag_w / trk_w );
647         gui->replace_h->update( plugin->config.replace_h = 100. * drag_h / trk_h );
648         plugin->send_configure_change();
649 }
650
651
652
653 FindObjAlgorithm::FindObjAlgorithm(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
654  : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.algorithm))
655 {
656         this->plugin = plugin;
657         this->gui = gui;
658 }
659
660 int FindObjAlgorithm::handle_event()
661 {
662         plugin->config.algorithm = from_text(get_text());
663         plugin->send_configure_change();
664         return 1;
665 }
666
667 void FindObjAlgorithm::create_objects()
668 {
669         add_item(new BC_MenuItem(to_text(NO_ALGORITHM)));
670 #ifdef _SIFT
671         add_item(new BC_MenuItem(to_text(ALGORITHM_SIFT)));
672 #endif
673 #ifdef _SURF
674         add_item(new BC_MenuItem(to_text(ALGORITHM_SURF)));
675 #endif
676 #ifdef _ORB
677         add_item(new BC_MenuItem(to_text(ALGORITHM_ORB)));
678 #endif
679 #ifdef _AKAZE
680         add_item(new BC_MenuItem(to_text(ALGORITHM_AKAZE)));
681 #endif
682 #ifdef _BRISK
683         add_item(new BC_MenuItem(to_text(ALGORITHM_BRISK)));
684 #endif
685 }
686
687 int FindObjAlgorithm::from_text(char *text)
688 {
689 #ifdef _SIFT
690         if(!strcmp(text, _("SIFT"))) return ALGORITHM_SIFT;
691 #endif
692 #ifdef _SURF
693         if(!strcmp(text, _("SURF"))) return ALGORITHM_SURF;
694 #endif
695 #ifdef _ORB
696         if(!strcmp(text, _("ORB"))) return ALGORITHM_ORB;
697 #endif
698 #ifdef _AKAZE
699         if(!strcmp(text, _("AKAZE"))) return ALGORITHM_AKAZE;
700 #endif
701 #ifdef _BRISK
702         if(!strcmp(text, _("BRISK"))) return ALGORITHM_BRISK;
703 #endif
704         return NO_ALGORITHM;
705 }
706
707 void FindObjAlgorithm::update(int mode)
708 {
709         set_text(to_text(mode));
710 }
711
712 char* FindObjAlgorithm::to_text(int mode)
713 {
714         switch( mode ) {
715 #ifdef _SIFT
716         case ALGORITHM_SIFT:    return _("SIFT");
717 #endif
718 #ifdef _SURF
719         case ALGORITHM_SURF:    return _("SURF");
720 #endif
721 #ifdef _ORB
722         case ALGORITHM_ORB:     return _("ORB");
723 #endif
724 #ifdef _AKAZE
725         case ALGORITHM_AKAZE:   return _("AKAZE");
726 #endif
727 #ifdef _BRISK
728         case ALGORITHM_BRISK:   return _("BRISK");
729 #endif
730         }
731         return _("Don't Calculate");
732 }
733
734 int FindObjAlgorithm::calculate_w(FindObjWindow *gui)
735 {
736         int result = 0;
737         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(NO_ALGORITHM)));
738 #ifdef _SIFT
739         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SIFT)));
740 #endif
741 #ifdef _SURF
742         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SURF)));
743 #endif
744 #ifdef _ORB
745         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_ORB)));
746 #endif
747 #ifdef _AKAZE
748         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_AKAZE)));
749 #endif
750 #ifdef _BRISK
751         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_BRISK)));
752 #endif
753         return result + xS(50);
754 }
755
756
757 FindObjUseFlann::FindObjUseFlann(FindObjMain *plugin, FindObjWindow *gui,
758         int x, int y)
759  : BC_CheckBox(x, y, plugin->config.use_flann, _("Use FLANN"))
760 {
761         this->gui = gui;
762         this->plugin = plugin;
763 }
764
765 int FindObjUseFlann::handle_event()
766 {
767         plugin->config.use_flann = get_value();
768         plugin->send_configure_change();
769         return 1;
770 }
771
772 FindObjDrawMatch::FindObjDrawMatch(FindObjMain *plugin, FindObjWindow *gui,
773         int x, int y)
774  : BC_CheckBox(x, y, plugin->config.draw_match, _("Draw match"))
775 {
776         this->gui = gui;
777         this->plugin = plugin;
778 }
779
780 int FindObjDrawMatch::handle_event()
781 {
782         plugin->config.draw_match = get_value();
783         plugin->send_configure_change();
784         return 1;
785 }
786
787 FindObjAspect::FindObjAspect(FindObjMain *plugin, FindObjWindow *gui,
788         int x, int y)
789  : BC_CheckBox(x, y, plugin->config.aspect, _("Aspect"))
790 {
791         this->gui = gui;
792         this->plugin = plugin;
793 }
794
795 int FindObjAspect::handle_event()
796 {
797         plugin->config.aspect = get_value();
798         plugin->send_configure_change();
799         return 1;
800 }
801
802 FindObjScale::FindObjScale(FindObjMain *plugin, FindObjWindow *gui,
803         int x, int y)
804  : BC_CheckBox(x, y, plugin->config.scale, _("Scale"))
805 {
806         this->gui = gui;
807         this->plugin = plugin;
808 }
809
810 int FindObjScale::handle_event()
811 {
812         plugin->config.scale = get_value();
813         plugin->send_configure_change();
814         return 1;
815 }
816
817 FindObjRotate::FindObjRotate(FindObjMain *plugin, FindObjWindow *gui,
818         int x, int y)
819  : BC_CheckBox(x, y, plugin->config.rotate, _("Rotate"))
820 {
821         this->gui = gui;
822         this->plugin = plugin;
823 }
824
825 int FindObjRotate::handle_event()
826 {
827         plugin->config.rotate = get_value();
828         plugin->send_configure_change();
829         return 1;
830 }
831
832 FindObjTranslate::FindObjTranslate(FindObjMain *plugin, FindObjWindow *gui,
833         int x, int y)
834  : BC_CheckBox(x, y, plugin->config.translate, _("Translate"))
835 {
836         this->gui = gui;
837         this->plugin = plugin;
838 }
839
840 int FindObjTranslate::handle_event()
841 {
842         plugin->config.translate = get_value();
843         plugin->send_configure_change();
844         return 1;
845 }
846
847 FindObjMode::FindObjMode(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
848  : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.mode))
849 {
850         this->plugin = plugin;
851         this->gui = gui;
852 }
853
854 int FindObjMode::handle_event()
855 {
856         plugin->config.mode = from_text(get_text());
857         plugin->send_configure_change();
858         return 1;
859 }
860
861 void FindObjMode::create_objects()
862 {
863         add_item(new BC_MenuItem(to_text(MODE_SQUARE)));
864         add_item(new BC_MenuItem(to_text(MODE_RHOMBUS)));
865         add_item(new BC_MenuItem(to_text(MODE_RECTANGLE)));
866         add_item(new BC_MenuItem(to_text(MODE_PARALLELOGRAM)));
867         add_item(new BC_MenuItem(to_text(MODE_QUADRILATERAL)));
868 }
869 int FindObjMode::from_text(char *text)
870 {
871         if(!strcmp(text, _("Square"))) return MODE_SQUARE;
872         if(!strcmp(text, _("Rhombus"))) return MODE_RHOMBUS;
873         if(!strcmp(text, _("Rectangle"))) return MODE_RECTANGLE;
874         if(!strcmp(text, _("Parallelogram"))) return MODE_PARALLELOGRAM;
875         if(!strcmp(text, _("Quadrilateral"))) return MODE_QUADRILATERAL;
876         return MODE_NONE;
877 }
878
879 void FindObjMode::update(int mode)
880 {
881         set_text(to_text(mode));
882 }
883
884 char* FindObjMode::to_text(int mode)
885 {
886         switch( mode ) {
887         case MODE_SQUARE: return _("Square");
888         case MODE_RHOMBUS: return _("Rhombus");
889         case MODE_RECTANGLE: return _("Rectangle");
890         case MODE_PARALLELOGRAM: return _("Parallelogram");
891         case MODE_QUADRILATERAL: return _("Quadrilateral");
892         }
893         return _("None");
894 }
895
896 int FindObjMode::calculate_w(FindObjWindow *gui)
897 {
898         int result = 0;
899         for( int mode=MODE_NONE; mode<MODE_MAX; ++mode )
900                 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(mode)));
901         return result + xS(50);
902 }
903
904
905 FindObjLayer::FindObjLayer(FindObjMain *plugin, FindObjWindow *gui,
906         int x, int y, int *value)
907  : BC_TumbleTextBox(gui, *value, MIN_LAYER, MAX_LAYER, x, y, calculate_w(gui))
908 {
909         this->plugin = plugin;
910         this->gui = gui;
911         this->value = value;
912 }
913
914 int FindObjLayer::handle_event()
915 {
916         *value = atoi(get_text());
917         plugin->send_configure_change();
918         return 1;
919 }
920
921 int FindObjLayer::calculate_w(FindObjWindow *gui)
922 {
923         int result = 0;
924         result = gui->get_text_width(MEDIUMFONT, "000");
925         return result + xS(50);
926 }
927
928
929 FindObjBlend::FindObjBlend(FindObjMain *plugin,
930         int x,
931         int y,
932         int *value)
933  : BC_IPot(x,
934                 y,
935                 (int64_t)*value,
936                 (int64_t)MIN_BLEND,
937                 (int64_t)MAX_BLEND)
938 {
939         this->plugin = plugin;
940         this->value = value;
941 }
942
943 int FindObjBlend::handle_event()
944 {
945         *value = (int)get_value();
946         plugin->send_configure_change();
947         return 1;
948 }
949