Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scroll wheel interaction across graph editor windows #1578

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 64 additions & 49 deletions source/MaterialXGraphEditor/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3241,13 +3241,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 @@ -3267,7 +3281,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 @@ -3830,56 +3847,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