Beispiel #1
0
        private static void drawTitle(Graphics g, Nodes.Node n, ref Rectangle nodeRect)
        {
            //draw title
            g.DrawString(n.getName(), nodeTitleFont, Brushes.Black, nodeRect.X + (nodeRect.Width - System.Windows.Forms.TextRenderer.MeasureText(n.getName(), nodeTitleFont).Width) / 2, nodeRect.Y);
            nodeRect.Y += nodeFont.Height;
            g.DrawLine(Pens.Black, nodeRect.Left, nodeRect.Y, nodeRect.Right, nodeRect.Y);

            //draw extra
            if (n.getExtra() != null && n.getExtra() != "")
            {
                g.DrawString(n.getExtra(), nodeExtraFont, Brushes.Black, nodeRect.Location);
                nodeRect.Y += nodeFont.Height;
                g.DrawLine(Pens.Black, nodeRect.Left, nodeRect.Y, nodeRect.Right, nodeRect.Y);
            }
        }
Beispiel #2
0
        public static Point getJointPos(Nodes.Node n, string port, bool input)
        {
            Rectangle nodeRect = getRect(n);
            Point     result   = nodeRect.Location;

            result.Y += nodeTitleFont.Height;
            if (n.getExtra() != null)
            {
                result.Y += nodeExtraFont.Height;
            }

            foreach (var kvp in n.getProperties())
            {
                if (kvp.Key == port)
                {
                    break;
                }
                if (kvp.Value.isInput || kvp.Value.isOutput)
                {
                    result.Y += nodeFont.Height;
                }
            }
            if (!input)
            {
                result.X += nodeRect.Width;
            }
            result.Y += ballSize / 2;
            return(result);
        }
Beispiel #3
0
        public static Rectangle getRect(Nodes.Node n)
        {
            int       titleWidth = System.Windows.Forms.TextRenderer.MeasureText(n.getName(), nodeTitleFont).Width;
            Rectangle nodeRect   = new Rectangle();

            nodeRect.Location = n.getPos();
            nodeRect.Width    = Math.Max(100, titleWidth);
            nodeRect.Height   = nodeTitleFont.Height;

            //count the lines to cover with text
            if (n.getExtra() != null && n.getExtra() != "")
            {
                nodeRect.Height += nodeExtraFont.Height;
            }
            foreach (var kvp in n.getProperties())
            {
                if (kvp.Value.isInput || kvp.Value.isOutput)
                {
                    nodeRect.Height += nodeFont.Height;
                }
            }
            return(nodeRect);
        }
Beispiel #4
0
        public static string hitJoint(Nodes.Node n, Rectangle rect, int x, int y, bool inputsOnly)
        {
            //assume using a padded rect
            //missed the balls.
            if (x > rect.Left + ballSize && x < rect.Right - ballSize)
            {
                return(null);
            }

            rect.Y += nodeTitleFont.Height;
            if (n.getExtra() != null)
            {
                rect.Y += nodeExtraFont.Height;
            }

            if (y < rect.Y)
            {
                return(null);
            }

            Point pos;

            foreach (var kvp in n.getProperties())
            {
                if ((kvp.Value.isInput && inputsOnly) || (kvp.Value.isOutput && !inputsOnly))
                {
                    pos    = getJointPos(n, kvp.Key, inputsOnly);
                    pos.X -= x; pos.Y -= y;

                    //intentionally dividing by 2 instead of 4 to expand the 'okay' selection radius.
                    if (pos.X * pos.X + pos.Y * pos.Y < ballSize * ballSize / 2)
                    {
                        return(kvp.Key);
                    }
                }
            }

            return(null);
        }