Example #1
0
        public FrameworkElement GetCustomNode()
        {
            var textBlock = new TextBlock()
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            textBlock.SetBinding(TextBlock.TextProperty, new Binding()
            {
                Path = new PropertyPath("NodeName")
            });

            var ui = new Path();

            ui.Stroke          = Brushes.Black;
            ui.StrokeThickness = 0.5;
            ui.Fill            = Brushes.Pink;
            var converter = new GeometryConverter();

            ui.Data    = (Geometry)converter.ConvertFrom(NodeStyle["Geometry"]);
            ui.Stretch = Stretch.Uniform;

            var grid = new Grid();

            grid.Children.Add(ui);
            grid.Children.Add(textBlock);
            return(grid);
        }
Example #2
0
 /// <summary> Gets the geometry from string.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <returns></returns>
 public static Geometry GetGeometry(string text)
 {
     if (String.IsNullOrEmpty(text))
     {
         return(null);
     }
     if (text.StartsWith(GeometryType.Path.ToString(), StringComparison.Ordinal))
     {
         string            content        = text.Substring(GeometryType.Path.ToString().Length + 1);
         GeometryConverter conv           = new GeometryConverter();
         StreamGeometry    streamGeometry = (StreamGeometry)conv.ConvertFrom(content);
         PathGeometry      geometry       = streamGeometry.GetFlattenedPathGeometry();
         return(geometry);
     }
     else if (text.StartsWith(GeometryType.Rectangle.ToString(), StringComparison.Ordinal))
     {
         string            content  = text.Substring(GeometryType.Rectangle.ToString().Length + 1);
         string[]          contents = content.Split(',');
         RectangleGeometry geometry = new RectangleGeometry();
         geometry.Rect = new Rect(Convert.ToDouble(contents[0], enUS),
                                  Convert.ToDouble(contents[1], enUS),
                                  Convert.ToDouble(contents[2], enUS),
                                  Convert.ToDouble(contents[3], enUS)
                                  );
         return(geometry);
     }
     else if (text.StartsWith(GeometryType.Ellipse.ToString(), StringComparison.Ordinal))
     {
         string          content  = text.Substring(GeometryType.Ellipse.ToString().Length + 1);
         string[]        contents = content.Split(',');
         EllipseGeometry geometry = new EllipseGeometry();
         geometry.Center  = new Point(Convert.ToDouble(contents[0], enUS) + Convert.ToDouble(contents[2], enUS) / 2.0, Convert.ToDouble(contents[1], enUS) + Convert.ToDouble(contents[3], enUS) / 2.0);
         geometry.RadiusX = Convert.ToDouble(contents[2], enUS) / 2.0;
         geometry.RadiusY = Convert.ToDouble(contents[3], enUS) / 2.0;
         return(geometry);
     }
     else if (text.StartsWith("Text:", StringComparison.Ordinal))
     {
         string            content  = text.Substring("Text:".Length);
         string[]          contents = content.Split(',');
         RectangleGeometry geometry = new RectangleGeometry();
         geometry.Rect = new Rect(Convert.ToDouble(contents[0], enUS),
                                  Convert.ToDouble(contents[1], enUS),
                                  Convert.ToDouble(contents[2], enUS),
                                  Convert.ToDouble(contents[3], enUS)
                                  );
         return(geometry);
     }
     else
     {
         throw new InvalidOperationException("This is not a valid geometry object in string");
     }
 }
Example #3
0
        public static FrameworkElement CreateContent(FlowNode node)
        {
            var textBlock = new TextBlock()
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var b = new Binding("Text");

            b.Source = node;
            textBlock.SetBinding(TextBlock.TextProperty, b);

            if (node.Kind == NodeKinds.Start || node.Kind == NodeKinds.End)
            {
                var ui = new Border();
                ui.CornerRadius    = new CornerRadius(15);
                ui.BorderBrush     = Brushes.Black;
                ui.BorderThickness = new Thickness(1);
                ui.Background      = Brushes.Yellow;
                ui.Child           = textBlock;
                return(ui);
            }
            else if (node.Kind == NodeKinds.Action)
            {
                var ui = new Border();
                ui.BorderBrush     = Brushes.Black;
                ui.BorderThickness = new Thickness(1);
                ui.Background      = Brushes.Lime;;
                ui.Child           = textBlock;
                return(ui);
            }
            else
            {
                var ui = new Path();
                ui.Stroke          = Brushes.Black;
                ui.StrokeThickness = 1;
                ui.Fill            = Brushes.Pink;
                var converter = new GeometryConverter();
                ui.Data    = (Geometry)converter.ConvertFrom("M 0,0.25 L 0.5 0 L 1,0.25 L 0.5,0.5 Z");
                ui.Stretch = Stretch.Uniform;

                var grid = new Grid();
                grid.Children.Add(ui);
                grid.Children.Add(textBlock);

                return(grid);
            }
        }
        public void DrawGeometry_Cubic_Besier_Curve()
        {
            UserControl userControl = new UserControl();

            userControl.Width  = 320;
            userControl.Height = 180;

            DrawGeometryControl testControl = new DrawGeometryControl();
            GeometryConverter   converter   = new GeometryConverter();

            testControl.Geometry = (Geometry)converter.ConvertFrom("M 10,100 C 10,300 300,-200 300,100");
            testControl.Brush    = new SolidColorBrush(Colors.Gray);
            testControl.Pen      = new Pen(new SolidColorBrush(Colors.Black), 1);
            userControl.Content  = testControl;

            this.RenderToFile(userControl);
            this.CompareImages();
        }
