imnodes: pin coloring and connectivity logic

AnimGraphEditor
Martin Felis 2022-04-08 12:48:04 +02:00
parent 5d8c1e289b
commit e7314e3477
2 changed files with 17 additions and 10 deletions

View File

@ -859,6 +859,11 @@ bool ShouldLinkSnapToPin(
return false;
}
if (start_pin.Shape != end_pin.Shape)
{
return false;
}
// The link to be created must not be a duplicate, unless it is the link which was created on
// snap. In that case we want to snap, since we want it to appear visually as if the created
// link remains snapped to the pin.
@ -1573,6 +1578,8 @@ void BeginPinAttribute(
const int id,
const ImNodesAttributeType type,
const ImNodesPinShape shape,
const ImU32 color_background,
const ImU32 color_hovered,
const int node_idx)
{
// Make sure to call BeginNode() before calling
@ -1595,8 +1602,8 @@ void BeginPinAttribute(
pin.Type = type;
pin.Shape = shape;
pin.Flags = GImNodes->CurrentAttributeFlags;
pin.ColorStyle.Background = GImNodes->Style.Colors[ImNodesCol_Pin];
pin.ColorStyle.Hovered = GImNodes->Style.Colors[ImNodesCol_PinHovered];
pin.ColorStyle.Background = color_background;
pin.ColorStyle.Hovered = color_hovered;
}
void EndPinAttribute()
@ -1877,7 +1884,7 @@ static void MiniMapUpdate()
editor.Panning = ImFloor(center - target);
}
// Reset callback info after use
// reset callback info after use
editor.MiniMapNodeHoveringCallback = NULL;
editor.MiniMapNodeHoveringCallbackUserData = NULL;
}
@ -2125,7 +2132,7 @@ void BeginNodeEditor()
assert(GImNodes->CurrentScope == ImNodesScope_None);
GImNodes->CurrentScope = ImNodesScope_Editor;
// Reset state from previous pass
// reset state from previous pass
ImNodesEditorContext& editor = EditorContextGet();
editor.AutoPanningDelta = ImVec2(0, 0);
@ -2458,16 +2465,16 @@ void EndNodeTitleBar()
ImGui::SetCursorPos(GridSpaceToEditorSpace(editor, GetNodeContentOrigin(node)));
}
void BeginInputAttribute(const int id, const ImNodesPinShape shape)
void BeginInputAttribute(const int id, const ImNodesPinShape shape, ImU32 color_background, ImU32 color_hovered)
{
BeginPinAttribute(id, ImNodesAttributeType_Input, shape, GImNodes->CurrentNodeIdx);
BeginPinAttribute(id, ImNodesAttributeType_Input, shape, color_background, color_hovered, GImNodes->CurrentNodeIdx);
}
void EndInputAttribute() { EndPinAttribute(); }
void BeginOutputAttribute(const int id, const ImNodesPinShape shape)
void BeginOutputAttribute(const int id, const ImNodesPinShape shape, ImU32 color_background, ImU32 color_hovered)
{
BeginPinAttribute(id, ImNodesAttributeType_Output, shape, GImNodes->CurrentNodeIdx);
BeginPinAttribute(id, ImNodesAttributeType_Output, shape, color_background, color_hovered, GImNodes->CurrentNodeIdx);
}
void EndOutputAttribute() { EndPinAttribute(); }

View File

@ -288,10 +288,10 @@ void EndNodeTitleBar();
// Each attribute id must be unique.
// Create an input attribute block. The pin is rendered on left side.
void BeginInputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled);
void BeginInputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled, ImU32 color_background = IM_COL32(53, 150, 250, 180), ImU32 color_hovered = IM_COL32(53, 150, 250, 255));
void EndInputAttribute();
// Create an output attribute block. The pin is rendered on the right side.
void BeginOutputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled);
void BeginOutputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled, ImU32 color_background = IM_COL32(53, 150, 250, 180), ImU32 color_hovered = IM_COL32(53, 150, 250, 255));
void EndOutputAttribute();
// Create a static attribute block. A static attribute has no pin, and therefore can't be linked to
// anything. However, you can still use IsAttributeActive() and IsAnyAttributeActive() to check for