Windows 0.2.22 clean UI-maintenance source delta; no private history or other platform changes

This commit is contained in:
2026-10-13 04:32:04 +00:00
parent 901f27baf5
commit 3ccaea3d52
19 changed files with 393 additions and 74 deletions
+14 -5
View File
@@ -6,7 +6,14 @@ namespace UCVL.VPNPlus;
internal sealed class TrafficChart : Control
{
private readonly Queue<(DateTimeOffset Time, double Up, double Down)> _points = new();
internal TrafficChart() { DoubleBuffered = true; BackColor = Color.White; Font = Brand.Font(7.3f); }
internal TrafficChart()
{
DoubleBuffered = true;
SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.Opaque, false);
BackColor = Color.Transparent;
Font = Brand.Font(7.3f);
}
internal void Add(double up, double down, DateTimeOffset? time = null)
{
var at = time ?? DateTimeOffset.Now;
@@ -27,7 +34,8 @@ internal sealed class TrafficChart : Control
ChartAxis.TimeLabels(e.Graphics, chart.Plot, Font, [end.AddMinutes(-5).ToString("HH:mm"), end.AddMinutes(-2.5).ToString("HH:mm"), end.ToString("HH:mm")]);
if (points.Length == 0)
{
TextRenderer.DrawText(e.Graphics, "等待代理流量采样", Font, Rectangle.Round(chart.Plot), Brand.Muted, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
TextRenderer.DrawText(e.Graphics, "等待代理流量采样", Font, Rectangle.Round(chart.Plot), Brand.Muted,
ChartAxis.PaintFlags | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
return;
}
PointF[] Line(bool up) => points.Select(p => new PointF(
@@ -40,6 +48,7 @@ internal sealed class TrafficChart : Control
internal static class ChartAxis
{
internal const TextFormatFlags PaintFlags = TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping;
internal static (RectangleF Plot, double Maximum) Draw(Graphics g, Rectangle bounds, Font font, int dpi, double peak, bool speed)
{
var scale = dpi / 96f;
@@ -53,13 +62,13 @@ internal static class ChartAxis
var left = Math.Max(31 * scale, TextRenderer.MeasureText(g, maximum.ToString("0.#"), font).Width + 5 * scale);
var plot = new RectangleF(left, fontHeight + 1, Math.Max(1, bounds.Width - left - 9 * scale), Math.Max(1, bounds.Height - fontHeight * 2 - 7 * scale));
g.SmoothingMode = SmoothingMode.AntiAlias;
TextRenderer.DrawText(g, unitName + (speed ? "/s" : ""), font, new Rectangle(0, 0, bounds.Width, fontHeight), Brand.Muted, TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, unitName + (speed ? "/s" : ""), font, new Rectangle(0, 0, bounds.Width, fontHeight), Brand.Muted, PaintFlags | TextFormatFlags.NoPadding);
using var grid = new Pen(Color.FromArgb(218, 230, 245), Math.Max(1, scale * .6f)) { DashStyle = DashStyle.Dash };
for (var i = 0; i <= 2; i++)
{
var y = plot.Bottom - plot.Height * i / 2;
g.DrawLine(grid, plot.Left, y, plot.Right, y);
TextRenderer.DrawText(g, (maximum * i / 2).ToString("0.#"), font, new Rectangle(0, (int)y - fontHeight / 2, (int)left - 4, fontHeight), Brand.Muted, TextFormatFlags.Right | TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, (maximum * i / 2).ToString("0.#"), font, new Rectangle(0, (int)y - fontHeight / 2, (int)left - 4, fontHeight), Brand.Muted, PaintFlags | TextFormatFlags.Right | TextFormatFlags.NoPadding);
}
for (var i = 0; i <= 6; i++)
{
@@ -77,7 +86,7 @@ internal static class ChartAxis
var x = plot.Left + i * plot.Width / Math.Max(1, labels.Length - 1);
// Align edge labels inside the chart rather than cutting their final digits.
var left = i == 0 ? x : i == labels.Length - 1 ? x - width : x - width / 2;
TextRenderer.DrawText(g, labels[i], font, new Point((int)left, (int)plot.Bottom + 3), Brand.Muted, TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, labels[i], font, new Point((int)left, (int)plot.Bottom + 3), Brand.Muted, PaintFlags | TextFormatFlags.NoPadding);
}
}