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 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); }
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); }
protected void DrawChildren(NVGcontext ctx) { int childCount = m_Children.Count; if (0 == childCount) { return; } Vector2 pos = this.localPosition; NanoVG.nvgTranslate(ctx, pos.X, pos.Y); for (int i = 0; childCount > i; ++i) { Widget child = m_Children[i]; if (child.isVisible) { child.Draw(ctx); } } NanoVG.nvgTranslate(ctx, -pos.X, -pos.Y); }
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); }
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(); }