-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix port and edge coloring/styling #4
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess float gives us a more granular way to define line thickness? This is a breaking change for our NewGraph framework. But if you clarify the importance of this I can think of making the aprropiate changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's exactly that, float adds a larger range of possible line thickness. Which is pretty important when working with values that, imo, should probably be between 1 and 3. And 1 seems too small and 3 seems too large. The constants above could stay int since they are local/private. I just assumed it was a mistake/oversight so I changed those as well. The important change is with public override float EdgeWidthUnselected { get; } = 1.5f;
public override float EdgeWidthSelected { get; } = 2.0f; |
||
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,27 +427,34 @@ 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; | ||
Painter2D painter2D = mgc.painter2D; | ||
|
||
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]); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid this magic number (0.3f) here somehow? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it could be some constant?