Пример #1
0
        public void Render()
        {
            var picked = Pick(_window.MouseScreenSpace.X, _window.MouseScreenSpace.Y);

            var lineHeight = (int)(_window.FontLineHeight * 1.5f);

            NanoVG.nvgFillColor(MainWindow.Nvg, picked ? Color.LightGray.ToNvgColor() : Color.White.ToNvgColor());
            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRect(MainWindow.Nvg, 0, lineHeight * Index, Parent.Width, lineHeight);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgSave(MainWindow.Nvg);
            NanoVG.nvgFillColor(MainWindow.Nvg, Color.Black.ToNvgColor());
            NanoVG.nvgTranslate(MainWindow.Nvg, 3, lineHeight * Index + 3);
            if (Shortcut == null)
            {
                NvgHelper.RenderString(Text);
            }
            else
            {
                NvgHelper.RenderString($"{Shortcut} {Text}");
                NanoVG.nvgFillColor(MainWindow.Nvg, Color.DarkGray.ToNvgColor());
                NvgHelper.RenderString(Shortcut);
            }

            NanoVG.nvgRestore(MainWindow.Nvg);
        }
Пример #2
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);
        }
Пример #3
0
 public void Render(NVGcontext nvg)
 {
     lock (_commands)
     {
         NanoVG.nvgSave(nvg);
         foreach (var simBody in _commands)
         {
             simBody.Execute(nvg);
         }
         NanoVG.nvgRestore(nvg);
     }
 }
Пример #4
0
        public void RenderConnections(Node node)
        {
            if (!ScreenContains(node))
            {
                return;
            }
            NanoVG.nvgSave(MainWindow.Nvg);
            NanoVG.nvgStrokeColor(MainWindow.Nvg, NanoVG.nvgRGBA(128, 128, 128, 255));

            foreach (var connection in node.Outputs)
            {
                if (connection.ConnectedNode != null)
                {
                    RenderConnection(connection, connection.ConnectedNode);
                }
            }

            NanoVG.nvgRestore(MainWindow.Nvg);
        }
Пример #5
0
        public void Render()
        {
            if (!Visible)
            {
                return;
            }

            NanoVG.nvgSave(MainWindow.Nvg);
            NanoVG.nvgTranslate(MainWindow.Nvg, X, Y);
            foreach (var menuItem in this)
            {
                menuItem.RenderBackground();
            }
            foreach (var menuItem in this)
            {
                menuItem.Render();
            }
            NanoVG.nvgRestore(MainWindow.Nvg);
        }
Пример #6
0
        public void RenderConnection(Connection connection, Vector2 end)
        {
            var bound = connection.GetBounds();
            var pos   = new Vector2(bound.X, bound.Y);
            var v     = new Vector2((pos - end).Length / 4, 0);

            if (pos == end)
            {
                return;
            }
            NanoVG.nvgSave(MainWindow.Nvg);
            NanoVG.nvgLineCap(MainWindow.Nvg, (int)NvgLineCap.Round);
            NanoVG.nvgStrokeColor(MainWindow.Nvg, NanoVG.nvgRGBA(128, 128, 128, 255));
            var ctrl1 = connection.Side == NodeSide.Input ? pos - v : pos + v;
            var ctrl2 = connection.Side == NodeSide.Input ? end + v : end - v;

            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgMoveTo(MainWindow.Nvg, pos.X, pos.Y);
            NanoVG.nvgBezierTo(MainWindow.Nvg, ctrl1.X, ctrl1.Y, ctrl2.X, ctrl2.Y, end.X, end.Y);
            NanoVG.nvgStroke(MainWindow.Nvg);
            NanoVG.nvgRestore(MainWindow.Nvg);
        }
Пример #7
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);
        }
