// Draw the node on canvas. public void Draw() { switch (Terminal) { case NodeTerminalType.NonTerminal: // Highlighting. if (Selected) { EditorCanvas.DrawQuad(new Rect(OutlineScope.x - _thickness, (int)OutlineScope.y - _thickness, OutlineScope.width + _thickness * 2, OutlineScope.height + _thickness * 2), Color.red); } // Main part of node. EditorCanvas.DrawQuad(OutlineScope, OutlineColor); EditorCanvas.DrawQuad(FilledScope, FilledColor); EditorCanvas.DrawQuad(TextScope, Color.clear, "<" + Ordering + ">\n" + Abbreviation, TextColor); break; case NodeTerminalType.Terminal: // Highlighting. if (Selected) { EditorCanvas.DrawDisc(Position, OutlineScope.width / 2 + _thickness, Color.red); } // Main part of node. EditorCanvas.DrawDisc(Position, OutlineScope.width / 2, OutlineColor); EditorCanvas.DrawDisc(Position, OutlineScope.width / 2 - _thickness, FilledColor); EditorCanvas.DrawQuad(TextScope, Color.clear, "<" + Ordering + ">\n" + Abbreviation, TextColor); break; } }
// Draw the node in the node list. public static void DrawNodeInList(GraphGrammarNode node) { node.PositionX = 30; node.PositionY = 25 + 50 * _nodes.FindIndex(n => n == node); // Background color of selectable area. Color rectColor = SampleStyle.ColorBlue; rectColor.a = 0.75f; EditorCanvas.DrawQuad(new Rect(5, node.PositionY - 23, Screen.width - 8, 46), node.Selected ? rectColor : Color.clear); // Draw this node. node.Draw(); }
// Draw the connection on canvas. public void Draw() { if (StartpointStickyOn != null) { StartPosition = StartpointStickyOn.Position + (EndPosition - StartpointStickyOn.Position).normalized * StartpointStickyOn.FilledScope.width / 2; } if (EndpointStickyOn != null) { EndPosition = EndpointStickyOn.Position + (StartPosition - EndpointStickyOn.Position).normalized * EndpointStickyOn.FilledScope.width / 2; } // Draw the main line about connection. EditorCanvas.DrawLine(StartPosition, EndPosition, OutlineColor, LineThickness); // Head size Vector2 dir = (EndPosition - StartPosition).normalized * LineThickness; Vector2 orthoptics = new Vector2(-dir.y, dir.x); // Arrow cap's points Vector3[] arrowHead = new Vector3[3]; arrowHead[0] = EndPosition - dir * 2 + orthoptics; arrowHead[1] = EndPosition - dir * 2 - orthoptics; arrowHead[2] = EndPosition; Vector3[] arrowHeadSec = new Vector3[3]; Vector2 dir2 = dir = dir + dir * 1f; arrowHeadSec[0] = EndPosition - dir2 * 2 + orthoptics; arrowHeadSec[1] = EndPosition - dir2 * 2 - orthoptics; arrowHeadSec[2] = EndPosition - dir2; // Draw the arraw part. switch (this.Arrow) { case ConnectionArrowType.Normal: EditorCanvas.DrawTriangle(arrowHead, OutlineColor); break; case ConnectionArrowType.Double: EditorCanvas.DrawTriangle(arrowHead, OutlineColor); EditorCanvas.DrawTriangle(arrowHeadSec, OutlineColor); break; case ConnectionArrowType.WithCircle: EditorCanvas.DrawTriangle(arrowHeadSec, OutlineColor); EditorCanvas.DrawDisc(EndPosition - dir2 / 2f, LineThickness, OutlineColor); EditorCanvas.DrawDisc(EndPosition - dir2 / 2f, LineThickness - 1, Color.white); break; } // Endpoints of conneciton. if (Selected) { EditorCanvas.DrawQuad(StartpointScope, Color.red); EditorCanvas.DrawQuad(EndpointScope, Color.blue); } }
// Draw the connection in the connection list. public static void DrawConnectionInList(GraphGrammarConnection connection) { connection.StartPositionX = 10; connection.EndPositionX = 60; connection.StartPositionY = connection.EndPositionY = 25 + 50 * _connections.FindIndex(c => c == connection); // Background color of selectable area. Color rectColor = SampleStyle.ColorBlue; rectColor.a = 0.75f; EditorCanvas.DrawQuad(new Rect(5, connection.StartPositionY - 23, Screen.width - 8, 46), connection.Selected ? rectColor : Color.clear); // Draw this connection. connection.Draw(); }