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