1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Drag noodle color now also comes from graphEditor.GetNoodleGradient

This commit is contained in:
Thor Brigsted 2019-10-07 09:58:19 +02:00
parent a35cd68dd7
commit 419714e479
2 changed files with 27 additions and 16 deletions

View File

@ -470,11 +470,7 @@ namespace XNodeEditor {
/// <summary> Draw a connection as we are dragging it </summary>
public void DrawDraggedConnection() {
if (IsDraggingPort) {
Color col = NodeEditorPreferences.GetTypeColor(draggedOutput.ValueType);
col.a = draggedOutputTarget != null ? 1.0f : 0.6f;
Gradient gradient = new Gradient();
gradient.SetKeys(new GradientColorKey[] { new GradientColorKey(col, 0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1f, 0f) });
Gradient gradient = graphEditor.GetNoodleGradient(draggedOutput, null);
Rect fromRect;
if (!_portConnectionPoints.TryGetValue(draggedOutput, out fromRect)) return;
@ -489,7 +485,7 @@ namespace XNodeEditor {
DrawNoodle(gradient, gridPoints);
Color bgcol = Color.black;
Color frcol = col;
Color frcol = gradient.colorKeys[0].color;
bgcol.a = 0.6f;
frcol.a = 0.6f;

View File

@ -64,18 +64,33 @@ namespace XNodeEditor {
}
/// <summary> Returned color is used to color noodles </summary>
/// <param name="output"> The output this noodle comes from. Never null. </param>
/// <param name="input"> The output this noodle comes from. Can be null if we are dragging the noodle. </param>
public virtual Gradient GetNoodleGradient(XNode.NodePort output, XNode.NodePort input) {
Color a = GetTypeColor(output.ValueType);
Color b = GetTypeColor(input.ValueType);
if (window.hoveredPort == output || window.hoveredPort == input) {
a = Color.Lerp(a, Color.white, 0.8f);
b = Color.Lerp(b, Color.white, 0.8f);
}
Gradient grad = new Gradient();
grad.SetKeys(
new GradientColorKey[] { new GradientColorKey(a, 0f), new GradientColorKey(b, 1f) },
new GradientAlphaKey[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }
);
// If dragging the noodle, draw solid, slightly transparent
if (input == null) {
Color a = GetTypeColor(output.ValueType);
grad.SetKeys(
new GradientColorKey[] { new GradientColorKey(a, 0f) },
new GradientAlphaKey[] { new GradientAlphaKey(0.6f, 0f) }
);
}
// If normal, draw gradient fading from one input color to the other
else {
Color a = GetTypeColor(output.ValueType);
Color b = GetTypeColor(input.ValueType);
// If any port is hovered, tint white
if (window.hoveredPort == output || window.hoveredPort == input) {
a = Color.Lerp(a, Color.white, 0.8f);
b = Color.Lerp(b, Color.white, 0.8f);
}
grad.SetKeys(
new GradientColorKey[] { new GradientColorKey(a, 0f), new GradientColorKey(b, 1f) },
new GradientAlphaKey[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }
);
}
return grad;
}