Пример #8
0
        public override void Draw(NVGcontext ctx)
        {
            Theme style = this.theme;
            int   ds    = style.windowDropShadowSize;
            int   cr    = style.windowCornerRadius;
            int   hh    = style.windowHeaderHeight;

            Vector2 pos  = this.localPosition;
            Vector2 size = this.size;

            NanoVG.nvgSave(ctx);
            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr);
            NanoVG.nvgFillColor(ctx, this.mouseFocus ? style.windowFillFocusedColor
                                 : style.windowFillUnfocusedColor);

            NanoVG.nvgFill(ctx);

            NVGpaint shadowPaint = NanoVG.nvgBoxGradient(ctx
                                                         , pos.X, pos.Y, size.X, size.Y
                                                         , cr * 2, ds * 2
                                                         , style.dropShadowColor
                                                         , style.transparentColor);

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRect(ctx, pos.X - ds, pos.Y - ds, size.X + 2 * ds, size.Y + 2 * ds);
            NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr);
            NanoVG.nvgPathWinding(ctx, (int)NVGsolidity.NVG_HOLE);
            NanoVG.nvgFillPaint(ctx, shadowPaint);
            NanoVG.nvgFill(ctx);

            // draw header.
            if (!string.IsNullOrEmpty(this.title))
            {
                NVGpaint headerPaint = NanoVG.nvgLinearGradient(
                    ctx
                    , pos.X, pos.Y, pos.X, pos.Y + hh
                    , style.windowHeaderGradientTopColor
                    , style.windowHeaderGradientBotColor
                    );

                NanoVG.nvgBeginPath(ctx);
                NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, hh, cr);
                NanoVG.nvgFillPaint(ctx, headerPaint);
                NanoVG.nvgFill(ctx);

                NanoVG.nvgBeginPath(ctx);
                NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, hh, cr);
                NanoVG.nvgStrokeColor(ctx, style.windowHeaderSepTopColor);

                NanoVG.nvgSave(ctx);
                NanoVG.nvgIntersectScissor(ctx, pos.X, pos.Y, size.X, 0.5f);
                NanoVG.nvgStroke(ctx);
                NanoVG.nvgResetScissor(ctx);
                NanoVG.nvgRestore(ctx);

                NanoVG.nvgBeginPath(ctx);
                NanoVG.nvgMoveTo(ctx, pos.X + 0.5f, pos.Y + hh - 1.5f);
                NanoVG.nvgLineTo(ctx, pos.X + size.X - 0.5f, pos.Y + hh - 1.5f);
                NanoVG.nvgStrokeColor(ctx, style.windowHeaderSepBotColor);
                NanoVG.nvgStroke(ctx);

                NanoVG.nvgFontSize(ctx, style.standardFontSize + 2f);
                NanoVG.nvgFontFace(ctx, style.fontBold);
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_CENTER | NVGalign.NVG_ALIGN_MIDDLE));

                Vector2 headerTextPos;
                headerTextPos.X = pos.X + size.X * 0.5f;
                headerTextPos.Y = pos.Y + hh * 0.5f;

                NanoVG.nvgFontBlur(ctx, 2f);
                NanoVG.nvgFillColor(ctx, style.dropShadowColor);
                NanoVG.nvgText(ctx, headerTextPos.X, headerTextPos.Y, this.title);

                NanoVG.nvgFontBlur(ctx, 0f);
                NanoVG.nvgFillColor(ctx, this.focused ? style.windowTitleFocusedColor
                                     : style.windowTitleUnfocusedColor);
                NanoVG.nvgText(ctx, headerTextPos.X, headerTextPos.Y - 1f, this.title);
            }

            NanoVG.nvgRestore(ctx);
            base.Draw(ctx);
        }
