diff --git a/Editor/Elements/Graph/BaseEdge.cs b/Editor/Elements/Graph/BaseEdge.cs index dd73250..167cfd5 100644 --- a/Editor/Elements/Graph/BaseEdge.cs +++ b/Editor/Elements/Graph/BaseEdge.cs @@ -211,7 +211,7 @@ private void SetPositionOverride(Vector2 position, out Vector2 overrideValueToSe overrideValueToSet = position; if (overrideFlagToSet != true) { overrideFlagToSet = true; - portToUpdate?.UpdateCapColor(); + portToUpdate?.UpdateCapVisiblity(); } OnEdgeChanged(); } @@ -219,8 +219,8 @@ private void SetPositionOverride(Vector2 position, out Vector2 overrideValueToSe public void UnsetPositionOverrides() { m_InputPositionOverridden = false; m_OutputPositionOverridden = false; - m_InputPort?.UpdateCapColor(); - m_OutputPort?.UpdateCapColor(); + m_InputPort?.UpdateCapVisiblity(); + m_OutputPort?.UpdateCapVisiblity(); OnEdgeChanged(); } diff --git a/Editor/Elements/Graph/BasePort.cs b/Editor/Elements/Graph/BasePort.cs index 8127cc2..0a0576a 100644 --- a/Editor/Elements/Graph/BasePort.cs +++ b/Editor/Elements/Graph/BasePort.cs @@ -14,7 +14,6 @@ public class BasePort : VisualElement, IPositionable { private const float portCirclelineWidth = 1f; private static readonly Color s_DefaultColor = new(240 / 255f, 240 / 255f, 240 / 255f); - private static readonly Color s_DefaultDisabledColor = new(70 / 255f, 70 / 255f, 70 / 255f); public readonly HashSet m_Connections; protected VisualElement m_ConnectorBox; @@ -66,6 +65,7 @@ public BasePort(Orientation orientation, Direction direction, PortCapacity capac m_ConnectorBox.AddToClassList("port-connector-box"); m_ConnectorBox.Add(m_ConnectorBoxCap); m_ConnectorBox.style.backgroundImage = new StyleBackground(PortCircleGraphics); + m_ConnectorBox.style.unityBackgroundImageTintColor = portColor; Add(m_ConnectorBox); @@ -139,11 +139,18 @@ public Color PortColor { get => portColor; set { portColor = value; - UpdateCapColor(); + CapColor = portColor; + m_ConnectorBox.style.unityBackgroundImageTintColor = portColor; } } public virtual Color DefaultPortColor { get; } = s_DefaultColor; - public virtual Color DisabledPortColor { get; } = s_DefaultDisabledColor; + public virtual Color DisabledPortColor { + get { + Color color = PortColor * 0.3f; + color.a = PortColor.a; + return color; + } + } public Orientation Orientation { get; } public PortCapacity Capacity { get; } @@ -177,14 +184,14 @@ public virtual void Connect(BaseEdge edge) { if (!m_Connections.Contains(edge)) { m_Connections.Add(edge); } - UpdateCapColor(); + UpdateCapVisiblity(); } public virtual void Disconnect(BaseEdge edge) { if (edge == null) { throw new ArgumentException("The value passed to PortPresenter.Disconnect is null"); } m_Connections.Remove(edge); - UpdateCapColor(); + UpdateCapVisiblity(); } public virtual bool CanConnectToMore(bool ignoreCandidateEdges = true) @@ -221,18 +228,15 @@ public virtual bool CanConnectTo(BasePort other, bool ignoreCandidateEdges = tru #endregion #region Style - internal void UpdateCapColor() { - if (Connected()) { m_ConnectorBoxCap.style.backgroundColor = PortColor; } else { m_ConnectorBoxCap.style.backgroundColor = StyleKeyword.Null; } + internal void UpdateCapVisiblity() { + if (Connected()) { m_ConnectorBoxCap.style.opacity = 1; } else { m_ConnectorBoxCap.style.opacity = StyleKeyword.Null; } } private void UpdateConnectorColorAndEnabledState() { if (m_ConnectorBox == null) { return; } Color color = Highlight ? PortColor : DisabledPortColor; - m_ConnectorBox.style.borderLeftColor = color; - m_ConnectorBox.style.borderTopColor = color; - m_ConnectorBox.style.borderRightColor = color; - m_ConnectorBox.style.borderBottomColor = color; + m_ConnectorBox.style.unityBackgroundImageTintColor = color; m_ConnectorBox.SetEnabled(Highlight); } @@ -298,8 +302,8 @@ private void OnDropEnter(DropEnterEvent e) { return; } - // But if it's compatible, light this port up - m_ConnectorBoxCap.style.backgroundColor = PortColor; + // But if it's compatible, light this port up + m_ConnectorBoxCap.style.opacity = 1; } } @@ -320,7 +324,7 @@ private void OnDrop(DropEvent e) { } // But if it's compatible, update caps as appropriate - UpdateCapColor(); + UpdateCapVisiblity(); } } @@ -333,7 +337,7 @@ private void OnDropExit(DropExitEvent e) { if (dropPayload.GetPayload().Count == 0) throw new("Drop payload was unexpectedly empty"); // But if it's compatible, update caps as appropriate - UpdateCapColor(); + UpdateCapVisiblity(); } } diff --git a/Editor/Elements/Graph/Edge.cs b/Editor/Elements/Graph/Edge.cs index 75d116c..a991f4c 100644 --- a/Editor/Elements/Graph/Edge.cs +++ b/Editor/Elements/Graph/Edge.cs @@ -11,8 +11,8 @@ public class Edge : BaseEdge { private const float k_InterceptWidth = 6.0f; private const float k_EdgeLengthFromPort = 12.0f; private const float k_EdgeTurnDiameter = 20.0f; - private const int k_DefaultEdgeWidth = 2; - private const int k_DefaultEdgeWidthSelected = 2; + private const float k_DefaultEdgeWidth = 2; + private const float k_DefaultEdgeWidthSelected = 2; private static readonly Color s_DefaultSelectedColor = new(240 / 255f, 240 / 255f, 240 / 255f); private static readonly Color s_DefaultColor = new(146 / 255f, 146 / 255f, 146 / 255f); @@ -25,7 +25,7 @@ public class Edge : BaseEdge { private float m_CapRadius = 5; private bool m_ControlPointsDirty = true; - private int m_EdgeWidth = 2; + private float m_EdgeWidth = 2; private VisualElement m_FromCap; private Color m_FromCapColor; private Color m_InputColor = Color.grey; @@ -104,6 +104,13 @@ public Color OutputColor { } } + public Color EdgeColor { + set { + InputColor = value; + OutputColor = value; + } + } + public Color FromCapColor { get => m_FromCapColor; set { @@ -135,7 +142,7 @@ public float CapRadius { } } - public int EdgeWidth { + public float EdgeWidth { get => m_EdgeWidth; set { if (m_EdgeWidth == value) { return; } @@ -182,8 +189,8 @@ public bool DrawToCap { } } - public virtual int EdgeWidthUnselected { get; } = k_DefaultEdgeWidth; - public virtual int EdgeWidthSelected { get; } = k_DefaultEdgeWidthSelected; + public virtual float EdgeWidthUnselected { get; } = k_DefaultEdgeWidth; + public virtual float EdgeWidthSelected { get; } = k_DefaultEdgeWidthSelected; public virtual Color ColorSelected { get; } = s_DefaultSelectedColor; public virtual Color ColorUnselected { get; } = s_DefaultColor; public float InterceptWidth { get; set; } = 5f; @@ -420,7 +427,7 @@ private void OnGenerateVisualContent(MeshGenerationContext mgc) { return; // Don't draw anything } - // Color outColor = this.outputColor; + Color outColor = OutputColor; Color inColor = InputColor; int cpt = m_RenderPoints.Count; @@ -428,19 +435,26 @@ private void OnGenerateVisualContent(MeshGenerationContext mgc) { float width = EdgeWidth; - // float alpha = 1.0f; + float alpha = 1.0f; float zoom = Graph.CurrentScale; - if (EdgeWidth * zoom < k_MinEdgeWidth) { + if (EdgeWidth * zoom < k_MinEdgeWidth) + { // alpha = edgeWidth * zoom / k_MinEdgeWidth; width = k_MinEdgeWidth / zoom; } - // k_Gradient.SetKeys(new[]{ new GradientColorKey(outColor, 0),new GradientColorKey(inColor, 1)},new []{new GradientAlphaKey(alpha, 0)}); painter2D.BeginPath(); - - // painter2D.strokeGradient = k_Gradient; - painter2D.strokeColor = inColor; + if (inColor == outColor) + { + painter2D.strokeColor = inColor; + } + else + { + Gradient k_Gradient = new Gradient(); + k_Gradient.SetKeys(new[] { new GradientColorKey(outColor, 0), new GradientColorKey(inColor, 1) }, new[] { new GradientAlphaKey(alpha, 0) }); + painter2D.strokeGradient = k_Gradient; + } painter2D.lineWidth = width; painter2D.MoveTo(m_RenderPoints[0]); diff --git a/Editor/Elements/GraphView.uss b/Editor/Elements/GraphView.uss index 4c645ca..e8c4c6f 100644 --- a/Editor/Elements/GraphView.uss +++ b/Editor/Elements/GraphView.uss @@ -90,8 +90,13 @@ flex-grow: 0; } -.port:hover .port-connector-cap{ +.port .port-connector-cap { background-color: rgb(240, 240, 240); + opacity: 0; +} + +.port:hover .port-connector-cap { + opacity: 1; } .port-input {