Exemplo n.º 1
0
        public static void FillCanvasWithAllNodes(Canvas c, Graph g)
        {
            c.Background = new SolidColorBrush(new System.Windows.Media.Color()
            {
                A = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).A,
                R = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).R,
                G = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).G,
                B = ((System.Drawing.Color)(Properties.Settings.Default["CanvasBackgroundBrushColour"])).B,
            });
            // Gett All Names and Sizes
            List <string> allNodeNames = g.GetAllNodeNames().ToList();
            List <Point>  sizes        = new List <Point>();

            foreach (string name in allNodeNames)
            {
                sizes.Add(NodeEllipse.GetEllipseWidthAndHeightBasedOnText(name,
                                                                          out _, g.GetNode(name)));
            }
            //allNodeNames.ForEach(x => Sizes.Add(NodeEllipse.GetEllipseWidthAndHeightBasedOnText(x)));

            // Actually Fill the Canvas
            for (int i = 0; i < allNodeNames.Count; i++)
            {
                Node n = g.GetNode(allNodeNames[i]);
                NodeEllipse.AddNodeEllipse(c, g, n, new Point(n.Position.X, n.Position.Y));
            }
            for (int j = 0; j < c.Children.Count; j++)
            {
                if (c.Children[j] is NodeEllipse nodeEllipse)
                {
                    nodeEllipse.InstantiateConnectionLines();
                }
            }
        }
Exemplo n.º 2
0
        private void InstantiateContent(Point p, Brush strokeBrush, Brush textBrush, int minDistanceToText = 10, int zIndex = 3)
        {
            Point Size = NodeEllipse.GetEllipseWidthAndHeightBasedOnText(this._node.Name, minDistanceToText);

            this._measurements = new Rect()
            {
                X      = p.X,
                Y      = p.Y,
                Width  = Size.X,
                Height = Size.Y
            };

            // Creating the Ellipse
            this._ellipse = new Ellipse()
            {
                Fill   = this._canvas.Background,
                Stroke = strokeBrush,
                Width  = this._measurements.Width,
                Height = this._measurements.Height
            };

            // Setting the Ellipse's coordinates
            Canvas.SetLeft(this._ellipse, 0);
            Canvas.SetTop(this._ellipse, 0);
            Canvas.SetZIndex(this._ellipse, zIndex);

            // Creating the TextBlock
            this._textBlock = new TextBlock()
            {
                Text          = this._node.Name,
                TextAlignment = TextAlignment.Center,
                Foreground    = textBrush,
                Width         = Size.X - 2 * minDistanceToText,
                Height        = Size.Y - 2 * minDistanceToText
            };

            //// Applying the appropriate width and height of the TextBlock
            //this._textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            //this._textBlock.Arrange(new Rect(this._textBlock.DesiredSize));


            // Setting the Textblock's coordinates
            Canvas.SetLeft(this._textBlock, 0 + minDistanceToText);
            Canvas.SetTop(this._textBlock, 0 + minDistanceToText);
            Canvas.SetZIndex(this._textBlock, zIndex + 1);

            // Drawing
            this.NodeEllipseCanvas.Children.Add(this._ellipse);
            this.NodeEllipseCanvas.Children.Add(this._textBlock);
        }
Exemplo n.º 3
0
        private void InstantiateContent(Point p, int zIndex = 3)
        {
            Point Size = NodeEllipse.GetEllipseWidthAndHeightBasedOnText(this._node.Name, out int minDistanceToText, this._node);

            this._measurements = new Rect()
            {
                X      = p.X,
                Y      = p.Y,
                Width  = Size.X,
                Height = Size.Y
            };

            // Creating the Ellipse
            this._ellipse = new Ellipse()
            {
                Stroke = new SolidColorBrush(
                    new System.Windows.Media.Color()
                {
                    A = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).A,
                    R = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).R,
                    G = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).G,
                    B = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseStrokeBrushColour"]).B,
                }),
                Fill = new SolidColorBrush(
                    new System.Windows.Media.Color()
                {
                    A = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).A,
                    R = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).R,
                    G = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).G,
                    B = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseFillBrushColour"]).B,
                }),
                Width  = this._measurements.Width,
                Height = this._measurements.Height
            };

            // Setting the Ellipse's coordinates
            Canvas.SetLeft(this._ellipse, 0);
            Canvas.SetTop(this._ellipse, 0);
            Canvas.SetZIndex(this._ellipse, zIndex);

            // Creating the TextBlock
            this._textBlock = new TextBlock()
            {
                Text          = this._node.Name,
                TextAlignment = TextAlignment.Center,
                Foreground    = new SolidColorBrush(
                    new System.Windows.Media.Color()
                {
                    A = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).A,
                    R = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).R,
                    G = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).G,
                    B = ((System.Drawing.Color)Properties.Settings.Default["NodeEllipseTextBrushColour"]).B,
                }),
                Width  = Size.X - 2 * minDistanceToText,
                Height = Size.Y - 2 * minDistanceToText
            };

            //// Applying the appropriate width and height of the TextBlock
            //this._textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            //this._textBlock.Arrange(new Rect(this._textBlock.DesiredSize));


            // Setting the Textblock's coordinates
            Canvas.SetLeft(this._textBlock, minDistanceToText);
            Canvas.SetTop(this._textBlock, minDistanceToText);
            Canvas.SetZIndex(this._textBlock, zIndex + 1);

            // Drawing
            this.NodeEllipseCanvas.Children.Add(this._ellipse);
            this.NodeEllipseCanvas.Children.Add(this._textBlock);
        }