Fix buggy mouse interaction with multiple views.
This commit is contained in:
@@ -595,6 +595,25 @@ namespace glfw
|
||||
return false;
|
||||
}
|
||||
|
||||
IGL_INLINE void Viewer::select_hovered_core()
|
||||
{
|
||||
int width_window, height_window;
|
||||
glfwGetFramebufferSize(window, &width_window, &height_window);
|
||||
for (int i = 0; i < core_list.size(); i++)
|
||||
{
|
||||
Eigen::Vector4f viewport = core_list[i].viewport;
|
||||
|
||||
if ((current_mouse_x > viewport[0]) &&
|
||||
(current_mouse_x < viewport[0] + viewport[2]) &&
|
||||
(height_window - current_mouse_y > viewport[1]) &&
|
||||
(height_window -current_mouse_y < viewport[1] + viewport[3]))
|
||||
{
|
||||
selected_core_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IGL_INLINE bool Viewer::mouse_down(MouseButton button,int modifier)
|
||||
{
|
||||
// Remember mouse location at down even if used by callback/plugin
|
||||
@@ -611,6 +630,9 @@ namespace glfw
|
||||
|
||||
down = true;
|
||||
|
||||
// Select the core containing the click location.
|
||||
select_hovered_core();
|
||||
|
||||
down_translation = core().camera_translation;
|
||||
|
||||
|
||||
@@ -693,20 +715,6 @@ namespace glfw
|
||||
if (callback_mouse_move(*this, mouse_x, mouse_y))
|
||||
return true;
|
||||
|
||||
int width_window, height_window;
|
||||
glfwGetFramebufferSize(window, &width_window, &height_window);
|
||||
for (int i = 0; i < core_list.size(); i++)
|
||||
{
|
||||
Eigen::Vector4f viewport = core_list[i].viewport;
|
||||
|
||||
if (mouse_x > viewport[0] && mouse_x < viewport[0] + viewport[2] &&
|
||||
height_window-mouse_y > viewport[1] && height_window-mouse_y < viewport[1] + viewport[3])
|
||||
{
|
||||
selected_core_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (down)
|
||||
{
|
||||
switch (mouse_mode)
|
||||
@@ -774,6 +782,10 @@ namespace glfw
|
||||
|
||||
IGL_INLINE bool Viewer::mouse_scroll(float delta_y)
|
||||
{
|
||||
// Direct the scrolling operation to the appropriate viewport
|
||||
// (unless the core selection is locked by an ongoing mouse interaction).
|
||||
if (!down)
|
||||
select_hovered_core();
|
||||
scroll_position += delta_y;
|
||||
|
||||
for (unsigned int i = 0; i<plugins.size(); ++i)
|
||||
|
||||
@@ -156,6 +156,10 @@ namespace glfw
|
||||
// Returns 0 if not found
|
||||
IGL_INLINE size_t core_index(const int id) const;
|
||||
|
||||
// Change selected_core_index to the viewport containing the mouse
|
||||
// (current_mouse_x, current_mouse_y)
|
||||
IGL_INLINE void select_hovered_core();
|
||||
|
||||
public:
|
||||
//////////////////////
|
||||
// Member variables //
|
||||
|
||||
@@ -34,6 +34,12 @@ int main(int argc, char * argv[])
|
||||
return false;
|
||||
};
|
||||
|
||||
viewer.callback_post_resize = [&](igl::opengl::glfw::Viewer &v, int w, int h) {
|
||||
v.core( left_view).viewport = Eigen::Vector4f(0, 0, w / 2, h);
|
||||
v.core(right_view).viewport = Eigen::Vector4f(w / 2, 0, w - (w / 2), h);
|
||||
return true;
|
||||
};
|
||||
|
||||
viewer.launch();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user