Example #1
0
        private void RenderNetwork(Network network, Cairo.Context gc)
        {
            lock (network) {
                Rectangle rect       = (Rectangle)network.Properties["rect"];
                SizeD     titleSize  = CalculateNetworkTitleSize(network, gc);
                Hashtable nodegroups = network.Properties["nodegroups"] as Hashtable;

                gc.Save();

                // Draw network box
                gc.Color = networkBG;
                gc.Rectangle(rect);
                gc.Fill();

                // Draw title, 2px/2px offset from top/left corner
                gc.Color = white;
                gc.MoveTo(rect.X + 2, rect.Y + 2 /* + titleSize.Height */);

                Pango.Layout layout = new Pango.Layout(this.PangoContext);
                layout.FontDescription      = this.PangoContext.FontDescription.Copy();
                layout.FontDescription.Size = Pango.Units.FromDouble(NetworkNameFontSize);
                layout.SetText(network.NetworkName);
                Pango.CairoHelper.ShowLayout(gc, layout);

                foreach (NodeGroup ng in nodegroups.Values)
                {
                    RenderNodeGroup(ng, network, gc);
                }

                gc.Restore();

                RenderConnections(network, gc);
            }
        }
Example #2
0
 public NodeGroup(string name, PointD position)
 {
     nodes          = ArrayList.Synchronized(new ArrayList());
     this.name      = name;
     this.position  = position;
     this.dimension = new SizeD(0, 0);
 }
Example #3
0
        private bool Inside(PointD thePoint, PointD rectOrigin, SizeD rectSize)
        {
            bool tl = thePoint.X >= rectOrigin.X && thePoint.Y >= rectOrigin.Y;
            bool br = thePoint.X < rectOrigin.X + rectSize.Width && thePoint.Y < rectOrigin.Y + rectSize.Height;

            return(tl && br);
        }
Example #4
0
 public NodeGroup()
 {
     nodes     = ArrayList.Synchronized(new ArrayList());
     name      = string.Empty;
     position  = new PointD(0, 0);
     dimension = new SizeD(0, 0);
 }
 public NodeGroup(string name, PointD position)
 {
     nodes = ArrayList.Synchronized(new ArrayList());
     this.name = name;
     this.position = position;
     this.dimension = new SizeD(0, 0);
 }
 public NodeGroup()
 {
     nodes = ArrayList.Synchronized(new ArrayList());
     name = string.Empty;
     position = new PointD(0, 0);
     dimension = new SizeD(0, 0);
 }
Example #7
0
        private void CalculateNetworkSize(Network network, Cairo.Context gc)
        {
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }

            if (gc == null)
            {
                throw new ArgumentNullException("gc");
            }

            SizeD titleSize = CalculateNetworkTitleSize(network, gc);

            double networkX      = -1;
            double networkY      = -1;
            double networkWidth  = titleSize.Width;
            double networkHeight = titleSize.Height;

            Hashtable nodegroups = network.Properties["nodegroups"] as Hashtable;

            foreach (NodeGroup ng in nodegroups.Values)
            {
                if (networkX == -1 | networkY == -1)
                {
                    networkX = ng.Position.X - 14;
                    networkY = ng.Position.Y - 14;
                }
                else
                {
                    networkX = Math.Min(networkX, ng.Position.X - 14);
                    networkY = Math.Min(networkY, ng.Position.Y - 14);
                }
            }

            foreach (NodeGroup ng in nodegroups.Values)
            {
                SizeD ngSize = CalculateNodeGroupSize(ng, gc);
                networkWidth  = Math.Max(networkWidth, ngSize.Width + ng.Position.X - networkX);
                networkHeight = Math.Max(networkHeight, ngSize.Height + ng.Position.Y - networkY);
            }

            Rectangle newNetworkRect = new Rectangle(networkX, networkY - titleSize.Height, networkWidth + 14, networkHeight + 14 + titleSize.Height);

            network.Properties["rect"] = newNetworkRect;
        }
