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); }
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 Execute(NVGcontext ctx) { NanoVG.nvgBeginPath(ctx); Draw(ctx); if (Fill) { NanoVG.nvgFill(ctx); } else { NanoVG.nvgStroke(ctx); } }
public override void Draw(NVGcontext ctx) { base.Draw(ctx); Theme style = this.theme; Vector2 pos = this.localPosition; Vector2 size = this.size; if (!string.IsNullOrEmpty(this.caption)) { int currFontSize = GetPreferredFontSize(); if (0 < currFontSize) { int currFontFace = Fonts.Get(this.theme.fontNormal); NVGcolor currTextColor = this.enabled ? style.textColor : style.disabledTextColor; NanoVG.nvgFontSize(ctx, currFontSize); NanoVG.nvgFontFace(ctx, currFontFace); NanoVG.nvgFillColor(ctx, currTextColor); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE)); NanoVG.nvgText(ctx, pos.X + size.Y * 1.2f + 5, pos.Y + this.size.Y * 0.5f, this.caption); } } Color4f col = Color4f.Black; Color4f icol = this.pushed ? col.WithAlpha(100) : col.WithAlpha(32); Color4f ocol = col.WithAlpha(180); NVGpaint bg = NanoVG.nvgBoxGradient(ctx, pos.X + 1.5f, pos.Y + 1.5f , size.X - 2f, size.Y - 2f, 3f, 3f , icol.ToNVGColor() , ocol.ToNVGColor()); NanoVG.nvgBeginPath(ctx); NanoVG.nvgRoundedRect(ctx, pos.X + 1f, pos.Y + 1f, size.Y - 2f, size.Y - 2f, 3f); NanoVG.nvgFillPaint(ctx, bg); NanoVG.nvgFill(ctx); if (this.check) { int fontIcons = Fonts.Get(style.fontIcons); NVGcolor iconColor = this.enabled ? style.iconColor : style.disabledTextColor; NanoVG.nvgFontSize(ctx, 1.8f * size.Y); NanoVG.nvgFontFace(ctx, fontIcons); NanoVG.nvgFillColor(ctx, iconColor); NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_CENTER | NVGalign.NVG_ALIGN_MIDDLE)); byte[] icon = Fonts.GetIconUTF8((int)Font.Entypo.ICON_CHECK); NanoVG.nvgText(ctx, pos.X + size.Y * 0.5f + 1f, pos.Y + size.Y * 0.5f, icon); } }
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); }
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); } }
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); }
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(); }
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); }