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