Example #8
0
        private void RenderNodeGroup(NodeGroup ng, Network network, Cairo.Context gc)
        {
            gc.Save();

            SizeD size = CalculateNodeGroupSize(ng, gc);

            ng.Dimension = size;
            CreateRoundedRectPath(gc, ng.Position.X, ng.Position.Y, size.Width, size.Height, 20);
            gc.Color = new Cairo.Color(0, 0, 0, 0.5);
            gc.FillPreserve();

            if (selectedGroup == ng)
            {
                gc.Save();
                gc.Color = orangeOverlay;
                gc.StrokePreserve();
                gc.Restore();
            }

            var titleTextSize = CalculateNodeGroupTitleTextSize(ng, gc);
            var titleSize     = new SizeD(size.Width, titleTextSize.Height + (Padding * 2.0));

            gc.Clip();
            gc.Rectangle(ng.Position.X, ng.Position.Y, titleSize.Width, titleSize.Height);
            gc.Fill();
            gc.ResetClip();

            gc.Color = lightGray;

            double hostTextX = ng.Position.X + (titleSize.Width / 2.0) - (titleTextSize.Width / 2.0);
            double hostTextY = ng.Position.Y + (titleSize.Height / 2.0) - (titleTextSize.Height / 2.0);

            gc.MoveTo(hostTextX, hostTextY /* + titleTextSize.Height */);

            Pango.Layout layout = new Pango.Layout(this.PangoContext);
            layout.FontDescription      = this.PangoContext.FontDescription.Copy();
            layout.FontDescription.Size = Pango.Units.FromDouble(NodegroupNameFontSize);
            layout.SetText(ng.Name);
            Pango.CairoHelper.ShowLayout(gc, layout);

            SizeD nodesSize = CalculateNodeGroupSize(ng, gc);

            if (ng.Nodes.Count == 1)
            {
                double positionY = ng.Position.Y + titleSize.Height + Padding;
                double positionX = ng.Position.X + (ng.Dimension.Width / 2.0) - HalfAvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], positionX, positionY);
            }
            else if (ng.Nodes.Count == 2)
            {
                // position them side-by-side, separated by (padding) number of pixels, centered in the
                // space.
                double positionY  = ng.Position.Y + titleSize.Height + Padding;
                double position1X = ng.Position.X + (ng.Dimension.Width / 2.0) - (Padding / 2.0) - AvatarDimension;
                double position2X = position1X + Padding + AvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], position1X, positionY);
                RenderNode(gc, (Node)ng.Nodes[1], position2X, positionY);
            }
            else
            {
                double deg = 0;
                double x   = 0;
                double y   = 0;

                var contentY      = ng.Position.Y + titleSize.Height;
                var contentHeight = size.Height - titleSize.Height;
                var middle        = new System.Drawing.Point(Convert.ToInt32(ng.Position.X + size.Width - (size.Width / 2.0)),
                                                             Convert.ToInt32(contentY + contentHeight - (contentHeight / 2.0)));

                int nodeSize = Convert.ToInt32(AvatarDimension);
                for (int i = 0; i < ng.Nodes.Count; i++)
                {
                    x = Math.Sin(deg) * ((size.Width / 2.0) - (nodeSize)) + middle.X - (nodeSize / 2.0);
                    y = Math.Cos(deg) * ((contentHeight / 2.0) - (nodeSize)) + middle.Y - (nodeSize / 2.0);
                    RenderNode(gc, (Node)ng.Nodes[i], x, y);
                    deg += Math.PI / (ng.Nodes.Count / 2.0);
                }
            }
            gc.Restore();
        }
        private void RenderNodeGroup(NodeGroup ng, Network network, Cairo.Context gc)
        {
            gc.Save();

            SizeD size = CalculateNodeGroupSize(ng, gc);
            ng.Dimension = size;
            CreateRoundedRectPath(gc, ng.Position.X, ng.Position.Y, size.Width, size.Height, 20);
            gc.Color = new Cairo.Color(0, 0, 0, 0.5);
            gc.FillPreserve();

            if (selectedGroup == ng) {
                gc.Save();
                gc.Color = orangeOverlay;
                gc.StrokePreserve();
                gc.Restore();
            }

            var titleTextSize = CalculateNodeGroupTitleTextSize(ng, gc);
            var titleSize = new SizeD(size.Width, titleTextSize.Height + (Padding * 2.0));

            gc.Clip();
            gc.Rectangle(ng.Position.X, ng.Position.Y, titleSize.Width, titleSize.Height);
            gc.Fill();
            gc.ResetClip();

            gc.Color = lightGray;

            double hostTextX = ng.Position.X + (titleSize.Width / 2.0) - (titleTextSize.Width / 2.0);
            double hostTextY = ng.Position.Y + (titleSize.Height / 2.0) - (titleTextSize.Height / 2.0);
            gc.MoveTo(hostTextX, hostTextY /* + titleTextSize.Height */);

            Pango.Layout layout = new Pango.Layout(this.PangoContext);
            layout.FontDescription = this.PangoContext.FontDescription.Copy();
            layout.FontDescription.Size = Pango.Units.FromDouble(NodegroupNameFontSize);
            layout.SetText(ng.Name);
            Pango.CairoHelper.ShowLayout(gc, layout);

            SizeD nodesSize = CalculateNodeGroupSize(ng, gc);

            if (ng.Nodes.Count == 1) {
                double positionY = ng.Position.Y + titleSize.Height + Padding;
                double positionX = ng.Position.X + (ng.Dimension.Width / 2.0) - HalfAvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], positionX, positionY);
            } else if (ng.Nodes.Count == 2) {
                // position them side-by-side, separated by (padding) number of pixels, centered in the
                // space.
                double positionY = ng.Position.Y + titleSize.Height + Padding;
                double position1X = ng.Position.X + (ng.Dimension.Width / 2.0) - (Padding / 2.0) - AvatarDimension;
                double position2X = position1X + Padding + AvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], position1X, positionY);
                RenderNode(gc, (Node)ng.Nodes[1], position2X, positionY);
            } else {
                double deg = 0;
                double x = 0;
                double y = 0;

                var contentY = ng.Position.Y + titleSize.Height;
                var contentHeight = size.Height - titleSize.Height;
                var middle = new System.Drawing.Point(Convert.ToInt32(ng.Position.X + size.Width - (size.Width / 2.0)),
                                                      Convert.ToInt32(contentY + contentHeight - (contentHeight / 2.0)));

                int nodeSize = Convert.ToInt32(AvatarDimension);
                for (int i = 0; i < ng.Nodes.Count; i++) {
                    x = Math.Sin(deg) * ((size.Width / 2.0) - (nodeSize)) + middle.X - (nodeSize / 2.0);
                    y = Math.Cos(deg) * ((contentHeight / 2.0) - (nodeSize)) + middle.Y - (nodeSize / 2.0);
                    RenderNode(gc, (Node)ng.Nodes[i], x, y);
                    deg += Math.PI / (ng.Nodes.Count / 2.0);
                }
            }
            gc.Restore();
        }
Example #10
0
 private bool Inside(PointD thePoint, PointD rectOrigin, SizeD rectSize)
 {
     bool tl = thePoint.X >= rectOrigin.X && thePoint.Y >= rectOrigin.Y;
     bool br = thePoint.X < rectOrigin.X + rectSize.Width && thePoint.Y < rectOrigin.Y + rectSize.Height;
     return tl && br;
 }