USNavalResearchLaboratory / simdissdk

SIMDIS SDK
Other
114 stars 39 forks source link

ImGui And Mouse Double Clicks #81

Closed cipperly closed 2 years ago

cipperly commented 2 years ago

In my testing with using ImGui with SIMDIS SDK, I have found that it is not processing mouse double clicks correctly. OsgImGuiHandler.cpp has this:

bool OsgImGuiHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
...
  case osgGA::GUIEventAdapter::DOUBLECLICK:
  {
    io.MousePos = ImVec2(ea.getX(), io.DisplaySize.y - ea.getY());
    mouseDoubleClicked_[0] = ea.getButtonMask() & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON;
    mouseDoubleClicked_[1] = ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON;
    mouseDoubleClicked_[2] = ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON;
    return wantCaptureMouse;
  }
...
}

which I have found needs to be the following so that g.IO.MouseClickedCount gets set correctly in ImGui:

bool OsgImGuiHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
...
  case osgGA::GUIEventAdapter::DOUBLECLICK:
  {
    io.MousePos = ImVec2(ea.getX(), io.DisplaySize.y - ea.getY());
    mousePressed_[0] = ea.getButtonMask() & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON;
    mousePressed_[1] = ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON;
    mousePressed_[2] = ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON;
    mouseDoubleClicked_[0] = ea.getButtonMask() & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON;
    mouseDoubleClicked_[1] = ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON;
    mouseDoubleClicked_[2] = ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON;
    return wantCaptureMouse;
  }
...
}

This can be tested by adding the following to the draw method in any example that uses ImGui:

    if (ImGui::TreeNodeEx("Test Root", ImGuiTreeNodeFlags_DefaultOpen |
      ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_OpenOnArrow |
      ImGuiTreeNodeFlags_OpenOnDoubleClick))
    {
      if (ImGui::TreeNodeEx("Test Node", ImGuiTreeNodeFlags_SpanAvailWidth |
        ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_DefaultOpen |
        ImGuiTreeNodeFlags_OpenOnDoubleClick))
      {
        if (ImGui::TreeNodeEx("Test Leaf", ImGuiTreeNodeFlags_Leaf |
          ImGuiTreeNodeFlags_SpanAvailWidth |
          ImGuiTreeNodeFlags_NoTreePushOnOpen))
        {
        }
        ImGui::TreePop();
      }
      ImGui::TreePop();
    }

And double click on the tree nodes to expand/collapse the node.

Test environment: OS: Windows 10 x64 Compiler: Visual Studio 2019

I am also using the latest version of the ImGui docking branch in my testing.

Thanks.

mk401 commented 2 years ago

Hi cipperly, thanks for the report. I agree that this is indeed an issue. We are still very much in the early phases of learning how to use ImGui with the SDK and have not worked out all the kinks yet. None of our SDK examples use ImGui::TreeNode, but with the number of flags available it's possible we wouldn't have noticed the issue anyway. I will get this added to the SDK soon.

cipperly commented 2 years ago

Thanks Martin. I'm glad you guys added ImGui support to SIMDIS SDK; makes it possible to create an application with UI using the SDK without needing an external UI framework.

emminizer commented 2 years ago

Fixed in https://github.com/USNavalResearchLaboratory/simdissdk/commit/72c885a92d