Example #5
0
        protected override void OnRender(DrawingContext dc)
        {
            var adornedElementRect = new Rect(AdornedElement.DesiredSize);

            Brush edgeBrush;
            Pen   linePen;

            switch (DropEffect)
            {
            case DragDropEffects.None: linePen = linePenNone; break;

            case DragDropEffects.Move: linePen = linePenMove; break;

            default: goto case DragDropEffects.Move;
            }

            switch (DropEffect)
            {
            case DragDropEffects.None: edgeBrush = edgeBrushNone; break;

            case DragDropEffects.Move: edgeBrush = edgeBrushMove; break;

            default: goto case DragDropEffects.Move;
            }

//			// Draw a circle at each corner.
//			drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
//			drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
//			drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
//			drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
            var gc = new GeometryConverter();

            switch (Position)
            {
            case DropPosition.Top:
                //dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopLeft, renderRadius, renderRadius);

                //dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopRight, renderRadius, renderRadius);
                dc.DrawGeometry(edgeBrush, linePen, (Geometry)gc.ConvertFrom("M" + (adornedElementRect.TopRight.X).ToStringEnUs() + "," + ((int)adornedElementRect.TopRight.Y - 3).ToStringEnUs() + " l0,6 l-5,-3 z"));
                dc.DrawLine(linePen, adornedElementRect.TopLeft, adornedElementRect.TopRight);
                if (DropEffect == DragDropEffects.None)
                {
                    dc.DrawEllipse(edgeBrush, edgePen, new Point(adornedElementRect.TopLeft.X, adornedElementRect.TopLeft.Y), 6, 6);
                    dc.DrawLine(edgePen2, new Point(adornedElementRect.TopLeft.X - 3, adornedElementRect.TopLeft.Y), new Point(adornedElementRect.TopLeft.X + 3, adornedElementRect.TopLeft.Y));
                }
                else
                {
                    dc.DrawGeometry(edgeBrush, linePen, (Geometry)gc.ConvertFrom("M" + (adornedElementRect.TopLeft.X).ToStringEnUs() + "," + (adornedElementRect.TopLeft.Y - 3).ToStringEnUs() + " l0,6 l5,-3 z"));
                }
                break;

            case DropPosition.Bottom:
                //dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomLeft, renderRadius, renderRadius);

                //dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomRight, renderRadius, renderRadius);
                dc.DrawGeometry(edgeBrush, linePen, (Geometry)gc.ConvertFrom("M" + (adornedElementRect.BottomRight.X).ToStringEnUs() + "," + ((int)adornedElementRect.BottomRight.Y - 3).ToStringEnUs() + " l0,6 l-5,-3 z"));
                dc.DrawLine(linePen, adornedElementRect.BottomLeft, adornedElementRect.BottomRight);

                if (DropEffect == DragDropEffects.None)
                {
                    dc.DrawEllipse(edgeBrush, edgePen, new Point(adornedElementRect.BottomLeft.X, adornedElementRect.BottomLeft.Y), 6, 6);
                    dc.DrawLine(edgePen2, new Point(adornedElementRect.BottomLeft.X - 3, adornedElementRect.BottomLeft.Y), new Point(adornedElementRect.BottomLeft.X + 3, adornedElementRect.BottomLeft.Y));
                }
                else
                {
                    dc.DrawGeometry(edgeBrush, linePen, (Geometry)gc.ConvertFrom("M" + (adornedElementRect.BottomLeft.X).ToStringEnUs() + "," + (adornedElementRect.BottomLeft.Y - 3).ToStringEnUs() + " l0,6 l5,-3 z"));
                }
                break;

            case DropPosition.Left:
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopLeft, renderRadius, renderRadius);
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
                dc.DrawLine(linePen, adornedElementRect.TopLeft, adornedElementRect.BottomLeft);
                break;

            case DropPosition.Right:
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopRight, renderRadius, renderRadius);
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomRight, renderRadius, renderRadius);
                dc.DrawLine(linePen, adornedElementRect.TopRight, adornedElementRect.BottomRight);
                break;

            case DropPosition.BottomLeft:
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
                break;

            case DropPosition.BottomRight:
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomRight, renderRadius, renderRadius);
                break;

            case DropPosition.TopLeft:
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopLeft, renderRadius, renderRadius);
                break;

            case DropPosition.TopRight:
                dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopRight, renderRadius, renderRadius);
                break;

            case DropPosition.Over:

