4 * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcdisplayinfo.h"
24 #include "dragcheckbox.h"
27 #include "findobjwindow.h"
29 #include "pluginserver.h"
34 FindObjWindow::FindObjWindow(FindObjMain *plugin)
35 : PluginClientWindow(plugin, 500, 660, 500, 660, 0)
37 this->plugin = plugin;
40 FindObjWindow::~FindObjWindow()
44 void FindObjWindow::create_objects()
46 int x = 10, y = 10, x1 = x, x2 = get_w()*1/3, x3 = get_w()*2/3;
47 plugin->load_configuration();
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;
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;
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));
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;
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;
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;
94 add_subwindow(title = new BC_Title(x+15, y, _("Units: 0 to 100 percent")));
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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));
291 FindObjReset::FindObjReset(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
292 : BC_GenericButton(x - BC_GenericButton::calculate_w(gui, _("Reset")), y, _("Reset"))
294 this->plugin = plugin;
298 int FindObjReset::handle_event()
300 plugin->config.reset();
301 gui->drag_scene->drag_deactivate();
302 gui->drag_object->drag_deactivate();
303 gui->drag_replace->drag_deactivate();
305 plugin->send_configure_change();
309 void FindObjWindow::update_drag()
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;
331 void FindObjWindow::update_gui()
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);
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)
386 this->plugin = plugin;
389 this->center_text = 0;
393 int FindObjScanFloat::handle_event()
395 *value = get_value();
396 center_text->update(*value);
398 plugin->send_configure_change();
402 void FindObjScanFloat::update(float v)
404 BC_FPot::update(*value = v);
405 center_text->update(v);
406 plugin->send_configure_change();
410 FindObjScanFloatText::FindObjScanFloatText(FindObjMain *plugin, FindObjWindow *gui,
411 int x, int y, float *value)
412 : BC_TextBox(x, y, 75, 1, *value)
414 this->plugin = plugin;
421 int FindObjScanFloatText::handle_event()
423 *value = atof(get_text());
424 center->update(*value);
426 plugin->send_configure_change();
431 FindObjDrawSceneBorder::FindObjDrawSceneBorder(FindObjMain *plugin, FindObjWindow *gui,
433 : BC_CheckBox(x, y, plugin->config.draw_scene_border, _("Draw scene border"))
436 this->plugin = plugin;
439 int FindObjDrawSceneBorder::handle_event()
441 plugin->config.draw_scene_border = get_value();
442 plugin->send_configure_change();
446 FindObjDrawObjectBorder::FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui,
448 : BC_CheckBox(x, y, plugin->config.draw_object_border, _("Draw object border"))
451 this->plugin = plugin;
454 int FindObjDrawObjectBorder::handle_event()
456 plugin->config.draw_object_border = get_value();
457 plugin->send_configure_change();
461 FindObjDrawReplaceBorder::FindObjDrawReplaceBorder(FindObjMain *plugin, FindObjWindow *gui,
463 : BC_CheckBox(x, y, plugin->config.draw_replace_border, _("Draw replace border"))
466 this->plugin = plugin;
469 int FindObjDrawReplaceBorder::handle_event()
471 plugin->config.draw_replace_border = get_value();
472 plugin->send_configure_change();
477 FindObjDrawKeypoints::FindObjDrawKeypoints(FindObjMain *plugin, FindObjWindow *gui,
479 : BC_CheckBox(x, y, plugin->config.draw_keypoints, _("Draw keypoints"))
482 this->plugin = plugin;
485 int FindObjDrawKeypoints::handle_event()
487 plugin->config.draw_keypoints = get_value();
488 plugin->send_configure_change();
493 FindObjReplace::FindObjReplace(FindObjMain *plugin, FindObjWindow *gui,
495 : BC_CheckBox(x, y, plugin->config.replace_object, _("Replace object"))
498 this->plugin = plugin;
501 int FindObjReplace::handle_event()
503 plugin->config.replace_object = get_value();
504 plugin->send_configure_change();
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)
514 this->plugin = plugin;
518 FindObjDragScene::~FindObjDragScene()
522 int FindObjDragScene::handle_event()
524 int ret = DragCheckBox::handle_event();
525 plugin->send_configure_change();
528 Track *FindObjDragScene::get_drag_track()
530 return plugin->server->plugin->track;
532 int64_t FindObjDragScene::get_drag_position()
534 return plugin->get_source_position();
536 void FindObjDragScene::update_gui()
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();
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)
554 this->plugin = plugin;
558 FindObjDragObject::~FindObjDragObject()
562 int FindObjDragObject::handle_event()
564 int ret = DragCheckBox::handle_event();
565 plugin->send_configure_change();
568 Track *FindObjDragObject::get_drag_track()
570 return plugin->server->plugin->track;
572 int64_t FindObjDragObject::get_drag_position()
574 return plugin->get_source_position();
576 void FindObjDragObject::update_gui()
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();
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)
594 this->plugin = plugin;
598 FindObjDragReplace::~FindObjDragReplace()
602 int FindObjDragReplace::handle_event()
604 int ret = DragCheckBox::handle_event();
605 plugin->send_configure_change();
608 Track *FindObjDragReplace::get_drag_track()
610 return plugin->server->plugin->track;
612 int64_t FindObjDragReplace::get_drag_position()
614 return plugin->get_source_position();
616 void FindObjDragReplace::update_gui()
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();
631 FindObjAlgorithm::FindObjAlgorithm(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
632 : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.algorithm))
634 this->plugin = plugin;
638 int FindObjAlgorithm::handle_event()
640 plugin->config.algorithm = from_text(get_text());
641 plugin->send_configure_change();
645 void FindObjAlgorithm::create_objects()
647 add_item(new BC_MenuItem(to_text(NO_ALGORITHM)));
649 add_item(new BC_MenuItem(to_text(ALGORITHM_SIFT)));
652 add_item(new BC_MenuItem(to_text(ALGORITHM_SURF)));
655 add_item(new BC_MenuItem(to_text(ALGORITHM_ORB)));
658 add_item(new BC_MenuItem(to_text(ALGORITHM_AKAZE)));
661 add_item(new BC_MenuItem(to_text(ALGORITHM_BRISK)));
665 int FindObjAlgorithm::from_text(char *text)
668 if(!strcmp(text, _("SIFT"))) return ALGORITHM_SIFT;
671 if(!strcmp(text, _("SURF"))) return ALGORITHM_SURF;
674 if(!strcmp(text, _("ORB"))) return ALGORITHM_ORB;
677 if(!strcmp(text, _("AKAZE"))) return ALGORITHM_AKAZE;
680 if(!strcmp(text, _("BRISK"))) return ALGORITHM_BRISK;
685 void FindObjAlgorithm::update(int mode)
687 set_text(to_text(mode));
690 char* FindObjAlgorithm::to_text(int mode)
694 case ALGORITHM_SIFT: return _("SIFT");
697 case ALGORITHM_SURF: return _("SURF");
700 case ALGORITHM_ORB: return _("ORB");
703 case ALGORITHM_AKAZE: return _("AKAZE");
706 case ALGORITHM_BRISK: return _("BRISK");
709 return _("Don't Calculate");
712 int FindObjAlgorithm::calculate_w(FindObjWindow *gui)
715 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(NO_ALGORITHM)));
717 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SIFT)));
720 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SURF)));
723 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_ORB)));
726 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_AKAZE)));
729 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_BRISK)));
735 FindObjUseFlann::FindObjUseFlann(FindObjMain *plugin, FindObjWindow *gui,
737 : BC_CheckBox(x, y, plugin->config.use_flann, _("Use FLANN"))
740 this->plugin = plugin;
743 int FindObjUseFlann::handle_event()
745 plugin->config.use_flann = get_value();
746 plugin->send_configure_change();
750 FindObjScale::FindObjScale(FindObjMain *plugin, FindObjWindow *gui,
752 : BC_CheckBox(x, y, plugin->config.scale, _("Scale"))
755 this->plugin = plugin;
758 int FindObjScale::handle_event()
760 plugin->config.scale = get_value();
761 plugin->send_configure_change();
765 FindObjRotate::FindObjRotate(FindObjMain *plugin, FindObjWindow *gui,
767 : BC_CheckBox(x, y, plugin->config.rotate, _("Rotate"))
770 this->plugin = plugin;
773 int FindObjRotate::handle_event()
775 plugin->config.rotate = get_value();
776 plugin->send_configure_change();
780 FindObjTranslate::FindObjTranslate(FindObjMain *plugin, FindObjWindow *gui,
782 : BC_CheckBox(x, y, plugin->config.translate, _("Translate"))
785 this->plugin = plugin;
788 int FindObjTranslate::handle_event()
790 plugin->config.translate = get_value();
791 plugin->send_configure_change();
795 FindObjMode::FindObjMode(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
796 : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.mode))
798 this->plugin = plugin;
802 int FindObjMode::handle_event()
804 plugin->config.mode = from_text(get_text());
805 plugin->send_configure_change();
809 void FindObjMode::create_objects()
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)));
817 int FindObjMode::from_text(char *text)
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;
827 void FindObjMode::update(int mode)
829 set_text(to_text(mode));
832 char* FindObjMode::to_text(int 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");
844 int FindObjMode::calculate_w(FindObjWindow *gui)
847 for( int mode=MODE_NONE; mode<MODE_MAX; ++mode )
848 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(mode)));
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))
857 this->plugin = plugin;
862 int FindObjLayer::handle_event()
864 *value = atoi(get_text());
865 plugin->send_configure_change();
869 int FindObjLayer::calculate_w(FindObjWindow *gui)
872 result = gui->get_text_width(MEDIUMFONT, "000");
877 FindObjBlend::FindObjBlend(FindObjMain *plugin,
887 this->plugin = plugin;
891 int FindObjBlend::handle_event()
893 *value = (int)get_value();
894 plugin->send_configure_change();