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(); }