//					dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopLeft, renderRadius, renderRadius);
//					dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.TopRight, renderRadius, renderRadius);
//					dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
//					dc.DrawEllipse(edgeBrush, edgePen, adornedElementRect.BottomRight, renderRadius, renderRadius);
                dc.DrawRectangle(null, linePen, adornedElementRect);

                if (DropEffect == DragDropEffects.None)
                {
//						dc.DrawEllipse(edgeBrush, edgePen, new Point(adornedElementRect.TopLeft.X,adornedElementRect.TopLeft.Y), 6, 6);
//						dc.DrawLine(edgePen2,new Point(adornedElementRect.TopLeft.X-3,adornedElementRect.TopLeft.Y), new Point(adornedElementRect.TopLeft.X+3,adornedElementRect.TopLeft.Y));

//						dc.DrawEllipse(Brushes.White, edgePen, new Point(adornedElementRect.TopLeft.X,adornedElementRect.TopLeft.Y), 6, 6);
//						dc.DrawEllipse(Brushes.White,  new Pen(new SolidColorBrush(Colors.Red), 1.5), new Point(adornedElementRect.TopLeft.X,adornedElementRect.TopLeft.Y), 4, 4);
//						dc.DrawLine(new Pen(new SolidColorBrush(Colors.Red), 1.5),new Point(adornedElementRect.TopLeft.X-3,adornedElementRect.TopLeft.Y-3), new Point(adornedElementRect.TopLeft.X+3,adornedElementRect.TopLeft.Y+3));

                    dc.DrawEllipse(Brushes.White, edgePen, new Point(adornedElementRect.TopLeft.X + 3.5, adornedElementRect.TopLeft.Y + 4), 6, 6);
                    dc.DrawEllipse(Brushes.White, new Pen(new SolidColorBrush(Colors.Red), 1.5), new Point(adornedElementRect.TopLeft.X + 4, adornedElementRect.TopLeft.Y + 4), 4, 4);
                    dc.DrawLine(new Pen(new SolidColorBrush(Colors.Red), 1.5), new Point(adornedElementRect.TopLeft.X + 1, adornedElementRect.TopLeft.Y + 1), new Point(adornedElementRect.TopLeft.X + 7, adornedElementRect.TopLeft.Y + 7));
                }
                break;
            }

//			drawingContext.DrawRectangle(renderBrush,renderPen,adornedElementRect);
        }
Example #6
0
        protected override void OnRender(DrawingContext dc)
        {
//			double width = AdornedElement.DesiredSize.Width;
//			double height = AdornedElement.DesiredSize.Height;

            var adornedElementRect = new Rect(AdornedElement.DesiredSize);

//			var renderBrush = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0));
            var renderPen1 = new Pen(new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)), 1.5);
            var renderPen2 = new Pen(new SolidColorBrush(Color.FromArgb(128, 255, 0, 0)), 2.5);
            var renderPen3 = new Pen(new SolidColorBrush(Color.FromArgb(64, 255, 0, 0)), 3.5);

            if (HasError)
            {
                dc.DrawRectangle(null, renderPen1, adornedElementRect);
                adornedElementRect.Inflate(-2, -2);
                dc.DrawRectangle(null, renderPen2, adornedElementRect);
                adornedElementRect.Inflate(-3, -3);
                dc.DrawRectangle(null, renderPen3, adornedElementRect);

                dc.DrawGeometry(new SolidColorBrush(Colors.Yellow), new Pen(new SolidColorBrush(Colors.Black), 1), (Geometry)GeometryConverter.ConvertFrom("M0,7 L8,7 L4,0z"));
            }
            else
            {
                dc.DrawRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 0, 128, 0)), 1.5), adornedElementRect);
            }

            var textPos   = adornedElementRect.TopLeft; textPos.Offset(8, 0);
            var typeface  = new Typeface(new FontFamily("Sergeo UI"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            var textBrush = Brushes.Black;

            if (!string.IsNullOrWhiteSpace(Text))
            {
                dc.DrawText(new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, 12, textBrush), textPos);
            }
        }
        public void DrawGeometry_Cubic_Besier_Curve()
        {
            UserControl userControl = new UserControl();
            userControl.Width = 320;
            userControl.Height = 180;

            DrawGeometryControl testControl = new DrawGeometryControl();
            GeometryConverter converter = new GeometryConverter();
            testControl.Geometry = (Geometry)converter.ConvertFrom("M 10,100 C 10,300 300,-200 300,100");
            testControl.Brush = new SolidColorBrush(Colors.Gray);
            testControl.Pen = new Pen(new SolidColorBrush(Colors.Black), 1);
            userControl.Content = testControl;

            this.RenderToFile(userControl);
            this.CompareImages();
        }