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