Skip to content

Commit

Permalink
Fix: Scroll wheel zooms and scrolls property editor
Browse files Browse the repository at this point in the history
Fixed the issue where using the scroll wheel will both zoom in the renderview as well as the panel bar.
This is done by doing a cursor bounds check and disabling scrolling for the panel if the cursor is inside the renderview.
  • Loading branch information
HudsonHN committed Oct 19, 2023
1 parent a5780ea commit 7a05857
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 50 deletions.
113 changes: 64 additions & 49 deletions source/MaterialXGraphEditor/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3245,13 +3245,27 @@ void Graph::graphButtons()

// Create two windows using splitter
float paneWidth = (leftPaneWidth - 2.0f);
ImGui::BeginChild("Selection", ImVec2(paneWidth, 0));

float aspectRatio = _renderer->getPixelRatio();
ImVec2 screenSize = ImVec2(paneWidth, paneWidth / aspectRatio);

ImVec2 mousePos = ImGui::GetMousePos();
ImVec2 tempWindowPos = ImGui::GetCursorPos();
bool cursorInRenderView = mousePos.x > tempWindowPos.x && mousePos.x < (tempWindowPos.x + screenSize.x) &&
mousePos.y > tempWindowPos.y && mousePos.y < (tempWindowPos.y + screenSize.y);

ImGuiWindowFlags windowFlags = 0;

if (cursorInRenderView)
{
windowFlags |= ImGuiWindowFlags_NoScrollWithMouse;
}

ImGui::BeginChild("Selection", ImVec2(paneWidth, 0), false, windowFlags);
ImVec2 windowPos = ImGui::GetWindowPos();

// RenderView window
ImVec2 wsize = ImVec2((float) _renderer->getViewWidth(), (float) _renderer->getViewHeight());
float aspectRatio = _renderer->getPixelRatio();
ImVec2 screenSize = ImVec2(paneWidth, paneWidth / aspectRatio);
_renderer->setViewWidth((int) screenSize[0]);
_renderer->setViewHeight((int) screenSize[1]);

Expand All @@ -3271,7 +3285,10 @@ void Graph::graphButtons()
ImGui::EndChild();
ImGui::SameLine(0.0f, 12.0f);

handleRenderViewInputs(windowPos, screenSize[0], screenSize[1]);
if (cursorInRenderView)
{
handleRenderViewInputs();
}
}

void Graph::propertyEditor()
Expand Down Expand Up @@ -3839,56 +3856,54 @@ void Graph::shaderPopup()
}
}

void Graph::handleRenderViewInputs(ImVec2 minValue, float width, float height)
void Graph::handleRenderViewInputs()
{
ImVec2 mousePos = ImGui::GetMousePos();
if (mousePos.x > minValue.x && mousePos.x < (minValue.x + width) && mousePos.y > minValue.y && mousePos.y < (minValue.y + height))
mx::Vector2 mxMousePos = mx::Vector2(mousePos.x, mousePos.y);
float scrollAmt = ImGui::GetIO().MouseWheel;
int button = -1;
bool down = false;
if (ImGui::IsMouseDragging(0) || ImGui::IsMouseDragging(1))
{
mx::Vector2 mxMousePos = mx::Vector2(mousePos.x, mousePos.y);
float scrollAmt = ImGui::GetIO().MouseWheel;
int button = -1;
bool down = false;
if (ImGui::IsMouseDragging(0) || ImGui::IsMouseDragging(1))
{
_renderer->setMouseMotionEvent(mxMousePos);
}
if (ImGui::IsMouseClicked(0))
{
button = 0;
down = true;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsMouseClicked(1))
{
button = 1;
down = true;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsMouseReleased(0))
{
button = 0;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsMouseReleased(1))
{
button = 1;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsKeyPressed(ImGuiKey_KeypadAdd))
{
_renderer->setKeyEvent(ImGuiKey_KeypadAdd);
}
else if (ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract))
{
_renderer->setKeyEvent(ImGuiKey_KeypadSubtract);
}
_renderer->setMouseMotionEvent(mxMousePos);
}
if (ImGui::IsMouseClicked(0))
{
button = 0;
down = true;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsMouseClicked(1))
{
button = 1;
down = true;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsMouseReleased(0))
{
button = 0;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsMouseReleased(1))
{
button = 1;
_renderer->setMouseButtonEvent(button, down, mxMousePos);
}
else if (ImGui::IsKeyPressed(ImGuiKey_KeypadAdd))
{
_renderer->setKeyEvent(ImGuiKey_KeypadAdd);
}
else if (ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract))
{
_renderer->setKeyEvent(ImGuiKey_KeypadSubtract);
}

// Scrolling not possible if open or save file dialog is open
if (scrollAmt != 0 && !_fileDialogSave.isOpened() && !_fileDialog.isOpened() && !_fileDialogGeom.isOpened())
{
_renderer->setScrollEvent(scrollAmt);
}
// Scrolling not possible if open or save file dialog is open
if (scrollAmt != 0 && !_fileDialogSave.isOpened() && !_fileDialog.isOpened() && !_fileDialogGeom.isOpened())
{
_renderer->setScrollEvent(scrollAmt);
}

}

void Graph::drawGraph(ImVec2 mousePos)
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGraphEditor/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class Graph
void selectMaterial(UiNodePtr node);

// Allow for camera manipulation of render view window
void handleRenderViewInputs(ImVec2 minValue, float width, float height);
void handleRenderViewInputs();

// Set the node to display in render view based on selected node or nodegraph
void setRenderMaterial(UiNodePtr node);
Expand Down

0 comments on commit 7a05857

Please sign in to comment.