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