From 15d3bcc5d8e15b91f2ea733c6e68eaa26553d75e Mon Sep 17 00:00:00 2001 From: sty Date: Mon, 20 Jun 2022 14:53:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=A4=84=E7=BD=AEimnodes.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imnodes2/imnodes.cpp | 473 ++++++++++++++++------------ nn-editor/nn-editor.vcxproj | 8 +- nn-editor/nn-editor.vcxproj.filters | 4 +- 3 files changed, 281 insertions(+), 204 deletions(-) diff --git a/imnodes2/imnodes.cpp b/imnodes2/imnodes.cpp index 09d012e..7689cb1 100644 --- a/imnodes2/imnodes.cpp +++ b/imnodes2/imnodes.cpp @@ -18,7 +18,6 @@ #error "Minimum ImGui version requirement not met -- please use a newer version!" #endif -#include #include #include #include @@ -27,6 +26,11 @@ #include #include // strlen, strncmp +// Use secure CRT function variants to avoid MSVC compiler errors +#ifdef _MSC_VER +#define sscanf sscanf_s +#endif + ImNodesContext* GImNodes = NULL; namespace IMNODES_NAMESPACE @@ -115,7 +119,7 @@ inline CubicBezier GetCubicBezier( const ImNodesAttributeType start_type, const float line_segments_per_length) { - assert( + IM_ASSERT( (start_type == ImNodesAttributeType_Input) || (start_type == ImNodesAttributeType_Output)); if (start_type == ImNodesAttributeType_Input) { @@ -123,7 +127,7 @@ inline CubicBezier GetCubicBezier( } const float link_length = ImSqrt(ImLengthSqr(end - start)); - const ImVec2 offset = ImVec2(0.f, 0.25f * link_length); + const ImVec2 offset = ImVec2(0.25f * link_length, 0.f); CubicBezier cubic_bezier; cubic_bezier.P0 = start; cubic_bezier.P1 = start + offset; @@ -287,20 +291,20 @@ inline ImVec2 MiniMapSpaceToGridSpace(const ImNodesEditorContext& editor, const { return (v - editor.MiniMapContentScreenSpace.Min) / editor.MiniMapScaling + editor.GridContentBounds.Min; -}; +} inline ImVec2 ScreenSpaceToMiniMapSpace(const ImNodesEditorContext& editor, const ImVec2& v) { return (ScreenSpaceToGridSpace(editor, v) - editor.GridContentBounds.Min) * editor.MiniMapScaling + editor.MiniMapContentScreenSpace.Min; -}; +} inline ImRect ScreenSpaceToMiniMapSpace(const ImNodesEditorContext& editor, const ImRect& r) { return ImRect( ScreenSpaceToMiniMapSpace(editor, r.Min), ScreenSpaceToMiniMapSpace(editor, r.Max)); -}; +} // [SECTION] draw list helper @@ -366,8 +370,8 @@ void ImDrawListSplitterSwapChannels( return; } - assert(lhs_idx >= 0 && lhs_idx < splitter._Count); - assert(rhs_idx >= 0 && rhs_idx < splitter._Count); + IM_ASSERT(lhs_idx >= 0 && lhs_idx < splitter._Count); + IM_ASSERT(rhs_idx >= 0 && rhs_idx < splitter._Count); ImDrawChannel& lhs_channel = splitter._Channels[lhs_idx]; ImDrawChannel& rhs_channel = splitter._Channels[rhs_idx]; @@ -463,7 +467,7 @@ void DrawListActivateNodeBackground(const int node_idx) // * SetNodeGridSpacePos // * SetNodeDraggable // after the BeginNode/EndNode function calls? - assert(submission_idx != -1); + IM_ASSERT(submission_idx != -1); const int background_channel_idx = DrawListSubmissionIdxToBackgroundChannelIdx(submission_idx); GImNodes->CanvasDrawList->_Splitter.SetCurrentChannel( GImNodes->CanvasDrawList, background_channel_idx); @@ -471,7 +475,7 @@ void DrawListActivateNodeBackground(const int node_idx) void DrawListSwapSubmissionIndices(const int lhs_idx, const int rhs_idx) { - assert(lhs_idx != rhs_idx); + IM_ASSERT(lhs_idx != rhs_idx); const int lhs_foreground_channel_idx = DrawListSubmissionIdxToForegroundChannelIdx(lhs_idx); const int lhs_background_channel_idx = DrawListSubmissionIdxToBackgroundChannelIdx(lhs_idx); @@ -495,7 +499,7 @@ void DrawListSortChannelsByDepth(const ImVector& node_idx_depth_order) return; } - assert(node_idx_depth_order.Size == GImNodes->NodeIdxSubmissionOrder.Size); + IM_ASSERT(node_idx_depth_order.Size == GImNodes->NodeIdxSubmissionOrder.Size); int start_idx = node_idx_depth_order.Size - 1; @@ -525,7 +529,7 @@ void DrawListSortChannelsByDepth(const ImVector& node_idx_depth_order) break; } } - assert(submission_idx >= 0); + IM_ASSERT(submission_idx >= 0); if (submission_idx == depth_idx) { @@ -547,11 +551,11 @@ ImVec2 GetScreenSpacePinCoordinates( const ImRect& attribute_rect, const ImNodesAttributeType type) { - assert(type == ImNodesAttributeType_Input || type == ImNodesAttributeType_Output); - const float y = type == ImNodesAttributeType_Input - ? (node_rect.Min.y - GImNodes->Style.PinOffset) - : (node_rect.Max.y + GImNodes->Style.PinOffset); - return ImVec2(0.5f * (attribute_rect.Min.x + attribute_rect.Max.x), y); + IM_ASSERT(type == ImNodesAttributeType_Input || type == ImNodesAttributeType_Output); + const float x = type == ImNodesAttributeType_Input + ? (node_rect.Min.x - GImNodes->Style.PinOffset) + : (node_rect.Max.x + GImNodes->Style.PinOffset); + return ImVec2(x, 0.5f * (attribute_rect.Min.y + attribute_rect.Max.y)); } ImVec2 GetScreenSpacePinCoordinates(const ImNodesEditorContext& editor, const ImPinData& pin) @@ -583,21 +587,50 @@ void BeginNodeSelection(ImNodesEditorContext& editor, const int node_idx) // If the node is not already contained in the selection, then we want only // the interaction node to be selected, effective immediately. // + // If the multiple selection modifier is active, we want to add this node + // to the current list of selected nodes. + // // Otherwise, we want to allow for the possibility of multiple nodes to be // moved at once. if (!editor.SelectedNodeIndices.contains(node_idx)) { - editor.SelectedNodeIndices.clear(); editor.SelectedLinkIndices.clear(); + if (!GImNodes->MultipleSelectModifier) + { + editor.SelectedNodeIndices.clear(); + } editor.SelectedNodeIndices.push_back(node_idx); // Ensure that individually selected nodes get rendered on top ImVector& depth_stack = editor.NodeDepthOrder; const int* const elem = depth_stack.find(node_idx); - assert(elem != depth_stack.end()); + IM_ASSERT(elem != depth_stack.end()); depth_stack.erase(elem); depth_stack.push_back(node_idx); } + // Deselect a previously-selected node + else if (GImNodes->MultipleSelectModifier) + { + const int* const node_ptr = editor.SelectedNodeIndices.find(node_idx); + editor.SelectedNodeIndices.erase(node_ptr); + + // Don't allow dragging after deselecting + editor.ClickInteraction.Type = ImNodesClickInteractionType_None; + } + + // To support snapping of multiple nodes, we need to store the offset of + // each node in the selection to the origin of the dragged node. + const ImVec2 ref_origin = editor.Nodes.Pool[node_idx].Origin; + editor.PrimaryNodeOffset = + ref_origin + GImNodes->CanvasOriginScreenSpace + editor.Panning - GImNodes->MousePos; + + editor.SelectedNodeOffsets.clear(); + for (int idx = 0; idx < editor.SelectedNodeIndices.Size; idx++) + { + const int node = editor.SelectedNodeIndices[idx]; + const ImVec2 node_origin = editor.Nodes.Pool[node].Origin - ref_origin; + editor.SelectedNodeOffsets.push_back(node_origin); + } } void BeginLinkSelection(ImNodesEditorContext& editor, const int link_idx) @@ -773,18 +806,44 @@ void BoxSelectorUpdateSelection(ImNodesEditorContext& editor, ImRect box_rect) } } +ImVec2 SnapOriginToGrid(ImVec2 origin) +{ + if (GImNodes->Style.Flags & ImNodesStyleFlags_GridSnapping) + { + const float spacing = GImNodes->Style.GridSpacing; + const float spacing2 = spacing * 0.5f; + + // Snap the origin to the nearest grid point in any direction + float modx = fmodf(fabsf(origin.x) + spacing2, spacing) - spacing2; + float mody = fmodf(fabsf(origin.y) + spacing2, spacing) - spacing2; + origin.x += (origin.x < 0.f) ? modx : -modx; + origin.y += (origin.y < 0.f) ? mody : -mody; + } + + return origin; +} + void TranslateSelectedNodes(ImNodesEditorContext& editor) { if (GImNodes->LeftMouseDragging) { - const ImGuiIO& io = ImGui::GetIO(); + // If we have grid snap enabled, don't start moving nodes until we've moved the mouse + // slightly + const bool shouldTranslate = (GImNodes->Style.Flags & ImNodesStyleFlags_GridSnapping) + ? ImGui::GetIO().MouseDragMaxDistanceSqr[0] > 5.0 + : true; + + const ImVec2 origin = SnapOriginToGrid( + GImNodes->MousePos - GImNodes->CanvasOriginScreenSpace - editor.Panning + + editor.PrimaryNodeOffset); for (int i = 0; i < editor.SelectedNodeIndices.size(); ++i) { - const int node_idx = editor.SelectedNodeIndices[i]; - ImNodeData& node = editor.Nodes.Pool[node_idx]; - if (node.Draggable) + const ImVec2 node_rel = editor.SelectedNodeOffsets[i]; + const int node_idx = editor.SelectedNodeIndices[i]; + ImNodeData& node = editor.Nodes.Pool[node_idx]; + if (node.Draggable && shouldTranslate) { - node.Origin += io.MouseDelta - editor.AutoPanningDelta; + node.Origin = origin + node_rel + editor.AutoPanningDelta; } } } @@ -1056,17 +1115,9 @@ void ClickInteractionUpdate(ImNodesEditorContext& editor) } } case ImNodesClickInteractionType_None: - { - const bool dragging = GImNodes->AltMouseDragging; - - if (dragging) - { - editor.Panning += ImGui::GetIO().MouseDelta; - } - } break; default: - assert(!"Unreachable code!"); + IM_ASSERT(!"Unreachable code!"); break; } } @@ -1174,7 +1225,7 @@ ImOptionalIndex ResolveHoveredNode(const ImVector& depth_stack) } } - assert(node_idx_on_top != -1); + IM_ASSERT(node_idx_on_top != -1); return ImOptionalIndex(node_idx_on_top); } @@ -1278,6 +1329,9 @@ inline ImRect GetNodeTitleRect(const ImNodeData& node) void DrawGrid(ImNodesEditorContext& editor, const ImVec2& canvas_size) { const ImVec2 offset = editor.Panning; + ImU32 line_color = GImNodes->Style.Colors[ImNodesCol_GridLine]; + ImU32 line_color_prim = GImNodes->Style.Colors[ImNodesCol_GridLinePrimary]; + bool draw_primary = GImNodes->Style.Flags & ImNodesStyleFlags_GridLinesPrimary; for (float x = fmodf(offset.x, GImNodes->Style.GridSpacing); x < canvas_size.x; x += GImNodes->Style.GridSpacing) @@ -1285,7 +1339,7 @@ void DrawGrid(ImNodesEditorContext& editor, const ImVec2& canvas_size) GImNodes->CanvasDrawList->AddLine( EditorSpaceToScreenSpace(ImVec2(x, 0.0f)), EditorSpaceToScreenSpace(ImVec2(x, canvas_size.y)), - GImNodes->Style.Colors[ImNodesCol_GridLine]); + offset.x - x == 0.f && draw_primary ? line_color_prim : line_color); } for (float y = fmodf(offset.y, GImNodes->Style.GridSpacing); y < canvas_size.y; @@ -1294,7 +1348,7 @@ void DrawGrid(ImNodesEditorContext& editor, const ImVec2& canvas_size) GImNodes->CanvasDrawList->AddLine( EditorSpaceToScreenSpace(ImVec2(0.0f, y)), EditorSpaceToScreenSpace(ImVec2(canvas_size.x, y)), - GImNodes->Style.Colors[ImNodesCol_GridLine]); + offset.y - y == 0.f && draw_primary ? line_color_prim : line_color); } } @@ -1419,7 +1473,7 @@ void DrawPinShape(const ImVec2& pin_pos, const ImPinData& pin, const ImU32 pin_c } break; default: - assert(!"Invalid PinShape value!"); + IM_ASSERT(!"Invalid PinShape value!"); break; } } @@ -1585,7 +1639,7 @@ void BeginPinAttribute( { // Make sure to call BeginNode() before calling // BeginAttribute() - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); GImNodes->CurrentScope = ImNodesScope_Attribute; ImGui::BeginGroup(); @@ -1609,7 +1663,7 @@ void BeginPinAttribute( void EndPinAttribute() { - assert(GImNodes->CurrentScope == ImNodesScope_Attribute); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Attribute); GImNodes->CurrentScope = ImNodesScope_Node; ImGui::PopID(); @@ -1638,12 +1692,12 @@ void Initialize(ImNodesContext* context) context->CurrentNodeIdx = INT_MAX; context->DefaultEditorCtx = EditorContextCreate(); - EditorContextSet(GImNodes->DefaultEditorCtx); + context->EditorCtx = context->DefaultEditorCtx; context->CurrentAttributeFlags = ImNodesAttributeFlags_None; context->AttributeFlagStack.push_back(GImNodes->CurrentAttributeFlags); - StyleColorsDark(); + StyleColorsDark(&context->Style); } void Shutdown(ImNodesContext* ctx) { EditorContextFree(ctx->DefaultEditorCtx); } @@ -1681,7 +1735,7 @@ static inline void CalcMiniMapLayout() const ImVec2 grid_content_size = editor.GridContentBounds.IsInverted() ? max_size : ImFloor(editor.GridContentBounds.GetSize()); - const float grid_content_aspect_ratio = grid_content_size.x / grid_content_size.y; + const float grid_content_aspect_ratio = grid_content_size.x / grid_content_size.y; mini_map_size = ImFloor( grid_content_aspect_ratio > max_size_aspect_ratio ? ImVec2(max_size.x, max_size.x / grid_content_aspect_ratio) @@ -1896,8 +1950,8 @@ template void SelectObject(const ImObjectPool& objects, ImVector& selected_indices, const int id) { const int idx = ObjectPoolFind(objects, id); - assert(idx >= 0); - assert(selected_indices.find(idx) == selected_indices.end()); + IM_ASSERT(idx >= 0); + IM_ASSERT(selected_indices.find(idx) == selected_indices.end()); selected_indices.push_back(idx); } @@ -1908,8 +1962,8 @@ void ClearObjectSelection( const int id) { const int idx = ObjectPoolFind(objects, id); - assert(idx >= 0); - assert(selected_indices.find(idx) != selected_indices.end()); + IM_ASSERT(idx >= 0); + IM_ASSERT(selected_indices.find(idx) != selected_indices.end()); selected_indices.find_erase_unsorted(idx); } @@ -1929,14 +1983,16 @@ ImNodesIO::EmulateThreeButtonMouse::EmulateThreeButtonMouse() : Modifier(NULL) { ImNodesIO::LinkDetachWithModifierClick::LinkDetachWithModifierClick() : Modifier(NULL) {} +ImNodesIO::MultipleSelectModifier::MultipleSelectModifier() : Modifier(NULL) {} + ImNodesIO::ImNodesIO() : EmulateThreeButtonMouse(), LinkDetachWithModifierClick(), - AltMouseButton(ImGuiMouseButton_Right), AutoPanningSpeed(1000.0f) + AltMouseButton(ImGuiMouseButton_Middle), AutoPanningSpeed(1000.0f) { } ImNodesStyle::ImNodesStyle() - : GridSpacing(32.f), NodeCornerRounding(4.f), NodePadding(8.f, 8.f), NodeBorderThickness(1.f), + : GridSpacing(24.f), NodeCornerRounding(4.f), NodePadding(8.f, 8.f), NodeBorderThickness(1.f), LinkThickness(3.f), LinkLineSegmentsPerLength(0.1f), LinkHoverDistance(10.f), PinCircleRadius(4.f), PinQuadSideLength(7.f), PinTriangleSideLength(9.5), PinLineThickness(1.f), PinHoverRadius(10.f), PinOffset(0.f), MiniMapPadding(8.0f, 8.0f), @@ -2012,137 +2068,147 @@ ImNodesIO& GetIO() { return GImNodes->Io; } ImNodesStyle& GetStyle() { return GImNodes->Style; } -void StyleColorsDark() +void StyleColorsDark(ImNodesStyle* dest) { - GImNodes->Style.Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); + if (dest == nullptr) + { + dest = &GImNodes->Style; + } + + dest->Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); + dest->Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); // title bar colors match ImGui's titlebg colors - GImNodes->Style.Colors[ImNodesCol_TitleBar] = IM_COL32(41, 74, 122, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarHovered] = IM_COL32(66, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarSelected] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_TitleBar] = IM_COL32(41, 74, 122, 255); + dest->Colors[ImNodesCol_TitleBarHovered] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_TitleBarSelected] = IM_COL32(66, 150, 250, 255); // link colors match ImGui's slider grab colors - GImNodes->Style.Colors[ImNodesCol_Link] = IM_COL32(61, 133, 224, 200); - GImNodes->Style.Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_LinkSelected] = IM_COL32(66, 150, 250, 255); - - GImNodes->Style.Colors[ImNodesCol_Link] = IM_COL32(66, 150, 250, 100); - GImNodes->Style.Colors[ImNodesCol_LinkHovered] = IM_COL32(99, 200, 250, 224); - GImNodes->Style.Colors[ImNodesCol_LinkSelected] = IM_COL32(255, 69, 91, 224); - + dest->Colors[ImNodesCol_Link] = IM_COL32(61, 133, 224, 200); + dest->Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_LinkSelected] = IM_COL32(66, 150, 250, 255); // pin colors match ImGui's button colors - GImNodes->Style.Colors[ImNodesCol_Pin] = IM_COL32(53, 150, 250, 180); - GImNodes->Style.Colors[ImNodesCol_PinHovered] = IM_COL32(53, 150, 250, 255); + dest->Colors[ImNodesCol_Pin] = IM_COL32(53, 150, 250, 180); + dest->Colors[ImNodesCol_PinHovered] = IM_COL32(53, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_BoxSelector] = IM_COL32(61, 133, 224, 30); - GImNodes->Style.Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(61, 133, 224, 150); + dest->Colors[ImNodesCol_BoxSelector] = IM_COL32(61, 133, 224, 30); + dest->Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(61, 133, 224, 150); - GImNodes->Style.Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); - GImNodes->Style.Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + dest->Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); + dest->Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + dest->Colors[ImNodesCol_GridLinePrimary] = IM_COL32(240, 240, 240, 60); // minimap colors - GImNodes->Style.Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 150); - GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered] = IM_COL32(200, 200, 200, 255); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapLink] = GImNodes->Style.Colors[ImNodesCol_Link]; - GImNodes->Style.Colors[ImNodesCol_MiniMapLinkSelected] = - GImNodes->Style.Colors[ImNodesCol_LinkSelected]; - GImNodes->Style.Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); - GImNodes->Style.Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); -} - -void StyleColorsClassic() -{ - GImNodes->Style.Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBar] = IM_COL32(69, 69, 138, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarHovered] = IM_COL32(82, 82, 161, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarSelected] = IM_COL32(82, 82, 161, 255); - GImNodes->Style.Colors[ImNodesCol_Link] = IM_COL32(255, 255, 255, 100); - GImNodes->Style.Colors[ImNodesCol_LinkHovered] = IM_COL32(105, 99, 204, 153); - GImNodes->Style.Colors[ImNodesCol_LinkSelected] = IM_COL32(105, 99, 204, 153); - GImNodes->Style.Colors[ImNodesCol_Pin] = IM_COL32(89, 102, 156, 170); - GImNodes->Style.Colors[ImNodesCol_PinHovered] = IM_COL32(102, 122, 179, 200); - GImNodes->Style.Colors[ImNodesCol_BoxSelector] = IM_COL32(82, 82, 161, 100); - GImNodes->Style.Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(82, 82, 161, 255); - GImNodes->Style.Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); - GImNodes->Style.Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + dest->Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 150); + dest->Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); + dest->Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); + dest->Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); + dest->Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered] = IM_COL32(200, 200, 200, 255); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; + dest->Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapLink] = dest->Colors[ImNodesCol_Link]; + dest->Colors[ImNodesCol_MiniMapLinkSelected] = dest->Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); + dest->Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); +} + +void StyleColorsClassic(ImNodesStyle* dest) +{ + if (dest == nullptr) + { + dest = &GImNodes->Style; + } + + dest->Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); + dest->Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); + dest->Colors[ImNodesCol_TitleBar] = IM_COL32(69, 69, 138, 255); + dest->Colors[ImNodesCol_TitleBarHovered] = IM_COL32(82, 82, 161, 255); + dest->Colors[ImNodesCol_TitleBarSelected] = IM_COL32(82, 82, 161, 255); + dest->Colors[ImNodesCol_Link] = IM_COL32(255, 255, 255, 100); + dest->Colors[ImNodesCol_LinkHovered] = IM_COL32(105, 99, 204, 153); + dest->Colors[ImNodesCol_LinkSelected] = IM_COL32(105, 99, 204, 153); + dest->Colors[ImNodesCol_Pin] = IM_COL32(89, 102, 156, 170); + dest->Colors[ImNodesCol_PinHovered] = IM_COL32(102, 122, 179, 200); + dest->Colors[ImNodesCol_BoxSelector] = IM_COL32(82, 82, 161, 100); + dest->Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(82, 82, 161, 255); + dest->Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); + dest->Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + dest->Colors[ImNodesCol_GridLinePrimary] = IM_COL32(240, 240, 240, 60); // minimap colors - GImNodes->Style.Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapLink] = GImNodes->Style.Colors[ImNodesCol_Link]; - GImNodes->Style.Colors[ImNodesCol_MiniMapLinkSelected] = - GImNodes->Style.Colors[ImNodesCol_LinkSelected]; - GImNodes->Style.Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); - GImNodes->Style.Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); -} - -void StyleColorsLight() -{ - GImNodes->Style.Colors[ImNodesCol_NodeBackground] = IM_COL32(240, 240, 240, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(240, 240, 240, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(240, 240, 240, 255); - GImNodes->Style.Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBar] = IM_COL32(248, 248, 248, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarHovered] = IM_COL32(209, 209, 209, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarSelected] = IM_COL32(209, 209, 209, 255); + dest->Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); + dest->Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); + dest->Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); + dest->Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); + dest->Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); + dest->Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapLink] = dest->Colors[ImNodesCol_Link]; + dest->Colors[ImNodesCol_MiniMapLinkSelected] = dest->Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); + dest->Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); +} + +void StyleColorsLight(ImNodesStyle* dest) +{ + if (dest == nullptr) + { + dest = &GImNodes->Style; + } + + dest->Colors[ImNodesCol_NodeBackground] = IM_COL32(240, 240, 240, 255); + dest->Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(240, 240, 240, 255); + dest->Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(240, 240, 240, 255); + dest->Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); + dest->Colors[ImNodesCol_TitleBar] = IM_COL32(248, 248, 248, 255); + dest->Colors[ImNodesCol_TitleBarHovered] = IM_COL32(209, 209, 209, 255); + dest->Colors[ImNodesCol_TitleBarSelected] = IM_COL32(209, 209, 209, 255); // original imgui values: 66, 150, 250 - GImNodes->Style.Colors[ImNodesCol_Link] = IM_COL32(66, 150, 250, 100); + dest->Colors[ImNodesCol_Link] = IM_COL32(66, 150, 250, 100); // original imgui values: 117, 138, 204 - GImNodes->Style.Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 224); - GImNodes->Style.Colors[ImNodesCol_LinkSelected] = IM_COL32(255, 69, 91, 224); + dest->Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 242); + dest->Colors[ImNodesCol_LinkSelected] = IM_COL32(66, 150, 250, 242); // original imgui values: 66, 150, 250 - GImNodes->Style.Colors[ImNodesCol_Pin] = IM_COL32(66, 150, 250, 160); - GImNodes->Style.Colors[ImNodesCol_PinHovered] = IM_COL32(66, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_BoxSelector] = IM_COL32(90, 170, 250, 30); - GImNodes->Style.Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(90, 170, 250, 150); - GImNodes->Style.Colors[ImNodesCol_GridBackground] = IM_COL32(225, 225, 225, 255); - GImNodes->Style.Colors[ImNodesCol_GridLine] = IM_COL32(180, 180, 180, 100); + dest->Colors[ImNodesCol_Pin] = IM_COL32(66, 150, 250, 160); + dest->Colors[ImNodesCol_PinHovered] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_BoxSelector] = IM_COL32(90, 170, 250, 30); + dest->Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(90, 170, 250, 150); + dest->Colors[ImNodesCol_GridBackground] = IM_COL32(225, 225, 225, 255); + dest->Colors[ImNodesCol_GridLine] = IM_COL32(180, 180, 180, 100); + dest->Colors[ImNodesCol_GridLinePrimary] = IM_COL32(120, 120, 120, 100); // minimap colors - GImNodes->Style.Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapLink] = GImNodes->Style.Colors[ImNodesCol_Link]; - GImNodes->Style.Colors[ImNodesCol_MiniMapLinkSelected] = - GImNodes->Style.Colors[ImNodesCol_LinkSelected]; - GImNodes->Style.Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); - GImNodes->Style.Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); + dest->Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); + dest->Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); + dest->Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); + dest->Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); + dest->Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); + dest->Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapLink] = dest->Colors[ImNodesCol_Link]; + dest->Colors[ImNodesCol_MiniMapLinkSelected] = dest->Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); + dest->Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); } void BeginNodeEditor() { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); GImNodes->CurrentScope = ImNodesScope_Editor; // Reset state from previous pass ImNodesEditorContext& editor = EditorContextGet(); editor.AutoPanningDelta = ImVec2(0, 0); - editor.GridContentBounds = ImRect(FLT_MAX, FLT_MAX, FLT_MIN, FLT_MIN); + editor.GridContentBounds = ImRect(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); editor.MiniMapEnabled = false; ObjectPoolReset(editor.Nodes); ObjectPoolReset(editor.Pins); @@ -2161,16 +2227,20 @@ void BeginNodeEditor() GImNodes->MousePos = ImGui::GetIO().MousePos; GImNodes->LeftMouseClicked = ImGui::IsMouseClicked(0); GImNodes->LeftMouseReleased = ImGui::IsMouseReleased(0); + GImNodes->LeftMouseDragging = ImGui::IsMouseDragging(0, 0.0f); GImNodes->AltMouseClicked = (GImNodes->Io.EmulateThreeButtonMouse.Modifier != NULL && *GImNodes->Io.EmulateThreeButtonMouse.Modifier && GImNodes->LeftMouseClicked) || ImGui::IsMouseClicked(GImNodes->Io.AltMouseButton); - GImNodes->LeftMouseDragging = ImGui::IsMouseDragging(0, 0.0f); GImNodes->AltMouseDragging = (GImNodes->Io.EmulateThreeButtonMouse.Modifier != NULL && GImNodes->LeftMouseDragging && (*GImNodes->Io.EmulateThreeButtonMouse.Modifier)) || ImGui::IsMouseDragging(GImNodes->Io.AltMouseButton, 0.0f); GImNodes->AltMouseScrollDelta = ImGui::GetIO().MouseWheel; + GImNodes->MultipleSelectModifier = + (GImNodes->Io.MultipleSelectModifier.Modifier != NULL + ? *GImNodes->Io.MultipleSelectModifier.Modifier + : ImGui::GetIO().KeyCtrl); GImNodes->ActiveAttribute = false; @@ -2207,7 +2277,7 @@ void BeginNodeEditor() void EndNodeEditor() { - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); GImNodes->CurrentScope = ImNodesScope_None; ImNodesEditorContext& editor = EditorContextGet(); @@ -2362,10 +2432,10 @@ void MiniMap( const ImNodesMiniMapNodeHoveringCallbackUserData node_hovering_callback_data) { // Check that editor size fraction is sane; must be in the range (0, 1] - assert(minimap_size_fraction > 0.f && minimap_size_fraction <= 1.f); + IM_ASSERT(minimap_size_fraction > 0.f && minimap_size_fraction <= 1.f); // Remember to call before EndNodeEditor - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); ImNodesEditorContext& editor = EditorContextGet(); @@ -2386,7 +2456,7 @@ void MiniMap( void BeginNode(const int node_id) { // Remember to call BeginNodeEditor before calling BeginNode - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); GImNodes->CurrentScope = ImNodesScope_Node; ImNodesEditorContext& editor = EditorContextGet(); @@ -2420,7 +2490,7 @@ void BeginNode(const int node_id) void EndNode() { - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); GImNodes->CurrentScope = ImNodesScope_Editor; ImNodesEditorContext& editor = EditorContextGet(); @@ -2446,20 +2516,20 @@ ImVec2 GetNodeDimensions(int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); // invalid node_id + IM_ASSERT(node_idx != -1); // invalid node_id const ImNodeData& node = editor.Nodes.Pool[node_idx]; return node.Rect.GetSize(); } void BeginNodeTitleBar() { - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); ImGui::BeginGroup(); } void EndNodeTitleBar() { - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); ImGui::EndGroup(); ImNodesEditorContext& editor = EditorContextGet(); @@ -2488,7 +2558,7 @@ void EndOutputAttribute() { EndPinAttribute(); } void BeginStaticAttribute(const int id) { // Make sure to call BeginNode() before calling BeginAttribute() - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); GImNodes->CurrentScope = ImNodesScope_Attribute; GImNodes->CurrentAttributeId = id; @@ -2500,7 +2570,7 @@ void BeginStaticAttribute(const int id) void EndStaticAttribute() { // Make sure to call BeginNode() before calling BeginAttribute() - assert(GImNodes->CurrentScope == ImNodesScope_Attribute); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Attribute); GImNodes->CurrentScope = ImNodesScope_Node; ImGui::PopID(); @@ -2523,7 +2593,7 @@ void PopAttributeFlag() { // PopAttributeFlag called without a matching PushAttributeFlag! // The bottom value is always the default value, pushed in Initialize(). - assert(GImNodes->AttributeFlagStack.size() > 1); + IM_ASSERT(GImNodes->AttributeFlagStack.size() > 1); GImNodes->AttributeFlagStack.pop_back(); GImNodes->CurrentAttributeFlags = GImNodes->AttributeFlagStack.back(); @@ -2531,7 +2601,7 @@ void PopAttributeFlag() void Link(const int id, const int start_attr_id, const int end_attr_id) { - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); ImNodesEditorContext& editor = EditorContextGet(); ImLinkData& link = ObjectPoolFindOrCreateObject(editor.Links, id); @@ -2562,7 +2632,7 @@ void PushColorStyle(const ImNodesCol item, unsigned int color) void PopColorStyle() { - assert(GImNodes->ColorModifierStack.size() > 0); + IM_ASSERT(GImNodes->ColorModifierStack.size() > 0); const ImNodesColElement elem = GImNodes->ColorModifierStack.back(); GImNodes->Style.Colors[elem.Item] = elem.Color; GImNodes->ColorModifierStack.pop_back(); @@ -2646,7 +2716,7 @@ void PopStyleVar(int count) { while (count > 0) { - assert(GImNodes->StyleModifierStack.size() > 0); + IM_ASSERT(GImNodes->StyleModifierStack.size() > 0); const ImNodesStyleVarElement style_backup = GImNodes->StyleModifierStack.back(); GImNodes->StyleModifierStack.pop_back(); const ImNodesStyleVarInfo* var_info = GetStyleVarInfo(style_backup.Item); @@ -2696,7 +2766,7 @@ ImVec2 GetNodeScreenSpacePos(const int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); + IM_ASSERT(node_idx != -1); ImNodeData& node = editor.Nodes.Pool[node_idx]; return GridSpaceToScreenSpace(editor, node.Origin); } @@ -2705,7 +2775,7 @@ ImVec2 GetNodeEditorSpacePos(const int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); + IM_ASSERT(node_idx != -1); ImNodeData& node = editor.Nodes.Pool[node_idx]; return GridSpaceToEditorSpace(editor, node.Origin); } @@ -2714,17 +2784,24 @@ ImVec2 GetNodeGridSpacePos(const int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); + IM_ASSERT(node_idx != -1); ImNodeData& node = editor.Nodes.Pool[node_idx]; return node.Origin; } +void SnapNodeToGrid(int node_id) +{ + ImNodesEditorContext& editor = EditorContextGet(); + ImNodeData& node = ObjectPoolFindOrCreateObject(editor.Nodes, node_id); + node.Origin = SnapOriginToGrid(node.Origin); +} + bool IsEditorHovered() { return MouseInCanvas(); } bool IsNodeHovered(int* const node_id) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(node_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(node_id != NULL); const bool is_hovered = GImNodes->HoveredNodeIdx.HasValue(); if (is_hovered) @@ -2737,8 +2814,8 @@ bool IsNodeHovered(int* const node_id) bool IsLinkHovered(int* const link_id) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(link_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(link_id != NULL); const bool is_hovered = GImNodes->HoveredLinkIdx.HasValue(); if (is_hovered) @@ -2751,8 +2828,8 @@ bool IsLinkHovered(int* const link_id) bool IsPinHovered(int* const attr) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(attr != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(attr != NULL); const bool is_hovered = GImNodes->HoveredPinIdx.HasValue(); if (is_hovered) @@ -2765,21 +2842,21 @@ bool IsPinHovered(int* const attr) int NumSelectedNodes() { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const ImNodesEditorContext& editor = EditorContextGet(); return editor.SelectedNodeIndices.size(); } int NumSelectedLinks() { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const ImNodesEditorContext& editor = EditorContextGet(); return editor.SelectedLinkIndices.size(); } void GetSelectedNodes(int* node_ids) { - assert(node_ids != NULL); + IM_ASSERT(node_ids != NULL); const ImNodesEditorContext& editor = EditorContextGet(); for (int i = 0; i < editor.SelectedNodeIndices.size(); ++i) @@ -2791,7 +2868,7 @@ void GetSelectedNodes(int* node_ids) void GetSelectedLinks(int* link_ids) { - assert(link_ids != NULL); + IM_ASSERT(link_ids != NULL); const ImNodesEditorContext& editor = EditorContextGet(); for (int i = 0; i < editor.SelectedLinkIndices.size(); ++i) @@ -2851,7 +2928,7 @@ bool IsLinkSelected(int link_id) bool IsAttributeActive() { - assert((GImNodes->CurrentScope & ImNodesScope_Node) != 0); + IM_ASSERT((GImNodes->CurrentScope & ImNodesScope_Node) != 0); if (!GImNodes->ActiveAttribute) { @@ -2863,7 +2940,7 @@ bool IsAttributeActive() bool IsAnyAttributeActive(int* const attribute_id) { - assert((GImNodes->CurrentScope & (ImNodesScope_Node | ImNodesScope_Attribute)) == 0); + IM_ASSERT((GImNodes->CurrentScope & (ImNodesScope_Node | ImNodesScope_Attribute)) == 0); if (!GImNodes->ActiveAttribute) { @@ -2881,8 +2958,8 @@ bool IsAnyAttributeActive(int* const attribute_id) bool IsLinkStarted(int* const started_at_id) { // Call this function after EndNodeEditor()! - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(started_at_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(started_at_id != NULL); const bool is_started = (GImNodes->ImNodesUIState & ImNodesUIState_LinkStarted) != 0; if (is_started) @@ -2898,7 +2975,7 @@ bool IsLinkStarted(int* const started_at_id) bool IsLinkDropped(int* const started_at_id, const bool including_detached_links) { // Call this function after EndNodeEditor()! - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const ImNodesEditorContext& editor = EditorContextGet(); @@ -2921,9 +2998,9 @@ bool IsLinkCreated( int* const ended_at_pin_id, bool* const created_from_snap) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(started_at_pin_id != NULL); - assert(ended_at_pin_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(started_at_pin_id != NULL); + IM_ASSERT(ended_at_pin_id != NULL); const bool is_created = (GImNodes->ImNodesUIState & ImNodesUIState_LinkCreated) != 0; @@ -2963,11 +3040,11 @@ bool IsLinkCreated( int* ended_at_pin_id, bool* created_from_snap) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(started_at_node_id != NULL); - assert(started_at_pin_id != NULL); - assert(ended_at_node_id != NULL); - assert(ended_at_pin_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(started_at_node_id != NULL); + IM_ASSERT(started_at_pin_id != NULL); + IM_ASSERT(ended_at_node_id != NULL); + IM_ASSERT(ended_at_pin_id != NULL); const bool is_created = (GImNodes->ImNodesUIState & ImNodesUIState_LinkCreated) != 0; @@ -3008,7 +3085,7 @@ bool IsLinkCreated( bool IsLinkDestroyed(int* const link_id) { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const bool link_destroyed = GImNodes->DeletedLinkIdx.HasValue(); if (link_destroyed) @@ -3037,7 +3114,7 @@ void NodeLineHandler(ImNodesEditorContext& editor, const char* const line) else if (sscanf(line, "origin=%i,%i", &x, &y) == 2) { ImNodeData& node = editor.Nodes.Pool[GImNodes->CurrentNodeIdx]; - node.Origin = ImVec2((float)x, (float)y); + node.Origin = SnapOriginToGrid(ImVec2((float)x, (float)y)); } } @@ -3056,7 +3133,7 @@ const char* SaveEditorStateToIniString( const ImNodesEditorContext* const editor_ptr, size_t* const data_size) { - assert(editor_ptr != NULL); + IM_ASSERT(editor_ptr != NULL); const ImNodesEditorContext& editor = *editor_ptr; GImNodes->TextBuffer.clear(); diff --git a/nn-editor/nn-editor.vcxproj b/nn-editor/nn-editor.vcxproj index b4244b3..9b9c72d 100644 --- a/nn-editor/nn-editor.vcxproj +++ b/nn-editor/nn-editor.vcxproj @@ -19,8 +19,8 @@ - - + + @@ -151,7 +151,7 @@ false _DEBUG;_CONSOLE;NETEDIT_LOADER_YAML_YOLO;NETEDIT_LOADER_NCNN;USE_OPENGL3;%(PreprocessorDefinitions) Default - ..;../..;D:\project\microsoft\vcpkg\installed\x64-windows\include\SDL2;../3rdparty/nb;../3rdparty/imgui/backends;../3rdparty/imgui;../3rdparty/imgui/misc/cpp;../3rdparty/imnodes;../3rdparty/ImGuiFileDialog + ..;../..;D:\project\microsoft\vcpkg\installed\x64-windows\include\SDL2;../3rdparty/mlcc;../3rdparty/imgui/backends;../3rdparty/imgui;../3rdparty/imgui/misc/cpp;../3rdparty/imnodes;../3rdparty/ImGuiFileDialog stdcpp17 @@ -170,7 +170,7 @@ false NDEBUG;_CONSOLE;USE_OPENGL3;NETEDIT_LOADER_YAML_YOLO;NETEDIT_LOADER_NCNN;%(PreprocessorDefinitions) true - ..;../..;D:\project\microsoft\vcpkg\installed\x64-windows\include\SDL2;../3rdparty/nb;../3rdparty/imgui/backends;../3rdparty/imgui;../3rdparty/imgui/misc/cpp;../3rdparty/imnodes;../3rdparty/ImGuiFileDialog + ..;../..;D:\project\microsoft\vcpkg\installed\x64-windows\include\SDL2;../3rdparty/mlcc;../3rdparty/imgui/backends;../3rdparty/imgui;../3rdparty/imgui/misc/cpp;../3rdparty/imnodes;../3rdparty/ImGuiFileDialog Default diff --git a/nn-editor/nn-editor.vcxproj.filters b/nn-editor/nn-editor.vcxproj.filters index b5c1e39..2a2476d 100644 --- a/nn-editor/nn-editor.vcxproj.filters +++ b/nn-editor/nn-editor.vcxproj.filters @@ -45,10 +45,10 @@ imgui - + 源文件 - + 源文件