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);
        }
        public void RenderBackground()
        {
            var lineHeight = (int)(_window.FontLineHeight * 1.5f);

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.Black.ToNvgColor());
            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRect(MainWindow.Nvg, -1, lineHeight * Index - 1, Parent.Width + 2, lineHeight + 2);
            NanoVG.nvgRect(MainWindow.Nvg, 1, lineHeight * Index + 1, Parent.Width + 1, lineHeight + 1);
            NanoVG.nvgFill(MainWindow.Nvg);
        }
Beispiel #3
0
        public override void Draw(NVGcontext ctx)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRect(ctx, X, Y, Width, Height);
            NanoVG.nvgStroke(ctx);
        }
Beispiel #4
0
        public override void Draw(NVGcontext ctx)
        {
            RefreshRelativePlacement();
            if (!this.isVisible)
            {
                return;
            }

            Vector2 pos   = this.localPosition;
            Vector2 size  = this.size;
            Theme   style = this.theme;

            int ds  = style.windowDropShadowSize;
            int cr  = style.windowCornerRadius;
            int ds2 = 2 * ds;
            int cr2 = 2 * cr;
            int ah  = this.anchorHeight;

            // draw drop shadow.
            NVGpaint shadowPaint = NanoVG.nvgBoxGradient(ctx, pos.X, pos.Y, size.X, size.Y, cr2, ds2
                                                         , style.dropShadowColor
                                                         , style.transparentColor);

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRect(ctx, pos.X - ds, pos.Y - ds, size.X + ds2, size.Y + ds2);
            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 window.
            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr);
            // draw anchor triangle.
            NanoVG.nvgMoveTo(ctx, pos.X - 15, pos.Y + ah);
            NanoVG.nvgLineTo(ctx, pos.X + 1, pos.Y + ah - 15);
            NanoVG.nvgLineTo(ctx, pos.X + 1, pos.Y + ah + 15);

            NanoVG.nvgFillColor(ctx, style.windowPopupColor);
            NanoVG.nvgFill(ctx);

            // draw contents.
            DrawChildren(ctx);
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
        }
        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();
        }