Пример #9
0
        private void Render(object sender, FrameEventArgs e)
        {
            // Reset the view
            GL.Clear(ClearBufferMask.ColorBufferBit |
                     ClearBufferMask.DepthBufferBit |
                     ClearBufferMask.StencilBufferBit);

            //GL.PushMatrix();
            NanoVG.nvgBeginFrame(Nvg, Width, Height, 1);
            NanoVG.nvgSave(Nvg);
            NanoVG.nvgScale(Nvg, Zoom, Zoom);

            //_grid.Draw();

            NanoVG.nvgTranslate(Nvg, _nodeRenderer.gridOffset.X, _nodeRenderer.gridOffset.Y);
            NanoVG.nvgStrokeWidth(Nvg, 2);

            NanoVG.nvgStrokeColor(Nvg, NanoVG.nvgRGBA(0, 0, 0, 255));

            NanoVG.nvgBeginPath(Nvg);
            NanoVG.nvgMoveTo(Nvg, -_nodeRenderer.gridPitch, 0);
            NanoVG.nvgLineTo(Nvg, _nodeRenderer.gridPitch, 0);
            NanoVG.nvgStroke(Nvg);

            NanoVG.nvgBeginPath(Nvg);
            NanoVG.nvgMoveTo(Nvg, 0, -_nodeRenderer.gridPitch);
            NanoVG.nvgLineTo(Nvg, 0, _nodeRenderer.gridPitch);
            NanoVG.nvgStroke(Nvg);

            const int cxnLineWidth = 3;

            NanoVG.nvgStrokeWidth(Nvg, cxnLineWidth);
            if (Selection.DraggingConnection != null)
            {
                var end = _mouseCanvasSpace;

                if (Selection.CreatingConnectedNode)
                {
                    end = new Vector2(_contextMenu.X, _contextMenu.Y);
                }

                var picked = Selection.HoveringConnection;
                if (picked != null && picked.Side != Selection.DraggingConnection.Side)
                {
                    var b = picked.GetBounds();
                    end = new Vector2(b.X, b.Y);
                }

                _nodeRenderer.RenderConnection(Selection.DraggingConnection, end);
            }

            foreach (var node in Graph)
            {
                _nodeRenderer.RenderConnections(node);
            }

            foreach (var node in Graph)
            {
                _nodeRenderer.RenderNode(node);
            }

            if (Selection.SelectionRectangle != null && Selection.SelectionRectangle.Width != 0 && Selection.SelectionRectangle.Height != 0)
            {
                NanoVG.nvgFillColor(Nvg, _selectionRectangleColor.ToNvgColor());
                NanoVG.nvgBeginPath(Nvg);
                var r = Selection.SelectionRectangle;
                var x = Math.Min(r.X, r.X + r.Width);
                var y = Math.Min(r.Y, r.Y + r.Height);
                var w = Math.Abs(r.Width);
                var h = Math.Abs(r.Height);
                NanoVG.nvgRect(Nvg, x, y, w, h);
                NanoVG.nvgFill(Nvg);
            }
            NanoVG.nvgRestore(Nvg);

            _contextMenu.Render();

            GL.Color4(0, 0, 0, 1f);
            if (Keyboard[Key.D] && Focused && TextBoxHandler.TextBox == null)
            {
                // Static diagnostic header
                NanoVG.nvgSave(Nvg);
                NanoVG.nvgFillColor(Nvg, Color.Black.ToNvgColor());
                NvgHelper.RenderString($"{Zoom}x Zoom");
                NanoVG.nvgTranslate(Nvg, 0, FontLineHeight);
                NvgHelper.RenderString($"{Graph.Count} Nodes");

                // Sparklines
                //                GL.Translate(5, (int)(Height - Font.Common.LineHeight * 1.4f * 2), 0);
                //                _fpsSparkline.Render(Color.Blue, Color.LimeGreen);
                //                GL.Translate(0, (int)(Font.Common.LineHeight * 1.4f), 0);
                //                _renderTimeSparkline.Render(Color.Blue, Color.LimeGreen);
                NanoVG.nvgRestore(Nvg);
            }

            NanoVG.nvgEndFrame(Nvg);
            // Swap the graphics buffer
            SwapBuffers();
        }
Пример #10
0
 public override void Draw(NVGcontext ctx)
 {
     NanoVG.nvgRestore(ctx);
 }