コード例 #1
0
        public Connection PickConnectionWithText(float x, float y)
        {
            var pickedNode = Graph.PickNode(x, y);

            if (pickedNode == null)
            {
                return(null);
            }

            foreach (var output in pickedNode.Outputs)
            {
                var s     = NvgHelper.MeasureString(output.Text);
                var bound = output.GetBounds();
                var r     = bound.Radius;
                var twor  = 2 * r;

                var outputRect = new Rectangle(bound.X - twor - s.Width, bound.Y - r, s.Width, s.Height);
                if (!outputRect.Pick(x, y))
                {
                    continue;
                }

                return(output);
            }

            return(null);
        }
コード例 #2
0
        public static void StartEditing(MainWindow window, Connection output)
        {
            var s          = NvgHelper.MeasureString(output.Text);
            var bound      = output.GetBounds();
            var r          = bound.Radius;
            var twor       = 2 * r;
            var outputRect = new Rectangle(bound.X - twor - s.Width - 3, bound.Y - r - 3, s.Width + 6, s.Height + 6);

            if (TextBox != null)
            {
                Destroy();
            }

            EditingConnection = output;
            TextBox           = new TextBox(window, outputRect)
            {
                Text      = output.Text,
                CursorPos = output.Text.Length
            };
            TextBox.Commit += (sender, args) =>
            {
                var finalText = ((TextBox)sender).Text;
                if (string.IsNullOrWhiteSpace(finalText))
                {
                    finalText = "Empty Dialog Option";
                }

                EditingConnection.Text = finalText;
                Destroy(false);
            };
        }
コード例 #3
0
        public static TextBox PickAndCreate(MainWindow window, Graph graph, float x, float y)
        {
            var pickedNode = graph.PickNode(x, y);

            if (TextBox != null && TextBox.BoundingBox.Pick(x, y))
            {
                return(TextBox);
            }

            if (pickedNode == null)
            {
                return(null);
            }

            foreach (var output in pickedNode.Outputs)
            {
                var s     = NvgHelper.MeasureString(output.Text);
                var bound = output.GetBounds();
                var r     = bound.Radius;
                var twor  = 2 * r;

                var outputRect = new Rectangle(bound.X - twor - s.Width, bound.Y - r, s.Width, s.Height);
                if (!outputRect.Pick(x, y) || !output.CanEditName)
                {
                    continue;
                }

                StartEditing(window, output);
                return(TextBox);
            }

            return(null);
        }
コード例 #4
0
        public void RenderNode(Node node)
        {
            if (!ScreenContains(node))
            {
                return;
            }
            const int   borderRadius   = 6;
            const int   panelInset     = 2;
            const float halfPanelInset = panelInset / 2f;

            var headerHeight = (int)(_window.FontLineHeight * 1.2f);

            NanoVG.nvgSave(MainWindow.Nvg);

            if (_window.Selection.SelectedNodes.Contains(node))
            {
                NanoVG.nvgFillColor(MainWindow.Nvg, Color.Black.ToNvgColor());
                NanoVG.nvgBeginPath(MainWindow.Nvg);
                NanoVG.nvgRoundedRect(MainWindow.Nvg, node.X - panelInset - 2, node.Y - 2, node.Width + 2 * (2 + panelInset), node.Height + 4, borderRadius + 2);
                NanoVG.nvgFill(MainWindow.Nvg);
            }

            NanoVG.nvgFillColor(MainWindow.Nvg, _colorMap.ContainsKey(node.NodeInfo) ? _colorMap[node.NodeInfo] : NanoVG.nvgRGBA(0, 0, 0, 255));

            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRoundedRect(MainWindow.Nvg, node.X - panelInset, node.Y, node.Width + 2 * panelInset, node.Height, borderRadius);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.DarkSlateGray.ToNvgColor());
            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRoundedRect(MainWindow.Nvg, node.X, node.Y + headerHeight + panelInset,
                                  node.Width, node.Height - headerHeight - 2 * panelInset,
                                  borderRadius - halfPanelInset);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.White.ToNvgColor());

            NanoVG.nvgSave(MainWindow.Nvg);
            var headerOffset = (headerHeight + panelInset) / 2f - NvgHelper.MeasureString(node.Name).Height / 2;

            NanoVG.nvgTranslate(MainWindow.Nvg, (int)(node.X + 2 * panelInset), (int)(node.Y + headerOffset));
            NvgHelper.RenderString(node.Name);
            NanoVG.nvgRestore(MainWindow.Nvg);

            if (node.Input != null)
            {
                RenderConnector(node.Input);
            }

            foreach (var nodeOutput in node.Outputs)
            {
                RenderConnector(nodeOutput);
            }
            NanoVG.nvgRestore(MainWindow.Nvg);
        }
