Esempio 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);
        }
Esempio 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);
        }
Esempio 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();
        }
Esempio n. 4
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);
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        public override void Draw(NVGcontext ctx)
        {
            base.Draw(ctx);

            Theme style = this.theme;

            NVGcolor gradTopColor = style.buttonGradientTopUnfocusedColor;
            NVGcolor gradBotColor = style.buttonGradientBotUnfocusedColor;

            if (this.pushed)
            {
                gradTopColor = style.buttonGradientTopPushedColor;
                gradBotColor = style.buttonGradientBotPushedColor;
            }
            else
            {
                gradTopColor = style.buttonGradientTopFocusedColor;
                gradBotColor = style.buttonGradientBotFocusedColor;
            }

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

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRoundedRect(ctx, pos.X + 1f, pos.Y + 1f, size.X - 2f, size.Y - 2f
                                  , style.buttonCornerRadius - 1f);

            NanoVG.nvgFillColor(ctx, gradTopColor);
            NanoVG.nvgFill(ctx);

            if (0f < this.backgroundColor.a)
            {
                // fill background.
            }

            NVGpaint gradient = NanoVG.nvgLinearGradient(ctx, pos.X, pos.Y, pos.X, pos.Y + size.Y
                                                         , gradTopColor, gradBotColor);

            NanoVG.nvgFillPaint(ctx, gradient);
            NanoVG.nvgFill(ctx);

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgStrokeWidth(ctx, 1f);
            NanoVG.nvgRoundedRect(ctx, pos.X + 0.5f, pos.Y + (this.pushed ? 0.5f : 1.5f)
                                  , size.X - 1f, size.Y - 1 - (this.pushed ? 0f : 1f)
                                  , style.buttonCornerRadius);
            NanoVG.nvgStrokeColor(ctx, style.borderLightColor);
            NanoVG.nvgStroke(ctx);

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRoundedRect(ctx, pos.X + 0.5f, pos.Y + 0.5f
                                  , size.X - 1f, size.Y - 2f
                                  , style.buttonCornerRadius);
            NanoVG.nvgStrokeColor(ctx, style.borderDarkColor);
            NanoVG.nvgStroke(ctx);

            int currFontSize = 0 > this.fontSize ? style.buttonFontSize : this.fontSize;

            NanoVG.nvgFontSize(ctx, currFontSize);
            NanoVG.nvgFontFace(ctx, style.fontBold);

            float    tw            = NanoVG.nvgTextBounds(ctx, 0f, 0f, this.caption, null);
            Vector2  center        = pos + size * 0.5f;
            Vector2  textPos       = new Vector2(center.X - tw * 0.5f, center.Y - 1f);
            NVGcolor currTextColor = GetCurrTextColor();

            int btnIcon = this.icon;

            if (0 != btnIcon)
            {
                float iw, ih;
                iw = 0f;
                ih = currFontSize;
                byte[] icon = Fonts.GetIconUTF8(btnIcon);
                if (NanoVG.nvgIsFontIcon(btnIcon))
                {
                    ih *= 1.5f;
                    NanoVG.nvgFontSize(ctx, ih);
                    NanoVG.nvgFontFace(ctx, style.fontIcons);
                    iw = NanoVG.nvgTextBounds(ctx, 0, 0, icon, null);
                }
                else
                {
                    int w, h;
                    w   = h = 1;
                    ih *= 0.9f;
                    NanoVG.nvgImageSize(ctx, btnIcon, ref w, ref h);
                    if (0 < h)
                    {
                        iw = w * ih / h;
                    }
                }

                if (!string.IsNullOrEmpty(this.caption))
                {
                    iw += size.Y * 0.15f;
                }
                NanoVG.nvgFillColor(ctx, currTextColor);
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE));
                Vector2 iconPos = center;
                iconPos.Y -= 1f;

                switch (this.iconAnchorType)
                {
                case IconAnchorType.LeftCentered:
                {
                    iconPos.X -= (tw + iw) * 0.5f;
                    textPos.X += iw * 0.5f;
                }
                break;

                case IconAnchorType.RightCentered:
                {
                    textPos.X -= iw * 0.5f;
                    iconPos.X += tw * 0.5f;
                }
                break;

                case IconAnchorType.Left:
                {
                    iconPos.X = pos.X + 8f;
                }
                break;

                case IconAnchorType.Right:
                {
                    iconPos.X = pos.X + size.X - iw - 8f;
                }
                break;

                default:
                    break;
                }

                if (NanoVG.nvgIsFontIcon(btnIcon))
                {
                    // NOTE: icon rendering bug, any unicode > 0x10000 not being rendered correctly.
                    //       e.g. 0x1F680 (Font.Entypo.ICON_ROCKET).
                    NanoVG.nvgText(ctx, iconPos.X, iconPos.Y + 1f, icon);
                }
                else
                {
                    float    imgAlpha = this.enabled ? 0.5f : 0.25f;
                    NVGpaint imgPaint = NanoVG.nvgImagePattern(
                        ctx
                        , iconPos.X, iconPos.Y - ih * 0.5f, iw, ih
                        , 0f, btnIcon, imgAlpha);
                    NanoVG.nvgFillPaint(ctx, imgPaint);
                    NanoVG.nvgFill(ctx);
                }

                // DEBUG: ICON BOUNDS
                //NanoVG.nvgStrokeWidth (ctx, 1.0f);
                //NanoVG.nvgBeginPath (ctx);
                //NanoVG.nvgRect (ctx, iconPos.X, iconPos.Y - ih * 0.5f, iw, ih);
                //NanoVG.nvgStrokeColor (ctx, textColor);
                //NanoVG.nvgStroke(ctx);
            }

            NanoVG.nvgFontSize(ctx, currFontSize);
            NanoVG.nvgFontFace(ctx, style.fontBold);
            NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE));
            NanoVG.nvgFillColor(ctx, style.textShadowColor);
            NanoVG.nvgText(ctx, textPos.X, textPos.Y, this.caption);
            NanoVG.nvgFillColor(ctx, currTextColor);
            NanoVG.nvgText(ctx, textPos.X, textPos.Y + 1f, this.caption);
        }
Esempio n. 7
0
 public override void Execute(NVGcontext ctx)
 {
     NanoVG.nvgStrokeColor(ctx, NanoVG.nvgRGBA(R, G, B, A));
 }