Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private void LoadHandler(object sender, EventArgs e)
        {
            // Set up caps
            GL.Disable(EnableCap.DepthTest);
            GL.Enable(EnableCap.RescaleNormal);

            // Set up blending
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            // Set background color
            GL.ClearColor(Color.White);

            // Init keyboard to ensure first frame won't NPE
            _keyboard = Keyboard.GetState();
            _mouse    = Mouse.GetState();

            GlNanoVG.nvgCreateGL(ref _nvg, (int)NvgCreateFlags.AntiAlias | (int)NvgCreateFlags.StencilStrokes);
            NanoVG.nvgStrokeWidth(_nvg, 1);
            NanoVG.nvgStrokeColor(_nvg, NanoVG.nvgRGBA(0, 0, 0, 255));

            _simulator = new Simulator();
        }
Ejemplo n.º 4
0
        public static void RenderGraph(NVGcontext vg, float x, float y)
        {
            int    i;
            float  avg, w, h;
            string str;

            avg = GetGraphAverage();

            w = 200;
            h = 35;

            NanoVG.nvgBeginPath(vg);
            NanoVG.nvgRect(vg, x, y, w, h);
            NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(0, 0, 0, 128));
            NanoVG.nvgFill(vg);

            NanoVG.nvgBeginPath(vg);
            NanoVG.nvgMoveTo(vg, x, y + h);
            if (style == (int)GraphrenderStyle.GRAPH_RENDER_FPS)
            {
                for (i = 0; i < GRAPH_HISTORY_COUNT; i++)
                {
                    float v = 1.0f / (0.00001f + values[(head + i) % GRAPH_HISTORY_COUNT]);
                    float vx, vy;
                    if (v > 80.0f)
                    {
                        v = 80.0f;
                    }
                    vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w;
                    vy = y + h - ((v / 80.0f) * h);
                    NanoVG.nvgLineTo(vg, vx, vy);
                }
            }
            else if (style == (int)GraphrenderStyle.GRAPH_RENDER_PERCENT)
            {
                for (i = 0; i < GRAPH_HISTORY_COUNT; i++)
                {
                    float v = values[(head + i) % GRAPH_HISTORY_COUNT] * 1.0f;
                    float vx, vy;
                    if (v > 100.0f)
                    {
                        v = 100.0f;
                    }
                    vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w;
                    vy = y + h - ((v / 100.0f) * h);
                    NanoVG.nvgLineTo(vg, vx, vy);
                }
            }
            else
            {
                for (i = 0; i < GRAPH_HISTORY_COUNT; i++)
                {
                    float v = values[(head + i) % GRAPH_HISTORY_COUNT] * 1000.0f;
                    float vx, vy;
                    if (v > 20.0f)
                    {
                        v = 20.0f;
                    }
                    vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w;
                    vy = y + h - ((v / 20.0f) * h);
                    NanoVG.nvgLineTo(vg, vx, vy);
                }
            }
            NanoVG.nvgLineTo(vg, x + w, y + h);
            NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(255, 192, 0, 128));
            NanoVG.nvgFill(vg);

            NanoVG.nvgFontFace(vg, "sans");

            if (name[0] != '\0')
            {
                NanoVG.nvgFontSize(vg, 14.0f);
                NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP));
                NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 192));
                NanoVG.nvgText(vg, x + 3, y + 1, name);
            }

            if (style == (int)GraphrenderStyle.GRAPH_RENDER_FPS)
            {
                NanoVG.nvgFontSize(vg, 18.0f);
                NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_TOP));
                NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 255));
                str = String.Format("{0:0.00} FPS", 1.0f / avg);
                NanoVG.nvgText(vg, x + w - 3, y + 1, str);

                NanoVG.nvgFontSize(vg, 15.0f);
                NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_BOTTOM));
                NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 160));
                str = String.Format("{0:0.00} ms", avg * 1000.0f);
                NanoVG.nvgText(vg, x + w - 3, y + h - 1, str);
            }
            else if (style == (int)GraphrenderStyle.GRAPH_RENDER_PERCENT)
            {
                NanoVG.nvgFontSize(vg, 18.0f);
                NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_TOP));
                NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 255));
                str = String.Format("{0:0.0} %", avg * 1.0f);
                NanoVG.nvgText(vg, x + w - 3, y + 1, str);
            }
            else
            {
                NanoVG.nvgFontSize(vg, 18.0f);
                NanoVG.nvgTextAlign(vg, (int)(NVGalign.NVG_ALIGN_RIGHT | NVGalign.NVG_ALIGN_TOP));
                NanoVG.nvgFillColor(vg, NanoVG.nvgRGBA(240, 240, 240, 255));
                str = String.Format("{0:0.00} ms", avg * 1000.0f);
                NanoVG.nvgText(vg, x + w - 3, y + 1, str);
            }
        }
Ejemplo n.º 5
0
 public static NVGcolor ToNvgColor(this Color4 color)
 {
     return(NanoVG.nvgRGBA((byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255), (byte)(color.A * 255)));
 }
Ejemplo n.º 6
0
 public static NVGcolor ToNvgColor(this Color color)
 {
     return(NanoVG.nvgRGBA(color.R, color.G, color.B, color.A));
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
0
 public override void Execute(NVGcontext ctx)
 {
     NanoVG.nvgFillColor(ctx, NanoVG.nvgRGBA(R, G, B, A));
 }