From c3bd4f2f1ff4478097b84980ce7c7e107e494c1b Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Wed, 16 Sep 2020 13:38:35 -0700 Subject: [PATCH] Enable mouse middle and right buttons for ImGui --- CHANGELOG.md | 1 + dart/gui/osg/ImGuiHandler.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 654269498b7d7..2e5224de7c292 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ * Fixed OSG transparent object sorting: [#1414](https://github.com/dartsim/dart/pull/1414) * Added modifier key support to ImGuiHandler: [#1436](https://github.com/dartsim/dart/pull/1436) * Fixed mixed intrinsic and extrinsic camera parameters in OpenGL projection matrix: [#1485](https://github.com/dartsim/dart/pull/1485) + * Enabled mouse middle and right buttons in ImGuiHandler: [#1500](https://github.com/dartsim/dart/pull/1500) * Parser diff --git a/dart/gui/osg/ImGuiHandler.cpp b/dart/gui/osg/ImGuiHandler.cpp index ff3ce89470ed0..f8c6acbdef131 100644 --- a/dart/gui/osg/ImGuiHandler.cpp +++ b/dart/gui/osg/ImGuiHandler.cpp @@ -349,7 +349,29 @@ bool ImGuiHandler::handle( { io.MousePos = ImVec2(eventAdapter.getX(), io.DisplaySize.y - eventAdapter.getY()); - mMousePressed[0] = true; + + if (eventAdapter.getButtonMask() + == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) + { + mMousePressed[0] = true; + } + else if ( + eventAdapter.getButtonMask() + == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) + { + mMousePressed[1] = true; + } + else if ( + eventAdapter.getButtonMask() + == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) + { + mMousePressed[2] = true; + } + else + { + // Shouldn't be reached to here. Mark left button by default. + mMousePressed[0] = true; + } return wantCapureMouse; } @@ -363,7 +385,11 @@ bool ImGuiHandler::handle( } case osgGA::GUIEventAdapter::RELEASE: { + // When a mouse button is released no button mask is set. So we mark all + // the buttons are released. mMousePressed[0] = false; + mMousePressed[1] = false; + mMousePressed[2] = false; return wantCapureMouse; }