Skip to content

Commit

Permalink
update to improve event grabbing
Browse files Browse the repository at this point in the history
  • Loading branch information
sgumhold committed Nov 29, 2023
1 parent bcc183f commit bbc972a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion libs/cg_nui/dispatcher.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ namespace cgv {
}
}
rfi.foc_att = foc_att;
rfi.report_ptr->action = rfa;
}
void dispatcher::detach_focus(refocus_action rfa, focus_attachment foc_att, const focus_info& fi, const cgv::gui::event& e, const dispatch_info& dis_info, refocus_info& rfi)
{
Expand Down Expand Up @@ -464,8 +465,10 @@ namespace cgv {
// next check whether object wants to grab focus and in this case change focus and send event
if (rfi.foc_info_ptr->config.refocus.grab) {
for (auto root_ptr : objects)
if (wants_to_grab_recursive(root_ptr, root_ptr, e, hid_id, rfi))
if (wants_to_grab_recursive(root_ptr, root_ptr, e, hid_id, rfi)) {
report_ptr->action = refocus_action::grab;
break;
}
}
// next we try to dispatch spatially check for spatial refocussing that can change root and object in focus
bool handle_called = false;
Expand Down
2 changes: 1 addition & 1 deletion libs/cg_nui/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace cgv {
cgv::base::base_ptr focused_object = 0;
dispatch_mode mode = dispatch_mode::none;
dispatch_info** di_ptr_ptr = 0;
refocus_action action;
refocus_action action = refocus_action::none;
};

struct CGV_API refocus_info
Expand Down
18 changes: 16 additions & 2 deletions plugins/vr_lab/vr_scene.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ bool vr_scene::handle(cgv::gui::event& e)
if (ke.get_action() == cgv::gui::KA_PRESS && ke.get_modifiers() == cgv::gui::EM_CTRL && ke.get_key() == 'M') {
dispatch_mouse_spatial = !dispatch_mouse_spatial;
on_set(&dispatch_mouse_spatial);
return true;
}
}
if ((e.get_flags() & cgv::gui::EF_VR) != 0 && e.get_kind() == cgv::gui::EID_KEY) {
Expand Down Expand Up @@ -606,8 +607,21 @@ bool vr_scene::handle(cgv::gui::event& e)
}
cgv::nui::dispatch_report report;
bool ret = dispatch(e, &report);
if (report.action != cgv::nui::refocus_action::none && auto_grab_focus)
grab_focus();
if (report.action != cgv::nui::refocus_action::none) {
// std::cout << "refocus: ";
//switch (report.action) {
//case cgv::nui::refocus_action::none: std::cout << "none"; break;
//case cgv::nui::refocus_action::grab: std::cout << "grab"; break;
//case cgv::nui::refocus_action::handle: std::cout << "handle"; break;
//case cgv::nui::refocus_action::proximity: std::cout << "proximity"; break;
//case cgv::nui::refocus_action::intersection: std::cout << "intersection"; break;
//}
if (auto_grab_focus) {
grab_focus();
// std::cout << " -> grabbing focus";
}
//std::cout << std::endl;
}
return ret;
}
void vr_scene::create_gui()
Expand Down
2 changes: 1 addition & 1 deletion plugins/vr_lab/vr_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class CGV_API vr_scene :
void set_label_border_width(float border_width);

protected:
bool auto_grab_focus = false;
bool auto_grab_focus = true;
bool draw_controller_mode;
cgv::render::sphere_render_style srs;
cgv::render::cone_render_style crs;
Expand Down

0 comments on commit bbc972a

Please sign in to comment.