コード例 #5
0
        public int GetNodeWidth(Node node)
        {
            var       width       = 120;
            const int textPadding = 40;

            width = (int)Math.Max(NvgHelper.MeasureString(node.Name).Width + textPadding, width);

            if (node.Input != null)
            {
                width = (int)Math.Max(NvgHelper.MeasureString(node.Input.Text).Width + textPadding, width);
            }

            foreach (var connection in node.Outputs)
            {
                width = (int)Math.Max(NvgHelper.MeasureString(connection.Text).Width + textPadding, width);
            }

            width = (int)(Math.Ceiling(width / gridPitch) * gridPitch);

            return(width);
        }
コード例 #6
0
        private void RenderConnector(Connection connection)
        {
            NanoVG.nvgSave(MainWindow.Nvg);

            var pickedForDeletion =
                _window.Selection.HoveringConnection == connection && _window.Keyboard[Key.ShiftLeft];
            var       bound          = connection.GetBounds();
            var       r              = bound.Radius;
            var       twor           = 2 * r;
            var       halfr          = r / 2;
            const int cxnBorderWidth = 2;

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.White.ToNvgColor());

            NanoVG.nvgSave(MainWindow.Nvg);
            if (connection != TextBoxHandler.EditingConnection)
            {
                switch (connection.Side)
                {
                case NodeSide.Input:
                    NanoVG.nvgTranslate(MainWindow.Nvg, bound.X + twor, bound.Y - r);
                    NvgHelper.RenderString(connection.Text);
                    break;

                case NodeSide.Output:
                    var s = connection.Text;
                    NanoVG.nvgTranslate(MainWindow.Nvg, bound.X - twor - NvgHelper.MeasureString(s).Width, bound.Y - r);
                    NvgHelper.RenderString(s);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                TextBoxHandler.TextBox.RenderBackground();
                TextBoxHandler.TextBox.RenderForeground();
            }

            NanoVG.nvgRestore(MainWindow.Nvg);

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.DarkSlateGray.ToNvgColor());

            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgCircle(MainWindow.Nvg, bound.X, bound.Y, r + cxnBorderWidth);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgFillColor(MainWindow.Nvg, connection.Side == NodeSide.Input ? Color.DeepSkyBlue.ToNvgColor() : Color.LimeGreen.ToNvgColor());
            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgCircle(MainWindow.Nvg, bound.X, bound.Y, r);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgBeginPath(MainWindow.Nvg);
            if (_window.Selection.HoveringConnection != null && _window.Selection.DraggingConnection == connection &&
                _window.Selection.HoveringConnection.Side != _window.Selection.DraggingConnection.Side)
            {
                NanoVG.nvgFillColor(MainWindow.Nvg, Color.SlateGray.ToNvgColor());
            }
            else if (connection.ConnectedNode != null)
            {
                NanoVG.nvgFillColor(MainWindow.Nvg, Color.DarkSlateGray.ToNvgColor());
            }

            NanoVG.nvgCircle(MainWindow.Nvg, bound.X, bound.Y, halfr);
            NanoVG.nvgFill(MainWindow.Nvg);

            if (pickedForDeletion)
            {
                NanoVG.nvgFillColor(MainWindow.Nvg, Color.Red.ToNvgColor());

                NanoVG.nvgBeginPath(MainWindow.Nvg);
                NanoVG.nvgCircle(MainWindow.Nvg, bound.X, bound.Y, halfr);
                NanoVG.nvgFill(MainWindow.Nvg);
            }

            NanoVG.nvgRestore(MainWindow.Nvg);
        }