public void CreateCustomBridge(IRenderContext context, GeneralPath path, PointD start, PointD end, double gapLength) { // first finish the last segment path.LineTo(start); // then calculate the gap var vectorLength = gapLength; if (vectorLength > 1) { // some helper vectors first var delta = end - start; var rightVector = delta / vectorLength; var upVector = new PointD(rightVector.Y, -rightVector.X); // get the height from the context double height = GetBridgeHeight(context); // determine bending for our arc double arc = 3; // now draw two arcs at the end and the start of the segment path.MoveTo(start + upVector * height - rightVector * arc); path.QuadTo(start + rightVector * arc, start + upVector * -height - rightVector * arc); path.MoveTo(end + rightVector * arc + upVector * height); path.QuadTo(end - rightVector * arc, end + upVector * -height + rightVector * arc); // finally make sure that the edge continues at the right location path.MoveTo(end); } else { // for very short gaps, we use a trivial rendering path.LineTo(start); path.MoveTo(end); } }
public override Visual CreateVisual(IRenderContext context) { VisualGroup container = new VisualGroup(); var bounds = Bounds; var width = bounds.Width; var height = bounds.Height; var path = new GeneralPath(); path.MoveTo(0, TopLeftRadius); path.QuadTo(0, 0, TopLeftRadius, 0); path.LineTo(width - TopRightRadius, 0); path.QuadTo(width, 0, width, TopRightRadius); path.LineTo(width, height - BottomRightRadius); path.QuadTo(width, height, width - BottomRightRadius, height); path.LineTo(BottomLeftRadius, height); path.QuadTo(0, height, 0, height - BottomRightRadius); path.Close(); var pathVisual = path.CreatePath(Brush, Pen, new Matrix2D(), FillMode.Always); container.Add(pathVisual); container.SetRenderDataCache(new PathIconState(width, height, Pen, Brush)); container.SetCanvasArrangeRect(bounds.ToRectD()); return(container); }
/// <summary> /// Creates an <see cref="IVisual"/> which renders the label. /// </summary> /// <remarks> /// Adds separate visuals for background and text in a VisualGroup. /// Delegates to method <see cref="LabelStyleBase{TVisual}.GetTransform"/> /// to get a valid transform for the label. /// </remarks> /// <param name="context">The Render Context.</param> /// <param name="label">The label to render.</param> /// <returns>A visual which renders the label.</returns> protected override VisualGroup CreateVisual(IRenderContext context, ILabel label) { var layout = label.GetLayout(); // don't render invisible labels if (layout.Width < 0 || layout.Height < 0) { return(null); } var group = new VisualGroup(); // convert to convenient coordinate space group.Transform = GetTransform(context, layout, true); // Draw the label background as a rounded rectangle GeneralPath gp = new GeneralPath(10); double xRad = layout.Width / 4; double yRad = layout.Height / 10; gp.MoveTo(0, yRad); gp.QuadTo(0, 0, xRad, 0); gp.LineTo(layout.Width - xRad, 0); gp.QuadTo(layout.Width, 0, layout.Width, yRad); gp.LineTo(layout.Width, layout.Height - yRad); gp.QuadTo(layout.Width, layout.Height, layout.Width - xRad, layout.Height); gp.LineTo(xRad, layout.Height); gp.QuadTo(0, layout.Height, 0, layout.Height - yRad); gp.Close(); var pathVisual = new GeneralPathVisual(gp) { Brush = new SolidBrush(Color.FromArgb(255, 240, 248, 255)), Pen = Pens.SkyBlue }; group.Add(pathVisual); // Draw the label's text if (context.Zoom >= buttonZoomThreshold) { // draw the action button group.Add(new ImageVisual { Image = Resources.edit_label, Rectangle = new RectD(layout.Width - (inset + buttonWidth), inset, buttonWidth, layout.Height - inset * 2) }); group.Add(new TextVisual { Text = label.Text, Font = Font, Brush = Brushes.Black, Location = PointD.Origin }); } else { group.Add(new TextVisual { Text = label.Text, Font = Font, Brush = Brushes.Black, Location = new PointD((buttonWidth + 2 * inset) * 0.5, 0) }); } return(group); }
static LogicGateNodeStyle() { // path for AND nodes AndOutlinePath = new GeneralPath(); AndOutlinePath.MoveTo(0.6, 0); AndOutlinePath.LineTo(0.1, 0); AndOutlinePath.LineTo(0.1, 1); AndOutlinePath.LineTo(0.6, 1); AndOutlinePath.QuadTo(0.8, 1.0, 0.8, 0.5); AndOutlinePath.QuadTo(0.8, 0.0, 0.6, 0); // path for OR nodes OrOutlinePath = new GeneralPath(); OrOutlinePath.MoveTo(0.6, 0); OrOutlinePath.LineTo(0.1, 0); OrOutlinePath.QuadTo(0.3, 0.5, 0.1, 1); OrOutlinePath.LineTo(0.6, 1); OrOutlinePath.QuadTo(0.8, 1.0, 0.8, 0.5); OrOutlinePath.QuadTo(0.8, 0.0, 0.6, 0); // path for NAND nodes NandOutlinePath = new GeneralPath(); NandOutlinePath.MoveTo(0.6, 0); NandOutlinePath.LineTo(0.1, 0); NandOutlinePath.LineTo(0.1, 1); NandOutlinePath.LineTo(0.6, 1); NandOutlinePath.QuadTo(0.8, 1.0, 0.8, 0.5); NandOutlinePath.QuadTo(0.8, 0.0, 0.6, 0); NandOutlinePath.AppendEllipse(new RectD(0.8, 0.4, 0.1, 0.2), false); // path for NOR nodes NorOutlinePath = new GeneralPath(); NorOutlinePath.MoveTo(0.6, 0); NorOutlinePath.LineTo(0.1, 0); NorOutlinePath.QuadTo(0.3, 0.5, 0.1, 1); NorOutlinePath.LineTo(0.6, 1); NorOutlinePath.QuadTo(0.8, 1.0, 0.8, 0.5); NorOutlinePath.QuadTo(0.8, 0.0, 0.6, 0); NorOutlinePath.AppendEllipse(new RectD(0.8, 0.4, 0.1, 0.2), false); // path for NOT nodes NotOutlinePath = new GeneralPath(); NotOutlinePath.MoveTo(0.8, 0.5); NotOutlinePath.LineTo(0.1, 0); NotOutlinePath.LineTo(0.1, 1); NotOutlinePath.LineTo(0.8, 0.5); NotOutlinePath.AppendEllipse(new RectD(0.8, 0.4, 0.1, 0.2), false); }
private static GeneralPath CreatePath(IOrientedRectangle layout) { GeneralPath gp = new GeneralPath(10); double xRad = layout.Width / 4; double yRad = layout.Height / 10; gp.MoveTo(0, yRad); gp.QuadTo(0, 0, xRad, 0); gp.LineTo(layout.Width - xRad, 0); gp.QuadTo(layout.Width, 0, layout.Width, yRad); gp.LineTo(layout.Width, layout.Height - yRad); gp.QuadTo(layout.Width, layout.Height, layout.Width - xRad, layout.Height); gp.LineTo(xRad, layout.Height); gp.QuadTo(0, layout.Height, 0, layout.Height - yRad); gp.Close(); return(gp); }
/// <summary> /// Creates an <see cref="IVisual"/> which renders the label. /// </summary> /// <remarks> /// Adds separate visuals for background and text in a VisualGroup. /// Delegates to method <see cref="LabelStyleBase{TVisual}.GetTransform"/> /// to get a valid transform for the label. /// </remarks> /// <param name="context">The Render Context.</param> /// <param name="label">The label to render.</param> /// <returns>A visual which renders the label.</returns> protected override VisualGroup CreateVisual(IRenderContext context, ILabel label) { var layout = label.GetLayout(); // don't render invisible labels if (layout.Width < 0 || layout.Height < 0) { return(null); } var group = new VisualGroup(); // convert to convenient coordinate space group.Transform = GetTransform(context, layout, true); // Draw the label background as a rounded rectangle GeneralPath gp = new GeneralPath(10); double xRad = layout.Width / 4; double yRad = layout.Height / 10; gp.MoveTo(0, yRad); gp.QuadTo(0, 0, xRad, 0); gp.LineTo(layout.Width - xRad, 0); gp.QuadTo(layout.Width, 0, layout.Width, yRad); gp.LineTo(layout.Width, layout.Height - yRad); gp.QuadTo(layout.Width, layout.Height, layout.Width - xRad, layout.Height); gp.LineTo(xRad, layout.Height); gp.QuadTo(0, layout.Height, 0, layout.Height - yRad); gp.Close(); var pathVisual = new GeneralPathVisual(gp) { Brush = new SolidBrush(Color.FromArgb(255, 155, 226, 255)), Pen = Pens.SkyBlue }; group.Add(pathVisual); // Draw the label's text group.Add(new TextVisual { Text = label.Text, Font = Font, Brush = Brushes.Black, Location = PointD.Origin }); return(group); }
protected override GeneralPath GetOutline(INode node) { // Create a rounded rectangle path var layout = node.Layout.ToRectD(); var path = new GeneralPath(12); var x = layout.X; var y = layout.Y; var w = layout.Width; var h = layout.Height; var arcX = Math.Min(w * 0.5, 5); var arcY = Math.Min(h * 0.5, 5); path.MoveTo(x, y + arcY); path.QuadTo(x, y, x + arcX, y); path.LineTo(x + w - arcX, y); path.QuadTo(x + w, y, x + w, y + arcY); path.LineTo(x + w, y + h - arcY); path.QuadTo(x + w, y + h, x + w - arcX, y + h); path.LineTo(x + arcX, y + h); path.QuadTo(x, y + h, x, y + h - arcY); path.Close(); return(path); }
public override IVisual CreateVisual(IRenderContext context) { var bounds = Bounds; var width = bounds.Width; var height = bounds.Height; var path = new GeneralPath(); path.MoveTo(0, TopLeftRadius); path.QuadTo(0, 0, TopLeftRadius, 0); path.LineTo(width - TopRightRadius, 0); path.QuadTo(width, 0, width, TopRightRadius); path.LineTo(width, height - BottomRightRadius); path.QuadTo(width, height, width - BottomRightRadius, height); path.LineTo(BottomLeftRadius, height); path.QuadTo(0, height, 0, height - BottomRightRadius); path.Close(); return(new GeneralPathVisual(path) { Brush = Brush, Pen = Pen, Transform = new Matrix(1, 0, 0, 1, (float)Bounds.X, (float)Bounds.Y) }); }