Skip to content

Commit

Permalink
Add zooming support to the node graph editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Feb 4, 2024
1 parent cd48b8a commit 55ef187
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ find_package(ImGui REQUIRED SourcesMiscCpp)
CPMAddPackage(
NAME imnodes
GITHUB_REPOSITORY Auburn/imnodes
GIT_TAG 1aa48f4af2a4f9f1b9a6ed53fe858ed76646b233
GIT_TAG 9d89b3e98c91ba2b414c9ad1cdf7e9c48510c6f0
GIT_SUBMODULES ".github"
EXCLUDE_FROM_ALL YES
OPTIONS
Expand Down
30 changes: 23 additions & 7 deletions tools/FastNoiseNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ void FastNoiseNodeEditor::Draw( const Matrix4& transformation, const Matrix4& pr
}

ImGuiExtra::MarkSettingsDirty();
}
}

ImNodes::BeginNodeEditor();

Expand All @@ -673,15 +673,27 @@ void FastNoiseNodeEditor::Draw( const Matrix4& transformation, const Matrix4& pr

ImNodes::MiniMap( 0.2f, ImNodesMiniMapLocation_BottomLeft );

#if 0
if( ImGui::IsWindowHovered() )
ImNodes::EndNodeEditor();

// Zoom
if( ImNodes::IsEditorHovered() && ImGui::GetIO().MouseWheel != 0 )
{
auto zoom = ImNodes::EditorContextGetZoom() + ImGui::GetIO().MouseWheel * 0.1f;
float zoom = ImNodes::EditorContextGetZoom();
if( ImGui::GetIO().MouseWheel > 0 )
{
zoom *= 1.5f;
if( zoom > 0.9f )
{
zoom = 1;
}
}
else
{
zoom /= 1.5f;
zoom = std::max( zoom, 0.2f );
}
ImNodes::EditorContextSetZoom( zoom, ImGui::GetMousePos() );
}
#endif

ImNodes::EndNodeEditor();

CheckLinks();

Expand Down Expand Up @@ -1115,6 +1127,10 @@ void FastNoiseNodeEditor::DoHelp()
ImGui::SameLine( alignPx );
ImGui::TextUnformatted( "Right mouse drag" );

ImGui::TextUnformatted( "Zoom graph" );
ImGui::SameLine( alignPx );
ImGui::TextUnformatted( "Mouse wheel" );

ImGui::TextUnformatted( "Delete node/link" );
ImGui::SameLine( alignPx );
ImGui::TextUnformatted( "Backspace or Delete" );
Expand Down
1 change: 1 addition & 0 deletions tools/NodeEditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ NodeEditorApp::NodeEditorApp( const Arguments& arguments ) :
}

ImGui::GetIO().IniFilename = "NodeEditor.ini";
ImGui::GetIO().ConfigDragClickToInputText = true;
mImGuiIntegrationContext = ImGuiIntegration::Context( *mImGuiContext, size, windowSize(), framebufferSize() );

GL::Renderer::enable( GL::Renderer::Feature::DepthTest );
Expand Down

0 comments on commit 55ef187

Please sign in to comment.