public void Render(float x, float y, Nvg nvg) { float avg = GraphAverage; float w = 200.0f; float h = 35.0f; nvg.BeginPath(); nvg.Rect(x, y, w, h); nvg.FillColour(nvg.Rgba(0, 0, 0, 128)); nvg.Fill(); nvg.BeginPath(); nvg.MoveTo(x, y + h); if (_style == GraphRenderStyle.Fps) { for (uint i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = 1.0f / (0.00001f + _values[(_head + i) % GRAPH_HISTORY_COUNT]); v = MathF.Min(v, 80.0f); float vx = ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w; float vy = y + h - ((v / 80.0f) * h); nvg.LineTo(vx, vy); } } else if (_style == GraphRenderStyle.Percent) { for (uint i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = _values[(_head + i) % GRAPH_HISTORY_COUNT] * 1.0f; v = MathF.Min(v, 100.0f); float vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w; float vy = y + h - ((v / 100.0f) * h); nvg.LineTo(vx, vy); } } else if (_style == GraphRenderStyle.Ms) { for (uint i = 0; i < GRAPH_HISTORY_COUNT; i++) { float v = _values[(_head + i) % GRAPH_HISTORY_COUNT] * 1000.0f; v = MathF.Min(v, 20.0f); float vx = x + ((float)i / (GRAPH_HISTORY_COUNT - 1)) * w; float vy = y + h - ((v / 20.0f) * h); nvg.LineTo(vx, vy); } } nvg.LineTo(x + w, y + h); nvg.FillColour(nvg.Rgba(255, 192, 0, 128)); nvg.Fill(); nvg.FontFace("sans"); if (_name != null) { nvg.FontSize(12.0f); nvg.TextAlign(Align.Left | Align.Top); nvg.FillColour(nvg.Rgba(240, 240, 240, 192)); _ = nvg.Text(x + 3.0f, y + 3.0f, _name); } if (_style == GraphRenderStyle.Fps) { nvg.FontSize(15.0f); nvg.TextAlign(Align.Right | Align.Top); nvg.FillColour(nvg.Rgba(240, 240, 240, 160)); float val = 1.0f / avg; string str = (float.IsInfinity(val) ? "inf" : val) + " FPS"; _ = nvg.Text(x + w - 3.0f, y + 3.0f, str); nvg.FontSize(13.0f); nvg.TextAlign(Align.Right | Align.Baseline); nvg.FillColour(nvg.Rgba(240, 240, 240, 160)); val = avg * 1000.0f; str = val + " ms"; _ = nvg.Text(x + w - 3.0f, y + h - 3.0f, str); } else if (_style == GraphRenderStyle.Percent) { nvg.FontSize(15.0f); nvg.TextAlign(Align.Right | Align.Top); nvg.FillColour(nvg.Rgba(240, 240, 240, 255)); string str = avg * 1.0f + "%"; _ = nvg.Text(x + w - 3.0f, y + 3.0f, str); } else if (_style == GraphRenderStyle.Ms) { nvg.FontSize(15.0f); nvg.TextAlign(Align.Right | Align.Top); nvg.FillColour(nvg.Rgba(240, 240, 240, 255)); string str = avg * 1000.0f + " ms"; _ = nvg.Text(x + w - 3.0f, y + 3.0f, str); } }
private void DrawWindow(string title, float x, float y, float w, float h) { const float cornerRadius = 3.0f; _nvg.Save(); _nvg.BeginPath(); _nvg.RoundedRect(x, y, w, h, cornerRadius); _nvg.FillColour(_nvg.Rgba(28, 30, 34, 192)); _nvg.Fill(); Paint shadowPaint = Paint.BoxGradient(x, y + 2.0f, w, h, cornerRadius * 2.0f, 10.0f, _nvg.Rgba(0, 0, 0, 128), _nvg.Rgba(0, 0, 0, 0)); _nvg.BeginPath(); _nvg.Rect(x - 10.0f, y - 10.0f, w + 20.0f, h + 30.0f); _nvg.RoundedRect(x, y, w, h, cornerRadius); _nvg.PathWinding(Solidity.Hole); _nvg.FillPaint(shadowPaint); _nvg.Fill(); Paint headerPaint = _nvg.LinearGradient(x, y, x, y + 15.0f, _nvg.Rgba(255, 255, 255, 8), _nvg.Rgba(0, 0, 0, 16)); _nvg.BeginPath(); _nvg.RoundedRect(x + 1.0f, y + 1.0f, w - 2.0f, 30.0f, cornerRadius - 1.0f); _nvg.FillPaint(headerPaint); _nvg.Fill(); _nvg.BeginPath(); _nvg.MoveTo(x + 0.5f, y + 0.5f + 30.0f); _nvg.LineTo(x + 0.5f + w - 1.0f, y + 0.5f + 30.0f); _nvg.StrokeColour(_nvg.Rgba(0, 0, 0, 30)); _nvg.Stroke(); _nvg.FontSize(15.0f); _nvg.FontFace("sans-bold"); _nvg.TextAlign(Align.Centre | Align.Middle); _nvg.FontBlur(2.0f); _nvg.FillColour(_nvg.Rgba(0, 0, 0, 128)); _ = _nvg.Text(x + w / 2.0f, y + 16.0f + 1.0f, title); _nvg.FontBlur(0); _nvg.FillColour(_nvg.Rgba(220, 220, 220, 160)); _ = _nvg.Text(x + w / 2.0f, y + 16.0f, title); _nvg.Restore(); }