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