Skip to content

Commit

Permalink
Move node editor context menus to main imgui context to avoid scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Dec 26, 2024
1 parent 6792ff9 commit d25e043
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tools/NodeEditor/FastNoiseNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ void FastNoiseNodeEditor::Node::GeneratePreview( bool nodeTreeChanged, bool benc
genRGB->SetSource( scale );
scale->SetSource( generator );
scale->SetScaling( editor.mNodeScale );

FastNoise::SmartNode<FastNoise::ConvertRGBA8> l(nullptr);

auto startTime = std::chrono::high_resolution_clock::now();

Expand Down Expand Up @@ -335,7 +333,7 @@ bool FastNoiseNodeEditor::MetadataMenuItem::CanDraw( std::function<bool( const F

const FastNoise::Metadata* FastNoiseNodeEditor::MetadataMenuItem::DrawUI( std::function<bool( const FastNoise::Metadata* )> isValid, bool drawGroups ) const
{
std::string format = FastNoise::Metadata::FormatMetadataNodeName( metadata, true );
std::string format = FastNoise::Metadata::FormatMetadataNodeName( metadata, drawGroups );

if( ImGui::MenuItem( format.c_str() ) )
{
Expand Down Expand Up @@ -589,6 +587,7 @@ void FastNoiseNodeEditor::SetupSettingsHandlers()

FastNoiseNodeEditor::FastNoiseNodeEditor( NodeEditorApp& nodeEditorApp ) :
mNodeEditorApp( nodeEditorApp ),
mMainContext( ImGui::GetCurrentContext() ),
mOverheadNode( *this, new FastNoise::NodeData( &FastNoise::Metadata::Get<FastNoise::Constant>() ), false )
{
if( !mNodeEditorApp.IsDetachedNodeGraph() )
Expand Down Expand Up @@ -830,9 +829,10 @@ void FastNoiseNodeEditor::Draw( const Matrix4& transformation, const Matrix4& pr
OpenStandaloneNodeGraph();
}

ImGui::SetCurrentContext( mMainContext );
DoHelp();

DoContextMenu();
ImGui::SetCurrentContext( ImNodes::GetNodeEditorImGuiContext() );

DoNodes();

Expand Down Expand Up @@ -1049,9 +1049,17 @@ void FastNoiseNodeEditor::DoNodes()

ImNodes::EndNodeTitleBar();

if( ImGui::IsMouseReleased( ImGuiMouseButton_Right ) && ImGui::IsItemHovered( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) )
{
ImGui::SetCurrentContext( mMainContext );
ImGui::OpenPopup( "node_title" );
}

ImGui::SetCurrentContext( mMainContext );
// Right click node title to change node type
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4, 4 ) );
if( ImGui::BeginPopupContextItem() )

if( ImGui::BeginPopup( "node_title" ) )
{
if( ImGui::MenuItem( "Copy Encoded Node Tree" ) )
{
Expand All @@ -1074,7 +1082,7 @@ void FastNoiseNodeEditor::DoNodes()
MatchingMembers( newMetadata->memberNodeLookups, nodeMetadata->memberNodeLookups ) &&
MatchingMembers( newMetadata->memberHybrids, nodeMetadata->memberHybrids ) )
{
nodeMetadata = newMetadata;
nodeMetadata = newMetadata;
}
else
{
Expand Down Expand Up @@ -1104,7 +1112,7 @@ void FastNoiseNodeEditor::DoNodes()
links.pop();
}

*node.second.data = std::move( newData );
*node.second.data = std::move( newData );
}

node.second.GeneratePreview();
Expand All @@ -1114,6 +1122,8 @@ void FastNoiseNodeEditor::DoNodes()
}
ImGui::PopStyleVar();

ImGui::SetCurrentContext( ImNodes::GetNodeEditorImGuiContext() );

ImGui::PushItemWidth( 90.0f );

ImNodes::PushAttributeFlag( ImNodesAttributeFlags_EnableLinkCreationOnSnap );
Expand Down Expand Up @@ -1286,7 +1296,7 @@ void FastNoiseNodeEditor::DoHelp()
ImGui::Text( " Help" );
if( ImGui::IsItemHovered() )
{
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4.f, 4.f ) );
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 6.f, 6.f ) );
ImGui::BeginTooltip();
constexpr float alignPx = 110;

Expand Down
1 change: 1 addition & 0 deletions tools/NodeEditor/FastNoiseNodeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ namespace Magnum
void UpdateSelected();

NodeEditorApp& mNodeEditorApp;
ImGuiContext* mMainContext;

std::unordered_map<FastNoise::NodeData*, Node> mNodes;
FastNoise::NodeData* mDroppedLinkNode = nullptr;
Expand Down

0 comments on commit d25e043

Please sign in to comment.